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

Side by Side Diff: lib/isolate.cc

Issue 10783035: Create frequently used symbols in the vm isolate (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 5 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
« no previous file with comments | « no previous file | lib/math.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/bootstrap_natives.h" 6 #include "vm/bootstrap_natives.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/dart.h" 8 #include "vm/dart.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
11 #include "vm/exceptions.h" 11 #include "vm/exceptions.h"
12 #include "vm/longjump.h" 12 #include "vm/longjump.h"
13 #include "vm/message_handler.h" 13 #include "vm/message_handler.h"
14 #include "vm/object.h" 14 #include "vm/object.h"
15 #include "vm/object_store.h" 15 #include "vm/object_store.h"
16 #include "vm/port.h" 16 #include "vm/port.h"
17 #include "vm/resolver.h" 17 #include "vm/resolver.h"
18 #include "vm/snapshot.h" 18 #include "vm/snapshot.h"
19 #include "vm/symbols.h"
19 #include "vm/thread.h" 20 #include "vm/thread.h"
20 21
21 namespace dart { 22 namespace dart {
22 23
23 class IsolateStartData { 24 class IsolateStartData {
24 public: 25 public:
25 IsolateStartData(char* library_url, 26 IsolateStartData(char* library_url,
26 char* class_name, 27 char* class_name,
27 intptr_t port_id) 28 intptr_t port_id)
28 : library_url_(library_url), 29 : library_url_(library_url),
(...skipping 29 matching lines...) Expand all
58 } 59 }
59 60
60 61
61 static void ThrowErrorException(Exceptions::ExceptionType type, 62 static void ThrowErrorException(Exceptions::ExceptionType type,
62 const char* error_msg, 63 const char* error_msg,
63 const char* library_url, 64 const char* library_url,
64 const char* class_name) { 65 const char* class_name) {
65 String& str = String::Handle(); 66 String& str = String::Handle();
66 String& name = String::Handle(); 67 String& name = String::Handle();
67 str ^= String::New(error_msg); 68 str ^= String::New(error_msg);
68 name ^= String::NewSymbol(library_url); 69 name ^= Symbols::New(library_url);
69 str ^= String::Concat(str, name); 70 str ^= String::Concat(str, name);
70 name ^= String::New(":"); 71 name ^= String::New(":");
71 str ^= String::Concat(str, name); 72 str ^= String::Concat(str, name);
72 name ^= String::NewSymbol(class_name); 73 name ^= Symbols::New(class_name);
73 str ^= String::Concat(str, name); 74 str ^= String::Concat(str, name);
74 GrowableArray<const Object*> arguments(1); 75 GrowableArray<const Object*> arguments(1);
75 arguments.Add(&str); 76 arguments.Add(&str);
76 Exceptions::ThrowByType(type, arguments); 77 Exceptions::ThrowByType(type, arguments);
77 } 78 }
78 79
79 80
80 // TODO(turnidge): Move to DartLibraryCalls. 81 // TODO(turnidge): Move to DartLibraryCalls.
81 RawObject* ReceivePortCreate(intptr_t port_id) { 82 RawObject* ReceivePortCreate(intptr_t port_id) {
82 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); 83 Library& isolate_lib = Library::Handle(Library::IsolateLibrary());
83 ASSERT(!isolate_lib.IsNull()); 84 ASSERT(!isolate_lib.IsNull());
84 const String& public_class_name = 85 const String& public_class_name =
85 String::Handle(String::NewSymbol("_ReceivePortImpl")); 86 String::Handle(Symbols::New("_ReceivePortImpl"));
86 const String& class_name = 87 const String& class_name =
87 String::Handle(isolate_lib.PrivateName(public_class_name)); 88 String::Handle(isolate_lib.PrivateName(public_class_name));
88 const String& function_name = 89 const String& function_name =
89 String::Handle(String::NewSymbol("_get_or_create")); 90 String::Handle(Symbols::New("_get_or_create"));
90 const int kNumArguments = 1; 91 const int kNumArguments = 1;
91 const Array& kNoArgumentNames = Array::Handle(); 92 const Array& kNoArgumentNames = Array::Handle();
92 const Function& function = Function::Handle( 93 const Function& function = Function::Handle(
93 Resolver::ResolveStatic(isolate_lib, 94 Resolver::ResolveStatic(isolate_lib,
94 class_name, 95 class_name,
95 function_name, 96 function_name,
96 kNumArguments, 97 kNumArguments,
97 kNoArgumentNames, 98 kNoArgumentNames,
98 Resolver::kIsQualified)); 99 Resolver::kIsQualified));
99 GrowableArray<const Object*> arguments(kNumArguments); 100 GrowableArray<const Object*> arguments(kNumArguments);
(...skipping 17 matching lines...) Expand all
117 intptr_t port_id = data->port_id_; 118 intptr_t port_id = data->port_id_;
118 delete data; 119 delete data;
119 120
120 { 121 {
121 StartIsolateScope start_scope(isolate); 122 StartIsolateScope start_scope(isolate);
122 Zone zone(isolate); 123 Zone zone(isolate);
123 HandleScope handle_scope(isolate); 124 HandleScope handle_scope(isolate);
124 ASSERT(ClassFinalizer::AllClassesFinalized()); 125 ASSERT(ClassFinalizer::AllClassesFinalized());
125 // Lookup the target class by name, create an instance and call the run 126 // Lookup the target class by name, create an instance and call the run
126 // method. 127 // method.
127 const String& lib_name = String::Handle(String::NewSymbol(library_url)); 128 const String& lib_name = String::Handle(Symbols::New(library_url));
128 free(library_url); 129 free(library_url);
129 const Library& lib = Library::Handle(Library::LookupLibrary(lib_name)); 130 const Library& lib = Library::Handle(Library::LookupLibrary(lib_name));
130 ASSERT(!lib.IsNull()); 131 ASSERT(!lib.IsNull());
131 const String& cls_name = String::Handle(String::NewSymbol(class_name)); 132 const String& cls_name = String::Handle(Symbols::New(class_name));
132 free(class_name); 133 free(class_name);
133 const Class& target_class = Class::Handle(lib.LookupClass(cls_name)); 134 const Class& target_class = Class::Handle(lib.LookupClass(cls_name));
134 // TODO(iposva): Deserialize or call the constructor after allocating. 135 // TODO(iposva): Deserialize or call the constructor after allocating.
135 // For now, we only support a non-parameterized or raw target class. 136 // For now, we only support a non-parameterized or raw target class.
136 const Instance& target = Instance::Handle(Instance::New(target_class)); 137 const Instance& target = Instance::Handle(Instance::New(target_class));
137 Object& result = Object::Handle(); 138 Object& result = Object::Handle();
138 139
139 // Invoke the default constructor. 140 // Invoke the default constructor.
140 const String& period = String::Handle(String::New(".")); 141 const String& period = String::Handle(String::New("."));
141 String& constructor_name = String::Handle(String::Concat(cls_name, period)); 142 String& constructor_name = String::Handle(String::Concat(cls_name, period));
142 const Function& default_constructor = 143 const Function& default_constructor =
143 Function::Handle(target_class.LookupConstructor(constructor_name)); 144 Function::Handle(target_class.LookupConstructor(constructor_name));
144 if (!default_constructor.IsNull()) { 145 if (!default_constructor.IsNull()) {
145 GrowableArray<const Object*> arguments(1); 146 GrowableArray<const Object*> arguments(1);
146 arguments.Add(&target); 147 arguments.Add(&target);
147 arguments.Add(&Smi::Handle(Smi::New(Function::kCtorPhaseAll))); 148 arguments.Add(&Smi::Handle(Smi::New(Function::kCtorPhaseAll)));
148 const Array& kNoArgumentNames = Array::Handle(); 149 const Array& kNoArgumentNames = Array::Handle();
149 result = DartEntry::InvokeStatic(default_constructor, 150 result = DartEntry::InvokeStatic(default_constructor,
150 arguments, 151 arguments,
151 kNoArgumentNames); 152 kNoArgumentNames);
152 if (result.IsError()) { 153 if (result.IsError()) {
153 StoreError(isolate, result); 154 StoreError(isolate, result);
154 return false; 155 return false;
155 } 156 }
156 ASSERT(result.IsNull()); 157 ASSERT(result.IsNull());
157 } 158 }
158 159
159 // Invoke the "_run" method. 160 // Invoke the "_run" method.
160 const Function& target_function = Function::Handle(Resolver::ResolveDynamic( 161 const Function& target_function = Function::Handle(Resolver::ResolveDynamic(
161 target, String::Handle(String::NewSymbol("_run")), 2, 0)); 162 target, String::Handle(Symbols::New("_run")), 2, 0));
162 // TODO(iposva): Proper error checking here. 163 // TODO(iposva): Proper error checking here.
163 ASSERT(!target_function.IsNull()); 164 ASSERT(!target_function.IsNull());
164 // TODO(iposva): Allocate the proper port number here. 165 // TODO(iposva): Allocate the proper port number here.
165 const Object& local_port = Object::Handle(ReceivePortCreate(port_id)); 166 const Object& local_port = Object::Handle(ReceivePortCreate(port_id));
166 if (local_port.IsError()) { 167 if (local_port.IsError()) {
167 StoreError(isolate, local_port); 168 StoreError(isolate, local_port);
168 return false; 169 return false;
169 } 170 }
170 GrowableArray<const Object*> arguments(1); 171 GrowableArray<const Object*> arguments(1);
171 arguments.Add(&local_port); 172 arguments.Add(&local_port);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 static bool CheckArguments(const char* library_url, const char* class_name) { 211 static bool CheckArguments(const char* library_url, const char* class_name) {
211 Isolate* isolate = Isolate::Current(); 212 Isolate* isolate = Isolate::Current();
212 Zone zone(isolate); 213 Zone zone(isolate);
213 HandleScope handle_scope(isolate); 214 HandleScope handle_scope(isolate);
214 String& name = String::Handle(); 215 String& name = String::Handle();
215 if (!ClassFinalizer::FinalizePendingClasses()) { 216 if (!ClassFinalizer::FinalizePendingClasses()) {
216 return false; 217 return false;
217 } 218 }
218 // Lookup the target class by name, create an instance and call the run 219 // Lookup the target class by name, create an instance and call the run
219 // method. 220 // method.
220 name ^= String::NewSymbol(library_url); 221 name ^= Symbols::New(library_url);
221 const Library& lib = Library::Handle(Library::LookupLibrary(name)); 222 const Library& lib = Library::Handle(Library::LookupLibrary(name));
222 if (lib.IsNull()) { 223 if (lib.IsNull()) {
223 const String& error_str = String::Handle( 224 const String& error_str = String::Handle(
224 String::New("Error starting Isolate, library not loaded : ")); 225 String::New("Error starting Isolate, library not loaded : "));
225 const Error& error = Error::Handle(LanguageError::New(error_str)); 226 const Error& error = Error::Handle(LanguageError::New(error_str));
226 Isolate::Current()->object_store()->set_sticky_error(error); 227 Isolate::Current()->object_store()->set_sticky_error(error);
227 return false; 228 return false;
228 } 229 }
229 name ^= String::NewSymbol(class_name); 230 name ^= Symbols::New(class_name);
230 const Class& target_class = Class::Handle(lib.LookupClass(name)); 231 const Class& target_class = Class::Handle(lib.LookupClass(name));
231 if (target_class.IsNull()) { 232 if (target_class.IsNull()) {
232 const String& error_str = String::Handle( 233 const String& error_str = String::Handle(
233 String::New("Error starting Isolate, class not loaded : ")); 234 String::New("Error starting Isolate, class not loaded : "));
234 const Error& error = Error::Handle(LanguageError::New(error_str)); 235 const Error& error = Error::Handle(LanguageError::New(error_str));
235 Isolate::Current()->object_store()->set_sticky_error(error); 236 Isolate::Current()->object_store()->set_sticky_error(error);
236 return false; 237 return false;
237 } 238 }
238 return true; // No errors. 239 return true; // No errors.
239 } 240 }
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 648
648 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) { 649 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) {
649 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port())); 650 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port()));
650 if (port.IsError()) { 651 if (port.IsError()) {
651 Exceptions::PropagateError(Error::Cast(port)); 652 Exceptions::PropagateError(Error::Cast(port));
652 } 653 }
653 arguments->SetReturn(port); 654 arguments->SetReturn(port);
654 } 655 }
655 656
656 } // namespace dart 657 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | lib/math.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698