OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/service.h" | 5 #include "vm/service.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 | 8 |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/coverage.h" | 10 #include "vm/coverage.h" |
11 #include "vm/cpu.h" | 11 #include "vm/cpu.h" |
12 #include "vm/dart_api_impl.h" | 12 #include "vm/dart_api_impl.h" |
13 #include "vm/dart_entry.h" | 13 #include "vm/dart_entry.h" |
14 #include "vm/debugger.h" | 14 #include "vm/debugger.h" |
15 #include "vm/isolate.h" | 15 #include "vm/isolate.h" |
16 #include "vm/message.h" | 16 #include "vm/message.h" |
| 17 #include "vm/message_handler.h" |
17 #include "vm/native_entry.h" | 18 #include "vm/native_entry.h" |
18 #include "vm/native_arguments.h" | 19 #include "vm/native_arguments.h" |
19 #include "vm/object.h" | 20 #include "vm/object.h" |
20 #include "vm/object_id_ring.h" | 21 #include "vm/object_id_ring.h" |
21 #include "vm/object_store.h" | 22 #include "vm/object_store.h" |
22 #include "vm/port.h" | 23 #include "vm/port.h" |
23 #include "vm/profiler.h" | 24 #include "vm/profiler.h" |
24 #include "vm/stack_frame.h" | 25 #include "vm/stack_frame.h" |
25 #include "vm/symbols.h" | 26 #include "vm/symbols.h" |
26 | 27 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 if (create_callback == NULL) { | 257 if (create_callback == NULL) { |
257 return NULL; | 258 return NULL; |
258 } | 259 } |
259 Isolate::SetCurrent(NULL); | 260 Isolate::SetCurrent(NULL); |
260 char* error = NULL; | 261 char* error = NULL; |
261 Isolate* isolate = reinterpret_cast<Isolate*>( | 262 Isolate* isolate = reinterpret_cast<Isolate*>( |
262 create_callback(callback_data, &error)); | 263 create_callback(callback_data, &error)); |
263 if (isolate == NULL) { | 264 if (isolate == NULL) { |
264 return NULL; | 265 return NULL; |
265 } | 266 } |
| 267 // We don't want to pause the service isolate. |
| 268 isolate->message_handler()->set_pause_on_start(false); |
| 269 isolate->message_handler()->set_pause_on_exit(false); |
266 Isolate::SetCurrent(isolate); | 270 Isolate::SetCurrent(isolate); |
267 { | 271 { |
268 // Install the dart:vmservice library. | 272 // Install the dart:vmservice library. |
269 StackZone zone(isolate); | 273 StackZone zone(isolate); |
270 HANDLESCOPE(isolate); | 274 HANDLESCOPE(isolate); |
271 Library& library = | 275 Library& library = |
272 Library::Handle(isolate, isolate->object_store()->root_library()); | 276 Library::Handle(isolate, isolate->object_store()->root_library()); |
273 // Isolate is empty. | 277 // Isolate is empty. |
274 ASSERT(library.IsNull()); | 278 ASSERT(library.IsNull()); |
275 // Grab embedder tag handler. | 279 // Grab embedder tag handler. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 ASSERT(!name.IsNull()); | 363 ASSERT(!name.IsNull()); |
360 const Array& list = Array::Handle( | 364 const Array& list = Array::Handle( |
361 MakeServiceControlMessage(Dart_GetMainPortId(), | 365 MakeServiceControlMessage(Dart_GetMainPortId(), |
362 VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID, | 366 VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID, |
363 name)); | 367 name)); |
364 ASSERT(!list.IsNull()); | 368 ASSERT(!list.IsNull()); |
365 uint8_t* data = NULL; | 369 uint8_t* data = NULL; |
366 MessageWriter writer(&data, &allocator); | 370 MessageWriter writer(&data, &allocator); |
367 writer.WriteMessage(list); | 371 writer.WriteMessage(list); |
368 intptr_t len = writer.BytesWritten(); | 372 intptr_t len = writer.BytesWritten(); |
| 373 if (FLAG_trace_service) { |
| 374 OS::Print("Isolate %s %" Pd64 " registered with service \n", |
| 375 name.ToCString(), |
| 376 Dart_GetMainPortId()); |
| 377 } |
369 return PortMap::PostMessage( | 378 return PortMap::PostMessage( |
370 new Message(port_, data, len, Message::kNormalPriority)); | 379 new Message(port_, data, len, Message::kNormalPriority)); |
371 } | 380 } |
372 | 381 |
373 | 382 |
374 bool Service::SendIsolateShutdownMessage() { | 383 bool Service::SendIsolateShutdownMessage() { |
375 if (!IsRunning()) { | 384 if (!IsRunning()) { |
376 return false; | 385 return false; |
377 } | 386 } |
378 Isolate* isolate = Isolate::Current(); | 387 Isolate* isolate = Isolate::Current(); |
379 ASSERT(isolate != NULL); | 388 ASSERT(isolate != NULL); |
380 HANDLESCOPE(isolate); | 389 HANDLESCOPE(isolate); |
| 390 const String& name = String::Handle(String::New(isolate->name())); |
| 391 ASSERT(!name.IsNull()); |
381 const Array& list = Array::Handle( | 392 const Array& list = Array::Handle( |
382 MakeServiceControlMessage(Dart_GetMainPortId(), | 393 MakeServiceControlMessage(Dart_GetMainPortId(), |
383 VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID, | 394 VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID, |
384 String::Handle(String::null()))); | 395 name)); |
385 ASSERT(!list.IsNull()); | 396 ASSERT(!list.IsNull()); |
386 uint8_t* data = NULL; | 397 uint8_t* data = NULL; |
387 MessageWriter writer(&data, &allocator); | 398 MessageWriter writer(&data, &allocator); |
388 writer.WriteMessage(list); | 399 writer.WriteMessage(list); |
389 intptr_t len = writer.BytesWritten(); | 400 intptr_t len = writer.BytesWritten(); |
| 401 if (FLAG_trace_service) { |
| 402 OS::Print("Isolate %s %" Pd64 " deregistered with service \n", |
| 403 name.ToCString(), |
| 404 Dart_GetMainPortId()); |
| 405 } |
390 return PortMap::PostMessage( | 406 return PortMap::PostMessage( |
391 new Message(port_, data, len, Message::kNormalPriority)); | 407 new Message(port_, data, len, Message::kNormalPriority)); |
392 } | 408 } |
393 | 409 |
394 | 410 |
395 bool Service::IsRunning() { | 411 bool Service::IsRunning() { |
396 return port_ != ILLEGAL_PORT; | 412 return port_ != ILLEGAL_PORT; |
397 } | 413 } |
398 | 414 |
399 | 415 |
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 } | 1423 } |
1408 if (js->num_arguments() != 1) { | 1424 if (js->num_arguments() != 1) { |
1409 PrintError(js, "Command too long"); | 1425 PrintError(js, "Command too long"); |
1410 return true; | 1426 return true; |
1411 } | 1427 } |
1412 isolate->class_table()->AllocationProfilePrintToJSONStream(js); | 1428 isolate->class_table()->AllocationProfilePrintToJSONStream(js); |
1413 return true; | 1429 return true; |
1414 } | 1430 } |
1415 | 1431 |
1416 | 1432 |
1417 static bool HandleUnpin(Isolate* isolate, JSONStream* js) { | 1433 static bool HandleResume(Isolate* isolate, JSONStream* js) { |
1418 // TODO(johnmccutchan): What do I respond with?? | 1434 // TODO(johnmccutchan): What do I respond with?? |
1419 isolate->ClosePinPort(); | 1435 if (isolate->message_handler()->pause_on_start()) { |
| 1436 isolate->message_handler()->set_pause_on_start(false); |
| 1437 return true; |
| 1438 } |
| 1439 if (isolate->message_handler()->pause_on_exit()) { |
| 1440 isolate->message_handler()->set_pause_on_exit(false); |
| 1441 return true; |
| 1442 } |
1420 return true; | 1443 return true; |
1421 } | 1444 } |
1422 | 1445 |
1423 | 1446 |
1424 static bool HandleHeapMap(Isolate* isolate, JSONStream* js) { | 1447 static bool HandleHeapMap(Isolate* isolate, JSONStream* js) { |
1425 isolate->heap()->PrintHeapMapToJSONStream(js); | 1448 isolate->heap()->PrintHeapMapToJSONStream(js); |
1426 return true; | 1449 return true; |
1427 } | 1450 } |
1428 | 1451 |
1429 | 1452 |
1430 static IsolateMessageHandlerEntry isolate_handlers[] = { | 1453 static IsolateMessageHandlerEntry isolate_handlers[] = { |
1431 { "_echo", HandleIsolateEcho }, | 1454 { "_echo", HandleIsolateEcho }, |
1432 { "", HandleIsolate }, | 1455 { "", HandleIsolate }, |
1433 { "allocationprofile", HandleAllocationProfile }, | 1456 { "allocationprofile", HandleAllocationProfile }, |
1434 { "classes", HandleClasses }, | 1457 { "classes", HandleClasses }, |
1435 { "code", HandleCode }, | 1458 { "code", HandleCode }, |
1436 { "coverage", HandleCoverage }, | 1459 { "coverage", HandleCoverage }, |
1437 { "cpu", HandleCpu }, | 1460 { "cpu", HandleCpu }, |
1438 { "debug", HandleDebug }, | 1461 { "debug", HandleDebug }, |
1439 { "heapmap", HandleHeapMap }, | 1462 { "heapmap", HandleHeapMap }, |
1440 { "libraries", HandleLibraries }, | 1463 { "libraries", HandleLibraries }, |
1441 { "objects", HandleObjects }, | 1464 { "objects", HandleObjects }, |
1442 { "profile", HandleProfile }, | 1465 { "profile", HandleProfile }, |
1443 { "unpin", HandleUnpin }, | 1466 { "resume", HandleResume }, |
1444 { "scripts", HandleScripts }, | 1467 { "scripts", HandleScripts }, |
1445 { "stacktrace", HandleStackTrace }, | 1468 { "stacktrace", HandleStackTrace }, |
1446 }; | 1469 }; |
1447 | 1470 |
1448 | 1471 |
1449 static IsolateMessageHandler FindIsolateMessageHandler(const char* command) { | 1472 static IsolateMessageHandler FindIsolateMessageHandler(const char* command) { |
1450 intptr_t num_message_handlers = sizeof(isolate_handlers) / | 1473 intptr_t num_message_handlers = sizeof(isolate_handlers) / |
1451 sizeof(isolate_handlers[0]); | 1474 sizeof(isolate_handlers[0]); |
1452 for (intptr_t i = 0; i < num_message_handlers; i++) { | 1475 for (intptr_t i = 0; i < num_message_handlers; i++) { |
1453 const IsolateMessageHandlerEntry& entry = isolate_handlers[i]; | 1476 const IsolateMessageHandlerEntry& entry = isolate_handlers[i]; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1655 while (current != NULL) { | 1678 while (current != NULL) { |
1656 if (strcmp(name, current->name()) == 0) { | 1679 if (strcmp(name, current->name()) == 0) { |
1657 return current; | 1680 return current; |
1658 } | 1681 } |
1659 current = current->next(); | 1682 current = current->next(); |
1660 } | 1683 } |
1661 return NULL; | 1684 return NULL; |
1662 } | 1685 } |
1663 | 1686 |
1664 } // namespace dart | 1687 } // namespace dart |
OLD | NEW |