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

Side by Side Diff: runtime/vm/bootstrap.cc

Issue 1401643002: Remove isolate parameter when allocating handles (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Sync Created 5 years, 2 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
« no previous file with comments | « no previous file | runtime/vm/coverage.h » ('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 "vm/bootstrap.h" 5 #include "vm/bootstrap.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "vm/bootstrap_natives.h" 9 #include "vm/bootstrap_natives.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } else { 154 } else {
155 // Compilation errors are not Dart instances, so just mark the library 155 // Compilation errors are not Dart instances, so just mark the library
156 // as having failed to load without providing an error instance. 156 // as having failed to load without providing an error instance.
157 library.SetLoadError(Object::null_instance()); 157 library.SetLoadError(Object::null_instance());
158 } 158 }
159 } 159 }
160 return error.raw(); 160 return error.raw();
161 } 161 }
162 162
163 163
164 static Dart_Handle LoadPartSource(Isolate* isolate, 164 static Dart_Handle LoadPartSource(Thread* thread,
165 const Library& lib, 165 const Library& lib,
166 const String& uri) { 166 const String& uri) {
167 Zone* zone = thread->zone();
168 Isolate* isolate = thread->isolate();
167 const String& part_source = String::Handle( 169 const String& part_source = String::Handle(
168 isolate, GetLibrarySource(lib, uri, false)); 170 zone, GetLibrarySource(lib, uri, false));
169 const String& lib_uri = String::Handle(isolate, lib.url()); 171 const String& lib_uri = String::Handle(zone, lib.url());
170 if (part_source.IsNull()) { 172 if (part_source.IsNull()) {
171 return Api::NewError("Unable to read part file '%s' of library '%s'", 173 return Api::NewError("Unable to read part file '%s' of library '%s'",
172 uri.ToCString(), lib_uri.ToCString()); 174 uri.ToCString(), lib_uri.ToCString());
173 } 175 }
174 176
175 // Prepend the library URI to form a unique script URI for the part. 177 // Prepend the library URI to form a unique script URI for the part.
176 const Array& strings = Array::Handle(isolate, Array::New(3)); 178 const Array& strings = Array::Handle(zone, Array::New(3));
177 strings.SetAt(0, lib_uri); 179 strings.SetAt(0, lib_uri);
178 strings.SetAt(1, Symbols::Slash()); 180 strings.SetAt(1, Symbols::Slash());
179 strings.SetAt(2, uri); 181 strings.SetAt(2, uri);
180 const String& part_uri = String::Handle(isolate, String::ConcatAll(strings)); 182 const String& part_uri = String::Handle(zone, String::ConcatAll(strings));
181 183
182 // Create a script object and compile the part. 184 // Create a script object and compile the part.
183 const Script& part_script = Script::Handle( 185 const Script& part_script = Script::Handle(
184 isolate, Script::New(part_uri, part_source, RawScript::kSourceTag)); 186 zone, Script::New(part_uri, part_source, RawScript::kSourceTag));
185 const Error& error = Error::Handle(isolate, Compile(lib, part_script)); 187 const Error& error = Error::Handle(zone, Compile(lib, part_script));
186 return Api::NewHandle(isolate, error.raw()); 188 return Api::NewHandle(isolate, error.raw());
187 } 189 }
188 190
189 191
190 static Dart_Handle BootstrapLibraryTagHandler(Dart_LibraryTag tag, 192 static Dart_Handle BootstrapLibraryTagHandler(Dart_LibraryTag tag,
191 Dart_Handle library, 193 Dart_Handle library,
192 Dart_Handle uri) { 194 Dart_Handle uri) {
193 Isolate* isolate = Isolate::Current(); 195 Thread* thread = Thread::Current();
196 Zone* zone = thread->zone();
194 if (!Dart_IsLibrary(library)) { 197 if (!Dart_IsLibrary(library)) {
195 return Api::NewError("not a library"); 198 return Api::NewError("not a library");
196 } 199 }
197 if (!Dart_IsString(uri)) { 200 if (!Dart_IsString(uri)) {
198 return Api::NewError("uri is not a string"); 201 return Api::NewError("uri is not a string");
199 } 202 }
200 if (tag == Dart_kCanonicalizeUrl) { 203 if (tag == Dart_kCanonicalizeUrl) {
201 // In the bootstrap loader we do not try and do any canonicalization. 204 // In the bootstrap loader we do not try and do any canonicalization.
202 return uri; 205 return uri;
203 } 206 }
204 const String& uri_str = Api::UnwrapStringHandle(isolate, uri); 207 const String& uri_str = Api::UnwrapStringHandle(zone, uri);
205 ASSERT(!uri_str.IsNull()); 208 ASSERT(!uri_str.IsNull());
206 if (tag == Dart_kImportTag) { 209 if (tag == Dart_kImportTag) {
207 // We expect the core bootstrap libraries to only import other 210 // We expect the core bootstrap libraries to only import other
208 // core bootstrap libraries. 211 // core bootstrap libraries.
209 // We have precreated all the bootstrap library objects hence 212 // We have precreated all the bootstrap library objects hence
210 // we do not expect to be called back with the tag set to kImportTag. 213 // we do not expect to be called back with the tag set to kImportTag.
211 // The bootstrap process explicitly loads all the libraries one by one. 214 // The bootstrap process explicitly loads all the libraries one by one.
212 return Api::NewError("Invalid import of '%s' in a bootstrap library", 215 return Api::NewError("Invalid import of '%s' in a bootstrap library",
213 uri_str.ToCString()); 216 uri_str.ToCString());
214 } 217 }
215 ASSERT(tag == Dart_kSourceTag); 218 ASSERT(tag == Dart_kSourceTag);
216 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); 219 const Library& lib = Api::UnwrapLibraryHandle(zone, library);
217 ASSERT(!lib.IsNull()); 220 ASSERT(!lib.IsNull());
218 return LoadPartSource(isolate, lib, uri_str); 221 return LoadPartSource(thread, lib, uri_str);
219 } 222 }
220 223
221 224
222 static RawError* LoadPatchFiles(Isolate* isolate, 225 static RawError* LoadPatchFiles(Zone* zone,
223 const Library& lib, 226 const Library& lib,
224 const String& patch_uri, 227 const String& patch_uri,
225 const char** patch_files) { 228 const char** patch_files) {
226 String& patch_file_uri = String::Handle(isolate); 229 String& patch_file_uri = String::Handle(zone);
227 String& source = String::Handle(isolate); 230 String& source = String::Handle(zone);
228 Script& script = Script::Handle(isolate); 231 Script& script = Script::Handle(zone);
229 Error& error = Error::Handle(isolate); 232 Error& error = Error::Handle(zone);
230 const Array& strings = Array::Handle(isolate, Array::New(3)); 233 const Array& strings = Array::Handle(zone, Array::New(3));
231 strings.SetAt(0, patch_uri); 234 strings.SetAt(0, patch_uri);
232 strings.SetAt(1, Symbols::Slash()); 235 strings.SetAt(1, Symbols::Slash());
233 for (intptr_t j = 0; patch_files[j] != NULL; j += 2) { 236 for (intptr_t j = 0; patch_files[j] != NULL; j += 2) {
234 patch_file_uri = String::New(patch_files[j]); 237 patch_file_uri = String::New(patch_files[j]);
235 source = GetLibrarySource(lib, patch_file_uri, true); 238 source = GetLibrarySource(lib, patch_file_uri, true);
236 if (source.IsNull()) { 239 if (source.IsNull()) {
237 const String& message = String::Handle( 240 const String& message = String::Handle(
238 String::NewFormatted("Unable to find dart patch source for %s", 241 String::NewFormatted("Unable to find dart patch source for %s",
239 patch_file_uri.ToCString())); 242 patch_file_uri.ToCString()));
240 return ApiError::New(message); 243 return ApiError::New(message);
241 } 244 }
242 // Prepend the patch library URI to form a unique script URI for the patch. 245 // Prepend the patch library URI to form a unique script URI for the patch.
243 strings.SetAt(2, patch_file_uri); 246 strings.SetAt(2, patch_file_uri);
244 patch_file_uri = String::ConcatAll(strings); 247 patch_file_uri = String::ConcatAll(strings);
245 script = Script::New(patch_file_uri, source, RawScript::kPatchTag); 248 script = Script::New(patch_file_uri, source, RawScript::kPatchTag);
246 error = lib.Patch(script); 249 error = lib.Patch(script);
247 if (!error.IsNull()) { 250 if (!error.IsNull()) {
248 return error.raw(); 251 return error.raw();
249 } 252 }
250 } 253 }
251 return Error::null(); 254 return Error::null();
252 } 255 }
253 256
254 257
255 RawError* Bootstrap::LoadandCompileScripts() { 258 RawError* Bootstrap::LoadandCompileScripts() {
256 Thread* thread = Thread::Current(); 259 Thread* thread = Thread::Current();
257 Isolate* isolate = thread->isolate(); 260 Isolate* isolate = thread->isolate();
258 String& uri = String::Handle(isolate); 261 Zone* zone = thread->zone();
259 String& patch_uri = String::Handle(isolate); 262 String& uri = String::Handle(zone);
260 String& source = String::Handle(isolate); 263 String& patch_uri = String::Handle(zone);
261 Script& script = Script::Handle(isolate); 264 String& source = String::Handle(zone);
262 Library& lib = Library::Handle(isolate); 265 Script& script = Script::Handle(zone);
263 Error& error = Error::Handle(isolate); 266 Library& lib = Library::Handle(zone);
267 Error& error = Error::Handle(zone);
264 Dart_LibraryTagHandler saved_tag_handler = isolate->library_tag_handler(); 268 Dart_LibraryTagHandler saved_tag_handler = isolate->library_tag_handler();
265 269
266 // Set the library tag handler for the isolate to the bootstrap 270 // Set the library tag handler for the isolate to the bootstrap
267 // library tag handler so that we can load all the bootstrap libraries. 271 // library tag handler so that we can load all the bootstrap libraries.
268 isolate->set_library_tag_handler(BootstrapLibraryTagHandler); 272 isolate->set_library_tag_handler(BootstrapLibraryTagHandler);
269 273
270 HANDLESCOPE(thread); 274 HANDLESCOPE(thread);
271 275
272 // Create library objects for all the bootstrap libraries. 276 // Create library objects for all the bootstrap libraries.
273 for (intptr_t i = 0; 277 for (intptr_t i = 0;
(...skipping 26 matching lines...) Expand all
300 break; 304 break;
301 } 305 }
302 script = Script::New(uri, source, RawScript::kLibraryTag); 306 script = Script::New(uri, source, RawScript::kLibraryTag);
303 error = Compile(lib, script); 307 error = Compile(lib, script);
304 if (!error.IsNull()) { 308 if (!error.IsNull()) {
305 break; 309 break;
306 } 310 }
307 // If a patch exists, load and patch the script. 311 // If a patch exists, load and patch the script.
308 if (bootstrap_libraries[i].patch_paths_ != NULL) { 312 if (bootstrap_libraries[i].patch_paths_ != NULL) {
309 patch_uri = Symbols::New(bootstrap_libraries[i].patch_uri_); 313 patch_uri = Symbols::New(bootstrap_libraries[i].patch_uri_);
310 error = LoadPatchFiles(isolate, 314 error = LoadPatchFiles(zone,
311 lib, 315 lib,
312 patch_uri, 316 patch_uri,
313 bootstrap_libraries[i].patch_paths_); 317 bootstrap_libraries[i].patch_paths_);
314 if (!error.IsNull()) { 318 if (!error.IsNull()) {
315 break; 319 break;
316 } 320 }
317 } 321 }
318 } 322 }
319 if (error.IsNull()) { 323 if (error.IsNull()) {
320 SetupNativeResolver(); 324 SetupNativeResolver();
321 ClassFinalizer::ProcessPendingClasses(); 325 ClassFinalizer::ProcessPendingClasses();
322 326
323 Class& cls = Class::Handle(isolate); 327 Class& cls = Class::Handle(zone);
324 // Eagerly compile the function implementation class as it is the super 328 // Eagerly compile the function implementation class as it is the super
325 // class of signature classes. This allows us to just finalize signature 329 // class of signature classes. This allows us to just finalize signature
326 // classes without going through the hoops of trying to compile them. 330 // classes without going through the hoops of trying to compile them.
327 const Type& type = 331 const Type& type =
328 Type::Handle(isolate, isolate->object_store()->function_impl_type()); 332 Type::Handle(zone, isolate->object_store()->function_impl_type());
329 cls = type.type_class(); 333 cls = type.type_class();
330 Compiler::CompileClass(cls); 334 Compiler::CompileClass(cls);
331 } 335 }
332 336
333 // Restore the library tag handler for the isolate. 337 // Restore the library tag handler for the isolate.
334 isolate->set_library_tag_handler(saved_tag_handler); 338 isolate->set_library_tag_handler(saved_tag_handler);
335 339
336 return error.raw(); 340 return error.raw();
337 } 341 }
338 342
339 } // namespace dart 343 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/coverage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698