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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 10825483: Add --use_cha (default true, switch to false if you use dynamic class loading). Use CHA to specify … (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/class_table.h ('k') | runtime/vm/flow_graph_optimizer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
===================================================================
--- runtime/vm/dart_api_impl.cc (revision 11101)
+++ 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();
+ const intptr_t num_cids = class_table.NumCids();
+ 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();
+ }
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);
« no previous file with comments | « runtime/vm/class_table.h ('k') | runtime/vm/flow_graph_optimizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698