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

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 1938653002: JIT precompilated snapshots. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months 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
« no previous file with comments | « runtime/vm/dart.cc ('k') | runtime/vm/megamorphic_cache_table.cc » ('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) 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 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 Dart_IsolateInterruptCallback interrupt, 1141 Dart_IsolateInterruptCallback interrupt,
1142 Dart_IsolateUnhandledExceptionCallback unhandled, 1142 Dart_IsolateUnhandledExceptionCallback unhandled,
1143 Dart_IsolateShutdownCallback shutdown, 1143 Dart_IsolateShutdownCallback shutdown,
1144 Dart_ThreadExitCallback thread_exit, 1144 Dart_ThreadExitCallback thread_exit,
1145 Dart_FileOpenCallback file_open, 1145 Dart_FileOpenCallback file_open,
1146 Dart_FileReadCallback file_read, 1146 Dart_FileReadCallback file_read,
1147 Dart_FileWriteCallback file_write, 1147 Dart_FileWriteCallback file_write,
1148 Dart_FileCloseCallback file_close, 1148 Dart_FileCloseCallback file_close,
1149 Dart_EntropySource entropy_source, 1149 Dart_EntropySource entropy_source,
1150 Dart_GetVMServiceAssetsArchive get_service_assets) { 1150 Dart_GetVMServiceAssetsArchive get_service_assets) {
1151 if ((instructions_snapshot != NULL) && !FLAG_precompiled_runtime) {
1152 return strdup("Flag --precompilation was not specified.");
1153 }
1154 if (interrupt != NULL) { 1151 if (interrupt != NULL) {
1155 return strdup("Dart_Initialize: " 1152 return strdup("Dart_Initialize: "
1156 "Setting of interrupt callback is not supported."); 1153 "Setting of interrupt callback is not supported.");
1157 } 1154 }
1158 if (unhandled != NULL) { 1155 if (unhandled != NULL) {
1159 return strdup("Dart_Initialize: " 1156 return strdup("Dart_Initialize: "
1160 "Setting of unhandled exception callback is not supported."); 1157 "Setting of unhandled exception callback is not supported.");
1161 } 1158 }
1162 const char* err_msg = Dart::InitOnce(vm_isolate_snapshot, 1159 const char* err_msg = Dart::InitOnce(vm_isolate_snapshot,
1163 instructions_snapshot, 1160 instructions_snapshot,
(...skipping 2658 matching lines...) Expand 10 before | Expand all | Expand 10 after
3822 redirect_type ^= redirect_type.Canonicalize(); 3819 redirect_type ^= redirect_type.Canonicalize();
3823 } 3820 }
3824 3821
3825 type_obj = redirect_type.raw(); 3822 type_obj = redirect_type.raw();
3826 type_arguments = redirect_type.arguments(); 3823 type_arguments = redirect_type.arguments();
3827 3824
3828 cls = type_obj.type_class(); 3825 cls = type_obj.type_class();
3829 } 3826 }
3830 if (constructor.IsGenerativeConstructor()) { 3827 if (constructor.IsGenerativeConstructor()) {
3831 #if defined(DEBUG) 3828 #if defined(DEBUG)
3832 if (!cls.is_allocated() && Dart::IsRunningPrecompiledCode()) { 3829 if (!cls.is_allocated() && (Dart::snapshot_kind() == Snapshot::kAppNoJIT)) {
3833 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); 3830 return Api::NewError("Precompilation dropped '%s'", cls.ToCString());
3834 } 3831 }
3835 #endif 3832 #endif
3836 // Create the new object. 3833 // Create the new object.
3837 new_object = Instance::New(cls); 3834 new_object = Instance::New(cls);
3838 } 3835 }
3839 3836
3840 // Create the argument list. 3837 // Create the argument list.
3841 intptr_t arg_index = 0; 3838 intptr_t arg_index = 0;
3842 int extra_args = 1; 3839 int extra_args = 1;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
3917 DARTSCOPE(Thread::Current()); 3914 DARTSCOPE(Thread::Current());
3918 CHECK_CALLBACK_STATE(T); 3915 CHECK_CALLBACK_STATE(T);
3919 3916
3920 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); 3917 const Type& type_obj = Api::UnwrapTypeHandle(Z, type);
3921 // Get the class to instantiate. 3918 // Get the class to instantiate.
3922 if (type_obj.IsNull()) { 3919 if (type_obj.IsNull()) {
3923 RETURN_TYPE_ERROR(Z, type, Type); 3920 RETURN_TYPE_ERROR(Z, type, Type);
3924 } 3921 }
3925 const Class& cls = Class::Handle(Z, type_obj.type_class()); 3922 const Class& cls = Class::Handle(Z, type_obj.type_class());
3926 #if defined(DEBUG) 3923 #if defined(DEBUG)
3927 if (!cls.is_allocated() && Dart::IsRunningPrecompiledCode()) { 3924 if (!cls.is_allocated() && (Dart::snapshot_kind() == Snapshot::kAppNoJIT)) {
3928 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); 3925 return Api::NewError("Precompilation dropped '%s'", cls.ToCString());
3929 } 3926 }
3930 #endif 3927 #endif
3931 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); 3928 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T));
3932 if (!error.IsNull()) { 3929 if (!error.IsNull()) {
3933 // An error occurred, return error object. 3930 // An error occurred, return error object.
3934 return Api::NewHandle(T, error.raw()); 3931 return Api::NewHandle(T, error.raw());
3935 } 3932 }
3936 return Api::NewHandle(T, AllocateObject(T, cls)); 3933 return Api::NewHandle(T, AllocateObject(T, cls));
3937 } 3934 }
3938 3935
3939 3936
3940 DART_EXPORT Dart_Handle Dart_AllocateWithNativeFields( 3937 DART_EXPORT Dart_Handle Dart_AllocateWithNativeFields(
3941 Dart_Handle type, 3938 Dart_Handle type,
3942 intptr_t num_native_fields, 3939 intptr_t num_native_fields,
3943 const intptr_t* native_fields) { 3940 const intptr_t* native_fields) {
3944 DARTSCOPE(Thread::Current()); 3941 DARTSCOPE(Thread::Current());
3945 CHECK_CALLBACK_STATE(T); 3942 CHECK_CALLBACK_STATE(T);
3946 3943
3947 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); 3944 const Type& type_obj = Api::UnwrapTypeHandle(Z, type);
3948 // Get the class to instantiate. 3945 // Get the class to instantiate.
3949 if (type_obj.IsNull()) { 3946 if (type_obj.IsNull()) {
3950 RETURN_TYPE_ERROR(Z, type, Type); 3947 RETURN_TYPE_ERROR(Z, type, Type);
3951 } 3948 }
3952 if (native_fields == NULL) { 3949 if (native_fields == NULL) {
3953 RETURN_NULL_ERROR(native_fields); 3950 RETURN_NULL_ERROR(native_fields);
3954 } 3951 }
3955 const Class& cls = Class::Handle(Z, type_obj.type_class()); 3952 const Class& cls = Class::Handle(Z, type_obj.type_class());
3956 #if defined(DEBUG) 3953 #if defined(DEBUG)
3957 if (!cls.is_allocated() && Dart::IsRunningPrecompiledCode()) { 3954 if (!cls.is_allocated() && (Dart::snapshot_kind() == Snapshot::kAppNoJIT)) {
3958 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); 3955 return Api::NewError("Precompilation dropped '%s'", cls.ToCString());
3959 } 3956 }
3960 #endif 3957 #endif
3961 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); 3958 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T));
3962 if (!error.IsNull()) { 3959 if (!error.IsNull()) {
3963 // An error occurred, return error object. 3960 // An error occurred, return error object.
3964 return Api::NewHandle(T, error.raw()); 3961 return Api::NewHandle(T, error.raw());
3965 } 3962 }
3966 if (num_native_fields != cls.num_native_fields()) { 3963 if (num_native_fields != cls.num_native_fields()) {
3967 return Api::NewError( 3964 return Api::NewError(
(...skipping 2146 matching lines...) Expand 10 before | Expand all | Expand 10 after
6114 if (assembly_buffer == NULL) { 6111 if (assembly_buffer == NULL) {
6115 RETURN_NULL_ERROR(assembly_buffer); 6112 RETURN_NULL_ERROR(assembly_buffer);
6116 } 6113 }
6117 if (assembly_size == NULL) { 6114 if (assembly_size == NULL) {
6118 RETURN_NULL_ERROR(assembly_size); 6115 RETURN_NULL_ERROR(assembly_size);
6119 } 6116 }
6120 I->heap()->CollectAllGarbage(); 6117 I->heap()->CollectAllGarbage();
6121 AssemblyInstructionsWriter instructions_writer(assembly_buffer, 6118 AssemblyInstructionsWriter instructions_writer(assembly_buffer,
6122 ApiReallocate, 6119 ApiReallocate,
6123 2 * MB /* initial_size */); 6120 2 * MB /* initial_size */);
6124 PrecompiledSnapshotWriter writer(vm_isolate_snapshot_buffer, 6121 FullSnapshotWriter writer(Snapshot::kAppNoJIT,
6125 isolate_snapshot_buffer, 6122 vm_isolate_snapshot_buffer,
6126 ApiReallocate, 6123 isolate_snapshot_buffer,
6127 &instructions_writer); 6124 ApiReallocate,
6125 &instructions_writer,
6126 false /* vm_isolate_is_symbolic */);
6127
6128 writer.WriteFullSnapshot(); 6128 writer.WriteFullSnapshot();
6129 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); 6129 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize();
6130 *isolate_snapshot_size = writer.IsolateSnapshotSize(); 6130 *isolate_snapshot_size = writer.IsolateSnapshotSize();
6131 *assembly_size = instructions_writer.AssemblySize(); 6131 *assembly_size = instructions_writer.AssemblySize();
6132 6132
6133 return Api::Success(); 6133 return Api::Success();
6134 } 6134 }
6135 6135
6136 6136
6137 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshotBlob( 6137 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshotBlob(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
6173 RETURN_NULL_ERROR(instructions_blob_buffer); 6173 RETURN_NULL_ERROR(instructions_blob_buffer);
6174 } 6174 }
6175 if (rodata_blob_size == NULL) { 6175 if (rodata_blob_size == NULL) {
6176 RETURN_NULL_ERROR(instructions_blob_size); 6176 RETURN_NULL_ERROR(instructions_blob_size);
6177 } 6177 }
6178 I->heap()->CollectAllGarbage(); 6178 I->heap()->CollectAllGarbage();
6179 BlobInstructionsWriter instructions_writer(instructions_blob_buffer, 6179 BlobInstructionsWriter instructions_writer(instructions_blob_buffer,
6180 rodata_blob_buffer, 6180 rodata_blob_buffer,
6181 ApiReallocate, 6181 ApiReallocate,
6182 2 * MB /* initial_size */); 6182 2 * MB /* initial_size */);
6183 PrecompiledSnapshotWriter writer(vm_isolate_snapshot_buffer, 6183 FullSnapshotWriter writer(Snapshot::kAppNoJIT,
6184 isolate_snapshot_buffer, 6184 vm_isolate_snapshot_buffer,
6185 ApiReallocate, 6185 isolate_snapshot_buffer,
6186 &instructions_writer); 6186 ApiReallocate,
6187 &instructions_writer,
6188 false /* vm_isolate_is_symbolic */);
6189
6187 writer.WriteFullSnapshot(); 6190 writer.WriteFullSnapshot();
6188 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); 6191 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize();
6189 *isolate_snapshot_size = writer.IsolateSnapshotSize(); 6192 *isolate_snapshot_size = writer.IsolateSnapshotSize();
6190 *instructions_blob_size = instructions_writer.InstructionsBlobSize(); 6193 *instructions_blob_size = instructions_writer.InstructionsBlobSize();
6191 *rodata_blob_size = instructions_writer.RodataBlobSize(); 6194 *rodata_blob_size = instructions_writer.RodataBlobSize();
6192 6195
6193 return Api::Success(); 6196 return Api::Success();
6194 } 6197 }
6195 #endif // DART_PRECOMPILER 6198 #endif // DART_PRECOMPILER
6196 6199
6197 6200
6201 DART_EXPORT Dart_Handle Dart_PrecompileJIT() {
6202 API_TIMELINE_BEGIN_END;
6203 DARTSCOPE(Thread::Current());
6204 Isolate* I = T->isolate();
6205 Dart_Handle result = Api::CheckAndFinalizePendingClasses(T);
6206 if (::Dart_IsError(result)) {
6207 return result;
6208 }
6209 CHECK_CALLBACK_STATE(T);
6210 GrowableObjectArray& libraries =
6211 GrowableObjectArray::Handle(Z, I->object_store()->libraries());
6212 Library& lib = Library::Handle(Z);
6213 Class& cls = Class::Handle(Z);
6214 Error& error = Error::Handle(Z);
6215 for (intptr_t i = 0; i < libraries.Length(); i++) {
6216 lib ^= libraries.At(i);
6217 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate);
6218 while (it.HasNext()) {
6219 cls = it.GetNextClass();
6220 if (cls.IsDynamicClass()) {
6221 continue; // class 'dynamic' is in the read-only VM isolate.
6222 }
6223 error = cls.EnsureIsFinalized(T);
6224 if (!error.IsNull()) {
6225 return Api::NewHandle(T, error.raw());
6226 }
6227 }
6228 }
6229 return Api::Success();
6230 }
6231
6232
6233 DART_EXPORT Dart_Handle Dart_CreatePrecompiledJITSnapshotBlob(
6234 uint8_t** vm_isolate_snapshot_buffer,
6235 intptr_t* vm_isolate_snapshot_size,
6236 uint8_t** isolate_snapshot_buffer,
6237 intptr_t* isolate_snapshot_size,
6238 uint8_t** instructions_blob_buffer,
6239 intptr_t* instructions_blob_size,
6240 uint8_t** rodata_blob_buffer,
6241 intptr_t* rodata_blob_size) {
6242 ASSERT(FLAG_load_deferred_eagerly);
6243 API_TIMELINE_DURATION;
6244 DARTSCOPE(Thread::Current());
6245 Isolate* I = T->isolate();
6246 if (vm_isolate_snapshot_buffer == NULL) {
6247 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer);
6248 }
6249 if (vm_isolate_snapshot_size == NULL) {
6250 RETURN_NULL_ERROR(vm_isolate_snapshot_size);
6251 }
6252 if (isolate_snapshot_buffer == NULL) {
6253 RETURN_NULL_ERROR(isolate_snapshot_buffer);
6254 }
6255 if (isolate_snapshot_size == NULL) {
6256 RETURN_NULL_ERROR(isolate_snapshot_size);
6257 }
6258 if (instructions_blob_buffer == NULL) {
6259 RETURN_NULL_ERROR(instructions_blob_buffer);
6260 }
6261 if (instructions_blob_size == NULL) {
6262 RETURN_NULL_ERROR(instructions_blob_size);
6263 }
6264 if (rodata_blob_buffer == NULL) {
6265 RETURN_NULL_ERROR(instructions_blob_buffer);
6266 }
6267 if (rodata_blob_size == NULL) {
6268 RETURN_NULL_ERROR(instructions_blob_size);
6269 }
6270 // Finalize all classes if needed.
6271 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T);
6272 if (::Dart_IsError(state)) {
6273 return state;
6274 }
6275 I->heap()->CollectAllGarbage();
6276 I->StopBackgroundCompiler();
6277
6278 BlobInstructionsWriter instructions_writer(instructions_blob_buffer,
6279 rodata_blob_buffer,
6280 ApiReallocate,
6281 2 * MB /* initial_size */);
6282 FullSnapshotWriter writer(Snapshot::kAppWithJIT,
6283 vm_isolate_snapshot_buffer,
6284 isolate_snapshot_buffer,
6285 ApiReallocate,
6286 &instructions_writer,
6287 false /* vm_isolate_is_symbolic */);
6288 writer.WriteFullSnapshot();
6289 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize();
6290 *isolate_snapshot_size = writer.IsolateSnapshotSize();
6291 *instructions_blob_size = instructions_writer.InstructionsBlobSize();
6292 *rodata_blob_size = instructions_writer.RodataBlobSize();
6293
6294 return Api::Success();
6295 }
6296
6297
6198 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { 6298 DART_EXPORT bool Dart_IsRunningPrecompiledCode() {
6199 return Dart::IsRunningPrecompiledCode(); 6299 return Snapshot::IncludesCode(Dart::snapshot_kind());
6200 } 6300 }
6201 6301
6202 } // namespace dart 6302 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart.cc ('k') | runtime/vm/megamorphic_cache_table.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698