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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 2525623002: VM: [Kernel] Split kernel API into 3 steps: ([read binary], parse-binary, bootstrap, load program) (Closed)
Patch Set: addressed comments Created 4 years, 1 month 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
« no previous file with comments | « runtime/vm/dart.cc ('k') | runtime/vm/kernel_reader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index 22c739305beae65933db4a48f90786656b2a7a3b..5e4f4cb7c3919a1be614737f6c78c920bdef039a 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -1240,11 +1240,10 @@ static Dart_Isolate CreateIsolate(const char* script_uri,
const char* main,
const uint8_t* snapshot_buffer,
intptr_t snapshot_length,
- bool from_kernel,
+ kernel::Program* kernel_program,
Dart_IsolateFlags* flags,
void* callback_data,
char** error) {
- ASSERT(!from_kernel || (snapshot_buffer != NULL));
CHECK_NO_ISOLATE(Isolate::Current());
char* isolate_name = BuildIsolateName(script_uri, main);
@@ -1270,10 +1269,10 @@ static Dart_Isolate CreateIsolate(const char* script_uri,
Dart_EnterScope();
const Error& error_obj = Error::Handle(
Z, Dart::InitializeIsolate(snapshot_buffer, snapshot_length,
- from_kernel, callback_data));
+ kernel_program, callback_data));
if (error_obj.IsNull()) {
#if defined(DART_NO_SNAPSHOT) && !defined(PRODUCT)
- if (FLAG_check_function_fingerprints && !from_kernel) {
+ if (FLAG_check_function_fingerprints && kernel_program == NULL) {
Library::CheckFunctionFingerprints();
}
#endif // defined(DART_NO_SNAPSHOT) && !defined(PRODUCT).
@@ -1302,20 +1301,19 @@ DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri,
Dart_IsolateFlags* flags,
void* callback_data,
char** error) {
- return CreateIsolate(script_uri, main, snapshot_buffer, -1, false, flags,
+ return CreateIsolate(script_uri, main, snapshot_buffer, -1, NULL, flags,
callback_data, error);
}
-DART_EXPORT Dart_Isolate
-Dart_CreateIsolateFromKernel(const char* script_uri,
- const char* main,
- const uint8_t* kernel_file,
- intptr_t kernel_length,
- Dart_IsolateFlags* flags,
- void* callback_data,
- char** error) {
- return CreateIsolate(script_uri, main, kernel_file, kernel_length, true,
+DART_EXPORT Dart_Isolate Dart_CreateIsolateFromKernel(const char* script_uri,
+ const char* main,
+ void* kernel_program,
+ Dart_IsolateFlags* flags,
+ void* callback_data,
+ char** error) {
+ return CreateIsolate(script_uri, main, NULL, -1,
+ reinterpret_cast<kernel::Program*>(kernel_program),
flags, callback_data, error);
}
@@ -5350,9 +5348,23 @@ DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer,
}
-DART_EXPORT Dart_Handle Dart_LoadKernel(const uint8_t* buffer,
+DART_EXPORT void* Dart_ReadKernelBinary(const uint8_t* buffer,
intptr_t buffer_len) {
API_TIMELINE_DURATION;
+
+#if defined(DART_PRECOMPILED_RUNTIME)
+ UNREACHABLE();
+ return NULL;
+#else
+ kernel::Program* program =
+ ReadPrecompiledKernelFromBuffer(buffer, buffer_len);
+ return program;
+#endif
+}
+
+
+DART_EXPORT Dart_Handle Dart_LoadKernel(void* kernel_program) {
+ API_TIMELINE_DURATION;
DARTSCOPE(Thread::Current());
StackZone zone(T);
@@ -5371,9 +5383,12 @@ DART_EXPORT Dart_Handle Dart_LoadKernel(const uint8_t* buffer,
CHECK_CALLBACK_STATE(T);
CHECK_COMPILATION_ALLOWED(I);
- // TODO(27588): Memory leak!
- kernel::KernelReader* reader = new kernel::KernelReader(buffer, buffer_len);
- const Object& tmp = reader->ReadProgram();
+ // NOTE: Now the VM owns the [kernel_program] memory! Currently we do not
+ // free it because (similar to the token stream) it will be used to repeatedly
+ // run the `kernel::FlowGraphBuilder()`.
+ kernel::KernelReader reader(
+ reinterpret_cast<kernel::Program*>(kernel_program));
+ const Object& tmp = reader.ReadProgram();
if (tmp.IsError()) {
return Api::NewHandle(T, tmp.raw());
}
« no previous file with comments | « runtime/vm/dart.cc ('k') | runtime/vm/kernel_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698