Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Unified Diff: runtime/vm/native_api_impl.cc

Issue 1318803002: Toward precompiled snapshots. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: READ_POINTERS Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/vm/native_api_impl.cc
diff --git a/runtime/vm/native_api_impl.cc b/runtime/vm/native_api_impl.cc
index a6688976e9924ee175f08f01754ad6959514374d..b0189366eb2261d31cde055071f089ec40ddbde4 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) {
@@ -103,6 +105,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() {
Isolate* isolate = Isolate::Current();
@@ -116,4 +124,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);
siva 2015/09/01 20:58:49 instead of asserting like this why not do what we
rmacnak 2015/09/01 23:43:47 That's in the embedder before loading. Here it is
+ Thread* thread = Thread::Current();
+ Isolate* isolate = thread->isolate();
+ DARTSCOPE(isolate);
+ if (vm_isolate_snapshot_buffer != NULL &&
+ 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(isolate);
+ if (::Dart_IsError(state)) {
+ return state;
+ }
+ isolate->heap()->CollectAllGarbage();
+ PrecompiledSnapshotWriter writer(vm_isolate_snapshot_buffer,
+ isolate_snapshot_buffer,
+ instructions_snapshot_buffer,
+ ApiReallocate);
+ writer.WriteFullSnapshot();
+ *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize();
siva 2015/09/01 20:58:49 if vm_isoolate_snapshot_buffer is NULL this could
rmacnak 2015/09/01 23:43:47 Now requiring vm_isolate_snapshot_buffer to be non
+ *isolate_snapshot_size = writer.IsolateSnapshotSize();
+ *instructions_snapshot_size = writer.InstructionsSnapshotSize();
+
+ return Api::Success();
+}
+
} // namespace dart

Powered by Google App Engine
This is Rietveld 408576698