| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 | 6 |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 old_size, | 606 old_size, |
| 607 new_size); | 607 new_size); |
| 608 return reinterpret_cast<uint8_t*>(new_ptr); | 608 return reinterpret_cast<uint8_t*>(new_ptr); |
| 609 } | 609 } |
| 610 | 610 |
| 611 | 611 |
| 612 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** buffer, | 612 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** buffer, |
| 613 intptr_t* size) { | 613 intptr_t* size) { |
| 614 Isolate* isolate = Isolate::Current(); | 614 Isolate* isolate = Isolate::Current(); |
| 615 DARTSCOPE(isolate); | 615 DARTSCOPE(isolate); |
| 616 TIMERSCOPE(time_creating_snapshot); |
| 616 if (buffer == NULL) { | 617 if (buffer == NULL) { |
| 617 return Api::Error("%s expects argument 'buffer' to be non-null.", | 618 return Api::Error("%s expects argument 'buffer' to be non-null.", |
| 618 CURRENT_FUNC); | 619 CURRENT_FUNC); |
| 619 } | 620 } |
| 620 if (size == NULL) { | 621 if (size == NULL) { |
| 621 return Api::Error("%s expects argument 'size' to be non-null.", | 622 return Api::Error("%s expects argument 'size' to be non-null.", |
| 622 CURRENT_FUNC); | 623 CURRENT_FUNC); |
| 623 } | 624 } |
| 624 const char* msg = CheckIsolateState(isolate, | 625 const char* msg = CheckIsolateState(isolate, |
| 625 ClassFinalizer::kGeneratingSnapshot); | 626 ClassFinalizer::kGeneratingSnapshot); |
| 626 if (msg != NULL) { | 627 if (msg != NULL) { |
| 627 return Api::Error(msg); | 628 return Api::Error(msg); |
| 628 } | 629 } |
| 629 // Since this is only a snapshot the root library should not be set. | 630 // Since this is only a snapshot the root library should not be set. |
| 630 isolate->object_store()->set_root_library(Library::Handle()); | 631 isolate->object_store()->set_root_library(Library::Handle()); |
| 631 SnapshotWriter writer(Snapshot::kFull, buffer, ApiAllocator); | 632 SnapshotWriter writer(Snapshot::kFull, buffer, ApiAllocator); |
| 632 writer.WriteFullSnapshot(); | 633 writer.WriteFullSnapshot(); |
| 633 *size = writer.Size(); | 634 *size = writer.Size(); |
| 634 return Api::Success(); | 635 return Api::Success(); |
| 635 } | 636 } |
| 636 | 637 |
| 637 | 638 |
| 638 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(Dart_Handle library, | 639 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, |
| 639 uint8_t** buffer, | |
| 640 intptr_t* size) { | 640 intptr_t* size) { |
| 641 Isolate* isolate = Isolate::Current(); | 641 Isolate* isolate = Isolate::Current(); |
| 642 DARTSCOPE(isolate); | 642 DARTSCOPE(isolate); |
| 643 TIMERSCOPE(time_creating_snapshot); |
| 643 if (buffer == NULL) { | 644 if (buffer == NULL) { |
| 644 return Api::Error("%s expects argument 'buffer' to be non-null.", | 645 return Api::Error("%s expects argument 'buffer' to be non-null.", |
| 645 CURRENT_FUNC); | 646 CURRENT_FUNC); |
| 646 } | 647 } |
| 647 if (size == NULL) { | 648 if (size == NULL) { |
| 648 return Api::Error("%s expects argument 'size' to be non-null.", | 649 return Api::Error("%s expects argument 'size' to be non-null.", |
| 649 CURRENT_FUNC); | 650 CURRENT_FUNC); |
| 650 } | 651 } |
| 651 const Library& root_lib = Api::UnwrapLibraryHandle(library); | |
| 652 if (root_lib.IsNull()) { | |
| 653 RETURN_TYPE_ERROR(library, Library); | |
| 654 } | |
| 655 const char* msg = CheckIsolateState(isolate); | 652 const char* msg = CheckIsolateState(isolate); |
| 656 if (msg != NULL) { | 653 if (msg != NULL) { |
| 657 return Api::Error(msg); | 654 return Api::Error(msg); |
| 658 } | 655 } |
| 659 ScriptSnapshotWriter writer(root_lib, buffer, ApiAllocator); | 656 Library& library = Library::Handle(isolate->object_store()->root_library()); |
| 660 writer.WriteScriptSnapshot(); | 657 if (library.IsNull()) { |
| 658 return Api::Error("%s expects the isolate to have a script loaded in it.", |
| 659 CURRENT_FUNC); |
| 660 } |
| 661 ScriptSnapshotWriter writer(buffer, ApiAllocator); |
| 662 writer.WriteScriptSnapshot(library); |
| 661 *size = writer.Size(); | 663 *size = writer.Size(); |
| 662 return Api::Success(); | 664 return Api::Success(); |
| 663 } | 665 } |
| 664 | 666 |
| 665 | 667 |
| 666 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { | 668 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { |
| 667 if (isolate == NULL) { | 669 if (isolate == NULL) { |
| 668 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 670 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
| 669 } | 671 } |
| 670 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 672 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
| (...skipping 1609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2280 source_str, | 2282 source_str, |
| 2281 RawScript::kScript, | 2283 RawScript::kScript, |
| 2282 &result); | 2284 &result); |
| 2283 return result; | 2285 return result; |
| 2284 } | 2286 } |
| 2285 | 2287 |
| 2286 | 2288 |
| 2287 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) { | 2289 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) { |
| 2288 Isolate* isolate = Isolate::Current(); | 2290 Isolate* isolate = Isolate::Current(); |
| 2289 DARTSCOPE(isolate); | 2291 DARTSCOPE(isolate); |
| 2292 TIMERSCOPE(time_script_loading); |
| 2290 if (buffer == NULL) { | 2293 if (buffer == NULL) { |
| 2291 return Api::Error("%s expects argument 'buffer' to be non-null.", | 2294 return Api::Error("%s expects argument 'buffer' to be non-null.", |
| 2292 CURRENT_FUNC); | 2295 CURRENT_FUNC); |
| 2293 } | 2296 } |
| 2294 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 2297 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
| 2295 if (!snapshot->IsScriptSnapshot()) { | 2298 if (!snapshot->IsScriptSnapshot()) { |
| 2296 return Api::Error("%s expects parameter 'buffer' to be a script type" | 2299 return Api::Error("%s expects parameter 'buffer' to be a script type" |
| 2297 " snapshot", CURRENT_FUNC); | 2300 " snapshot", CURRENT_FUNC); |
| 2298 } | 2301 } |
| 2299 Library& library = Library::Handle(isolate->object_store()->root_library()); | 2302 Library& library = Library::Handle(isolate->object_store()->root_library()); |
| 2300 if (!library.IsNull()) { | 2303 if (!library.IsNull()) { |
| 2301 const String& library_url = String::Handle(library.url()); | 2304 const String& library_url = String::Handle(library.url()); |
| 2302 return Api::Error("%s: A script has already been loaded from '%s'.", | 2305 return Api::Error("%s: A script has already been loaded from '%s'.", |
| 2303 CURRENT_FUNC, library_url.ToCString()); | 2306 CURRENT_FUNC, library_url.ToCString()); |
| 2304 } | 2307 } |
| 2305 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store()); | 2308 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store()); |
| 2306 const Object& tmp = Object::Handle(reader.ReadObject()); | 2309 const Object& tmp = Object::Handle(reader.ReadObject()); |
| 2307 if (!tmp.IsLibrary()) { | 2310 if (!tmp.IsLibrary()) { |
| 2308 return Api::Error("%s: Unable to deserialize snapshot correctly.", | 2311 return Api::Error("%s: Unable to deserialize snapshot correctly.", |
| 2309 CURRENT_FUNC); | 2312 CURRENT_FUNC); |
| 2310 } | 2313 } |
| 2311 library ^= tmp.raw(); | 2314 library ^= tmp.raw(); |
| 2315 library.Register(); |
| 2312 isolate->object_store()->set_root_library(library); | 2316 isolate->object_store()->set_root_library(library); |
| 2313 return Api::NewLocalHandle(library); | 2317 return Api::NewLocalHandle(library); |
| 2314 } | 2318 } |
| 2315 | 2319 |
| 2316 | 2320 |
| 2317 DEFINE_FLAG(bool, compile_all, false, "Eagerly compile all code."); | 2321 DEFINE_FLAG(bool, compile_all, false, "Eagerly compile all code."); |
| 2318 | 2322 |
| 2319 static void CompileAll(Isolate* isolate, Dart_Handle* result) { | 2323 static void CompileAll(Isolate* isolate, Dart_Handle* result) { |
| 2320 *result = Api::Success(); | 2324 *result = Api::Success(); |
| 2321 if (FLAG_compile_all) { | 2325 if (FLAG_compile_all) { |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2512 } | 2516 } |
| 2513 delete debug_region; | 2517 delete debug_region; |
| 2514 } else { | 2518 } else { |
| 2515 *buffer = NULL; | 2519 *buffer = NULL; |
| 2516 *buffer_size = 0; | 2520 *buffer_size = 0; |
| 2517 } | 2521 } |
| 2518 } | 2522 } |
| 2519 | 2523 |
| 2520 | 2524 |
| 2521 } // namespace dart | 2525 } // namespace dart |
| OLD | NEW |