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

Side by Side Diff: vm/dart_api_impl.cc

Issue 9018002: Refactor some of the snapshot writer classes to eliminate code duplication. (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 | « no previous file | vm/snapshot.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 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 } 643 }
644 const char* msg = CheckIsolateState(isolate, 644 const char* msg = CheckIsolateState(isolate,
645 ClassFinalizer::kGeneratingSnapshot); 645 ClassFinalizer::kGeneratingSnapshot);
646 if (msg != NULL) { 646 if (msg != NULL) {
647 return Api::Error(msg); 647 return Api::Error(msg);
648 } 648 }
649 // Since this is only a snapshot the root library should not be set. 649 // Since this is only a snapshot the root library should not be set.
650 isolate->object_store()->set_root_library(Library::Handle()); 650 isolate->object_store()->set_root_library(Library::Handle());
651 SnapshotWriter writer(Snapshot::kFull, buffer, ApiAllocator); 651 SnapshotWriter writer(Snapshot::kFull, buffer, ApiAllocator);
652 writer.WriteFullSnapshot(); 652 writer.WriteFullSnapshot();
653 *size = writer.Size(); 653 *size = writer.BytesWritten();
654 return Api::Success(); 654 return Api::Success();
655 } 655 }
656 656
657 657
658 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, 658 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer,
659 intptr_t* size) { 659 intptr_t* size) {
660 Isolate* isolate = Isolate::Current(); 660 Isolate* isolate = Isolate::Current();
661 DARTSCOPE(isolate); 661 DARTSCOPE(isolate);
662 TIMERSCOPE(time_creating_snapshot); 662 TIMERSCOPE(time_creating_snapshot);
663 if (buffer == NULL) { 663 if (buffer == NULL) {
664 return Api::Error("%s expects argument 'buffer' to be non-null.", 664 return Api::Error("%s expects argument 'buffer' to be non-null.",
665 CURRENT_FUNC); 665 CURRENT_FUNC);
666 } 666 }
667 if (size == NULL) { 667 if (size == NULL) {
668 return Api::Error("%s expects argument 'size' to be non-null.", 668 return Api::Error("%s expects argument 'size' to be non-null.",
669 CURRENT_FUNC); 669 CURRENT_FUNC);
670 } 670 }
671 const char* msg = CheckIsolateState(isolate); 671 const char* msg = CheckIsolateState(isolate);
672 if (msg != NULL) { 672 if (msg != NULL) {
673 return Api::Error(msg); 673 return Api::Error(msg);
674 } 674 }
675 Library& library = Library::Handle(isolate->object_store()->root_library()); 675 Library& library = Library::Handle(isolate->object_store()->root_library());
676 if (library.IsNull()) { 676 if (library.IsNull()) {
677 return Api::Error("%s expects the isolate to have a script loaded in it.", 677 return Api::Error("%s expects the isolate to have a script loaded in it.",
678 CURRENT_FUNC); 678 CURRENT_FUNC);
679 } 679 }
680 ScriptSnapshotWriter writer(buffer, ApiAllocator); 680 ScriptSnapshotWriter writer(buffer, ApiAllocator);
681 writer.WriteScriptSnapshot(library); 681 writer.WriteScriptSnapshot(library);
682 *size = writer.Size(); 682 *size = writer.BytesWritten();
683 return Api::Success(); 683 return Api::Success();
684 } 684 }
685 685
686 686
687 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { 687 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) {
688 if (isolate == NULL) { 688 if (isolate == NULL) {
689 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); 689 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC);
690 } 690 }
691 Isolate* iso = reinterpret_cast<Isolate*>(isolate); 691 Isolate* iso = reinterpret_cast<Isolate*>(isolate);
692 iso->ScheduleInterrupts(Isolate::kApiInterrupt); 692 iso->ScheduleInterrupts(Isolate::kApiInterrupt);
(...skipping 1842 matching lines...) Expand 10 before | Expand all | Expand 10 after
2535 } 2535 }
2536 delete debug_region; 2536 delete debug_region;
2537 } else { 2537 } else {
2538 *buffer = NULL; 2538 *buffer = NULL;
2539 *buffer_size = 0; 2539 *buffer_size = 0;
2540 } 2540 }
2541 } 2541 }
2542 2542
2543 2543
2544 } // namespace dart 2544 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | vm/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698