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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 14 matching lines...) Expand all
25 #include "vm/resolver.h" 25 #include "vm/resolver.h"
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 31
32 namespace dart { 32 namespace dart {
33 33
34 DECLARE_FLAG(bool, print_class_table); 34 DECLARE_FLAG(bool, print_class_table);
35 DECLARE_FLAG(bool, use_cha);
35 36
36 ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey; 37 ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey;
37 38
38 39
39 const char* CanonicalFunction(const char* func) { 40 const char* CanonicalFunction(const char* func) {
40 if (strncmp(func, "dart::", 6) == 0) { 41 if (strncmp(func, "dart::", 6) == 0) {
41 return func + 6; 42 return func + 6;
42 } else { 43 } else {
43 return func; 44 return func;
44 } 45 }
(...skipping 3689 matching lines...) Expand 10 before | Expand all | Expand 10 after
3734 } 3735 }
3735 } else { 3736 } else {
3736 *result = Api::NewHandle(isolate, error.raw()); 3737 *result = Api::NewHandle(isolate, error.raw());
3737 if (update_lib_status) { 3738 if (update_lib_status) {
3738 lib.SetLoadError(); 3739 lib.SetLoadError();
3739 } 3740 }
3740 } 3741 }
3741 } 3742 }
3742 3743
3743 3744
3745 // Removes optimized code once we load more classes, since --use_cha based
3746 // optimizations may have become invalid.
3747 // TODO(srdjan): Note which functions use which CHA decision and deoptimize
3748 // only the necessary ones.
3749 static void RemoveOptimizedCode() {
3750 ASSERT(FLAG_use_cha);
3751 const ClassTable& class_table = *Isolate::Current()->class_table();
3752 Class& cls = Class::Handle();
3753 Array& array = Array::Handle();
3754 Function& function = Function::Handle();
3755 intptr_t num_cids = class_table.NumCids();
regis 2012/08/21 20:52:21 const
srdjan 2012/08/21 22:08:15 Done.
3756 for (intptr_t i = kInstanceCid; i < num_cids; i++) {
3757 if (!class_table.HasValidClassAt(i)) continue;
3758 cls = class_table.At(i);
3759 ASSERT(!cls.IsNull());
3760 array = cls.functions();
3761 intptr_t num_functions = array.IsNull() ? 0 : array.Length();
3762 for (intptr_t f = 0; f < num_functions; f++) {
3763 function ^= array.At(f);
3764 ASSERT(!function.IsNull());
3765 if (function.HasOptimizedCode()) {
3766 function.SwitchToUnoptimizedCode();
3767 }
3768 }
3769 }
3770 }
3771
3772
3744 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, 3773 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
3745 Dart_Handle source) { 3774 Dart_Handle source) {
3746 TIMERSCOPE(time_script_loading); 3775 TIMERSCOPE(time_script_loading);
3747 Isolate* isolate = Isolate::Current(); 3776 Isolate* isolate = Isolate::Current();
3748 DARTSCOPE(isolate); 3777 DARTSCOPE(isolate);
3778 if (FLAG_use_cha) {
3779 RemoveOptimizedCode();
3780 }
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.
3749 const String& url_str = Api::UnwrapStringHandle(isolate, url); 3781 const String& url_str = Api::UnwrapStringHandle(isolate, url);
3750 if (url_str.IsNull()) { 3782 if (url_str.IsNull()) {
3751 RETURN_TYPE_ERROR(isolate, url, String); 3783 RETURN_TYPE_ERROR(isolate, url, String);
3752 } 3784 }
3753 const String& source_str = Api::UnwrapStringHandle(isolate, source); 3785 const String& source_str = Api::UnwrapStringHandle(isolate, source);
3754 if (source_str.IsNull()) { 3786 if (source_str.IsNull()) {
3755 RETURN_TYPE_ERROR(isolate, source, String); 3787 RETURN_TYPE_ERROR(isolate, source, String);
3756 } 3788 }
3757 Library& library = 3789 Library& library =
3758 Library::Handle(isolate, isolate->object_store()->root_library()); 3790 Library::Handle(isolate, isolate->object_store()->root_library());
(...skipping 17 matching lines...) Expand all
3776 } 3808 }
3777 3809
3778 3810
3779 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) { 3811 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) {
3780 Isolate* isolate = Isolate::Current(); 3812 Isolate* isolate = Isolate::Current();
3781 DARTSCOPE(isolate); 3813 DARTSCOPE(isolate);
3782 TIMERSCOPE(time_script_loading); 3814 TIMERSCOPE(time_script_loading);
3783 if (buffer == NULL) { 3815 if (buffer == NULL) {
3784 RETURN_NULL_ERROR(buffer); 3816 RETURN_NULL_ERROR(buffer);
3785 } 3817 }
3818 if (FLAG_use_cha) {
3819 RemoveOptimizedCode();
3820 }
3786 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); 3821 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
3787 if (!snapshot->IsScriptSnapshot()) { 3822 if (!snapshot->IsScriptSnapshot()) {
3788 return Api::NewError("%s expects parameter 'buffer' to be a script type" 3823 return Api::NewError("%s expects parameter 'buffer' to be a script type"
3789 " snapshot", CURRENT_FUNC); 3824 " snapshot", CURRENT_FUNC);
3790 } 3825 }
3791 Library& library = 3826 Library& library =
3792 Library::Handle(isolate, isolate->object_store()->root_library()); 3827 Library::Handle(isolate, isolate->object_store()->root_library());
3793 if (!library.IsNull()) { 3828 if (!library.IsNull()) {
3794 const String& library_url = String::Handle(isolate, library.url()); 3829 const String& library_url = String::Handle(isolate, library.url());
3795 return Api::NewError("%s: A script has already been loaded from '%s'.", 3830 return Api::NewError("%s: A script has already been loaded from '%s'.",
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
3940 return Api::NewHandle(isolate, library.raw()); 3975 return Api::NewHandle(isolate, library.raw());
3941 } 3976 }
3942 } 3977 }
3943 3978
3944 3979
3945 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, 3980 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url,
3946 Dart_Handle source) { 3981 Dart_Handle source) {
3947 TIMERSCOPE(time_script_loading); 3982 TIMERSCOPE(time_script_loading);
3948 Isolate* isolate = Isolate::Current(); 3983 Isolate* isolate = Isolate::Current();
3949 DARTSCOPE(isolate); 3984 DARTSCOPE(isolate);
3985 if (FLAG_use_cha) {
3986 RemoveOptimizedCode();
3987 }
3950 const String& url_str = Api::UnwrapStringHandle(isolate, url); 3988 const String& url_str = Api::UnwrapStringHandle(isolate, url);
3951 if (url_str.IsNull()) { 3989 if (url_str.IsNull()) {
3952 RETURN_TYPE_ERROR(isolate, url, String); 3990 RETURN_TYPE_ERROR(isolate, url, String);
3953 } 3991 }
3954 const String& source_str = Api::UnwrapStringHandle(isolate, source); 3992 const String& source_str = Api::UnwrapStringHandle(isolate, source);
3955 if (source_str.IsNull()) { 3993 if (source_str.IsNull()) {
3956 RETURN_TYPE_ERROR(isolate, source, String); 3994 RETURN_TYPE_ERROR(isolate, source, String);
3957 } 3995 }
3958 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str)); 3996 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str));
3959 if (library.IsNull()) { 3997 if (library.IsNull()) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
4005 return Api::Success(isolate); 4043 return Api::Success(isolate);
4006 } 4044 }
4007 4045
4008 4046
4009 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, 4047 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library,
4010 Dart_Handle url, 4048 Dart_Handle url,
4011 Dart_Handle source) { 4049 Dart_Handle source) {
4012 TIMERSCOPE(time_script_loading); 4050 TIMERSCOPE(time_script_loading);
4013 Isolate* isolate = Isolate::Current(); 4051 Isolate* isolate = Isolate::Current();
4014 DARTSCOPE(isolate); 4052 DARTSCOPE(isolate);
4053 if (FLAG_use_cha) {
4054 RemoveOptimizedCode();
4055 }
4015 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); 4056 const Library& lib = Api::UnwrapLibraryHandle(isolate, library);
4016 if (lib.IsNull()) { 4057 if (lib.IsNull()) {
4017 RETURN_TYPE_ERROR(isolate, library, Library); 4058 RETURN_TYPE_ERROR(isolate, library, Library);
4018 } 4059 }
4019 const String& url_str = Api::UnwrapStringHandle(isolate, url); 4060 const String& url_str = Api::UnwrapStringHandle(isolate, url);
4020 if (url_str.IsNull()) { 4061 if (url_str.IsNull()) {
4021 RETURN_TYPE_ERROR(isolate, url, String); 4062 RETURN_TYPE_ERROR(isolate, url, String);
4022 } 4063 }
4023 const String& source_str = Api::UnwrapStringHandle(isolate, source); 4064 const String& source_str = Api::UnwrapStringHandle(isolate, source);
4024 if (source_str.IsNull()) { 4065 if (source_str.IsNull()) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
4081 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { 4122 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) {
4082 Dart::set_perf_events_writer(function); 4123 Dart::set_perf_events_writer(function);
4083 } 4124 }
4084 4125
4085 4126
4086 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { 4127 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) {
4087 Dart::set_flow_graph_writer(function); 4128 Dart::set_flow_graph_writer(function);
4088 } 4129 }
4089 4130
4090 } // namespace dart 4131 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698