Chromium Code Reviews| Index: runtime/vm/dart_api_impl.cc |
| =================================================================== |
| --- runtime/vm/dart_api_impl.cc (revision 11068) |
| +++ runtime/vm/dart_api_impl.cc (working copy) |
| @@ -32,6 +32,7 @@ |
| namespace dart { |
| DECLARE_FLAG(bool, print_class_table); |
| +DECLARE_FLAG(bool, use_cha); |
| ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey; |
| @@ -3741,11 +3742,42 @@ |
| } |
| +// Removes optimized code once we load more classes, since --use_cha based |
| +// optimizations may have become invalid. |
| +// TODO(srdjan): Note which functions use which CHA decision and deoptimize |
| +// only the necessary ones. |
| +static void RemoveOptimizedCode() { |
| + ASSERT(FLAG_use_cha); |
| + const ClassTable& class_table = *Isolate::Current()->class_table(); |
| + Class& cls = Class::Handle(); |
| + Array& array = Array::Handle(); |
| + Function& function = Function::Handle(); |
| + intptr_t num_cids = class_table.NumCids(); |
|
regis
2012/08/21 20:52:21
const
srdjan
2012/08/21 22:08:15
Done.
|
| + for (intptr_t i = kInstanceCid; i < num_cids; i++) { |
| + if (!class_table.HasValidClassAt(i)) continue; |
| + cls = class_table.At(i); |
| + ASSERT(!cls.IsNull()); |
| + array = cls.functions(); |
| + intptr_t num_functions = array.IsNull() ? 0 : array.Length(); |
| + for (intptr_t f = 0; f < num_functions; f++) { |
| + function ^= array.At(f); |
| + ASSERT(!function.IsNull()); |
| + if (function.HasOptimizedCode()) { |
| + function.SwitchToUnoptimizedCode(); |
| + } |
| + } |
| + } |
| +} |
| + |
| + |
| DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, |
| Dart_Handle source) { |
| TIMERSCOPE(time_script_loading); |
| Isolate* isolate = Isolate::Current(); |
| DARTSCOPE(isolate); |
| + if (FLAG_use_cha) { |
| + RemoveOptimizedCode(); |
| + } |
|
siva
2012/08/21 21:39:19
These checks on every load library/script/source s
srdjan
2012/08/21 22:08:15
No difference seen in CorelibIsolateStartup.
|
| const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| if (url_str.IsNull()) { |
| RETURN_TYPE_ERROR(isolate, url, String); |
| @@ -3783,6 +3815,9 @@ |
| if (buffer == NULL) { |
| RETURN_NULL_ERROR(buffer); |
| } |
| + if (FLAG_use_cha) { |
| + RemoveOptimizedCode(); |
| + } |
| const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
| if (!snapshot->IsScriptSnapshot()) { |
| return Api::NewError("%s expects parameter 'buffer' to be a script type" |
| @@ -3947,6 +3982,9 @@ |
| TIMERSCOPE(time_script_loading); |
| Isolate* isolate = Isolate::Current(); |
| DARTSCOPE(isolate); |
| + if (FLAG_use_cha) { |
| + RemoveOptimizedCode(); |
| + } |
| const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| if (url_str.IsNull()) { |
| RETURN_TYPE_ERROR(isolate, url, String); |
| @@ -4012,6 +4050,9 @@ |
| TIMERSCOPE(time_script_loading); |
| Isolate* isolate = Isolate::Current(); |
| DARTSCOPE(isolate); |
| + if (FLAG_use_cha) { |
| + RemoveOptimizedCode(); |
| + } |
| const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| if (lib.IsNull()) { |
| RETURN_TYPE_ERROR(isolate, library, Library); |