OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 } \ | 78 } \ |
79 } while (0) | 79 } while (0) |
80 | 80 |
81 | 81 |
82 // Return error if isolate is in an inconsistent state. | 82 // Return error if isolate is in an inconsistent state. |
83 // Return NULL when no error condition exists. | 83 // Return NULL when no error condition exists. |
84 // | 84 // |
85 // TODO(turnidge): Make this function return an error handle directly | 85 // TODO(turnidge): Make this function return an error handle directly |
86 // rather than returning an error string. The current behavior can | 86 // rather than returning an error string. The current behavior can |
87 // cause compilation errors to appear to be api errors. | 87 // cause compilation errors to appear to be api errors. |
88 const char* CheckIsolateState(Isolate* isolate, bool generating_snapshot) { | 88 const char* CheckIsolateState(Isolate* isolate) { |
89 bool success = true; | 89 if (ClassFinalizer::FinalizePendingClasses() && |
90 if (!ClassFinalizer::AllClassesFinalized()) { | 90 isolate->object_store()->PreallocateObjects()) { |
91 success = (generating_snapshot) ? | 91 // Success. |
92 ClassFinalizer::FinalizePendingClassesForSnapshotCreation() : | 92 return NULL; |
93 ClassFinalizer::FinalizePendingClasses(); | |
94 } | |
95 if (success) { | |
96 success = isolate->object_store()->PreallocateObjects(); | |
97 if (success) { | |
98 return NULL; | |
99 } | |
100 } | 93 } |
101 // Make a copy of the error message as the original message string | 94 // Make a copy of the error message as the original message string |
102 // may get deallocated when we return back from the Dart API call. | 95 // may get deallocated when we return back from the Dart API call. |
103 const Error& err = Error::Handle(isolate->object_store()->sticky_error()); | 96 const Error& err = Error::Handle(isolate->object_store()->sticky_error()); |
104 const char* errmsg = err.ToErrorCString(); | 97 const char* errmsg = err.ToErrorCString(); |
105 intptr_t errlen = strlen(errmsg) + 1; | 98 intptr_t errlen = strlen(errmsg) + 1; |
106 char* msg = Api::TopScope(isolate)->zone()->Alloc<char>(errlen); | 99 char* msg = Api::TopScope(isolate)->zone()->Alloc<char>(errlen); |
107 OS::SNPrint(msg, errlen, "%s", errmsg); | 100 OS::SNPrint(msg, errlen, "%s", errmsg); |
108 return msg; | 101 return msg; |
109 } | 102 } |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 intptr_t* size) { | 802 intptr_t* size) { |
810 Isolate* isolate = Isolate::Current(); | 803 Isolate* isolate = Isolate::Current(); |
811 DARTSCOPE(isolate); | 804 DARTSCOPE(isolate); |
812 TIMERSCOPE(time_creating_snapshot); | 805 TIMERSCOPE(time_creating_snapshot); |
813 if (buffer == NULL) { | 806 if (buffer == NULL) { |
814 RETURN_NULL_ERROR(buffer); | 807 RETURN_NULL_ERROR(buffer); |
815 } | 808 } |
816 if (size == NULL) { | 809 if (size == NULL) { |
817 RETURN_NULL_ERROR(size); | 810 RETURN_NULL_ERROR(size); |
818 } | 811 } |
819 const char* msg = CheckIsolateState(isolate, | 812 const char* msg = CheckIsolateState(isolate); |
820 ClassFinalizer::kGeneratingSnapshot); | |
821 if (msg != NULL) { | 813 if (msg != NULL) { |
822 return Api::NewError(msg); | 814 return Api::NewError(msg); |
823 } | 815 } |
824 // Since this is only a snapshot the root library should not be set. | 816 // Since this is only a snapshot the root library should not be set. |
825 isolate->object_store()->set_root_library(Library::Handle(isolate)); | 817 isolate->object_store()->set_root_library(Library::Handle(isolate)); |
826 SnapshotWriter writer(Snapshot::kFull, buffer, ApiReallocate); | 818 SnapshotWriter writer(Snapshot::kFull, buffer, ApiReallocate); |
827 writer.WriteFullSnapshot(); | 819 writer.WriteFullSnapshot(); |
828 *size = writer.BytesWritten(); | 820 *size = writer.BytesWritten(); |
829 return Api::Success(isolate); | 821 return Api::Success(isolate); |
830 } | 822 } |
(...skipping 3305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4136 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { | 4128 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { |
4137 Dart::set_perf_events_writer(function); | 4129 Dart::set_perf_events_writer(function); |
4138 } | 4130 } |
4139 | 4131 |
4140 | 4132 |
4141 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { | 4133 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { |
4142 Dart::set_flow_graph_writer(function); | 4134 Dart::set_flow_graph_writer(function); |
4143 } | 4135 } |
4144 | 4136 |
4145 } // namespace dart | 4137 } // namespace dart |
OLD | NEW |