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

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 2485993002: VM: Support bootstrapping core libraries from Kernel binaries instead of source. (Closed)
Patch Set: Done 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 unified diff | Download patch
OLDNEW
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 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 } 1252 }
1253 1253
1254 char* chars = NULL; 1254 char* chars = NULL;
1255 intptr_t len = OS::SNPrint(NULL, 0, "%s$%s", script_uri, main) + 1; 1255 intptr_t len = OS::SNPrint(NULL, 0, "%s$%s", script_uri, main) + 1;
1256 chars = reinterpret_cast<char*>(malloc(len)); 1256 chars = reinterpret_cast<char*>(malloc(len));
1257 OS::SNPrint(chars, len, "%s$%s", script_uri, main); 1257 OS::SNPrint(chars, len, "%s$%s", script_uri, main);
1258 return chars; 1258 return chars;
1259 } 1259 }
1260 1260
1261 1261
1262 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri, 1262 static Dart_Isolate CreateIsolate(const char* script_uri,
1263 const char* main, 1263 const char* main,
1264 const uint8_t* snapshot, 1264 const uint8_t* snapshot_buffer,
1265 Dart_IsolateFlags* flags, 1265 intptr_t snapshot_length,
1266 void* callback_data, 1266 bool from_kernel,
1267 char** error) { 1267 Dart_IsolateFlags* flags,
1268 void* callback_data,
1269 char** error) {
1270 ASSERT(!from_kernel || (snapshot_buffer != NULL));
1268 CHECK_NO_ISOLATE(Isolate::Current()); 1271 CHECK_NO_ISOLATE(Isolate::Current());
1269 char* isolate_name = BuildIsolateName(script_uri, main); 1272 char* isolate_name = BuildIsolateName(script_uri, main);
1270 1273
1271 // Setup default flags in case none were passed. 1274 // Setup default flags in case none were passed.
1272 Dart_IsolateFlags api_flags; 1275 Dart_IsolateFlags api_flags;
1273 if (flags == NULL) { 1276 if (flags == NULL) {
1274 Isolate::FlagsInitialize(&api_flags); 1277 Isolate::FlagsInitialize(&api_flags);
1275 flags = &api_flags; 1278 flags = &api_flags;
1276 } 1279 }
1277 Isolate* I = Dart::CreateIsolate(isolate_name, *flags); 1280 Isolate* I = Dart::CreateIsolate(isolate_name, *flags);
1278 free(isolate_name); 1281 free(isolate_name);
1279 if (I == NULL) { 1282 if (I == NULL) {
1280 *error = strdup("Isolate creation failed"); 1283 *error = strdup("Isolate creation failed");
1281 return reinterpret_cast<Dart_Isolate>(NULL); 1284 return reinterpret_cast<Dart_Isolate>(NULL);
1282 } 1285 }
1283 { 1286 {
1284 Thread* T = Thread::Current(); 1287 Thread* T = Thread::Current();
1285 StackZone zone(T); 1288 StackZone zone(T);
1286 HANDLESCOPE(T); 1289 HANDLESCOPE(T);
1287 // We enter an API scope here as InitializeIsolate could compile some 1290 // We enter an API scope here as InitializeIsolate could compile some
1288 // bootstrap library files which call out to a tag handler that may create 1291 // bootstrap library files which call out to a tag handler that may create
1289 // Api Handles when an error is encountered. 1292 // Api Handles when an error is encountered.
1290 Dart_EnterScope(); 1293 Dart_EnterScope();
1291 const Error& error_obj = 1294 const Error& error_obj = Error::Handle(
1292 Error::Handle(Z, Dart::InitializeIsolate(snapshot, callback_data)); 1295 Z, Dart::InitializeIsolate(snapshot_buffer, snapshot_length,
1296 from_kernel, callback_data));
1293 if (error_obj.IsNull()) { 1297 if (error_obj.IsNull()) {
1294 #if defined(DART_NO_SNAPSHOT) && !defined(PRODUCT) 1298 #if defined(DART_NO_SNAPSHOT) && !defined(PRODUCT)
1295 if (FLAG_check_function_fingerprints) { 1299 if (FLAG_check_function_fingerprints && !from_kernel) {
1296 Library::CheckFunctionFingerprints(); 1300 Library::CheckFunctionFingerprints();
1297 } 1301 }
1298 #endif // defined(DART_NO_SNAPSHOT) && !defined(PRODUCT). 1302 #endif // defined(DART_NO_SNAPSHOT) && !defined(PRODUCT).
1299 // We exit the API scope entered above. 1303 // We exit the API scope entered above.
1300 Dart_ExitScope(); 1304 Dart_ExitScope();
1301 // A Thread structure has been associated to the thread, we do the 1305 // A Thread structure has been associated to the thread, we do the
1302 // safepoint transition explicity here instead of using the 1306 // safepoint transition explicity here instead of using the
1303 // TransitionXXX scope objects as the reverse transition happens 1307 // TransitionXXX scope objects as the reverse transition happens
1304 // outside this scope in Dart_ShutdownIsolate/Dart_ExitIsolate. 1308 // outside this scope in Dart_ShutdownIsolate/Dart_ExitIsolate.
1305 T->set_execution_state(Thread::kThreadInNative); 1309 T->set_execution_state(Thread::kThreadInNative);
1306 T->EnterSafepoint(); 1310 T->EnterSafepoint();
1307 return Api::CastIsolate(I); 1311 return Api::CastIsolate(I);
1308 } 1312 }
1309 *error = strdup(error_obj.ToErrorCString()); 1313 *error = strdup(error_obj.ToErrorCString());
1310 // We exit the API scope entered above. 1314 // We exit the API scope entered above.
1311 Dart_ExitScope(); 1315 Dart_ExitScope();
1312 } 1316 }
1313 Dart::ShutdownIsolate(); 1317 Dart::ShutdownIsolate();
1314 return reinterpret_cast<Dart_Isolate>(NULL); 1318 return reinterpret_cast<Dart_Isolate>(NULL);
1315 } 1319 }
1316 1320
1317 1321
1322 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri,
1323 const char* main,
1324 const uint8_t* snapshot_buffer,
1325 Dart_IsolateFlags* flags,
1326 void* callback_data,
1327 char** error) {
1328 return CreateIsolate(script_uri, main, snapshot_buffer, -1, false, flags,
1329 callback_data, error);
1330 }
1331
1332
1333 DART_EXPORT Dart_Isolate Dart_CreateIsolateFromKernel(
1334 const char* script_uri,
1335 const char* main,
1336 const uint8_t* kernel_file,
1337 intptr_t kernel_length,
1338 Dart_IsolateFlags* flags,
1339 void* callback_data,
1340 char** error) {
1341 return CreateIsolate(script_uri, main, kernel_file, kernel_length, true,
1342 flags, callback_data, error);
1343 }
1344
1345
1318 DART_EXPORT void Dart_ShutdownIsolate() { 1346 DART_EXPORT void Dart_ShutdownIsolate() {
1319 Thread* T = Thread::Current(); 1347 Thread* T = Thread::Current();
1320 Isolate* I = T->isolate(); 1348 Isolate* I = T->isolate();
1321 CHECK_ISOLATE(I); 1349 CHECK_ISOLATE(I);
1322 I->WaitForOutstandingSpawns(); 1350 I->WaitForOutstandingSpawns();
1323 { 1351 {
1324 StackZone zone(T); 1352 StackZone zone(T);
1325 HandleScope handle_scope(T); 1353 HandleScope handle_scope(T);
1326 Dart::RunShutdownCallback(); 1354 Dart::RunShutdownCallback();
1327 // The Thread structure is disassociated from the isolate, we do the 1355 // The Thread structure is disassociated from the isolate, we do the
(...skipping 5307 matching lines...) Expand 10 before | Expand all | Expand 10 after
6635 6663
6636 DART_EXPORT bool Dart_IsPrecompiledRuntime() { 6664 DART_EXPORT bool Dart_IsPrecompiledRuntime() {
6637 #if defined(DART_PRECOMPILED_RUNTIME) 6665 #if defined(DART_PRECOMPILED_RUNTIME)
6638 return true; 6666 return true;
6639 #else 6667 #else
6640 return false; 6668 return false;
6641 #endif 6669 #endif
6642 } 6670 }
6643 6671
6644 } // namespace dart 6672 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698