Index: runtime/vm/native_api_impl.cc |
diff --git a/runtime/vm/native_api_impl.cc b/runtime/vm/native_api_impl.cc |
index 0fe234f7a5f5e8b2206fbbd548e04934b976eaf7..1f60a969522201532ebcc81c7b75782523bd06be 100644 |
--- a/runtime/vm/native_api_impl.cc |
+++ b/runtime/vm/native_api_impl.cc |
@@ -15,6 +15,8 @@ |
namespace dart { |
+DECLARE_FLAG(bool, load_deferred_eagerly); |
+ |
// --- Message sending/receiving from native code --- |
static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
@@ -102,6 +104,12 @@ DART_EXPORT Dart_Handle Dart_CompileAll() { |
return result; |
} |
+static uint8_t* ApiReallocate(uint8_t* ptr, |
+ intptr_t old_size, |
+ intptr_t new_size) { |
+ return Api::TopScope(Isolate::Current())->zone()->Realloc<uint8_t>( |
+ ptr, old_size, new_size); |
+} |
DART_EXPORT Dart_Handle Dart_Precompile() { |
DARTSCOPE(Thread::Current()); |
@@ -114,4 +122,49 @@ DART_EXPORT Dart_Handle Dart_Precompile() { |
return result; |
} |
+DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshot( |
+ uint8_t** vm_isolate_snapshot_buffer, |
+ intptr_t* vm_isolate_snapshot_size, |
+ uint8_t** isolate_snapshot_buffer, |
+ intptr_t* isolate_snapshot_size, |
+ uint8_t** instructions_snapshot_buffer, |
+ intptr_t* instructions_snapshot_size) { |
+ ASSERT(FLAG_load_deferred_eagerly); |
+ DARTSCOPE(Thread::Current()); |
+ if (vm_isolate_snapshot_buffer == NULL) { |
+ RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); |
+ } |
+ if (vm_isolate_snapshot_size == NULL) { |
+ RETURN_NULL_ERROR(vm_isolate_snapshot_size); |
+ } |
+ if (isolate_snapshot_buffer == NULL) { |
+ RETURN_NULL_ERROR(isolate_snapshot_buffer); |
+ } |
+ if (isolate_snapshot_size == NULL) { |
+ RETURN_NULL_ERROR(isolate_snapshot_size); |
+ } |
+ if (instructions_snapshot_buffer == NULL) { |
+ RETURN_NULL_ERROR(instructions_snapshot_buffer); |
+ } |
+ if (instructions_snapshot_size == NULL) { |
+ RETURN_NULL_ERROR(instructions_snapshot_size); |
+ } |
+ // Finalize all classes if needed. |
+ Dart_Handle state = Api::CheckAndFinalizePendingClasses(I); |
+ if (::Dart_IsError(state)) { |
+ return state; |
+ } |
+ I->heap()->CollectAllGarbage(); |
+ PrecompiledSnapshotWriter writer(vm_isolate_snapshot_buffer, |
+ isolate_snapshot_buffer, |
+ instructions_snapshot_buffer, |
+ ApiReallocate); |
+ writer.WriteFullSnapshot(); |
+ *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
+ *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
+ *instructions_snapshot_size = writer.InstructionsSnapshotSize(); |
+ |
+ return Api::Success(); |
+} |
+ |
} // namespace dart |