| 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/longjump.h" |
| 13 #include "vm/object.h" | 13 #include "vm/object.h" |
| 14 #include "vm/object_store.h" | 14 #include "vm/object_store.h" |
| 15 #include "vm/port.h" | 15 #include "vm/port.h" |
| 16 #include "vm/snapshot.h" | 16 #include "vm/snapshot.h" |
| 17 #include "vm/stub_code.h" | 17 #include "vm/stub_code.h" |
| 18 #include "vm/virtual_memory.h" | 18 #include "vm/virtual_memory.h" |
| 19 #include "vm/zone.h" | 19 #include "vm/zone.h" |
| 20 | 20 |
| 21 namespace dart { | 21 namespace dart { |
| 22 | 22 |
| 23 Isolate* Dart::vm_isolate_ = NULL; | 23 Isolate* Dart::vm_isolate_ = NULL; |
| 24 DebugInfo* Dart::pprof_symbol_generator_ = NULL; | 24 DebugInfo* Dart::pprof_symbol_generator_ = NULL; |
| 25 | 25 |
| 26 bool Dart::InitOnce(int argc, const char** argv, | 26 bool Dart::InitOnce(int argc, const char** argv, |
| 27 Dart_IsolateInitCallback callback) { | 27 Dart_IsolateCreateCallback callback) { |
| 28 // TODO(iposva): Fix race condition here. | 28 // TODO(iposva): Fix race condition here. |
| 29 if (vm_isolate_ != NULL) { | 29 if (vm_isolate_ != NULL) { |
| 30 return false; | 30 return false; |
| 31 } | 31 } |
| 32 OS::InitOnce(); | 32 OS::InitOnce(); |
| 33 Flags::ProcessCommandLineFlags(argc, argv); | 33 Flags::ProcessCommandLineFlags(argc, argv); |
| 34 VirtualMemory::InitOnce(); | 34 VirtualMemory::InitOnce(); |
| 35 Isolate::InitOnce(); | 35 Isolate::InitOnce(); |
| 36 PortMap::InitOnce(); | 36 PortMap::InitOnce(); |
| 37 // Create the VM isolate and finish the VM initialization. | 37 // Create the VM isolate and finish the VM initialization. |
| 38 { | 38 { |
| 39 ASSERT(vm_isolate_ == NULL); | 39 ASSERT(vm_isolate_ == NULL); |
| 40 vm_isolate_ = Isolate::Init(); | 40 vm_isolate_ = Isolate::Init(); |
| 41 Zone zone(vm_isolate_); | 41 Zone zone(vm_isolate_); |
| 42 HandleScope handle_scope(vm_isolate_); | 42 HandleScope handle_scope(vm_isolate_); |
| 43 Heap::Init(vm_isolate_); | 43 Heap::Init(vm_isolate_); |
| 44 ObjectStore::Init(vm_isolate_); | 44 ObjectStore::Init(vm_isolate_); |
| 45 Object::InitOnce(); | 45 Object::InitOnce(); |
| 46 StubCode::InitOnce(); | 46 StubCode::InitOnce(); |
| 47 Scanner::InitOnce(); | 47 Scanner::InitOnce(); |
| 48 } | 48 } |
| 49 Isolate::SetCurrent(NULL); // Unregister the VM isolate from this thread. | 49 Isolate::SetCurrent(NULL); // Unregister the VM isolate from this thread. |
| 50 Isolate::SetInitCallback(callback); | 50 Isolate::SetCreateCallback(callback); |
| 51 return true; | 51 return true; |
| 52 } | 52 } |
| 53 | 53 |
| 54 | 54 |
| 55 Isolate* Dart::CreateIsolate() { | 55 Isolate* Dart::CreateIsolate() { |
| 56 // Create and initialize a new isolate. | 56 // Create a new isolate. |
| 57 Isolate* isolate = Isolate::Init(); | 57 Isolate* isolate = Isolate::Init(); |
| 58 ASSERT(isolate != NULL); | 58 ASSERT(isolate != NULL); |
| 59 return isolate; | 59 return isolate; |
| 60 } | 60 } |
| 61 | 61 |
| 62 | 62 |
| 63 void Dart::InitializeIsolate(const Dart_Snapshot* snapshot_buffer, void* data) { | 63 void Dart::InitializeIsolate(const Dart_Snapshot* snapshot_buffer, void* data) { |
| 64 // Initialize the new isolate. | 64 // Initialize the new isolate. |
| 65 Isolate* isolate = Isolate::Current(); | 65 Isolate* isolate = Isolate::Current(); |
| 66 ASSERT(isolate != NULL); | 66 ASSERT(isolate != NULL); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 77 Object::InitFromSnapshot(isolate); | 77 Object::InitFromSnapshot(isolate); |
| 78 const Snapshot* snapshot = Snapshot::SetupFromBuffer(snapshot_buffer); | 78 const Snapshot* snapshot = Snapshot::SetupFromBuffer(snapshot_buffer); |
| 79 SnapshotReader reader(snapshot, | 79 SnapshotReader reader(snapshot, |
| 80 isolate->heap(), | 80 isolate->heap(), |
| 81 isolate->object_store()); | 81 isolate->object_store()); |
| 82 reader.ReadFullSnapshot(); | 82 reader.ReadFullSnapshot(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 StubCode::Init(isolate); | 85 StubCode::Init(isolate); |
| 86 CodeIndexTable::Init(isolate); | 86 CodeIndexTable::Init(isolate); |
| 87 | |
| 88 // Give the embedder a shot at setting up this isolate. | |
| 89 // Isolates spawned from within this isolate will be given the | |
| 90 // callback data returned by the callback. | |
| 91 data = Isolate::InitCallback()(data); | |
| 92 isolate->set_init_callback_data(data); | 87 isolate->set_init_callback_data(data); |
| 93 } | 88 } |
| 94 | 89 |
| 95 | 90 |
| 96 void Dart::ShutdownIsolate() { | 91 void Dart::ShutdownIsolate() { |
| 97 Isolate* isolate = Isolate::Current(); | 92 Isolate* isolate = Isolate::Current(); |
| 98 isolate->Shutdown(); | 93 isolate->Shutdown(); |
| 99 delete isolate; | 94 delete isolate; |
| 100 } | 95 } |
| 101 | 96 |
| 102 } // namespace dart | 97 } // namespace dart |
| OLD | NEW |