| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/dart.h" | 5 #include "vm/dart.h" |
| 6 | 6 |
| 7 #include "vm/code_index_table.h" | 7 #include "vm/code_index_table.h" |
| 8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
| 9 #include "vm/handles.h" | 9 #include "vm/handles.h" |
| 10 #include "vm/heap.h" | 10 #include "vm/heap.h" |
| 11 #include "vm/isolate.h" | 11 #include "vm/isolate.h" |
| 12 #include "vm/longjump.h" |
| 12 #include "vm/object.h" | 13 #include "vm/object.h" |
| 13 #include "vm/object_store.h" | 14 #include "vm/object_store.h" |
| 14 #include "vm/port.h" | 15 #include "vm/port.h" |
| 15 #include "vm/snapshot.h" | 16 #include "vm/snapshot.h" |
| 16 #include "vm/stub_code.h" | 17 #include "vm/stub_code.h" |
| 17 #include "vm/virtual_memory.h" | 18 #include "vm/virtual_memory.h" |
| 18 #include "vm/zone.h" | 19 #include "vm/zone.h" |
| 19 | 20 |
| 20 namespace dart { | 21 namespace dart { |
| 21 | 22 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 44 StubCode::InitOnce(); | 45 StubCode::InitOnce(); |
| 45 PortMap::InitOnce(); | 46 PortMap::InitOnce(); |
| 46 Scanner::InitOnce(); | 47 Scanner::InitOnce(); |
| 47 } | 48 } |
| 48 Isolate::SetCurrent(NULL); // Unregister the VM isolate from this thread. | 49 Isolate::SetCurrent(NULL); // Unregister the VM isolate from this thread. |
| 49 Isolate::SetInitCallback(callback); | 50 Isolate::SetInitCallback(callback); |
| 50 return true; | 51 return true; |
| 51 } | 52 } |
| 52 | 53 |
| 53 | 54 |
| 54 Isolate* Dart::CreateIsolate(const Dart_Snapshot* snapshot_buffer, | 55 Isolate* Dart::CreateIsolate() { |
| 55 void* data) { | |
| 56 // Create and initialize a new isolate. | 56 // Create and initialize a new isolate. |
| 57 Isolate* isolate = Isolate::Init(); | 57 Isolate* isolate = Isolate::Init(); |
| 58 ASSERT(isolate != NULL); |
| 59 return isolate; |
| 60 } |
| 61 |
| 62 |
| 63 void Dart::InitializeIsolate(const Dart_Snapshot* snapshot_buffer, void* data) { |
| 64 // Initialize the new isolate. |
| 65 Isolate* isolate = Isolate::Current(); |
| 66 ASSERT(isolate != NULL); |
| 58 Zone zone; | 67 Zone zone; |
| 59 HandleScope handle_scope; | 68 HandleScope handle_scope; |
| 60 Heap::Init(isolate); | 69 Heap::Init(isolate); |
| 61 ObjectStore::Init(isolate); | 70 ObjectStore::Init(isolate); |
| 62 | 71 |
| 63 if (snapshot_buffer == NULL) { | 72 if (snapshot_buffer == NULL) { |
| 64 Object::Init(isolate); | 73 Object::Init(isolate); |
| 65 } else { | 74 } else { |
| 66 // Initialize from snapshot (this should replicate the functionality | 75 // Initialize from snapshot (this should replicate the functionality |
| 67 // of Object::Init(..) in a regular isolate creation path. | 76 // of Object::Init(..) in a regular isolate creation path. |
| 68 Object::InitFromSnapshot(isolate); | 77 Object::InitFromSnapshot(isolate); |
| 69 const Snapshot* snapshot = Snapshot::SetupFromBuffer(snapshot_buffer); | 78 const Snapshot* snapshot = Snapshot::SetupFromBuffer(snapshot_buffer); |
| 70 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store()); | 79 SnapshotReader reader(snapshot, |
| 80 isolate->heap(), |
| 81 isolate->object_store()); |
| 71 reader.ReadFullSnapshot(); | 82 reader.ReadFullSnapshot(); |
| 72 } | 83 } |
| 73 | 84 |
| 74 StubCode::Init(isolate); | 85 StubCode::Init(isolate); |
| 75 CodeIndexTable::Init(isolate); | 86 CodeIndexTable::Init(isolate); |
| 76 | 87 |
| 77 // Give the embedder a shot at setting up this isolate. | 88 // Give the embedder a shot at setting up this isolate. |
| 78 // Isolates spawned from within this isolate will be given the callback data | 89 // Isolates spawned from within this isolate will be given the |
| 79 // returned by the callback. | 90 // callback data returned by the callback. |
| 80 data = Isolate::InitCallback()(data); | 91 data = Isolate::InitCallback()(data); |
| 81 // TODO(iposva): Shutdown the isolate on failure. | |
| 82 isolate->set_init_callback_data(data); | 92 isolate->set_init_callback_data(data); |
| 83 return isolate; | |
| 84 } | 93 } |
| 85 | 94 |
| 86 | 95 |
| 87 void Dart::ShutdownIsolate() { | 96 void Dart::ShutdownIsolate() { |
| 88 Isolate* isolate = Isolate::Current(); | 97 Isolate* isolate = Isolate::Current(); |
| 89 isolate->Shutdown(); | 98 isolate->Shutdown(); |
| 90 delete isolate; | 99 delete isolate; |
| 91 } | 100 } |
| 92 | 101 |
| 93 } // namespace dart | 102 } // namespace dart |
| OLD | NEW |