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

Side by Side Diff: vm/dart_api_impl.cc

Issue 8772061: First step towards generation of application script snapshots (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « tests/vm/vm.status ('k') | vm/object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 static uint8_t* ApiAllocator(uint8_t* ptr, 602 static uint8_t* ApiAllocator(uint8_t* ptr,
603 intptr_t old_size, 603 intptr_t old_size,
604 intptr_t new_size) { 604 intptr_t new_size) {
605 uword new_ptr = Api::Reallocate(reinterpret_cast<uword>(ptr), 605 uword new_ptr = Api::Reallocate(reinterpret_cast<uword>(ptr),
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** snapshot_buffer, 612 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** buffer,
613 intptr_t* snapshot_size) { 613 intptr_t* size) {
614 Isolate* isolate = Isolate::Current(); 614 Isolate* isolate = Isolate::Current();
615 DARTSCOPE(isolate); 615 DARTSCOPE(isolate);
616 if (snapshot_buffer == NULL || snapshot_size == NULL) { 616 if (buffer == NULL) {
617 return Api::Error("Invalid input parameters to Dart_CreateSnapshot"); 617 return Api::Error("%s expects argument 'buffer' to be non-null.",
618 CURRENT_FUNC);
619 }
620 if (size == NULL) {
621 return Api::Error("%s expects argument 'size' to be non-null.",
622 CURRENT_FUNC);
618 } 623 }
619 const char* msg = CheckIsolateState(isolate, 624 const char* msg = CheckIsolateState(isolate,
620 ClassFinalizer::kGeneratingSnapshot); 625 ClassFinalizer::kGeneratingSnapshot);
621 if (msg != NULL) { 626 if (msg != NULL) {
622 return Api::Error(msg); 627 return Api::Error(msg);
623 } 628 }
624 // Since this is only a snapshot the root library should not be set. 629 // Since this is only a snapshot the root library should not be set.
625 isolate->object_store()->set_root_library(Library::Handle()); 630 isolate->object_store()->set_root_library(Library::Handle());
626 SnapshotWriter writer(true, snapshot_buffer, ApiAllocator); 631 SnapshotWriter writer(Snapshot::kFull, buffer, ApiAllocator);
627 writer.WriteFullSnapshot(); 632 writer.WriteFullSnapshot();
628 *snapshot_size = writer.Size(); 633 *size = writer.Size();
634 return Api::Success();
635 }
636
637
638 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(Dart_Handle library,
639 uint8_t** buffer,
640 intptr_t* size) {
641 Isolate* isolate = Isolate::Current();
642 DARTSCOPE(isolate);
643 if (buffer == NULL) {
644 return Api::Error("%s expects argument 'buffer' to be non-null.",
645 CURRENT_FUNC);
646 }
647 if (size == NULL) {
648 return Api::Error("%s expects argument 'size' to be non-null.",
649 CURRENT_FUNC);
650 }
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);
656 if (msg != NULL) {
657 return Api::Error(msg);
658 }
659 ScriptSnapshotWriter writer(root_lib, buffer, ApiAllocator);
660 writer.WriteScriptSnapshot();
661 *size = writer.Size();
629 return Api::Success(); 662 return Api::Success();
630 } 663 }
631 664
632 665
633 // --- Messages and Ports --- 666 // --- Messages and Ports ---
634 667
635 668
636 DART_EXPORT void Dart_SetMessageCallbacks( 669 DART_EXPORT void Dart_SetMessageCallbacks(
637 Dart_PostMessageCallback post_message_callback, 670 Dart_PostMessageCallback post_message_callback,
638 Dart_ClosePortCallback close_port_callback) { 671 Dart_ClosePortCallback close_port_callback) {
639 Isolate* isolate = Isolate::Current(); 672 Isolate* isolate = Isolate::Current();
640 CHECK_ISOLATE(isolate); 673 CHECK_ISOLATE(isolate);
641 ASSERT(post_message_callback != NULL); 674 ASSERT(post_message_callback != NULL);
642 ASSERT(close_port_callback != NULL); 675 ASSERT(close_port_callback != NULL);
643 isolate->set_post_message_callback(post_message_callback); 676 isolate->set_post_message_callback(post_message_callback);
644 isolate->set_close_port_callback(close_port_callback); 677 isolate->set_close_port_callback(close_port_callback);
645 } 678 }
646 679
647 680
648 static RawInstance* DeserializeMessage(void* data) { 681 static RawInstance* DeserializeMessage(void* data) {
649 // Create a snapshot object using the buffer. 682 // Create a snapshot object using the buffer.
650 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); 683 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data);
651 ASSERT(snapshot->IsPartialSnapshot()); 684 ASSERT(snapshot->IsMessageSnapshot());
652 685
653 // Read object back from the snapshot. 686 // Read object back from the snapshot.
654 Isolate* isolate = Isolate::Current(); 687 Isolate* isolate = Isolate::Current();
655 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store()); 688 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store());
656 Instance& instance = Instance::Handle(); 689 Instance& instance = Instance::Handle();
657 instance ^= reader.ReadObject(); 690 instance ^= reader.ReadObject();
658 return instance.raw(); 691 return instance.raw();
659 } 692 }
660 693
661 694
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 return PortMap::PostMessage(port_id, kNoReplyPort, Api::CastMessage(buffer)); 770 return PortMap::PostMessage(port_id, kNoReplyPort, Api::CastMessage(buffer));
738 } 771 }
739 772
740 773
741 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { 774 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) {
742 Isolate* isolate = Isolate::Current(); 775 Isolate* isolate = Isolate::Current();
743 CHECK_ISOLATE(isolate); 776 CHECK_ISOLATE(isolate);
744 DARTSCOPE_NOCHECKS(isolate); 777 DARTSCOPE_NOCHECKS(isolate);
745 const Object& object = Object::Handle(Api::UnwrapHandle(handle)); 778 const Object& object = Object::Handle(Api::UnwrapHandle(handle));
746 uint8_t* data = NULL; 779 uint8_t* data = NULL;
747 SnapshotWriter writer(false, &data, &allocator); 780 SnapshotWriter writer(Snapshot::kMessage, &data, &allocator);
748 writer.WriteObject(object.raw()); 781 writer.WriteObject(object.raw());
749 writer.FinalizeBuffer(); 782 writer.FinalizeBuffer();
750 return PortMap::PostMessage(port_id, kNoReplyPort, Api::CastMessage(data)); 783 return PortMap::PostMessage(port_id, kNoReplyPort, Api::CastMessage(data));
751 } 784 }
752 785
753 786
754 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { 787 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) {
755 Isolate* isolate = Isolate::Current(); 788 Isolate* isolate = Isolate::Current();
756 DARTSCOPE(isolate); 789 DARTSCOPE(isolate);
757 const String& class_name = String::Handle(String::NewSymbol("SendPortImpl")); 790 const String& class_name = String::Handle(String::NewSymbol("SendPortImpl"));
(...skipping 1444 matching lines...) Expand 10 before | Expand all | Expand 10 after
2202 CompileSource(isolate, 2235 CompileSource(isolate,
2203 library, 2236 library,
2204 url_str, 2237 url_str,
2205 source_str, 2238 source_str,
2206 RawScript::kScript, 2239 RawScript::kScript,
2207 &result); 2240 &result);
2208 return result; 2241 return result;
2209 } 2242 }
2210 2243
2211 2244
2245 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) {
2246 Isolate* isolate = Isolate::Current();
2247 DARTSCOPE(isolate);
2248 if (buffer == NULL) {
2249 return Api::Error("%s expects argument 'buffer' to be non-null.",
2250 CURRENT_FUNC);
2251 }
2252 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
2253 if (!snapshot->IsScriptSnapshot()) {
2254 return Api::Error("%s expects parameter 'buffer' to be a script type"
2255 " snapshot", CURRENT_FUNC);
2256 }
2257 Library& library = Library::Handle(isolate->object_store()->root_library());
2258 if (!library.IsNull()) {
2259 const String& library_url = String::Handle(library.url());
2260 return Api::Error("%s: A script has already been loaded from '%s'.",
2261 CURRENT_FUNC, library_url.ToCString());
2262 }
2263 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store());
2264 const Object& tmp = Object::Handle(reader.ReadObject());
2265 if (!tmp.IsLibrary()) {
2266 return Api::Error("%s: Unable to deserialize snapshot correctly.",
2267 CURRENT_FUNC);
2268 }
2269 library ^= tmp.raw();
2270 isolate->object_store()->set_root_library(library);
2271 return Api::NewLocalHandle(library);
2272 }
2273
2274
2212 DEFINE_FLAG(bool, compile_all, false, "Eagerly compile all code."); 2275 DEFINE_FLAG(bool, compile_all, false, "Eagerly compile all code.");
2213 2276
2214 static void CompileAll(Isolate* isolate, Dart_Handle* result) { 2277 static void CompileAll(Isolate* isolate, Dart_Handle* result) {
2215 *result = Api::Success(); 2278 *result = Api::Success();
2216 if (FLAG_compile_all) { 2279 if (FLAG_compile_all) {
2217 ASSERT(isolate != NULL); 2280 ASSERT(isolate != NULL);
2218 LongJump* base = isolate->long_jump_base(); 2281 LongJump* base = isolate->long_jump_base();
2219 LongJump jump; 2282 LongJump jump;
2220 isolate->set_long_jump_base(&jump); 2283 isolate->set_long_jump_base(&jump);
2221 if (setjmp(*jump.Set()) == 0) { 2284 if (setjmp(*jump.Set()) == 0) {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
2407 } 2470 }
2408 delete debug_region; 2471 delete debug_region;
2409 } else { 2472 } else {
2410 *buffer = NULL; 2473 *buffer = NULL;
2411 *buffer_size = 0; 2474 *buffer_size = 0;
2412 } 2475 }
2413 } 2476 }
2414 2477
2415 2478
2416 } // namespace dart 2479 } // namespace dart
OLDNEW
« no previous file with comments | « tests/vm/vm.status ('k') | vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698