| 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 15 matching lines...) Expand all Loading... |
| 26 #include "vm/stack_frame.h" | 26 #include "vm/stack_frame.h" |
| 27 #include "vm/symbols.h" | 27 #include "vm/symbols.h" |
| 28 #include "vm/timer.h" | 28 #include "vm/timer.h" |
| 29 #include "vm/unicode.h" | 29 #include "vm/unicode.h" |
| 30 #include "vm/verifier.h" | 30 #include "vm/verifier.h" |
| 31 #include "vm/version.h" | 31 #include "vm/version.h" |
| 32 | 32 |
| 33 namespace dart { | 33 namespace dart { |
| 34 | 34 |
| 35 DECLARE_FLAG(bool, print_class_table); | 35 DECLARE_FLAG(bool, print_class_table); |
| 36 DECLARE_FLAG(bool, use_cha); | |
| 37 | 36 |
| 38 ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey; | 37 ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey; |
| 39 | 38 |
| 40 | 39 |
| 41 const char* CanonicalFunction(const char* func) { | 40 const char* CanonicalFunction(const char* func) { |
| 42 if (strncmp(func, "dart::", 6) == 0) { | 41 if (strncmp(func, "dart::", 6) == 0) { |
| 43 return func + 6; | 42 return func + 6; |
| 44 } else { | 43 } else { |
| 45 return func; | 44 return func; |
| 46 } | 45 } |
| (...skipping 3948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3995 } | 3994 } |
| 3996 } else { | 3995 } else { |
| 3997 *result = Api::NewHandle(isolate, error.raw()); | 3996 *result = Api::NewHandle(isolate, error.raw()); |
| 3998 if (update_lib_status) { | 3997 if (update_lib_status) { |
| 3999 lib.SetLoadError(); | 3998 lib.SetLoadError(); |
| 4000 } | 3999 } |
| 4001 } | 4000 } |
| 4002 } | 4001 } |
| 4003 | 4002 |
| 4004 | 4003 |
| 4005 // Removes optimized code once we load more classes, since --use_cha based | |
| 4006 // optimizations may have become invalid. | |
| 4007 // TODO(srdjan): Note which functions use which CHA decision and deoptimize | |
| 4008 // only the necessary ones. | |
| 4009 static void RemoveOptimizedCode() { | |
| 4010 ASSERT(FLAG_use_cha); | |
| 4011 // Deoptimize all live frames. | |
| 4012 DeoptimizeAll(); | |
| 4013 // Switch all functions' code to unoptimized. | |
| 4014 const ClassTable& class_table = *Isolate::Current()->class_table(); | |
| 4015 Class& cls = Class::Handle(); | |
| 4016 Array& array = Array::Handle(); | |
| 4017 Function& function = Function::Handle(); | |
| 4018 const intptr_t num_cids = class_table.NumCids(); | |
| 4019 for (intptr_t i = kInstanceCid; i < num_cids; i++) { | |
| 4020 if (!class_table.HasValidClassAt(i)) continue; | |
| 4021 cls = class_table.At(i); | |
| 4022 ASSERT(!cls.IsNull()); | |
| 4023 array = cls.functions(); | |
| 4024 intptr_t num_functions = array.IsNull() ? 0 : array.Length(); | |
| 4025 for (intptr_t f = 0; f < num_functions; f++) { | |
| 4026 function ^= array.At(f); | |
| 4027 ASSERT(!function.IsNull()); | |
| 4028 if (function.HasOptimizedCode()) { | |
| 4029 function.SwitchToUnoptimizedCode(); | |
| 4030 } | |
| 4031 } | |
| 4032 } | |
| 4033 } | |
| 4034 | |
| 4035 | |
| 4036 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, | 4004 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, |
| 4037 Dart_Handle source) { | 4005 Dart_Handle source) { |
| 4038 TIMERSCOPE(time_script_loading); | 4006 TIMERSCOPE(time_script_loading); |
| 4039 Isolate* isolate = Isolate::Current(); | 4007 Isolate* isolate = Isolate::Current(); |
| 4040 DARTSCOPE(isolate); | 4008 DARTSCOPE(isolate); |
| 4041 if (FLAG_use_cha) { | |
| 4042 RemoveOptimizedCode(); | |
| 4043 } | |
| 4044 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4009 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 4045 if (url_str.IsNull()) { | 4010 if (url_str.IsNull()) { |
| 4046 RETURN_TYPE_ERROR(isolate, url, String); | 4011 RETURN_TYPE_ERROR(isolate, url, String); |
| 4047 } | 4012 } |
| 4048 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 4013 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
| 4049 if (source_str.IsNull()) { | 4014 if (source_str.IsNull()) { |
| 4050 RETURN_TYPE_ERROR(isolate, source, String); | 4015 RETURN_TYPE_ERROR(isolate, source, String); |
| 4051 } | 4016 } |
| 4052 Library& library = | 4017 Library& library = |
| 4053 Library::Handle(isolate, isolate->object_store()->root_library()); | 4018 Library::Handle(isolate, isolate->object_store()->root_library()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4071 } | 4036 } |
| 4072 | 4037 |
| 4073 | 4038 |
| 4074 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) { | 4039 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) { |
| 4075 Isolate* isolate = Isolate::Current(); | 4040 Isolate* isolate = Isolate::Current(); |
| 4076 DARTSCOPE(isolate); | 4041 DARTSCOPE(isolate); |
| 4077 TIMERSCOPE(time_script_loading); | 4042 TIMERSCOPE(time_script_loading); |
| 4078 if (buffer == NULL) { | 4043 if (buffer == NULL) { |
| 4079 RETURN_NULL_ERROR(buffer); | 4044 RETURN_NULL_ERROR(buffer); |
| 4080 } | 4045 } |
| 4081 if (FLAG_use_cha) { | |
| 4082 RemoveOptimizedCode(); | |
| 4083 } | |
| 4084 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 4046 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
| 4085 if (!snapshot->IsScriptSnapshot()) { | 4047 if (!snapshot->IsScriptSnapshot()) { |
| 4086 return Api::NewError("%s expects parameter 'buffer' to be a script type" | 4048 return Api::NewError("%s expects parameter 'buffer' to be a script type" |
| 4087 " snapshot.", CURRENT_FUNC); | 4049 " snapshot.", CURRENT_FUNC); |
| 4088 } | 4050 } |
| 4089 Library& library = | 4051 Library& library = |
| 4090 Library::Handle(isolate, isolate->object_store()->root_library()); | 4052 Library::Handle(isolate, isolate->object_store()->root_library()); |
| 4091 if (!library.IsNull()) { | 4053 if (!library.IsNull()) { |
| 4092 const String& library_url = String::Handle(isolate, library.url()); | 4054 const String& library_url = String::Handle(isolate, library.url()); |
| 4093 return Api::NewError("%s: A script has already been loaded from '%s'.", | 4055 return Api::NewError("%s: A script has already been loaded from '%s'.", |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4245 return Api::NewHandle(isolate, library.raw()); | 4207 return Api::NewHandle(isolate, library.raw()); |
| 4246 } | 4208 } |
| 4247 } | 4209 } |
| 4248 | 4210 |
| 4249 | 4211 |
| 4250 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, | 4212 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, |
| 4251 Dart_Handle source) { | 4213 Dart_Handle source) { |
| 4252 TIMERSCOPE(time_script_loading); | 4214 TIMERSCOPE(time_script_loading); |
| 4253 Isolate* isolate = Isolate::Current(); | 4215 Isolate* isolate = Isolate::Current(); |
| 4254 DARTSCOPE(isolate); | 4216 DARTSCOPE(isolate); |
| 4255 if (FLAG_use_cha) { | |
| 4256 RemoveOptimizedCode(); | |
| 4257 } | |
| 4258 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4217 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 4259 if (url_str.IsNull()) { | 4218 if (url_str.IsNull()) { |
| 4260 RETURN_TYPE_ERROR(isolate, url, String); | 4219 RETURN_TYPE_ERROR(isolate, url, String); |
| 4261 } | 4220 } |
| 4262 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 4221 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
| 4263 if (source_str.IsNull()) { | 4222 if (source_str.IsNull()) { |
| 4264 RETURN_TYPE_ERROR(isolate, source, String); | 4223 RETURN_TYPE_ERROR(isolate, source, String); |
| 4265 } | 4224 } |
| 4266 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str)); | 4225 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str)); |
| 4267 if (library.IsNull()) { | 4226 if (library.IsNull()) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4337 return Api::Success(isolate); | 4296 return Api::Success(isolate); |
| 4338 } | 4297 } |
| 4339 | 4298 |
| 4340 | 4299 |
| 4341 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, | 4300 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, |
| 4342 Dart_Handle url, | 4301 Dart_Handle url, |
| 4343 Dart_Handle source) { | 4302 Dart_Handle source) { |
| 4344 TIMERSCOPE(time_script_loading); | 4303 TIMERSCOPE(time_script_loading); |
| 4345 Isolate* isolate = Isolate::Current(); | 4304 Isolate* isolate = Isolate::Current(); |
| 4346 DARTSCOPE(isolate); | 4305 DARTSCOPE(isolate); |
| 4347 if (FLAG_use_cha) { | |
| 4348 RemoveOptimizedCode(); | |
| 4349 } | |
| 4350 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 4306 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 4351 if (lib.IsNull()) { | 4307 if (lib.IsNull()) { |
| 4352 RETURN_TYPE_ERROR(isolate, library, Library); | 4308 RETURN_TYPE_ERROR(isolate, library, Library); |
| 4353 } | 4309 } |
| 4354 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4310 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 4355 if (url_str.IsNull()) { | 4311 if (url_str.IsNull()) { |
| 4356 RETURN_TYPE_ERROR(isolate, url, String); | 4312 RETURN_TYPE_ERROR(isolate, url, String); |
| 4357 } | 4313 } |
| 4358 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 4314 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
| 4359 if (source_str.IsNull()) { | 4315 if (source_str.IsNull()) { |
| 4360 RETURN_TYPE_ERROR(isolate, source, String); | 4316 RETURN_TYPE_ERROR(isolate, source, String); |
| 4361 } | 4317 } |
| 4362 Dart_Handle result; | 4318 Dart_Handle result; |
| 4363 CompileSource(isolate, lib, url_str, source_str, | 4319 CompileSource(isolate, lib, url_str, source_str, |
| 4364 RawScript::kSourceTag, &result); | 4320 RawScript::kSourceTag, &result); |
| 4365 return result; | 4321 return result; |
| 4366 } | 4322 } |
| 4367 | 4323 |
| 4368 | 4324 |
| 4369 DART_EXPORT Dart_Handle Dart_LoadPatch(Dart_Handle library, | 4325 DART_EXPORT Dart_Handle Dart_LoadPatch(Dart_Handle library, |
| 4370 Dart_Handle url, | 4326 Dart_Handle url, |
| 4371 Dart_Handle patch_source) { | 4327 Dart_Handle patch_source) { |
| 4372 TIMERSCOPE(time_script_loading); | 4328 TIMERSCOPE(time_script_loading); |
| 4373 Isolate* isolate = Isolate::Current(); | 4329 Isolate* isolate = Isolate::Current(); |
| 4374 DARTSCOPE(isolate); | 4330 DARTSCOPE(isolate); |
| 4375 if (FLAG_use_cha) { | |
| 4376 RemoveOptimizedCode(); | |
| 4377 } | |
| 4378 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 4331 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 4379 if (lib.IsNull()) { | 4332 if (lib.IsNull()) { |
| 4380 RETURN_TYPE_ERROR(isolate, library, Library); | 4333 RETURN_TYPE_ERROR(isolate, library, Library); |
| 4381 } | 4334 } |
| 4382 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4335 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 4383 if (url_str.IsNull()) { | 4336 if (url_str.IsNull()) { |
| 4384 RETURN_TYPE_ERROR(isolate, url, String); | 4337 RETURN_TYPE_ERROR(isolate, url, String); |
| 4385 } | 4338 } |
| 4386 const String& source_str = Api::UnwrapStringHandle(isolate, patch_source); | 4339 const String& source_str = Api::UnwrapStringHandle(isolate, patch_source); |
| 4387 if (source_str.IsNull()) { | 4340 if (source_str.IsNull()) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4481 } | 4434 } |
| 4482 { | 4435 { |
| 4483 NoGCScope no_gc; | 4436 NoGCScope no_gc; |
| 4484 RawObject* raw_obj = obj.raw(); | 4437 RawObject* raw_obj = obj.raw(); |
| 4485 isolate->heap()->SetPeer(raw_obj, peer); | 4438 isolate->heap()->SetPeer(raw_obj, peer); |
| 4486 } | 4439 } |
| 4487 return Api::Success(isolate); | 4440 return Api::Success(isolate); |
| 4488 } | 4441 } |
| 4489 | 4442 |
| 4490 } // namespace dart | 4443 } // namespace dart |
| OLD | NEW |