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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 DARTSCOPE(Thread::Current()); | 97 DARTSCOPE(Thread::Current()); |
96 Dart_Handle result = Api::CheckAndFinalizePendingClasses(I); | 98 Dart_Handle result = Api::CheckAndFinalizePendingClasses(I); |
97 if (::Dart_IsError(result)) { | 99 if (::Dart_IsError(result)) { |
98 return result; | 100 return result; |
99 } | 101 } |
100 CHECK_CALLBACK_STATE(I); | 102 CHECK_CALLBACK_STATE(I); |
101 CompileAll(I, &result); | 103 CompileAll(I, &result); |
102 return result; | 104 return result; |
103 } | 105 } |
104 | 106 |
| 107 static uint8_t* ApiReallocate(uint8_t* ptr, |
| 108 intptr_t old_size, |
| 109 intptr_t new_size) { |
| 110 return Api::TopScope(Isolate::Current())->zone()->Realloc<uint8_t>( |
| 111 ptr, old_size, new_size); |
| 112 } |
105 | 113 |
106 DART_EXPORT Dart_Handle Dart_Precompile() { | 114 DART_EXPORT Dart_Handle Dart_Precompile() { |
107 DARTSCOPE(Thread::Current()); | 115 DARTSCOPE(Thread::Current()); |
108 Dart_Handle result = Api::CheckAndFinalizePendingClasses(I); | 116 Dart_Handle result = Api::CheckAndFinalizePendingClasses(I); |
109 if (::Dart_IsError(result)) { | 117 if (::Dart_IsError(result)) { |
110 return result; | 118 return result; |
111 } | 119 } |
112 CHECK_CALLBACK_STATE(I); | 120 CHECK_CALLBACK_STATE(I); |
113 Precompile(I, &result); | 121 Precompile(I, &result); |
114 return result; | 122 return result; |
115 } | 123 } |
116 | 124 |
| 125 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshot( |
| 126 uint8_t** vm_isolate_snapshot_buffer, |
| 127 intptr_t* vm_isolate_snapshot_size, |
| 128 uint8_t** isolate_snapshot_buffer, |
| 129 intptr_t* isolate_snapshot_size, |
| 130 uint8_t** instructions_snapshot_buffer, |
| 131 intptr_t* instructions_snapshot_size) { |
| 132 ASSERT(FLAG_load_deferred_eagerly); |
| 133 DARTSCOPE(Thread::Current()); |
| 134 if (vm_isolate_snapshot_buffer == NULL) { |
| 135 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); |
| 136 } |
| 137 if (vm_isolate_snapshot_size == NULL) { |
| 138 RETURN_NULL_ERROR(vm_isolate_snapshot_size); |
| 139 } |
| 140 if (isolate_snapshot_buffer == NULL) { |
| 141 RETURN_NULL_ERROR(isolate_snapshot_buffer); |
| 142 } |
| 143 if (isolate_snapshot_size == NULL) { |
| 144 RETURN_NULL_ERROR(isolate_snapshot_size); |
| 145 } |
| 146 if (instructions_snapshot_buffer == NULL) { |
| 147 RETURN_NULL_ERROR(instructions_snapshot_buffer); |
| 148 } |
| 149 if (instructions_snapshot_size == NULL) { |
| 150 RETURN_NULL_ERROR(instructions_snapshot_size); |
| 151 } |
| 152 // Finalize all classes if needed. |
| 153 Dart_Handle state = Api::CheckAndFinalizePendingClasses(I); |
| 154 if (::Dart_IsError(state)) { |
| 155 return state; |
| 156 } |
| 157 I->heap()->CollectAllGarbage(); |
| 158 PrecompiledSnapshotWriter writer(vm_isolate_snapshot_buffer, |
| 159 isolate_snapshot_buffer, |
| 160 instructions_snapshot_buffer, |
| 161 ApiReallocate); |
| 162 writer.WriteFullSnapshot(); |
| 163 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
| 164 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
| 165 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); |
| 166 |
| 167 return Api::Success(); |
| 168 } |
| 169 |
117 } // namespace dart | 170 } // namespace dart |
OLD | NEW |