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

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
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(I->object_store()->libraries());
6212 Library& lib = Library::Handle();
6213 Class& cls = Class::Handle();
6214 Error& error = Error::Handle();
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);
Florian Schneider 2016/05/03 09:20:35 Why do all classes need to be finalized?
rmacnak 2016/05/03 19:54:20 It's not required now, the idea is to do some work
6224 if (!error.IsNull()) {
6225 return Api::NewHandle(T, error.raw());
6226 }
6227 }
6228 }
6229
6230 return Api::Success();
6231 }
6232
6233
6234 DART_EXPORT Dart_Handle Dart_CreatePrecompiledJITSnapshotBlob(
6235 uint8_t** vm_isolate_snapshot_buffer,
6236 intptr_t* vm_isolate_snapshot_size,
6237 uint8_t** isolate_snapshot_buffer,
6238 intptr_t* isolate_snapshot_size,
6239 uint8_t** instructions_blob_buffer,
6240 intptr_t* instructions_blob_size,
6241 uint8_t** rodata_blob_buffer,
6242 intptr_t* rodata_blob_size) {
6243 ASSERT(FLAG_load_deferred_eagerly);
6244 API_TIMELINE_DURATION;
6245 DARTSCOPE(Thread::Current());
6246 Isolate* I = T->isolate();
6247 if (vm_isolate_snapshot_buffer == NULL) {
6248 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer);
6249 }
6250 if (vm_isolate_snapshot_size == NULL) {
6251 RETURN_NULL_ERROR(vm_isolate_snapshot_size);
6252 }
6253 if (isolate_snapshot_buffer == NULL) {
6254 RETURN_NULL_ERROR(isolate_snapshot_buffer);
6255 }
6256 if (isolate_snapshot_size == NULL) {
6257 RETURN_NULL_ERROR(isolate_snapshot_size);
6258 }
6259 if (instructions_blob_buffer == NULL) {
6260 RETURN_NULL_ERROR(instructions_blob_buffer);
6261 }
6262 if (instructions_blob_size == NULL) {
6263 RETURN_NULL_ERROR(instructions_blob_size);
6264 }
6265 if (rodata_blob_buffer == NULL) {
6266 RETURN_NULL_ERROR(instructions_blob_buffer);
6267 }
6268 if (rodata_blob_size == NULL) {
6269 RETURN_NULL_ERROR(instructions_blob_size);
6270 }
6271 // Finalize all classes if needed.
6272 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T);
6273 if (::Dart_IsError(state)) {
6274 return state;
6275 }
6276 I->heap()->CollectAllGarbage();
6277 I->StopBackgroundCompiler();
6278
6279 BlobInstructionsWriter instructions_writer(instructions_blob_buffer,
6280 rodata_blob_buffer,
6281 ApiReallocate,
6282 2 * MB /* initial_size */);
6283 FullSnapshotWriter writer(Snapshot::kAppWithJIT,
6284 vm_isolate_snapshot_buffer,
6285 isolate_snapshot_buffer,
6286 ApiReallocate,
6287 &instructions_writer,
6288 false /* vm_isolate_is_symbolic */);
6289 writer.WriteFullSnapshot();
6290 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize();
6291 *isolate_snapshot_size = writer.IsolateSnapshotSize();
6292 *instructions_blob_size = instructions_writer.InstructionsBlobSize();
6293 *rodata_blob_size = instructions_writer.RodataBlobSize();
6294
6295 return Api::Success();
6296 }
6297
6298
6198 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { 6299 DART_EXPORT bool Dart_IsRunningPrecompiledCode() {
6199 return Dart::IsRunningPrecompiledCode(); 6300 return Snapshot::IncludesCode(Dart::snapshot_kind());
6200 } 6301 }
6201 6302
6202 } // namespace dart 6303 } // namespace dart
OLDNEW
« runtime/vm/dart.cc ('K') | « runtime/vm/dart.cc ('k') | runtime/vm/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698