| 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_api.h" | 5 #include "include/dart_api.h" |
| 6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
| 7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
| 8 | 8 |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "lib/stacktrace.h" | 10 #include "lib/stacktrace.h" |
| (...skipping 1445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1456 return Api::TopScope(Thread::Current())->zone()->Realloc<uint8_t>( | 1456 return Api::TopScope(Thread::Current())->zone()->Realloc<uint8_t>( |
| 1457 ptr, old_size, new_size); | 1457 ptr, old_size, new_size); |
| 1458 } | 1458 } |
| 1459 | 1459 |
| 1460 | 1460 |
| 1461 DART_EXPORT Dart_Handle Dart_CreateSnapshot( | 1461 DART_EXPORT Dart_Handle Dart_CreateSnapshot( |
| 1462 uint8_t** vm_isolate_snapshot_buffer, | 1462 uint8_t** vm_isolate_snapshot_buffer, |
| 1463 intptr_t* vm_isolate_snapshot_size, | 1463 intptr_t* vm_isolate_snapshot_size, |
| 1464 uint8_t** isolate_snapshot_buffer, | 1464 uint8_t** isolate_snapshot_buffer, |
| 1465 intptr_t* isolate_snapshot_size) { | 1465 intptr_t* isolate_snapshot_size) { |
| 1466 ASSERT(FLAG_load_deferred_eagerly); | |
| 1467 DARTSCOPE(Thread::Current()); | 1466 DARTSCOPE(Thread::Current()); |
| 1468 API_TIMELINE_DURATION; | 1467 API_TIMELINE_DURATION; |
| 1469 Isolate* I = T->isolate(); | 1468 Isolate* I = T->isolate(); |
| 1469 if (!FLAG_load_deferred_eagerly) { |
| 1470 return Dart_NewApiError( |
| 1471 "Creating full snapshots requires --load_deferred_eagerly"); |
| 1472 } |
| 1470 if (vm_isolate_snapshot_buffer != NULL && | 1473 if (vm_isolate_snapshot_buffer != NULL && |
| 1471 vm_isolate_snapshot_size == NULL) { | 1474 vm_isolate_snapshot_size == NULL) { |
| 1472 RETURN_NULL_ERROR(vm_isolate_snapshot_size); | 1475 RETURN_NULL_ERROR(vm_isolate_snapshot_size); |
| 1473 } | 1476 } |
| 1474 if (isolate_snapshot_buffer == NULL) { | 1477 if (isolate_snapshot_buffer == NULL) { |
| 1475 RETURN_NULL_ERROR(isolate_snapshot_buffer); | 1478 RETURN_NULL_ERROR(isolate_snapshot_buffer); |
| 1476 } | 1479 } |
| 1477 if (isolate_snapshot_size == NULL) { | 1480 if (isolate_snapshot_size == NULL) { |
| 1478 RETURN_NULL_ERROR(isolate_snapshot_size); | 1481 RETURN_NULL_ERROR(isolate_snapshot_size); |
| 1479 } | 1482 } |
| (...skipping 3752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5232 if (buffer == NULL) { | 5235 if (buffer == NULL) { |
| 5233 RETURN_NULL_ERROR(buffer); | 5236 RETURN_NULL_ERROR(buffer); |
| 5234 } | 5237 } |
| 5235 NoHeapGrowthControlScope no_growth_control; | 5238 NoHeapGrowthControlScope no_growth_control; |
| 5236 | 5239 |
| 5237 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 5240 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
| 5238 if (snapshot == NULL) { | 5241 if (snapshot == NULL) { |
| 5239 return Api::NewError("%s expects parameter 'buffer' to be a script type" | 5242 return Api::NewError("%s expects parameter 'buffer' to be a script type" |
| 5240 " snapshot with a valid length.", CURRENT_FUNC); | 5243 " snapshot with a valid length.", CURRENT_FUNC); |
| 5241 } | 5244 } |
| 5242 if (!snapshot->IsScriptSnapshot()) { | 5245 if (snapshot->kind() != Snapshot::kScript) { |
| 5243 return Api::NewError("%s expects parameter 'buffer' to be a script type" | 5246 return Api::NewError("%s expects parameter 'buffer' to be a script type" |
| 5244 " snapshot.", CURRENT_FUNC); | 5247 " snapshot.", CURRENT_FUNC); |
| 5245 } | 5248 } |
| 5246 if (snapshot->length() != buffer_len) { | 5249 if (snapshot->length() != buffer_len) { |
| 5247 return Api::NewError("%s: 'buffer_len' of %" Pd " is not equal to %" Pd | 5250 return Api::NewError("%s: 'buffer_len' of %" Pd " is not equal to %" Pd |
| 5248 " which is the expected length in the snapshot.", | 5251 " which is the expected length in the snapshot.", |
| 5249 CURRENT_FUNC, buffer_len, snapshot->length()); | 5252 CURRENT_FUNC, buffer_len, snapshot->length()); |
| 5250 } | 5253 } |
| 5251 Library& library = Library::Handle(Z, I->object_store()->root_library()); | 5254 Library& library = Library::Handle(Z, I->object_store()->root_library()); |
| 5252 if (!library.IsNull()) { | 5255 if (!library.IsNull()) { |
| (...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6149 } | 6152 } |
| 6150 | 6153 |
| 6151 | 6154 |
| 6152 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshotAssembly( | 6155 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshotAssembly( |
| 6153 uint8_t** vm_isolate_snapshot_buffer, | 6156 uint8_t** vm_isolate_snapshot_buffer, |
| 6154 intptr_t* vm_isolate_snapshot_size, | 6157 intptr_t* vm_isolate_snapshot_size, |
| 6155 uint8_t** isolate_snapshot_buffer, | 6158 uint8_t** isolate_snapshot_buffer, |
| 6156 intptr_t* isolate_snapshot_size, | 6159 intptr_t* isolate_snapshot_size, |
| 6157 uint8_t** assembly_buffer, | 6160 uint8_t** assembly_buffer, |
| 6158 intptr_t* assembly_size) { | 6161 intptr_t* assembly_size) { |
| 6159 ASSERT(FLAG_load_deferred_eagerly); | |
| 6160 API_TIMELINE_DURATION; | 6162 API_TIMELINE_DURATION; |
| 6161 DARTSCOPE(Thread::Current()); | 6163 DARTSCOPE(Thread::Current()); |
| 6162 Isolate* I = T->isolate(); | 6164 Isolate* I = T->isolate(); |
| 6163 if (I->compilation_allowed()) { | 6165 if (I->compilation_allowed()) { |
| 6164 return Dart_NewApiError("Isolate is not precompiled. " | 6166 return Dart_NewApiError("Isolate is not precompiled. " |
| 6165 "Did you forget to call Dart_Precompile?"); | 6167 "Did you forget to call Dart_Precompile?"); |
| 6166 } | 6168 } |
| 6169 ASSERT(FLAG_load_deferred_eagerly); |
| 6167 if (vm_isolate_snapshot_buffer == NULL) { | 6170 if (vm_isolate_snapshot_buffer == NULL) { |
| 6168 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); | 6171 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); |
| 6169 } | 6172 } |
| 6170 if (vm_isolate_snapshot_size == NULL) { | 6173 if (vm_isolate_snapshot_size == NULL) { |
| 6171 RETURN_NULL_ERROR(vm_isolate_snapshot_size); | 6174 RETURN_NULL_ERROR(vm_isolate_snapshot_size); |
| 6172 } | 6175 } |
| 6173 if (isolate_snapshot_buffer == NULL) { | 6176 if (isolate_snapshot_buffer == NULL) { |
| 6174 RETURN_NULL_ERROR(isolate_snapshot_buffer); | 6177 RETURN_NULL_ERROR(isolate_snapshot_buffer); |
| 6175 } | 6178 } |
| 6176 if (isolate_snapshot_size == NULL) { | 6179 if (isolate_snapshot_size == NULL) { |
| 6177 RETURN_NULL_ERROR(isolate_snapshot_size); | 6180 RETURN_NULL_ERROR(isolate_snapshot_size); |
| 6178 } | 6181 } |
| 6179 if (assembly_buffer == NULL) { | 6182 if (assembly_buffer == NULL) { |
| 6180 RETURN_NULL_ERROR(assembly_buffer); | 6183 RETURN_NULL_ERROR(assembly_buffer); |
| 6181 } | 6184 } |
| 6182 if (assembly_size == NULL) { | 6185 if (assembly_size == NULL) { |
| 6183 RETURN_NULL_ERROR(assembly_size); | 6186 RETURN_NULL_ERROR(assembly_size); |
| 6184 } | 6187 } |
| 6188 |
| 6189 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), |
| 6190 "WriteAppAOTSnapshot")); |
| 6185 AssemblyInstructionsWriter instructions_writer(assembly_buffer, | 6191 AssemblyInstructionsWriter instructions_writer(assembly_buffer, |
| 6186 ApiReallocate, | 6192 ApiReallocate, |
| 6187 2 * MB /* initial_size */); | 6193 2 * MB /* initial_size */); |
| 6188 FullSnapshotWriter writer(Snapshot::kAppNoJIT, | 6194 FullSnapshotWriter writer(Snapshot::kAppNoJIT, |
| 6189 vm_isolate_snapshot_buffer, | 6195 vm_isolate_snapshot_buffer, |
| 6190 isolate_snapshot_buffer, | 6196 isolate_snapshot_buffer, |
| 6191 ApiReallocate, | 6197 ApiReallocate, |
| 6192 &instructions_writer); | 6198 &instructions_writer); |
| 6193 | 6199 |
| 6194 writer.WriteFullSnapshot(); | 6200 writer.WriteFullSnapshot(); |
| 6195 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 6201 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
| 6196 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 6202 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
| 6197 *assembly_size = instructions_writer.AssemblySize(); | 6203 *assembly_size = instructions_writer.AssemblySize(); |
| 6198 | 6204 |
| 6199 return Api::Success(); | 6205 return Api::Success(); |
| 6200 } | 6206 } |
| 6201 | 6207 |
| 6202 | 6208 |
| 6203 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshotBlob( | 6209 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshotBlob( |
| 6204 uint8_t** vm_isolate_snapshot_buffer, | 6210 uint8_t** vm_isolate_snapshot_buffer, |
| 6205 intptr_t* vm_isolate_snapshot_size, | 6211 intptr_t* vm_isolate_snapshot_size, |
| 6206 uint8_t** isolate_snapshot_buffer, | 6212 uint8_t** isolate_snapshot_buffer, |
| 6207 intptr_t* isolate_snapshot_size, | 6213 intptr_t* isolate_snapshot_size, |
| 6208 uint8_t** instructions_blob_buffer, | 6214 uint8_t** instructions_blob_buffer, |
| 6209 intptr_t* instructions_blob_size, | 6215 intptr_t* instructions_blob_size, |
| 6210 uint8_t** rodata_blob_buffer, | 6216 uint8_t** rodata_blob_buffer, |
| 6211 intptr_t* rodata_blob_size) { | 6217 intptr_t* rodata_blob_size) { |
| 6212 ASSERT(FLAG_load_deferred_eagerly); | |
| 6213 API_TIMELINE_DURATION; | 6218 API_TIMELINE_DURATION; |
| 6214 DARTSCOPE(Thread::Current()); | 6219 DARTSCOPE(Thread::Current()); |
| 6215 Isolate* I = T->isolate(); | 6220 Isolate* I = T->isolate(); |
| 6216 if (I->compilation_allowed()) { | 6221 if (I->compilation_allowed()) { |
| 6217 return Dart_NewApiError("Isolate is not precompiled. " | 6222 return Dart_NewApiError("Isolate is not precompiled. " |
| 6218 "Did you forget to call Dart_Precompile?"); | 6223 "Did you forget to call Dart_Precompile?"); |
| 6219 } | 6224 } |
| 6225 ASSERT(FLAG_load_deferred_eagerly); |
| 6220 if (vm_isolate_snapshot_buffer == NULL) { | 6226 if (vm_isolate_snapshot_buffer == NULL) { |
| 6221 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); | 6227 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); |
| 6222 } | 6228 } |
| 6223 if (vm_isolate_snapshot_size == NULL) { | 6229 if (vm_isolate_snapshot_size == NULL) { |
| 6224 RETURN_NULL_ERROR(vm_isolate_snapshot_size); | 6230 RETURN_NULL_ERROR(vm_isolate_snapshot_size); |
| 6225 } | 6231 } |
| 6226 if (isolate_snapshot_buffer == NULL) { | 6232 if (isolate_snapshot_buffer == NULL) { |
| 6227 RETURN_NULL_ERROR(isolate_snapshot_buffer); | 6233 RETURN_NULL_ERROR(isolate_snapshot_buffer); |
| 6228 } | 6234 } |
| 6229 if (isolate_snapshot_size == NULL) { | 6235 if (isolate_snapshot_size == NULL) { |
| 6230 RETURN_NULL_ERROR(isolate_snapshot_size); | 6236 RETURN_NULL_ERROR(isolate_snapshot_size); |
| 6231 } | 6237 } |
| 6232 if (instructions_blob_buffer == NULL) { | 6238 if (instructions_blob_buffer == NULL) { |
| 6233 RETURN_NULL_ERROR(instructions_blob_buffer); | 6239 RETURN_NULL_ERROR(instructions_blob_buffer); |
| 6234 } | 6240 } |
| 6235 if (instructions_blob_size == NULL) { | 6241 if (instructions_blob_size == NULL) { |
| 6236 RETURN_NULL_ERROR(instructions_blob_size); | 6242 RETURN_NULL_ERROR(instructions_blob_size); |
| 6237 } | 6243 } |
| 6238 if (rodata_blob_buffer == NULL) { | 6244 if (rodata_blob_buffer == NULL) { |
| 6239 RETURN_NULL_ERROR(instructions_blob_buffer); | 6245 RETURN_NULL_ERROR(instructions_blob_buffer); |
| 6240 } | 6246 } |
| 6241 if (rodata_blob_size == NULL) { | 6247 if (rodata_blob_size == NULL) { |
| 6242 RETURN_NULL_ERROR(instructions_blob_size); | 6248 RETURN_NULL_ERROR(instructions_blob_size); |
| 6243 } | 6249 } |
| 6250 |
| 6251 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), |
| 6252 "WriteAppAOTSnapshot")); |
| 6244 BlobInstructionsWriter instructions_writer(instructions_blob_buffer, | 6253 BlobInstructionsWriter instructions_writer(instructions_blob_buffer, |
| 6245 rodata_blob_buffer, | 6254 rodata_blob_buffer, |
| 6246 ApiReallocate, | 6255 ApiReallocate, |
| 6247 2 * MB /* initial_size */); | 6256 2 * MB /* initial_size */); |
| 6248 FullSnapshotWriter writer(Snapshot::kAppNoJIT, | 6257 FullSnapshotWriter writer(Snapshot::kAppNoJIT, |
| 6249 vm_isolate_snapshot_buffer, | 6258 vm_isolate_snapshot_buffer, |
| 6250 isolate_snapshot_buffer, | 6259 isolate_snapshot_buffer, |
| 6251 ApiReallocate, | 6260 ApiReallocate, |
| 6252 &instructions_writer); | 6261 &instructions_writer); |
| 6253 | 6262 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6296 | 6305 |
| 6297 DART_EXPORT Dart_Handle Dart_CreatePrecompiledJITSnapshotBlob( | 6306 DART_EXPORT Dart_Handle Dart_CreatePrecompiledJITSnapshotBlob( |
| 6298 uint8_t** vm_isolate_snapshot_buffer, | 6307 uint8_t** vm_isolate_snapshot_buffer, |
| 6299 intptr_t* vm_isolate_snapshot_size, | 6308 intptr_t* vm_isolate_snapshot_size, |
| 6300 uint8_t** isolate_snapshot_buffer, | 6309 uint8_t** isolate_snapshot_buffer, |
| 6301 intptr_t* isolate_snapshot_size, | 6310 intptr_t* isolate_snapshot_size, |
| 6302 uint8_t** instructions_blob_buffer, | 6311 uint8_t** instructions_blob_buffer, |
| 6303 intptr_t* instructions_blob_size, | 6312 intptr_t* instructions_blob_size, |
| 6304 uint8_t** rodata_blob_buffer, | 6313 uint8_t** rodata_blob_buffer, |
| 6305 intptr_t* rodata_blob_size) { | 6314 intptr_t* rodata_blob_size) { |
| 6306 ASSERT(FLAG_load_deferred_eagerly); | |
| 6307 API_TIMELINE_DURATION; | 6315 API_TIMELINE_DURATION; |
| 6308 DARTSCOPE(Thread::Current()); | 6316 DARTSCOPE(Thread::Current()); |
| 6309 Isolate* I = T->isolate(); | 6317 Isolate* I = T->isolate(); |
| 6318 if (!FLAG_load_deferred_eagerly) { |
| 6319 return Dart_NewApiError( |
| 6320 "Creating full snapshots requires --load_deferred_eagerly"); |
| 6321 } |
| 6310 if (vm_isolate_snapshot_buffer == NULL) { | 6322 if (vm_isolate_snapshot_buffer == NULL) { |
| 6311 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); | 6323 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); |
| 6312 } | 6324 } |
| 6313 if (vm_isolate_snapshot_size == NULL) { | 6325 if (vm_isolate_snapshot_size == NULL) { |
| 6314 RETURN_NULL_ERROR(vm_isolate_snapshot_size); | 6326 RETURN_NULL_ERROR(vm_isolate_snapshot_size); |
| 6315 } | 6327 } |
| 6316 if (isolate_snapshot_buffer == NULL) { | 6328 if (isolate_snapshot_buffer == NULL) { |
| 6317 RETURN_NULL_ERROR(isolate_snapshot_buffer); | 6329 RETURN_NULL_ERROR(isolate_snapshot_buffer); |
| 6318 } | 6330 } |
| 6319 if (isolate_snapshot_size == NULL) { | 6331 if (isolate_snapshot_size == NULL) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 6331 if (rodata_blob_size == NULL) { | 6343 if (rodata_blob_size == NULL) { |
| 6332 RETURN_NULL_ERROR(instructions_blob_size); | 6344 RETURN_NULL_ERROR(instructions_blob_size); |
| 6333 } | 6345 } |
| 6334 // Finalize all classes if needed. | 6346 // Finalize all classes if needed. |
| 6335 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); | 6347 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); |
| 6336 if (::Dart_IsError(state)) { | 6348 if (::Dart_IsError(state)) { |
| 6337 return state; | 6349 return state; |
| 6338 } | 6350 } |
| 6339 I->StopBackgroundCompiler(); | 6351 I->StopBackgroundCompiler(); |
| 6340 | 6352 |
| 6353 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), |
| 6354 "WriteAppJITSnapshot")); |
| 6341 BlobInstructionsWriter instructions_writer(instructions_blob_buffer, | 6355 BlobInstructionsWriter instructions_writer(instructions_blob_buffer, |
| 6342 rodata_blob_buffer, | 6356 rodata_blob_buffer, |
| 6343 ApiReallocate, | 6357 ApiReallocate, |
| 6344 2 * MB /* initial_size */); | 6358 2 * MB /* initial_size */); |
| 6345 FullSnapshotWriter writer(Snapshot::kAppWithJIT, | 6359 FullSnapshotWriter writer(Snapshot::kAppWithJIT, |
| 6346 vm_isolate_snapshot_buffer, | 6360 vm_isolate_snapshot_buffer, |
| 6347 isolate_snapshot_buffer, | 6361 isolate_snapshot_buffer, |
| 6348 ApiReallocate, | 6362 ApiReallocate, |
| 6349 &instructions_writer); | 6363 &instructions_writer); |
| 6350 writer.WriteFullSnapshot(); | 6364 writer.WriteFullSnapshot(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 6364 | 6378 |
| 6365 DART_EXPORT bool Dart_IsPrecompiledRuntime() { | 6379 DART_EXPORT bool Dart_IsPrecompiledRuntime() { |
| 6366 #if defined(DART_PRECOMPILED_RUNTIME) | 6380 #if defined(DART_PRECOMPILED_RUNTIME) |
| 6367 return true; | 6381 return true; |
| 6368 #else | 6382 #else |
| 6369 return false; | 6383 return false; |
| 6370 #endif | 6384 #endif |
| 6371 } | 6385 } |
| 6372 | 6386 |
| 6373 } // namespace dart | 6387 } // namespace dart |
| OLD | NEW |