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 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 } | 1234 } |
1235 | 1235 |
1236 char* chars = NULL; | 1236 char* chars = NULL; |
1237 intptr_t len = OS::SNPrint(NULL, 0, "%s$%s", script_uri, main) + 1; | 1237 intptr_t len = OS::SNPrint(NULL, 0, "%s$%s", script_uri, main) + 1; |
1238 chars = reinterpret_cast<char*>(malloc(len)); | 1238 chars = reinterpret_cast<char*>(malloc(len)); |
1239 OS::SNPrint(chars, len, "%s$%s", script_uri, main); | 1239 OS::SNPrint(chars, len, "%s$%s", script_uri, main); |
1240 return chars; | 1240 return chars; |
1241 } | 1241 } |
1242 | 1242 |
1243 | 1243 |
1244 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri, | 1244 static Dart_Isolate CreateIsolate(const char* script_uri, |
1245 const char* main, | 1245 const char* main, |
1246 const uint8_t* snapshot, | 1246 const uint8_t* snapshot_buffer, |
1247 Dart_IsolateFlags* flags, | 1247 intptr_t snapshot_length, |
1248 void* callback_data, | 1248 bool from_kernel, |
1249 char** error) { | 1249 Dart_IsolateFlags* flags, |
| 1250 void* callback_data, |
| 1251 char** error) { |
| 1252 ASSERT(!from_kernel || (snapshot_buffer != NULL)); |
1250 CHECK_NO_ISOLATE(Isolate::Current()); | 1253 CHECK_NO_ISOLATE(Isolate::Current()); |
1251 char* isolate_name = BuildIsolateName(script_uri, main); | 1254 char* isolate_name = BuildIsolateName(script_uri, main); |
1252 | 1255 |
1253 // Setup default flags in case none were passed. | 1256 // Setup default flags in case none were passed. |
1254 Dart_IsolateFlags api_flags; | 1257 Dart_IsolateFlags api_flags; |
1255 if (flags == NULL) { | 1258 if (flags == NULL) { |
1256 Isolate::FlagsInitialize(&api_flags); | 1259 Isolate::FlagsInitialize(&api_flags); |
1257 flags = &api_flags; | 1260 flags = &api_flags; |
1258 } | 1261 } |
1259 Isolate* I = Dart::CreateIsolate(isolate_name, *flags); | 1262 Isolate* I = Dart::CreateIsolate(isolate_name, *flags); |
1260 free(isolate_name); | 1263 free(isolate_name); |
1261 if (I == NULL) { | 1264 if (I == NULL) { |
1262 *error = strdup("Isolate creation failed"); | 1265 *error = strdup("Isolate creation failed"); |
1263 return reinterpret_cast<Dart_Isolate>(NULL); | 1266 return reinterpret_cast<Dart_Isolate>(NULL); |
1264 } | 1267 } |
1265 { | 1268 { |
1266 Thread* T = Thread::Current(); | 1269 Thread* T = Thread::Current(); |
1267 StackZone zone(T); | 1270 StackZone zone(T); |
1268 HANDLESCOPE(T); | 1271 HANDLESCOPE(T); |
1269 // We enter an API scope here as InitializeIsolate could compile some | 1272 // We enter an API scope here as InitializeIsolate could compile some |
1270 // bootstrap library files which call out to a tag handler that may create | 1273 // bootstrap library files which call out to a tag handler that may create |
1271 // Api Handles when an error is encountered. | 1274 // Api Handles when an error is encountered. |
1272 Dart_EnterScope(); | 1275 Dart_EnterScope(); |
1273 const Error& error_obj = | 1276 const Error& error_obj = Error::Handle( |
1274 Error::Handle(Z, Dart::InitializeIsolate(snapshot, callback_data)); | 1277 Z, Dart::InitializeIsolate(snapshot_buffer, snapshot_length, |
| 1278 from_kernel, callback_data)); |
1275 if (error_obj.IsNull()) { | 1279 if (error_obj.IsNull()) { |
1276 #if defined(DART_NO_SNAPSHOT) && !defined(PRODUCT) | 1280 #if defined(DART_NO_SNAPSHOT) && !defined(PRODUCT) |
1277 if (FLAG_check_function_fingerprints) { | 1281 if (FLAG_check_function_fingerprints && !from_kernel) { |
1278 Library::CheckFunctionFingerprints(); | 1282 Library::CheckFunctionFingerprints(); |
1279 } | 1283 } |
1280 #endif // defined(DART_NO_SNAPSHOT) && !defined(PRODUCT). | 1284 #endif // defined(DART_NO_SNAPSHOT) && !defined(PRODUCT). |
1281 // We exit the API scope entered above. | 1285 // We exit the API scope entered above. |
1282 Dart_ExitScope(); | 1286 Dart_ExitScope(); |
1283 // A Thread structure has been associated to the thread, we do the | 1287 // A Thread structure has been associated to the thread, we do the |
1284 // safepoint transition explicity here instead of using the | 1288 // safepoint transition explicity here instead of using the |
1285 // TransitionXXX scope objects as the reverse transition happens | 1289 // TransitionXXX scope objects as the reverse transition happens |
1286 // outside this scope in Dart_ShutdownIsolate/Dart_ExitIsolate. | 1290 // outside this scope in Dart_ShutdownIsolate/Dart_ExitIsolate. |
1287 T->set_execution_state(Thread::kThreadInNative); | 1291 T->set_execution_state(Thread::kThreadInNative); |
1288 T->EnterSafepoint(); | 1292 T->EnterSafepoint(); |
1289 return Api::CastIsolate(I); | 1293 return Api::CastIsolate(I); |
1290 } | 1294 } |
1291 *error = strdup(error_obj.ToErrorCString()); | 1295 *error = strdup(error_obj.ToErrorCString()); |
1292 // We exit the API scope entered above. | 1296 // We exit the API scope entered above. |
1293 Dart_ExitScope(); | 1297 Dart_ExitScope(); |
1294 } | 1298 } |
1295 Dart::ShutdownIsolate(); | 1299 Dart::ShutdownIsolate(); |
1296 return reinterpret_cast<Dart_Isolate>(NULL); | 1300 return reinterpret_cast<Dart_Isolate>(NULL); |
1297 } | 1301 } |
1298 | 1302 |
1299 | 1303 |
| 1304 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri, |
| 1305 const char* main, |
| 1306 const uint8_t* snapshot_buffer, |
| 1307 Dart_IsolateFlags* flags, |
| 1308 void* callback_data, |
| 1309 char** error) { |
| 1310 return CreateIsolate(script_uri, main, snapshot_buffer, -1, false, flags, |
| 1311 callback_data, error); |
| 1312 } |
| 1313 |
| 1314 |
| 1315 DART_EXPORT Dart_Isolate Dart_CreateIsolateFromKernel( |
| 1316 const char* script_uri, |
| 1317 const char* main, |
| 1318 const uint8_t* kernel_file, |
| 1319 intptr_t kernel_length, |
| 1320 Dart_IsolateFlags* flags, |
| 1321 void* callback_data, |
| 1322 char** error) { |
| 1323 return CreateIsolate(script_uri, main, kernel_file, kernel_length, true, |
| 1324 flags, callback_data, error); |
| 1325 } |
| 1326 |
| 1327 |
1300 DART_EXPORT void Dart_ShutdownIsolate() { | 1328 DART_EXPORT void Dart_ShutdownIsolate() { |
1301 Thread* T = Thread::Current(); | 1329 Thread* T = Thread::Current(); |
1302 Isolate* I = T->isolate(); | 1330 Isolate* I = T->isolate(); |
1303 CHECK_ISOLATE(I); | 1331 CHECK_ISOLATE(I); |
1304 I->WaitForOutstandingSpawns(); | 1332 I->WaitForOutstandingSpawns(); |
1305 { | 1333 { |
1306 StackZone zone(T); | 1334 StackZone zone(T); |
1307 HandleScope handle_scope(T); | 1335 HandleScope handle_scope(T); |
1308 Dart::RunShutdownCallback(); | 1336 Dart::RunShutdownCallback(); |
1309 // The Thread structure is disassociated from the isolate, we do the | 1337 // The Thread structure is disassociated from the isolate, we do the |
(...skipping 4015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5325 return Api::NewHandle(T, library.raw()); | 5353 return Api::NewHandle(T, library.raw()); |
5326 } | 5354 } |
5327 | 5355 |
5328 | 5356 |
5329 DART_EXPORT Dart_Handle Dart_LoadKernel(const uint8_t* buffer, | 5357 DART_EXPORT Dart_Handle Dart_LoadKernel(const uint8_t* buffer, |
5330 intptr_t buffer_len) { | 5358 intptr_t buffer_len) { |
5331 API_TIMELINE_DURATION; | 5359 API_TIMELINE_DURATION; |
5332 DARTSCOPE(Thread::Current()); | 5360 DARTSCOPE(Thread::Current()); |
5333 StackZone zone(T); | 5361 StackZone zone(T); |
5334 | 5362 |
5335 #if defined(DART_PRECOMPILED_RUNTIME) && !defined(DART_PRECOMPILER) | 5363 #if defined(DART_PRECOMPILED_RUNTIME) |
5336 return Api::NewError("%s: Can't load Kernel files from precompiled runtime.", | 5364 return Api::NewError("%s: Can't load Kernel files from precompiled runtime.", |
5337 CURRENT_FUNC); | 5365 CURRENT_FUNC); |
5338 #else | 5366 #else |
5339 Isolate* I = T->isolate(); | 5367 Isolate* I = T->isolate(); |
5340 | 5368 |
5341 Library& library = Library::Handle(Z, I->object_store()->root_library()); | 5369 Library& library = Library::Handle(Z, I->object_store()->root_library()); |
5342 if (!library.IsNull()) { | 5370 if (!library.IsNull()) { |
5343 const String& library_url = String::Handle(Z, library.url()); | 5371 const String& library_url = String::Handle(Z, library.url()); |
5344 return Api::NewError("%s: A script has already been loaded from '%s'.", | 5372 return Api::NewError("%s: A script has already been loaded from '%s'.", |
5345 CURRENT_FUNC, library_url.ToCString()); | 5373 CURRENT_FUNC, library_url.ToCString()); |
(...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6573 | 6601 |
6574 DART_EXPORT bool Dart_IsPrecompiledRuntime() { | 6602 DART_EXPORT bool Dart_IsPrecompiledRuntime() { |
6575 #if defined(DART_PRECOMPILED_RUNTIME) | 6603 #if defined(DART_PRECOMPILED_RUNTIME) |
6576 return true; | 6604 return true; |
6577 #else | 6605 #else |
6578 return false; | 6606 return false; |
6579 #endif | 6607 #endif |
6580 } | 6608 } |
6581 | 6609 |
6582 } // namespace dart | 6610 } // namespace dart |
OLD | NEW |