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

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

Issue 8506001: Finalize all classes (fix issue 364). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years, 1 month 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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/object.h" 5 #include "vm/object.h"
6 6
7 #include "vm/assembler.h" 7 #include "vm/assembler.h"
8 #include "vm/assert.h" 8 #include "vm/assert.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // be true before calling Class::New<Class>(), or it will fail. 232 // be true before calling Class::New<Class>(), or it will fail.
233 class_class_ = Class::Handle().raw(); // Set 'class_class_' to 'null_'. 233 class_class_ = Class::Handle().raw(); // Set 'class_class_' to 'null_'.
234 cls = Class::New<Class>(); 234 cls = Class::New<Class>();
235 cls.set_is_finalized(); 235 cls.set_is_finalized();
236 class_class_ = cls.raw(); 236 class_class_ = cls.raw();
237 // Make the class_ field point to itself. 237 // Make the class_ field point to itself.
238 class_class_->ptr()->class_ = class_class_; 238 class_class_->ptr()->class_ = class_class_;
239 239
240 // Allocate and initialize the null class. 240 // Allocate and initialize the null class.
241 cls = Class::New<Instance>(); 241 cls = Class::New<Instance>();
242 cls.set_is_finalized();
242 null_class_ = cls.raw(); 243 null_class_ = cls.raw();
243 244
244 // Complete initialization of null_ instance, i.e. initialize its class_ 245 // Complete initialization of null_ instance, i.e. initialize its class_
245 // field. 246 // field.
246 null_->ptr()->class_ = null_class_; 247 null_->ptr()->class_ = null_class_;
247 248
248 // Allocate and initialize the sentinel values of an instance class. 249 // Allocate and initialize the sentinel values of an instance class.
249 { 250 {
250 cls = Class::New<Instance>(); 251 cls = Class::New<Instance>();
251 Instance& sentinel = Instance::Handle(); 252 Instance& sentinel = Instance::Handle();
252 sentinel ^= Object::Allocate(cls, Instance::InstanceSize(), Heap::kOld); 253 sentinel ^= Object::Allocate(cls, Instance::InstanceSize(), Heap::kOld);
253 sentinel_ = sentinel.raw(); 254 sentinel_ = sentinel.raw();
254 255
255 Instance& transition_sentinel = Instance::Handle(); 256 Instance& transition_sentinel = Instance::Handle();
256 transition_sentinel ^= 257 transition_sentinel ^=
257 Object::Allocate(cls, Instance::InstanceSize(), Heap::kOld); 258 Object::Allocate(cls, Instance::InstanceSize(), Heap::kOld);
258 transition_sentinel_ = transition_sentinel.raw(); 259 transition_sentinel_ = transition_sentinel.raw();
259 } 260 }
260 261
261 // The interface "Dynamic" is not a VM internal class. It is the type class of 262 // The interface "Dynamic" is not a VM internal class. It is the type class of
262 // the "unknown type". For efficiency, we allocate it in the VM isolate. 263 // the "unknown type". For efficiency, we allocate it in the VM isolate.
263 // Therefore, it cannot have a heap allocated name (the name is hard coded, 264 // Therefore, it cannot have a heap allocated name (the name is hard coded,
264 // see GetSingletonClassIndex) and its array fields cannot be set to the empty 265 // see GetSingletonClassIndex) and its array fields cannot be set to the empty
265 // array, but remain null. 266 // array, but remain null.
266 cls = Class::New<Instance>(); 267 cls = Class::New<Instance>();
268 cls.set_is_finalized();
267 cls.set_is_interface(); 269 cls.set_is_interface();
268 dynamic_class_ = cls.raw(); 270 dynamic_class_ = cls.raw();
269 271
270 // Allocate the remaining VM internal classes. 272 // Allocate the remaining VM internal classes.
271 cls = Class::New<UnresolvedClass>(); 273 cls = Class::New<UnresolvedClass>();
272 unresolved_class_class_ = cls.raw(); 274 unresolved_class_class_ = cls.raw();
273 275
274 cls = Class::New<Instance>(); 276 cls = Class::New<Instance>();
277 cls.set_is_finalized();
275 void_class_ = cls.raw(); 278 void_class_ = cls.raw();
276 279
277 cls = Class::New<ParameterizedType>(); 280 cls = Class::New<ParameterizedType>();
278 parameterized_type_class_ = cls.raw(); 281 parameterized_type_class_ = cls.raw();
279 282
280 cls = Class::New<TypeParameter>(); 283 cls = Class::New<TypeParameter>();
281 type_parameter_class_ = cls.raw(); 284 type_parameter_class_ = cls.raw();
282 285
283 cls = Class::New<InstantiatedType>(); 286 cls = Class::New<InstantiatedType>();
284 instantiated_type_class_ = cls.raw(); 287 instantiated_type_class_ = cls.raw();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 cls = Class::New<ContextScope>(); 331 cls = Class::New<ContextScope>();
329 context_scope_class_ = cls.raw(); 332 context_scope_class_ = cls.raw();
330 333
331 cls = Class::New<ApiFailure>(); 334 cls = Class::New<ApiFailure>();
332 api_failure_class_ = cls.raw(); 335 api_failure_class_ = cls.raw();
333 336
334 ASSERT(class_class() != null_); 337 ASSERT(class_class() != null_);
335 } 338 }
336 339
337 340
341 RawClass* Object::CreateAndRegisterCoreInterface(
342 const char* cname,
343 const Script& script,
344 GrowableArray<const Class*>* classes) {
srdjan 2011/11/09 21:22:43 I think it would be clearer if classes->Add() woul
regis 2011/11/09 23:31:01 Done.
345 const String& name = String::Handle(String::NewSymbol(cname));
346 Class& cls = Class::ZoneHandle(Class::NewInterface(name, script));
347 Library& core_lib = Library::Handle(Library::CoreLibrary());
348 core_lib.AddClass(cls);
349 classes->Add(&cls);
350 return cls.raw();
351 }
352
353
354 void Object::RegisterCoreImplClass(
355 const Class& cls,
356 const char* cname,
357 const Script& impl_script,
358 GrowableArray<const Class*>* classes) {
srdjan 2011/11/09 21:22:43 Ditto
regis 2011/11/09 23:31:01 Done.
359 const String& name = String::Handle(String::NewSymbol(cname));
360 cls.set_name(name);
361 cls.set_script(impl_script);
362 Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary());
363 core_impl_lib.AddClass(cls);
364 const Class& pending_class = Class::ZoneHandle(cls.raw());
365 classes->Add(&pending_class);
366 }
367
368
338 void Object::Init(Isolate* isolate) { 369 void Object::Init(Isolate* isolate) {
339 TIMERSCOPE(time_bootstrap); 370 TIMERSCOPE(time_bootstrap);
340 ObjectStore* object_store = isolate->object_store(); 371 ObjectStore* object_store = isolate->object_store();
341 372
342 Class& cls = Class::Handle(); 373 Class& cls = Class::Handle();
343 Type& type = Type::Handle(); 374 Type& type = Type::Handle();
344 String& name = String::Handle();
345 Array& array = Array::Handle(); 375 Array& array = Array::Handle();
346 376
347 // All RawArray fields will be initialized to an empty array, therefore 377 // All RawArray fields will be initialized to an empty array, therefore
348 // initialize array class first. 378 // initialize array class first.
349 cls = Class::New<Array>(); 379 cls = Class::New<Array>();
350 object_store->set_array_class(cls); 380 object_store->set_array_class(cls);
351 381
352 // Array and ImmutableArray are the only VM classes that are parameterized. 382 // Array and ImmutableArray are the only VM classes that are parameterized.
353 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we 383 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we
354 // need to set the offset of their type_arguments_ field, which is explicitly 384 // need to set the offset of their type_arguments_ field, which is explicitly
355 // declared in RawArray. 385 // declared in RawArray.
356 cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset()); 386 cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset());
357 387
358 Array& empty_array = Array::Handle(); 388 Array& empty_array = Array::Handle();
359 empty_array = Array::New(0, Heap::kOld); 389 empty_array = Array::New(0, Heap::kOld);
360 object_store->set_empty_array(empty_array); 390 object_store->set_empty_array(empty_array);
361 391
362 // Re-initialize fields of the array class now that the empty array 392 // Re-initialize fields of the array class now that the empty array
363 // has been created. 393 // has been created.
364 cls.InitEmptyFields(); 394 cls.InitEmptyFields();
365 395
366 cls = Class::New<ImmutableArray>();
367 object_store->set_immutable_array_class(cls);
368 cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset());
369
370 // Allocate and initialize the object class and type.
371 cls = Class::New<Instance>();
372 object_store->set_object_class(cls);
373 type = Type::NewNonParameterizedType(cls);
374 object_store->set_object_type(type);
375
376 cls = Class::New<Smi>();
377 object_store->set_smi_class(cls);
378
379 cls = Class::New<Mint>();
380 object_store->set_mint_class(cls);
381
382 cls = Class::New<Bigint>();
383 object_store->set_bigint_class(cls);
384
385 cls = Class::New<Double>();
386 object_store->set_double_class(cls);
387
388 cls = Class::New<OneByteString>();
389 object_store->set_one_byte_string_class(cls);
390
391 cls = Class::New<TwoByteString>();
392 object_store->set_two_byte_string_class(cls);
393
394 cls = Class::New<FourByteString>();
395 object_store->set_four_byte_string_class(cls);
396
397 cls = Class::New<Bool>();
398 object_store->set_bool_class(cls);
399
400 cls = Class::New<UnhandledException>();
401 object_store->set_unhandled_exception_class(cls);
402
403 cls = Class::New<Stacktrace>();
404 object_store->set_stacktrace_class(cls);
405 // Set the super type so that the 'toString' method is implemented.
406 type = object_store->object_type();
407 cls.set_super_type(type);
408
409 cls = Class::New<JSRegExp>();
410 object_store->set_jsregexp_class(cls);
411
412 // Setup the symbol table used within the String class. 396 // Setup the symbol table used within the String class.
413 const int kInitialSymbolTableSize = 16; 397 const int kInitialSymbolTableSize = 16;
414 array = Array::New(kInitialSymbolTableSize + 1); 398 array = Array::New(kInitialSymbolTableSize + 1);
415 // Last element contains the count of used slots. 399 // Last element contains the count of used slots.
416 array.SetAt(kInitialSymbolTableSize, Smi::Handle(Smi::New(0))); 400 array.SetAt(kInitialSymbolTableSize, Smi::Handle(Smi::New(0)));
417 object_store->set_symbol_table(array); 401 object_store->set_symbol_table(array);
418 402
403 // Pre-allocate the OneByteString class needed by the symbol table.
404 cls = Class::New<OneByteString>();
405 object_store->set_one_byte_string_class(cls);
406
419 // Basic infrastructure has been setup, initialize the class dictionary. 407 // Basic infrastructure has been setup, initialize the class dictionary.
420 Library::InitCoreLibrary(isolate); 408 Library::InitCoreLibrary(isolate);
421 Library& core_lib = Library::Handle(isolate->object_store()->core_library()); 409 Library& core_lib = Library::Handle(Library::CoreLibrary());
422 ASSERT(!core_lib.IsNull()); 410 ASSERT(!core_lib.IsNull());
423 Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); 411 Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary());
424 ASSERT(!core_impl_lib.IsNull()); 412 ASSERT(!core_impl_lib.IsNull());
425 413
426 // Allocate pre-initialized values. 414 object_store->set_pending_classes(Array::Handle());
427 Bool& bool_value = Bool::Handle();
428 bool_value = Bool::New(true);
429 object_store->set_true_value(bool_value);
430 bool_value = Bool::New(false);
431 object_store->set_false_value(bool_value);
432
433 object_store->set_pending_classes(Array::Handle(Array::Empty()));
434 415
435 Context& context = Context::Handle(Context::New(0)); 416 Context& context = Context::Handle(Context::New(0));
436 object_store->set_empty_context(context); 417 object_store->set_empty_context(context);
437 418
438 // Now that the String class is initialized and the dictionary has been setup, 419 // Now that the symbol table is initialized and that the core dictionary as
439 // add the names to preallocated classes and register them in the dictionary. 420 // well as the core implementation dictionary have been setup, preallocate
421 // remaining classes and register them by name in the dictionaries.
440 const Script& impl_script = Script::Handle(Bootstrap::LoadImplScript()); 422 const Script& impl_script = Script::Handle(Bootstrap::LoadImplScript());
423 GrowableArray<const Class*> pending_classes;
441 424
442 name = String::NewSymbol("Smi"); 425 cls = Class::New<Smi>();
443 cls = object_store->smi_class(); 426 object_store->set_smi_class(cls);
444 cls.set_name(name); 427 RegisterCoreImplClass(cls, "Smi", impl_script, &pending_classes);
445 cls.set_script(impl_script);
446 core_impl_lib.AddClass(cls);
447 428
448 name = String::NewSymbol("OneByteString"); 429 cls = Class::New<Mint>();
449 cls = object_store->one_byte_string_class(); 430 object_store->set_mint_class(cls);
450 cls.set_name(name); 431 RegisterCoreImplClass(cls, "Mint", impl_script, &pending_classes);
451 cls.set_script(impl_script);
452 core_impl_lib.AddClass(cls);
453 432
454 name = String::NewSymbol("TwoByteString"); 433 cls = Class::New<Bigint>();
455 cls = object_store->two_byte_string_class(); 434 object_store->set_bigint_class(cls);
456 cls.set_name(name); 435 RegisterCoreImplClass(cls, "Bigint", impl_script, &pending_classes);
457 cls.set_script(impl_script);
458 core_impl_lib.AddClass(cls);
459 436
460 name = String::NewSymbol("FourByteString"); 437 cls = Class::New<Double>();
461 cls = object_store->four_byte_string_class(); 438 object_store->set_double_class(cls);
462 cls.set_name(name); 439 RegisterCoreImplClass(cls, "Double", impl_script, &pending_classes);
463 cls.set_script(impl_script);
464 core_impl_lib.AddClass(cls);
465 440
466 name = String::NewSymbol("Mint"); 441 cls = Class::New<Bool>();
467 cls = object_store->mint_class(); 442 object_store->set_bool_class(cls);
468 cls.set_name(name); 443 RegisterCoreImplClass(cls, "Bool", impl_script, &pending_classes);
469 cls.set_script(impl_script);
470 core_impl_lib.AddClass(cls);
471 444
472 name = String::NewSymbol("Bigint"); 445 cls = object_store->array_class(); // Was allocated above.
473 cls = object_store->bigint_class(); 446 RegisterCoreImplClass(cls, "ObjectArray", impl_script, &pending_classes);
474 cls.set_name(name);
475 cls.set_script(impl_script);
476 core_impl_lib.AddClass(cls);
477 447
478 name = String::NewSymbol("Double"); 448 cls = Class::New<ImmutableArray>();
479 cls = object_store->double_class(); 449 object_store->set_immutable_array_class(cls);
480 cls.set_name(name); 450 cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset());
481 cls.set_script(impl_script); 451 ASSERT(object_store->immutable_array_class() != object_store->array_class());
482 core_impl_lib.AddClass(cls); 452 RegisterCoreImplClass(cls, "ImmutableArray", impl_script, &pending_classes);
483 453
484 name = String::NewSymbol("Bool"); 454 cls = object_store->one_byte_string_class(); // Was allocated above.
485 cls = object_store->bool_class(); 455 RegisterCoreImplClass(cls, "OneByteString", impl_script, &pending_classes);
486 cls.set_name(name);
487 cls.set_script(impl_script);
488 core_impl_lib.AddClass(cls);
489 456
490 name = String::NewSymbol("ObjectArray"); 457 cls = Class::New<TwoByteString>();
491 cls = object_store->array_class(); 458 object_store->set_two_byte_string_class(cls);
492 cls.set_name(name); 459 RegisterCoreImplClass(cls, "TwoByteString", impl_script, &pending_classes);
493 cls.set_script(impl_script);
494 core_impl_lib.AddClass(cls);
495 460
496 name = String::NewSymbol("ImmutableArray"); 461 cls = Class::New<FourByteString>();
497 cls = object_store->immutable_array_class(); 462 object_store->set_four_byte_string_class(cls);
498 ASSERT(object_store->immutable_array_class() != object_store->array_class()); 463 RegisterCoreImplClass(cls, "FourByteString", impl_script, &pending_classes);
499 cls.set_name(name);
500 cls.set_script(impl_script);
501 core_impl_lib.AddClass(cls);
502 464
503 name = String::NewSymbol("UnhandledException"); 465 cls = Class::New<UnhandledException>();
504 cls = object_store->unhandled_exception_class(); 466 object_store->set_unhandled_exception_class(cls);
505 cls.set_name(name); 467 RegisterCoreImplClass(
506 cls.set_script(impl_script); 468 cls, "UnhandledException", impl_script, &pending_classes);
507 core_impl_lib.AddClass(cls);
508 469
509 name = String::NewSymbol("Stacktrace"); 470 cls = Class::New<Stacktrace>();
510 cls = object_store->stacktrace_class(); 471 object_store->set_stacktrace_class(cls);
511 cls.set_name(name); 472 RegisterCoreImplClass(cls, "Stacktrace", impl_script, &pending_classes);
512 cls.set_script(impl_script); 473 // Super type set below, after Object is allocated.
513 core_impl_lib.AddClass(cls);
514 474
515 name = String::NewSymbol("JSSyntaxRegExp"); 475 cls = Class::New<JSRegExp>();
516 cls = object_store->jsregexp_class(); 476 object_store->set_jsregexp_class(cls);
517 cls.set_name(name); 477 RegisterCoreImplClass(cls, "JSSyntaxRegExp", impl_script, &pending_classes);
518 cls.set_script(impl_script);
519 core_impl_lib.AddClass(cls);
520 478
521 // Initialize the base interfaces used by the core VM classes. 479 // Initialize the base interfaces used by the core VM classes.
522 const Script& script = Script::Handle(Bootstrap::LoadScript()); 480 const Script& script = Script::Handle(Bootstrap::LoadScript());
523 481
524 name = String::NewSymbol("Object"); 482 // Allocate and initialize the Object class and type.
525 cls = object_store->object_class(); 483 // Object class is the only pre-allocated non-interface in the core library.
526 cls.set_name(name); 484 cls = Class::New<Instance>();
485 object_store->set_object_class(cls);
486 cls.set_name(String::Handle(String::NewSymbol("Object")));
527 cls.set_script(script); 487 cls.set_script(script);
528 core_lib.AddClass(cls); 488 core_lib.AddClass(cls);
489 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
490 type = Type::NewNonParameterizedType(cls);
491 object_store->set_object_type(type);
529 492
530 name = String::NewSymbol("Function"); 493 // Set the super type of class Stacktrace to Object type so that the
531 cls = Class::NewInterface(name, script); 494 // 'toString' method is implemented.
532 core_lib.AddClass(cls); 495 cls = object_store->stacktrace_class();
496 cls.set_super_type(type);
497
498 cls = CreateAndRegisterCoreInterface("Function", script, &pending_classes);
533 type = Type::NewNonParameterizedType(cls); 499 type = Type::NewNonParameterizedType(cls);
534 object_store->set_function_interface(type); 500 object_store->set_function_interface(type);
535 501
536 name = String::NewSymbol("num"); 502 cls = CreateAndRegisterCoreInterface("num", script, &pending_classes);
537 cls = Class::NewInterface(name, script);
538 core_lib.AddClass(cls);
539 type = Type::NewNonParameterizedType(cls); 503 type = Type::NewNonParameterizedType(cls);
540 object_store->set_number_interface(type); 504 object_store->set_number_interface(type);
541 505
542 name = String::NewSymbol("int"); 506 cls = CreateAndRegisterCoreInterface("int", script, &pending_classes);
543 cls = Class::NewInterface(name, script);
544 core_lib.AddClass(cls);
545 type = Type::NewNonParameterizedType(cls); 507 type = Type::NewNonParameterizedType(cls);
546 object_store->set_int_interface(type); 508 object_store->set_int_interface(type);
547 509
548 name = String::NewSymbol("double"); 510 cls = CreateAndRegisterCoreInterface("double", script, &pending_classes);
549 cls = Class::NewInterface(name, script);
550 core_lib.AddClass(cls);
551 type = Type::NewNonParameterizedType(cls); 511 type = Type::NewNonParameterizedType(cls);
552 object_store->set_double_interface(type); 512 object_store->set_double_interface(type);
553 513
554 name = String::NewSymbol("String"); 514 cls = CreateAndRegisterCoreInterface("String", script, &pending_classes);
555 cls = Class::NewInterface(name, script);
556 core_lib.AddClass(cls);
557 type = Type::NewNonParameterizedType(cls); 515 type = Type::NewNonParameterizedType(cls);
558 object_store->set_string_interface(type); 516 object_store->set_string_interface(type);
559 517
560 name = String::NewSymbol("bool"); 518 cls = CreateAndRegisterCoreInterface("bool", script, &pending_classes);
561 cls = Class::NewInterface(name, script);
562 core_lib.AddClass(cls);
563 type = Type::NewNonParameterizedType(cls); 519 type = Type::NewNonParameterizedType(cls);
564 object_store->set_bool_interface(type); 520 object_store->set_bool_interface(type);
565 521
566 name = String::NewSymbol("List"); 522 cls = CreateAndRegisterCoreInterface("List", script, &pending_classes);
567 cls = Class::NewInterface(name, script);
568 core_lib.AddClass(cls);
569 type = Type::NewNonParameterizedType(cls); 523 type = Type::NewNonParameterizedType(cls);
570 object_store->set_list_interface(type); 524 object_store->set_list_interface(type);
571 525
572 // The classes 'Null' and 'void' are not registered in the class dictionary, 526 // The classes 'Null' and 'void' are not registered in the class dictionary,
573 // because their names are reserved keywords. Their names are not heap 527 // because their names are reserved keywords. Their names are not heap
574 // allocated, because the classes reside in the VM isolate. 528 // allocated, because the classes reside in the VM isolate.
575 // The corresponding types are stored in the object store. 529 // The corresponding types are stored in the object store.
576 cls = null_class_; 530 cls = null_class_;
577 type = Type::NewNonParameterizedType(cls); 531 type = Type::NewNonParameterizedType(cls);
578 object_store->set_null_type(type); 532 object_store->set_null_type(type);
579 533
580 cls = void_class_; 534 cls = void_class_;
581 type = Type::NewNonParameterizedType(cls); 535 type = Type::NewNonParameterizedType(cls);
582 object_store->set_void_type(type); 536 object_store->set_void_type(type);
583 537
584 // The class 'Dynamic' is registered in the class dictionary because its name 538 // The class 'Dynamic' is registered in the class dictionary because its name
585 // is a built-in identifier, rather than a reserved keyword. Its name is not 539 // is a built-in identifier, rather than a reserved keyword. Its name is not
586 // heap allocated, because the class resides in the VM isolate. 540 // heap allocated, because the class resides in the VM isolate.
587 // The corresponding type, the "unknown type", is stored in the object store. 541 // The corresponding type, the "unknown type", is stored in the object store.
588 cls = dynamic_class_; 542 cls = dynamic_class_;
589 type = Type::NewNonParameterizedType(cls); 543 type = Type::NewNonParameterizedType(cls);
590 object_store->set_dynamic_type(type); 544 object_store->set_dynamic_type(type);
591 core_lib.AddClass(cls); 545 core_lib.AddClass(cls);
592 546
593 // Finish the initialization by compiling the bootstrap script containing the 547 // Add the preallocated classes to the list of classes to be finalized.
594 // implementation of the internal classes. 548 ClassFinalizer::ExpectPendingClasses();
595 Bootstrap::Compile(Library::Handle(Library::CoreLibrary()), script); 549 ClassFinalizer::AddPendingClasses(pending_classes);
596 Bootstrap::Compile(Library::Handle(Library::CoreImplLibrary()), impl_script); 550
551 // Allocate pre-initialized values.
552 Bool& bool_value = Bool::Handle();
553 bool_value = Bool::New(true);
554 object_store->set_true_value(bool_value);
555 bool_value = Bool::New(false);
556 object_store->set_false_value(bool_value);
557
558 // Finish the initialization by compiling the bootstrap scripts containing the
559 // base interfaces and the implementation of the internal classes.
560 Bootstrap::Compile(core_lib, script);
561 Bootstrap::Compile(core_impl_lib, impl_script);
597 562
598 Bootstrap::SetupNativeResolver(); 563 Bootstrap::SetupNativeResolver();
599 564
600 // Remove the Object superclass cycle by setting the super type to null (not 565 // Remove the Object superclass cycle by setting the super type to null (not
601 // to the type of null). 566 // to the type of null).
602 cls = object_store->object_class(); 567 cls = object_store->object_class();
603 cls.set_super_type(Type::Handle()); 568 cls.set_super_type(Type::Handle());
604 569
605 ClassFinalizer::VerifyBootstrapClasses(); 570 ClassFinalizer::VerifyBootstrapClasses();
606 } 571 }
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 } 1016 }
1052 } 1017 }
1053 } 1018 }
1054 Class& result = Class::Handle(New<Closure>(name, script)); 1019 Class& result = Class::Handle(New<Closure>(name, script));
1055 result.set_super_type(super_type); 1020 result.set_super_type(super_type);
1056 result.set_signature_function(signature_function); 1021 result.set_signature_function(signature_function);
1057 result.set_type_parameters(type_parameters); 1022 result.set_type_parameters(type_parameters);
1058 result.set_type_parameter_extends(type_parameter_extends); 1023 result.set_type_parameter_extends(type_parameter_extends);
1059 result.SetFields(Array::Handle(Array::Empty())); 1024 result.SetFields(Array::Handle(Array::Empty()));
1060 result.SetFunctions(Array::Handle(Array::Empty())); 1025 result.SetFunctions(Array::Handle(Array::Empty()));
1061 // Implements interface Function. 1026 // Implements interface "Function".
1062 const Type& function_interface = Type::Handle(Type::FunctionInterface()); 1027 const Type& function_interface = Type::Handle(Type::FunctionInterface());
1063 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); 1028 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld));
1064 interfaces.SetAt(0, function_interface); 1029 interfaces.SetAt(0, function_interface);
1065 result.set_interfaces(interfaces); 1030 result.set_interfaces(interfaces);
1066 // Unless the signature function already has a signature class, create a 1031 // Unless the signature function already has a signature class, create a
1067 // canonical signature class by having the signature function pointing back to 1032 // canonical signature class by having the signature function point back to
1068 // the signature class. 1033 // the signature class.
1069 if (signature_function.signature_class() == Object::null()) { 1034 if (signature_function.signature_class() == Object::null()) {
1070 signature_function.set_signature_class(result); 1035 signature_function.set_signature_class(result);
1071 } 1036 }
1037 // If the class finalizer is expecting more pending classes to finalize, it
1038 // will add the signature class to the pending list in order to postpone
1039 // finalization of the signature type.
1040 const Type& signature_type = Type::Handle(result.SignatureType());
1041 ASSERT(!signature_type.IsFinalized());
1042 String& errmsg = String::Handle();
1043 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, &errmsg);
1044 ASSERT(errmsg.IsNull());
1072 return result.raw(); 1045 return result.raw();
1073 } 1046 }
1074 1047
1075 1048
1076 RawClass* Class::GetClass(ObjectKind kind) { 1049 RawClass* Class::GetClass(ObjectKind kind) {
1077 ObjectStore* object_store = Isolate::Current()->object_store(); 1050 ObjectStore* object_store = Isolate::Current()->object_store();
1078 switch (kind) { 1051 switch (kind) {
1079 case kUnhandledException: 1052 case kUnhandledException:
1080 ASSERT(object_store->unhandled_exception_class() != Class::null()); 1053 ASSERT(object_store->unhandled_exception_class() != Class::null());
1081 return object_store->unhandled_exception_class(); 1054 return object_store->unhandled_exception_class();
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 1302
1330 bool Class::IsTopLevel() const { 1303 bool Class::IsTopLevel() const {
1331 return String::Handle(Name()).Length() == 0; 1304 return String::Handle(Name()).Length() == 0;
1332 } 1305 }
1333 1306
1334 1307
1335 bool Class::TestType(TypeTestKind test, 1308 bool Class::TestType(TypeTestKind test,
1336 const TypeArguments& type_arguments, 1309 const TypeArguments& type_arguments,
1337 const Class& other, 1310 const Class& other,
1338 const TypeArguments& other_type_arguments) const { 1311 const TypeArguments& other_type_arguments) const {
1312 ASSERT(is_finalized());
1313 ASSERT(other.is_finalized());
1339 if (test == kIsAssignableTo) { 1314 if (test == kIsAssignableTo) {
1340 // The spec states that "a type T is assignable to a type S if T is a 1315 // The spec states that "a type T is assignable to a type S if T is a
1341 // subtype of S or S is a subtype of T". This is from the perspective of a 1316 // subtype of S or S is a subtype of T". This is from the perspective of a
1342 // static checker, which does not know the actual type of the assigned 1317 // static checker, which does not know the actual type of the assigned
1343 // value. However, this type information is available at run time in checked 1318 // value. However, this type information is available at run time in checked
1344 // mode. We therefore apply a more restrictive subtype check, which prevents 1319 // mode. We therefore apply a more restrictive subtype check, which prevents
1345 // heap pollution. We only keep the assignability check when assigning 1320 // heap pollution. We only keep the assignability check when assigning
1346 // values of a function type. 1321 // values of a function type.
1347 if (IsSignatureClass() && other.IsSignatureClass()) { 1322 if (IsSignatureClass() && other.IsSignatureClass()) {
1348 const Function& src_fun = Function::Handle(signature_function()); 1323 const Function& src_fun = Function::Handle(signature_function());
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1797 (type_class() == Type::Handle(Type::StringInterface()).type_class()); 1772 (type_class() == Type::Handle(Type::StringInterface()).type_class());
1798 } 1773 }
1799 1774
1800 1775
1801 bool Type::IsFunctionInterface() const { 1776 bool Type::IsFunctionInterface() const {
1802 return HasResolvedTypeClass() && 1777 return HasResolvedTypeClass() &&
1803 (type_class() == Type::Handle(Type::FunctionInterface()).type_class()); 1778 (type_class() == Type::Handle(Type::FunctionInterface()).type_class());
1804 } 1779 }
1805 1780
1806 1781
1782 bool Type::IsSignatureType() const {
1783 return HasResolvedTypeClass() &&
1784 Class::Handle(type_class()).IsSignatureClass();
1785 }
1786
1787
1807 bool Type::IsMoreSpecificThan(const Type& other) const { 1788 bool Type::IsMoreSpecificThan(const Type& other) const {
1808 ASSERT(IsFinalized()); 1789 ASSERT(IsFinalized());
1809 ASSERT(other.IsFinalized()); 1790 ASSERT(other.IsFinalized());
1810 // Type parameters cannot be handled by Class::IsMoreSpecificThan(). 1791 // Type parameters cannot be handled by Class::IsMoreSpecificThan().
1811 if (IsTypeParameter() || other.IsTypeParameter()) { 1792 if (IsTypeParameter() || other.IsTypeParameter()) {
1812 return IsTypeParameter() && other.IsTypeParameter() && 1793 return IsTypeParameter() && other.IsTypeParameter() &&
1813 (Index() == other.Index()); 1794 (Index() == other.Index());
1814 } 1795 }
1815 const Class& cls = Class::Handle(type_class()); 1796 const Class& cls = Class::Handle(type_class());
1816 return cls.IsMoreSpecificThan(TypeArguments::Handle(arguments()), 1797 return cls.IsMoreSpecificThan(TypeArguments::Handle(arguments()),
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1996 intptr_t offset) const { 1977 intptr_t offset) const {
1997 ASSERT(IsFinalized()); 1978 ASSERT(IsFinalized());
1998 ASSERT(!IsInstantiated()); 1979 ASSERT(!IsInstantiated());
1999 TypeArguments& type_arguments = TypeArguments::Handle(); 1980 TypeArguments& type_arguments = TypeArguments::Handle();
2000 if (!instantiator_type_arguments.IsNull()) { 1981 if (!instantiator_type_arguments.IsNull()) {
2001 type_arguments = arguments(); 1982 type_arguments = arguments();
2002 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, 1983 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments,
2003 offset); 1984 offset);
2004 } 1985 }
2005 const Class& cls = Class::Handle(type_class()); 1986 const Class& cls = Class::Handle(type_class());
1987 ASSERT(cls.is_finalized());
2006 ParameterizedType& instantiated_type = ParameterizedType::Handle( 1988 ParameterizedType& instantiated_type = ParameterizedType::Handle(
2007 ParameterizedType::New(cls, type_arguments)); 1989 ParameterizedType::New(cls, type_arguments));
2008 ASSERT(type_arguments.IsNull() || 1990 ASSERT(type_arguments.IsNull() ||
2009 (type_arguments.Length() == cls.NumTypeArguments())); 1991 (type_arguments.Length() == cls.NumTypeArguments()));
2010 instantiated_type.set_is_finalized(); 1992 instantiated_type.set_is_finalized();
2011 return instantiated_type.raw(); 1993 return instantiated_type.raw();
2012 } 1994 }
2013 1995
2014 1996
2015 bool ParameterizedType::Equals(const Type& other) const { 1997 bool ParameterizedType::Equals(const Type& other) const {
(...skipping 4928 matching lines...) Expand 10 before | Expand all | Expand 10 after
6944 const String& str = String::Handle(pattern()); 6926 const String& str = String::Handle(pattern());
6945 const char* format = "JSRegExp: pattern=%s flags=%s"; 6927 const char* format = "JSRegExp: pattern=%s flags=%s";
6946 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 6928 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
6947 char* chars = reinterpret_cast<char*>( 6929 char* chars = reinterpret_cast<char*>(
6948 Isolate::Current()->current_zone()->Allocate(len + 1)); 6930 Isolate::Current()->current_zone()->Allocate(len + 1));
6949 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 6931 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
6950 return chars; 6932 return chars;
6951 } 6933 }
6952 6934
6953 } // namespace dart 6935 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698