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 "include/dart_native_api.h" | 5 #include "include/dart_native_api.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
9 #include "vm/dart_api_message.h" | 9 #include "vm/dart_api_message.h" |
10 #include "vm/dart_api_state.h" | 10 #include "vm/dart_api_state.h" |
11 #include "vm/message.h" | 11 #include "vm/message.h" |
12 #include "vm/native_message_handler.h" | 12 #include "vm/native_message_handler.h" |
13 #include "vm/port.h" | 13 #include "vm/port.h" |
14 #include "vm/precompiler.h" | 14 #include "vm/precompiler.h" |
15 | 15 |
16 namespace dart { | 16 namespace dart { |
17 | 17 |
| 18 DECLARE_FLAG(bool, load_deferred_eagerly); |
| 19 |
18 // --- Message sending/receiving from native code --- | 20 // --- Message sending/receiving from native code --- |
19 | 21 |
20 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 22 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
21 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 23 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
22 return reinterpret_cast<uint8_t*>(new_ptr); | 24 return reinterpret_cast<uint8_t*>(new_ptr); |
23 } | 25 } |
24 | 26 |
25 | 27 |
26 DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message) { | 28 DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message) { |
27 uint8_t* buffer = NULL; | 29 uint8_t* buffer = NULL; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 DARTSCOPE(isolate); | 98 DARTSCOPE(isolate); |
97 Dart_Handle result = Api::CheckAndFinalizePendingClasses(isolate); | 99 Dart_Handle result = Api::CheckAndFinalizePendingClasses(isolate); |
98 if (::Dart_IsError(result)) { | 100 if (::Dart_IsError(result)) { |
99 return result; | 101 return result; |
100 } | 102 } |
101 CHECK_CALLBACK_STATE(isolate); | 103 CHECK_CALLBACK_STATE(isolate); |
102 CompileAll(isolate, &result); | 104 CompileAll(isolate, &result); |
103 return result; | 105 return result; |
104 } | 106 } |
105 | 107 |
| 108 static uint8_t* ApiReallocate(uint8_t* ptr, |
| 109 intptr_t old_size, |
| 110 intptr_t new_size) { |
| 111 return Api::TopScope(Isolate::Current())->zone()->Realloc<uint8_t>( |
| 112 ptr, old_size, new_size); |
| 113 } |
106 | 114 |
107 DART_EXPORT Dart_Handle Dart_Precompile() { | 115 DART_EXPORT Dart_Handle Dart_Precompile() { |
108 Isolate* isolate = Isolate::Current(); | 116 Isolate* isolate = Isolate::Current(); |
109 DARTSCOPE(isolate); | 117 DARTSCOPE(isolate); |
110 Dart_Handle result = Api::CheckAndFinalizePendingClasses(isolate); | 118 Dart_Handle result = Api::CheckAndFinalizePendingClasses(isolate); |
111 if (::Dart_IsError(result)) { | 119 if (::Dart_IsError(result)) { |
112 return result; | 120 return result; |
113 } | 121 } |
114 CHECK_CALLBACK_STATE(isolate); | 122 CHECK_CALLBACK_STATE(isolate); |
115 Precompile(isolate, &result); | 123 Precompile(isolate, &result); |
116 return result; | 124 return result; |
117 } | 125 } |
118 | 126 |
| 127 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshot( |
| 128 uint8_t** vm_isolate_snapshot_buffer, |
| 129 intptr_t* vm_isolate_snapshot_size, |
| 130 uint8_t** isolate_snapshot_buffer, |
| 131 intptr_t* isolate_snapshot_size, |
| 132 uint8_t** instructions_snapshot_buffer, |
| 133 intptr_t* instructions_snapshot_size) { |
| 134 ASSERT(FLAG_load_deferred_eagerly); |
| 135 Thread* thread = Thread::Current(); |
| 136 Isolate* isolate = thread->isolate(); |
| 137 DARTSCOPE(isolate); |
| 138 if (vm_isolate_snapshot_buffer != NULL && |
| 139 vm_isolate_snapshot_size == NULL) { |
| 140 RETURN_NULL_ERROR(vm_isolate_snapshot_size); |
| 141 } |
| 142 if (isolate_snapshot_buffer == NULL) { |
| 143 RETURN_NULL_ERROR(isolate_snapshot_buffer); |
| 144 } |
| 145 if (isolate_snapshot_size == NULL) { |
| 146 RETURN_NULL_ERROR(isolate_snapshot_size); |
| 147 } |
| 148 if (instructions_snapshot_buffer == NULL) { |
| 149 RETURN_NULL_ERROR(instructions_snapshot_buffer); |
| 150 } |
| 151 if (instructions_snapshot_size == NULL) { |
| 152 RETURN_NULL_ERROR(instructions_snapshot_size); |
| 153 } |
| 154 // Finalize all classes if needed. |
| 155 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate); |
| 156 if (::Dart_IsError(state)) { |
| 157 return state; |
| 158 } |
| 159 isolate->heap()->CollectAllGarbage(); |
| 160 PrecompiledSnapshotWriter writer(vm_isolate_snapshot_buffer, |
| 161 isolate_snapshot_buffer, |
| 162 instructions_snapshot_buffer, |
| 163 ApiReallocate); |
| 164 writer.WriteFullSnapshot(); |
| 165 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
| 166 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
| 167 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); |
| 168 |
| 169 return Api::Success(); |
| 170 } |
| 171 |
119 } // namespace dart | 172 } // namespace dart |
OLD | NEW |