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

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

Issue 8491055: Second attempt at finalizing all classes in the VM (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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.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) 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<ApiError>(); 334 cls = Class::New<ApiError>();
332 api_error_class_ = cls.raw(); 335 api_error_class_ = cls.raw();
333 336
334 ASSERT(class_class() != null_); 337 ASSERT(class_class() != null_);
335 } 338 }
336 339
337 340
341 RawClass* Object::CreateAndRegisterInterface(const char* cname,
342 const Script& script,
343 const Library& lib) {
344 const String& name = String::Handle(String::NewSymbol(cname));
345 const Class& cls = Class::Handle(Class::NewInterface(name, script));
346 lib.AddClass(cls);
347 return cls.raw();
348 }
349
350
351 void Object::RegisterClass(const Class& cls,
352 const char* cname,
353 const Script& script,
354 const Library& lib) {
355 const String& name = String::Handle(String::NewSymbol(cname));
356 cls.set_name(name);
357 cls.set_script(script);
358 lib.AddClass(cls);
359 }
360
361
338 void Object::Init(Isolate* isolate) { 362 void Object::Init(Isolate* isolate) {
339 TIMERSCOPE(time_bootstrap); 363 TIMERSCOPE(time_bootstrap);
340 ObjectStore* object_store = isolate->object_store(); 364 ObjectStore* object_store = isolate->object_store();
341 365
342 Class& cls = Class::Handle(); 366 Class& cls = Class::Handle();
343 Type& type = Type::Handle(); 367 Type& type = Type::Handle();
344 String& name = String::Handle();
345 Array& array = Array::Handle(); 368 Array& array = Array::Handle();
346 369
347 // All RawArray fields will be initialized to an empty array, therefore 370 // All RawArray fields will be initialized to an empty array, therefore
348 // initialize array class first. 371 // initialize array class first.
349 cls = Class::New<Array>(); 372 cls = Class::New<Array>();
350 object_store->set_array_class(cls); 373 object_store->set_array_class(cls);
351 374
352 // Array and ImmutableArray are the only VM classes that are parameterized. 375 // Array and ImmutableArray are the only VM classes that are parameterized.
353 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we 376 // 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 377 // need to set the offset of their type_arguments_ field, which is explicitly
355 // declared in RawArray. 378 // declared in RawArray.
356 cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset()); 379 cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset());
357 380
358 Array& empty_array = Array::Handle(); 381 Array& empty_array = Array::Handle();
359 empty_array = Array::New(0, Heap::kOld); 382 empty_array = Array::New(0, Heap::kOld);
360 object_store->set_empty_array(empty_array); 383 object_store->set_empty_array(empty_array);
361 384
362 // Re-initialize fields of the array class now that the empty array 385 // Re-initialize fields of the array class now that the empty array
363 // has been created. 386 // has been created.
364 cls.InitEmptyFields(); 387 cls.InitEmptyFields();
365 388
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. 389 // Setup the symbol table used within the String class.
413 const int kInitialSymbolTableSize = 16; 390 const int kInitialSymbolTableSize = 16;
414 array = Array::New(kInitialSymbolTableSize + 1); 391 array = Array::New(kInitialSymbolTableSize + 1);
415 // Last element contains the count of used slots. 392 // Last element contains the count of used slots.
416 array.SetAt(kInitialSymbolTableSize, Smi::Handle(Smi::New(0))); 393 array.SetAt(kInitialSymbolTableSize, Smi::Handle(Smi::New(0)));
417 object_store->set_symbol_table(array); 394 object_store->set_symbol_table(array);
418 395
396 // Pre-allocate the OneByteString class needed by the symbol table.
397 cls = Class::New<OneByteString>();
398 object_store->set_one_byte_string_class(cls);
399
419 // Basic infrastructure has been setup, initialize the class dictionary. 400 // Basic infrastructure has been setup, initialize the class dictionary.
420 Library::InitCoreLibrary(isolate); 401 Library::InitCoreLibrary(isolate);
421 Library& core_lib = Library::Handle(isolate->object_store()->core_library()); 402 Library& core_lib = Library::Handle(Library::CoreLibrary());
422 ASSERT(!core_lib.IsNull()); 403 ASSERT(!core_lib.IsNull());
423 Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); 404 Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary());
424 ASSERT(!core_impl_lib.IsNull()); 405 ASSERT(!core_impl_lib.IsNull());
425 406
426 // Allocate pre-initialized values.
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())); 407 object_store->set_pending_classes(Array::Handle(Array::Empty()));
434 408
435 Context& context = Context::Handle(Context::New(0)); 409 Context& context = Context::Handle(Context::New(0));
436 object_store->set_empty_context(context); 410 object_store->set_empty_context(context);
437 411
438 // Now that the String class is initialized and the dictionary has been setup, 412 // 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. 413 // well as the core implementation dictionary have been setup, preallocate
414 // remaining classes and register them by name in the dictionaries.
440 const Script& impl_script = Script::Handle(Bootstrap::LoadImplScript()); 415 const Script& impl_script = Script::Handle(Bootstrap::LoadImplScript());
416 GrowableArray<const Class*> pending_classes;
441 417
442 name = String::NewSymbol("Smi"); 418 cls = Class::New<Smi>();
443 cls = object_store->smi_class(); 419 object_store->set_smi_class(cls);
444 cls.set_name(name); 420 RegisterClass(cls, "Smi", impl_script, core_impl_lib);
445 cls.set_script(impl_script); 421 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
446 core_impl_lib.AddClass(cls);
447 422
448 name = String::NewSymbol("OneByteString"); 423 cls = Class::New<Mint>();
449 cls = object_store->one_byte_string_class(); 424 object_store->set_mint_class(cls);
450 cls.set_name(name); 425 RegisterClass(cls, "Mint", impl_script, core_impl_lib);
451 cls.set_script(impl_script); 426 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
452 core_impl_lib.AddClass(cls);
453 427
454 name = String::NewSymbol("TwoByteString"); 428 cls = Class::New<Bigint>();
455 cls = object_store->two_byte_string_class(); 429 object_store->set_bigint_class(cls);
456 cls.set_name(name); 430 RegisterClass(cls, "Bigint", impl_script, core_impl_lib);
457 cls.set_script(impl_script); 431 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
458 core_impl_lib.AddClass(cls);
459 432
460 name = String::NewSymbol("FourByteString"); 433 cls = Class::New<Double>();
461 cls = object_store->four_byte_string_class(); 434 object_store->set_double_class(cls);
462 cls.set_name(name); 435 RegisterClass(cls, "Double", impl_script, core_impl_lib);
463 cls.set_script(impl_script); 436 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
464 core_impl_lib.AddClass(cls);
465 437
466 name = String::NewSymbol("Mint"); 438 cls = Class::New<Bool>();
467 cls = object_store->mint_class(); 439 object_store->set_bool_class(cls);
468 cls.set_name(name); 440 RegisterClass(cls, "Bool", impl_script, core_impl_lib);
469 cls.set_script(impl_script); 441 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
470 core_impl_lib.AddClass(cls);
471 442
472 name = String::NewSymbol("Bigint"); 443 cls = object_store->array_class(); // Was allocated above.
473 cls = object_store->bigint_class(); 444 RegisterClass(cls, "ObjectArray", impl_script, core_impl_lib);
474 cls.set_name(name); 445 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
475 cls.set_script(impl_script);
476 core_impl_lib.AddClass(cls);
477 446
478 name = String::NewSymbol("Double"); 447 cls = Class::New<ImmutableArray>();
479 cls = object_store->double_class(); 448 object_store->set_immutable_array_class(cls);
480 cls.set_name(name); 449 cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset());
481 cls.set_script(impl_script); 450 ASSERT(object_store->immutable_array_class() != object_store->array_class());
482 core_impl_lib.AddClass(cls); 451 RegisterClass(cls, "ImmutableArray", impl_script, core_impl_lib);
452 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
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 RegisterClass(cls, "OneByteString", impl_script, core_impl_lib);
486 cls.set_name(name); 456 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
487 cls.set_script(impl_script);
488 core_impl_lib.AddClass(cls);
489 457
490 name = String::NewSymbol("ObjectArray"); 458 cls = Class::New<TwoByteString>();
491 cls = object_store->array_class(); 459 object_store->set_two_byte_string_class(cls);
492 cls.set_name(name); 460 RegisterClass(cls, "TwoByteString", impl_script, core_impl_lib);
493 cls.set_script(impl_script); 461 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
494 core_impl_lib.AddClass(cls);
495 462
496 name = String::NewSymbol("ImmutableArray"); 463 cls = Class::New<FourByteString>();
497 cls = object_store->immutable_array_class(); 464 object_store->set_four_byte_string_class(cls);
498 ASSERT(object_store->immutable_array_class() != object_store->array_class()); 465 RegisterClass(cls, "FourByteString", impl_script, core_impl_lib);
499 cls.set_name(name); 466 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
500 cls.set_script(impl_script);
501 core_impl_lib.AddClass(cls);
502 467
503 name = String::NewSymbol("UnhandledException"); 468 cls = Class::New<UnhandledException>();
504 cls = object_store->unhandled_exception_class(); 469 object_store->set_unhandled_exception_class(cls);
505 cls.set_name(name); 470 RegisterClass(cls, "UnhandledException", impl_script, core_impl_lib);
506 cls.set_script(impl_script); 471 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
507 core_impl_lib.AddClass(cls);
508 472
509 name = String::NewSymbol("Stacktrace"); 473 cls = Class::New<Stacktrace>();
510 cls = object_store->stacktrace_class(); 474 object_store->set_stacktrace_class(cls);
511 cls.set_name(name); 475 RegisterClass(cls, "Stacktrace", impl_script, core_impl_lib);
512 cls.set_script(impl_script); 476 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
513 core_impl_lib.AddClass(cls); 477 // Super type set below, after Object is allocated.
514 478
515 name = String::NewSymbol("JSSyntaxRegExp"); 479 cls = Class::New<JSRegExp>();
516 cls = object_store->jsregexp_class(); 480 object_store->set_jsregexp_class(cls);
517 cls.set_name(name); 481 RegisterClass(cls, "JSSyntaxRegExp", impl_script, core_impl_lib);
518 cls.set_script(impl_script); 482 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
519 core_impl_lib.AddClass(cls);
520 483
521 // Initialize the base interfaces used by the core VM classes. 484 // Initialize the base interfaces used by the core VM classes.
522 const Script& script = Script::Handle(Bootstrap::LoadScript()); 485 const Script& script = Script::Handle(Bootstrap::LoadScript());
523 486
524 name = String::NewSymbol("Object"); 487 // Allocate and initialize the Object class and type.
525 cls = object_store->object_class(); 488 // Object class is the only pre-allocated non-interface in the core library.
526 cls.set_name(name); 489 cls = Class::New<Instance>();
490 object_store->set_object_class(cls);
491 cls.set_name(String::Handle(String::NewSymbol("Object")));
527 cls.set_script(script); 492 cls.set_script(script);
528 core_lib.AddClass(cls); 493 core_lib.AddClass(cls);
494 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
495 type = Type::NewNonParameterizedType(cls);
496 object_store->set_object_type(type);
529 497
530 name = String::NewSymbol("Function"); 498 // Set the super type of class Stacktrace to Object type so that the
531 cls = Class::NewInterface(name, script); 499 // 'toString' method is implemented.
532 core_lib.AddClass(cls); 500 cls = object_store->stacktrace_class();
501 cls.set_super_type(type);
502
503 cls = CreateAndRegisterInterface("Function", script, core_lib);
504 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
533 type = Type::NewNonParameterizedType(cls); 505 type = Type::NewNonParameterizedType(cls);
534 object_store->set_function_interface(type); 506 object_store->set_function_interface(type);
535 507
536 name = String::NewSymbol("num"); 508 cls = CreateAndRegisterInterface("num", script, core_lib);
537 cls = Class::NewInterface(name, script); 509 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
538 core_lib.AddClass(cls);
539 type = Type::NewNonParameterizedType(cls); 510 type = Type::NewNonParameterizedType(cls);
540 object_store->set_number_interface(type); 511 object_store->set_number_interface(type);
541 512
542 name = String::NewSymbol("int"); 513 cls = CreateAndRegisterInterface("int", script, core_lib);
543 cls = Class::NewInterface(name, script); 514 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
544 core_lib.AddClass(cls);
545 type = Type::NewNonParameterizedType(cls); 515 type = Type::NewNonParameterizedType(cls);
546 object_store->set_int_interface(type); 516 object_store->set_int_interface(type);
547 517
548 name = String::NewSymbol("double"); 518 cls = CreateAndRegisterInterface("double", script, core_lib);
549 cls = Class::NewInterface(name, script); 519 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
550 core_lib.AddClass(cls);
551 type = Type::NewNonParameterizedType(cls); 520 type = Type::NewNonParameterizedType(cls);
552 object_store->set_double_interface(type); 521 object_store->set_double_interface(type);
553 522
554 name = String::NewSymbol("String"); 523 cls = CreateAndRegisterInterface("String", script, core_lib);
555 cls = Class::NewInterface(name, script); 524 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
556 core_lib.AddClass(cls);
557 type = Type::NewNonParameterizedType(cls); 525 type = Type::NewNonParameterizedType(cls);
558 object_store->set_string_interface(type); 526 object_store->set_string_interface(type);
559 527
560 name = String::NewSymbol("bool"); 528 cls = CreateAndRegisterInterface("bool", script, core_lib);
561 cls = Class::NewInterface(name, script); 529 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
562 core_lib.AddClass(cls);
563 type = Type::NewNonParameterizedType(cls); 530 type = Type::NewNonParameterizedType(cls);
564 object_store->set_bool_interface(type); 531 object_store->set_bool_interface(type);
565 532
566 name = String::NewSymbol("List"); 533 cls = CreateAndRegisterInterface("List", script, core_lib);
567 cls = Class::NewInterface(name, script); 534 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
568 core_lib.AddClass(cls);
569 type = Type::NewNonParameterizedType(cls); 535 type = Type::NewNonParameterizedType(cls);
570 object_store->set_list_interface(type); 536 object_store->set_list_interface(type);
571 537
572 // The classes 'Null' and 'void' are not registered in the class dictionary, 538 // The classes 'Null' and 'void' are not registered in the class dictionary,
573 // because their names are reserved keywords. Their names are not heap 539 // because their names are reserved keywords. Their names are not heap
574 // allocated, because the classes reside in the VM isolate. 540 // allocated, because the classes reside in the VM isolate.
575 // The corresponding types are stored in the object store. 541 // The corresponding types are stored in the object store.
576 cls = null_class_; 542 cls = null_class_;
577 type = Type::NewNonParameterizedType(cls); 543 type = Type::NewNonParameterizedType(cls);
578 object_store->set_null_type(type); 544 object_store->set_null_type(type);
579 545
580 cls = void_class_; 546 cls = void_class_;
581 type = Type::NewNonParameterizedType(cls); 547 type = Type::NewNonParameterizedType(cls);
582 object_store->set_void_type(type); 548 object_store->set_void_type(type);
583 549
584 // The class 'Dynamic' is registered in the class dictionary because its name 550 // 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 551 // 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. 552 // heap allocated, because the class resides in the VM isolate.
587 // The corresponding type, the "unknown type", is stored in the object store. 553 // The corresponding type, the "unknown type", is stored in the object store.
588 cls = dynamic_class_; 554 cls = dynamic_class_;
589 type = Type::NewNonParameterizedType(cls); 555 type = Type::NewNonParameterizedType(cls);
590 object_store->set_dynamic_type(type); 556 object_store->set_dynamic_type(type);
591 core_lib.AddClass(cls); 557 core_lib.AddClass(cls);
592 558
593 // Finish the initialization by compiling the bootstrap script containing the 559 // Add the preallocated classes to the list of classes to be finalized.
594 // implementation of the internal classes. 560 ClassFinalizer::AddPendingClasses(pending_classes);
595 Bootstrap::Compile(Library::Handle(Library::CoreLibrary()), script); 561
596 Bootstrap::Compile(Library::Handle(Library::CoreImplLibrary()), impl_script); 562 // Allocate pre-initialized values.
563 Bool& bool_value = Bool::Handle();
564 bool_value = Bool::New(true);
565 object_store->set_true_value(bool_value);
566 bool_value = Bool::New(false);
567 object_store->set_false_value(bool_value);
568
569 // Finish the initialization by compiling the bootstrap scripts containing the
570 // base interfaces and the implementation of the internal classes.
571 Bootstrap::Compile(core_lib, script);
572 Bootstrap::Compile(core_impl_lib, impl_script);
597 573
598 Bootstrap::SetupNativeResolver(); 574 Bootstrap::SetupNativeResolver();
599 575
600 // Remove the Object superclass cycle by setting the super type to null (not 576 // Remove the Object superclass cycle by setting the super type to null (not
601 // to the type of null). 577 // to the type of null).
602 cls = object_store->object_class(); 578 cls = object_store->object_class();
603 cls.set_super_type(Type::Handle()); 579 cls.set_super_type(Type::Handle());
604 580
605 ClassFinalizer::VerifyBootstrapClasses(); 581 ClassFinalizer::VerifyBootstrapClasses();
606 } 582 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 if (raw_ptr()->name_ != String::null()) { 682 if (raw_ptr()->name_ != String::null()) {
707 return raw_ptr()->name_; 683 return raw_ptr()->name_;
708 } 684 }
709 ASSERT(class_class() != null_); // Or GetSingletonClassIndex will not work. 685 ASSERT(class_class() != null_); // Or GetSingletonClassIndex will not work.
710 intptr_t index = GetSingletonClassIndex(raw()); 686 intptr_t index = GetSingletonClassIndex(raw());
711 return String::NewSymbol(GetSingletonClassName(index)); 687 return String::NewSymbol(GetSingletonClassName(index));
712 } 688 }
713 689
714 690
715 RawType* Class::SignatureType() const { 691 RawType* Class::SignatureType() const {
716 // Return the only canonical signature type if already computed. 692 // Return the first canonical signature type if already computed.
717 const Array& signature_types = Array::Handle(canonical_types()); 693 const Array& signature_types = Array::Handle(canonical_types());
718 if (signature_types.Length() > 0) { 694 if (signature_types.Length() > 0) {
719 Type& signature_type = Type::Handle(); 695 Type& signature_type = Type::Handle();
720 signature_type ^= signature_types.At(0); 696 signature_type ^= signature_types.At(0);
721 if (!signature_type.IsNull()) { 697 if (!signature_type.IsNull()) {
722 // A signature class has a unique canonical signature type.
723 ASSERT((signature_types.Length() == 1) ||
724 signature_types.At(1) == Object::null());
725 return signature_type.raw(); 698 return signature_type.raw();
726 } 699 }
727 } 700 }
728 ASSERT(IsSignatureClass()); 701 ASSERT(IsSignatureClass());
729 TypeArguments& signature_type_arguments = TypeArguments::Handle(); 702 TypeArguments& signature_type_arguments = TypeArguments::Handle();
730 const intptr_t num_type_params = NumTypeParameters(); 703 const intptr_t num_type_params = NumTypeParameters();
731 // If the signature class extends a parameterized class, the type arguments of 704 // A signature class extends class Instance and is parameterized in the same
732 // the super class will be prepended to the type argument vector during type 705 // way as the owner class of its non-static signature function.
733 // finalization. We only need to provide the type parameters of the signature 706 // It is not type parameterized if its signature function is static.
734 // class here. 707 // See Class::NewSignatureClass() for the setup of its type parameters.
708 // During type finalization, the type arguments of the super class of the
709 // owner class of its signature function will be prepended to the type
710 // argument vector. Therefore, we only need to set the type arguments
711 // matching the type parameters here.
735 if (num_type_params > 0) { 712 if (num_type_params > 0) {
736 const Array& type_params = Array::Handle(type_parameters()); 713 const Array& type_params = Array::Handle(type_parameters());
737 signature_type_arguments = TypeArguments::NewTypeArray(num_type_params); 714 signature_type_arguments = TypeArguments::NewTypeArray(num_type_params);
738 String& type_param_name = String::Handle(); 715 String& type_param_name = String::Handle();
739 Type& type_param = Type::Handle(); 716 Type& type_param = Type::Handle();
740 for (int i = 0; i < num_type_params; i++) { 717 for (int i = 0; i < num_type_params; i++) {
741 type_param_name ^= type_params.At(i); 718 type_param_name ^= type_params.At(i);
742 type_param = Type::NewTypeParameter(i, type_param_name); 719 type_param = Type::NewTypeParameter(i, type_param_name);
743 signature_type_arguments.SetTypeAt(i, type_param); 720 signature_type_arguments.SetTypeAt(i, type_param);
744 } 721 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 return 0; 828 return 0;
852 } else { 829 } else {
853 return type_params.Length(); 830 return type_params.Length();
854 } 831 }
855 } 832 }
856 833
857 834
858 intptr_t Class::NumTypeArguments() const { 835 intptr_t Class::NumTypeArguments() const {
859 // To work properly, this call requires the super class of this class to be 836 // To work properly, this call requires the super class of this class to be
860 // resolved, which is checked by the SuperClass() call. 837 // resolved, which is checked by the SuperClass() call.
838 Class& cls = Class::Handle(raw());
839 if (IsSignatureClass()) {
840 const Function& signature_fun = Function::Handle(signature_function());
841 if (!signature_fun.is_static() &&
842 !signature_fun.HasInstantiatedSignature()) {
843 cls = signature_fun.owner();
844 }
845 }
861 intptr_t num_type_args = NumTypeParameters(); 846 intptr_t num_type_args = NumTypeParameters();
862 const Class& superclass = Class::Handle(SuperClass()); 847 const Class& superclass = Class::Handle(cls.SuperClass());
863 // Object is its own super class during bootstrap. 848 // Object is its own super class during bootstrap.
864 if (!superclass.IsNull() && (superclass.raw() != raw())) { 849 if (!superclass.IsNull() && (superclass.raw() != raw())) {
865 num_type_args += superclass.NumTypeArguments(); 850 num_type_args += superclass.NumTypeArguments();
866 } 851 }
867 return num_type_args; 852 return num_type_args;
868 } 853 }
869 854
870 855
856 bool Class::HasTypeArguments() const {
857 if (!IsSignatureClass() && (is_finalized() || is_prefinalized())) {
858 // More efficient than calling NumTypeArguments().
859 return type_arguments_instance_field_offset() != kNoTypeArguments;
860 } else {
861 // No need to check NumTypeArguments() if class has type parameters.
862 return (NumTypeParameters() > 0) || (NumTypeArguments() > 0);
863 }
864 }
865
866
871 RawClass* Class::SuperClass() const { 867 RawClass* Class::SuperClass() const {
872 const Type& sup_type = Type::Handle(super_type()); 868 const Type& sup_type = Type::Handle(super_type());
873 if (sup_type.IsNull()) { 869 if (sup_type.IsNull()) {
874 return Class::null(); 870 return Class::null();
875 } 871 }
876 return sup_type.type_class(); 872 return sup_type.type_class();
877 } 873 }
878 874
879 875
880 void Class::set_super_type(const Type& value) const { 876 void Class::set_super_type(const Type& value) const {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 Class& result = Class::Handle(New<Instance>(name, script)); 1022 Class& result = Class::Handle(New<Instance>(name, script));
1027 result.set_is_interface(); 1023 result.set_is_interface();
1028 return result.raw(); 1024 return result.raw();
1029 } 1025 }
1030 1026
1031 1027
1032 RawClass* Class::NewSignatureClass(const String& name, 1028 RawClass* Class::NewSignatureClass(const String& name,
1033 const Function& signature_function, 1029 const Function& signature_function,
1034 const Script& script) { 1030 const Script& script) {
1035 ASSERT(!signature_function.IsNull()); 1031 ASSERT(!signature_function.IsNull());
1036 Type& super_type = Type::Handle(Type::ObjectType());
1037 const Class& owner_class = Class::Handle(signature_function.owner()); 1032 const Class& owner_class = Class::Handle(signature_function.owner());
1038 ASSERT(!owner_class.IsNull()); 1033 ASSERT(!owner_class.IsNull());
1039 Array& type_parameters = Array::Handle(); 1034 Array& type_parameters = Array::Handle();
1040 TypeArray& type_parameter_extends = TypeArray::Handle(); 1035 TypeArray& type_parameter_extends = TypeArray::Handle();
1036 // A signature class extends class Instance and is parameterized in the same
1037 // way as the owner class of its non-static signature function.
1038 // It is not type parameterized if its signature function is static.
1041 if (!signature_function.is_static()) { 1039 if (!signature_function.is_static()) {
1042 if ((owner_class.NumTypeParameters() > 0) && 1040 if ((owner_class.NumTypeParameters() > 0) &&
1043 !signature_function.HasInstantiatedSignature()) { 1041 !signature_function.HasInstantiatedSignature()) {
1044 // Share the function owner super class as the super class of the
1045 // signature class, so that the type argument vector of the closure at
1046 // run time matches the type argument vector of the closure instantiator.
1047 type_parameters = owner_class.type_parameters(); 1042 type_parameters = owner_class.type_parameters();
1048 type_parameter_extends = owner_class.type_parameter_extends(); 1043 type_parameter_extends = owner_class.type_parameter_extends();
1049 if (!owner_class.is_interface()) {
1050 super_type = owner_class.super_type();
1051 }
1052 } 1044 }
1053 } 1045 }
1054 Class& result = Class::Handle(New<Closure>(name, script)); 1046 Class& result = Class::Handle(New<Closure>(name, script));
1047 const Type& super_type = Type::Handle(Type::ObjectType());
1048 ASSERT(!super_type.IsNull());
1055 result.set_super_type(super_type); 1049 result.set_super_type(super_type);
1056 result.set_signature_function(signature_function); 1050 result.set_signature_function(signature_function);
1057 result.set_type_parameters(type_parameters); 1051 result.set_type_parameters(type_parameters);
1058 result.set_type_parameter_extends(type_parameter_extends); 1052 result.set_type_parameter_extends(type_parameter_extends);
1059 result.SetFields(Array::Handle(Array::Empty())); 1053 result.SetFields(Array::Handle(Array::Empty()));
1060 result.SetFunctions(Array::Handle(Array::Empty())); 1054 result.SetFunctions(Array::Handle(Array::Empty()));
1061 // Implements interface Function. 1055 // Implements interface "Function".
1062 const Type& function_interface = Type::Handle(Type::FunctionInterface()); 1056 const Type& function_interface = Type::Handle(Type::FunctionInterface());
1063 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); 1057 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld));
1064 interfaces.SetAt(0, function_interface); 1058 interfaces.SetAt(0, function_interface);
1065 result.set_interfaces(interfaces); 1059 result.set_interfaces(interfaces);
1066 // Unless the signature function already has a signature class, create a 1060 // Unless the signature function already has a signature class, create a
1067 // canonical signature class by having the signature function pointing back to 1061 // canonical signature class by having the signature function point back to
1068 // the signature class. 1062 // the signature class.
1069 if (signature_function.signature_class() == Object::null()) { 1063 if (signature_function.signature_class() == Object::null()) {
1070 signature_function.set_signature_class(result); 1064 signature_function.set_signature_class(result);
1071 } 1065 }
1066 result.set_is_finalized();
1067 // Instances of a signature class can only be closures.
1068 ASSERT(result.instance_size() == Closure::InstanceSize());
1069 // Cache the signature type as the first canonicalized type in result.
1070 const Type& signature_type = Type::Handle(result.SignatureType());
1071 ASSERT(!signature_type.IsFinalized());
1072 const Array& new_canonical_types = Array::Handle(Array::New(1, Heap::kOld));
1073 new_canonical_types.SetAt(0, signature_type);
1074 result.set_canonical_types(new_canonical_types);
1072 return result.raw(); 1075 return result.raw();
1073 } 1076 }
1074 1077
1075 1078
1076 RawClass* Class::GetClass(ObjectKind kind) { 1079 RawClass* Class::GetClass(ObjectKind kind) {
1077 ObjectStore* object_store = Isolate::Current()->object_store(); 1080 ObjectStore* object_store = Isolate::Current()->object_store();
1078 switch (kind) { 1081 switch (kind) {
1079 case kUnhandledException: 1082 case kUnhandledException:
1080 ASSERT(object_store->unhandled_exception_class() != Class::null()); 1083 ASSERT(object_store->unhandled_exception_class() != Class::null());
1081 return object_store->unhandled_exception_class(); 1084 return object_store->unhandled_exception_class();
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 1332
1330 bool Class::IsTopLevel() const { 1333 bool Class::IsTopLevel() const {
1331 return String::Handle(Name()).Length() == 0; 1334 return String::Handle(Name()).Length() == 0;
1332 } 1335 }
1333 1336
1334 1337
1335 bool Class::TestType(TypeTestKind test, 1338 bool Class::TestType(TypeTestKind test,
1336 const TypeArguments& type_arguments, 1339 const TypeArguments& type_arguments,
1337 const Class& other, 1340 const Class& other,
1338 const TypeArguments& other_type_arguments) const { 1341 const TypeArguments& other_type_arguments) const {
1342 ASSERT(is_finalized() || !ClassFinalizer::AllClassesFinalized());
1343 ASSERT(other.is_finalized() || !ClassFinalizer::AllClassesFinalized());
1339 if (test == kIsAssignableTo) { 1344 if (test == kIsAssignableTo) {
1340 // The spec states that "a type T is assignable to a type S if T is a 1345 // 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 1346 // 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 1347 // 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 1348 // value. However, this type information is available at run time in checked
1344 // mode. We therefore apply a more restrictive subtype check, which prevents 1349 // mode. We therefore apply a more restrictive subtype check, which prevents
1345 // heap pollution. We only keep the assignability check when assigning 1350 // heap pollution. We only keep the assignability check when assigning
1346 // values of a function type. 1351 // values of a function type.
1347 if (IsSignatureClass() && other.IsSignatureClass()) { 1352 if (IsSignatureClass() && other.IsSignatureClass()) {
1348 const Function& src_fun = Function::Handle(signature_function()); 1353 const Function& src_fun = Function::Handle(signature_function());
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); 1689 const intptr_t num_args = args.IsNull() ? 0 : args.Length();
1685 String& class_name = String::Handle(); 1690 String& class_name = String::Handle();
1686 intptr_t first_type_param_index; 1691 intptr_t first_type_param_index;
1687 intptr_t num_type_params; // Number of type parameters to print. 1692 intptr_t num_type_params; // Number of type parameters to print.
1688 if (HasResolvedTypeClass()) { 1693 if (HasResolvedTypeClass()) {
1689 const Class& cls = Class::Handle(type_class()); 1694 const Class& cls = Class::Handle(type_class());
1690 class_name = cls.Name(); 1695 class_name = cls.Name();
1691 num_type_params = cls.NumTypeParameters(); // Do not print the full vector. 1696 num_type_params = cls.NumTypeParameters(); // Do not print the full vector.
1692 if (num_type_params > num_args) { 1697 if (num_type_params > num_args) {
1693 first_type_param_index = 0; 1698 first_type_param_index = 0;
1694 if (IsBeingFinalized()) { 1699 if (!IsFinalized() || IsBeingFinalized()) {
1695 // Most probably an illformed type. Do not fill up with "Dynamic". 1700 // Most probably an illformed type. Do not fill up with "Dynamic".
1696 num_type_params = num_args; 1701 num_type_params = num_args;
1697 } else { 1702 } else {
1698 ASSERT(num_args == 0); // Type is raw. 1703 ASSERT(num_args == 0); // Type is raw.
1699 // We fill up with "Dynamic". 1704 // We fill up with "Dynamic".
1700 } 1705 }
1701 } else { 1706 } else {
1702 first_type_param_index = num_args - num_type_params; 1707 first_type_param_index = num_args - num_type_params;
1703 } 1708 }
1704 if (cls.IsSignatureClass()) { 1709 if (cls.IsSignatureClass()) {
1705 // We may be reporting an error about an illformed function type. In that 1710 // We may be reporting an error about an illformed function type. In that
1706 // case, avoid instantiating the signature, since it may lead to cycles. 1711 // case, avoid instantiating the signature, since it may lead to cycles.
1707 if (IsBeingFinalized()) { 1712 if (!IsFinalized() || IsBeingFinalized()) {
1708 return class_name.raw(); 1713 return class_name.raw();
1709 } 1714 }
1710 const Function& signature_function = Function::Handle( 1715 const Function& signature_function = Function::Handle(
1711 cls.signature_function()); 1716 cls.signature_function());
1712 return signature_function.InstantiatedSignatureFrom( 1717 return signature_function.InstantiatedSignatureFrom(
1713 args, first_type_param_index); 1718 args, first_type_param_index);
1714 } 1719 }
1715 } else { 1720 } else {
1716 const UnresolvedClass& cls = UnresolvedClass::Handle(unresolved_class()); 1721 const UnresolvedClass& cls = UnresolvedClass::Handle(unresolved_class());
1717 class_name = cls.Name(); 1722 class_name = cls.Name();
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
2000 const TypeArguments& args = TypeArguments::Handle(arguments()); 2005 const TypeArguments& args = TypeArguments::Handle(arguments());
2001 return args.IsNull() || args.IsInstantiated(); 2006 return args.IsNull() || args.IsInstantiated();
2002 } 2007 }
2003 2008
2004 2009
2005 RawType* ParameterizedType::InstantiateFrom( 2010 RawType* ParameterizedType::InstantiateFrom(
2006 const TypeArguments& instantiator_type_arguments, 2011 const TypeArguments& instantiator_type_arguments,
2007 intptr_t offset) const { 2012 intptr_t offset) const {
2008 ASSERT(IsFinalized()); 2013 ASSERT(IsFinalized());
2009 ASSERT(!IsInstantiated()); 2014 ASSERT(!IsInstantiated());
2010 TypeArguments& type_arguments = TypeArguments::Handle(); 2015 TypeArguments& type_arguments = TypeArguments::Handle(arguments());
2011 if (!instantiator_type_arguments.IsNull()) { 2016 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments,
2012 type_arguments = arguments(); 2017 offset);
2013 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments,
2014 offset);
2015 }
2016 const Class& cls = Class::Handle(type_class()); 2018 const Class& cls = Class::Handle(type_class());
2019 ASSERT(cls.is_finalized());
2017 ParameterizedType& instantiated_type = ParameterizedType::Handle( 2020 ParameterizedType& instantiated_type = ParameterizedType::Handle(
2018 ParameterizedType::New(cls, type_arguments)); 2021 ParameterizedType::New(cls, type_arguments));
2019 ASSERT(type_arguments.IsNull() || 2022 ASSERT(type_arguments.IsNull() ||
2020 (type_arguments.Length() == cls.NumTypeArguments())); 2023 (type_arguments.Length() == cls.NumTypeArguments()));
2021 instantiated_type.set_is_finalized(); 2024 instantiated_type.set_is_finalized();
2022 return instantiated_type.raw(); 2025 return instantiated_type.raw();
2023 } 2026 }
2024 2027
2025 2028
2026 bool ParameterizedType::Equals(const Type& other) const { 2029 bool ParameterizedType::Equals(const Type& other) const {
2027 ASSERT(IsFinalized() && other.IsFinalized()); 2030 ASSERT(IsFinalized() && other.IsFinalized());
2028 if (raw() == other.raw()) { 2031 if (raw() == other.raw()) {
2029 return true; 2032 return true;
2030 } 2033 }
2031 if (!other.IsParameterizedType()) { 2034 if (!other.IsParameterizedType()) {
2032 return false; 2035 return false;
2033 } 2036 }
2034 ParameterizedType& other_parameterized_type = ParameterizedType::Handle(); 2037 ParameterizedType& other_parameterized_type = ParameterizedType::Handle();
2035 other_parameterized_type ^= other.raw(); 2038 other_parameterized_type ^= other.raw();
2036 if (type_class() != other_parameterized_type.type_class()) { 2039 if (type_class() != other_parameterized_type.type_class()) {
2037 return false; 2040 return false;
2038 } 2041 }
2039 return TypeArguments::AreEqual(TypeArguments::Handle(arguments()), 2042 return TypeArguments::AreEqual(TypeArguments::Handle(arguments()),
2040 TypeArguments::Handle(other.arguments())); 2043 TypeArguments::Handle(other.arguments()));
2041 } 2044 }
2042 2045
2043 2046
2044 RawType* ParameterizedType::Canonicalize() const { 2047 RawType* ParameterizedType::Canonicalize() const {
2048 ASSERT(IsFinalized());
2045 const Class& cls = Class::Handle(type_class()); 2049 const Class& cls = Class::Handle(type_class());
2046 Array& canonical_types = Array::Handle(cls.canonical_types()); 2050 Array& canonical_types = Array::Handle(cls.canonical_types());
2047 if (canonical_types.IsNull()) { 2051 if (canonical_types.IsNull()) {
2048 // Types defined in the VM isolate are canonicalized via the object store. 2052 // Types defined in the VM isolate are canonicalized via the object store.
2049 // TODO(regis): Should we add null_class_, void_class_, dynamic_class_ to 2053 // TODO(regis): Should we add null_class_, void_class_, dynamic_class_ to
2050 // the object store, remove all types from the object store, and replace 2054 // the object store, remove all types from the object store, and replace
2051 // the test above by an assert? 2055 // the test above by an assert?
2052 return this->raw(); 2056 return this->raw();
2053 } 2057 }
2054 const intptr_t canonical_types_len = canonical_types.Length(); 2058 const intptr_t canonical_types_len = canonical_types.Length();
2055 // Linear search to see whether this type is already present in the 2059 // Linear search to see whether this type is already present in the
2056 // list of canonicalized types. 2060 // list of canonicalized types.
2057 Type& type = Type::Handle(); 2061 Type& type = Type::Handle();
2058 intptr_t index = 0; 2062 intptr_t index = 0;
2059 while (index < canonical_types_len) { 2063 while (index < canonical_types_len) {
2060 type ^= canonical_types.At(index); 2064 type ^= canonical_types.At(index);
2061 if (type.IsNull()) { 2065 if (type.IsNull()) {
2062 break; 2066 break;
2063 } 2067 }
2068 if (!type.IsFinalized()) {
2069 ASSERT((index == 0) && cls.IsSignatureClass());
2070 index++;
2071 continue;
2072 }
2064 if (this->Equals(type)) { 2073 if (this->Equals(type)) {
2065 return type.raw(); 2074 return type.raw();
2066 } 2075 }
2067 index++; 2076 index++;
2068 } 2077 }
2069 // The type needs to be added to the list. Grow the list if it is full. 2078 // The type needs to be added to the list. Grow the list if it is full.
2070 if (index == canonical_types_len) { 2079 if (index == canonical_types_len) {
2071 const intptr_t kLengthIncrement = 2; // Raw and parameterized. 2080 const intptr_t kLengthIncrement = 2; // Raw and parameterized.
2072 const intptr_t new_length = canonical_types.Length() + kLengthIncrement; 2081 const intptr_t new_length = canonical_types.Length() + kLengthIncrement;
2073 const Array& new_canonical_types = 2082 const Array& new_canonical_types =
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
2437 } 2446 }
2438 } 2447 }
2439 return true; 2448 return true;
2440 } 2449 }
2441 2450
2442 2451
2443 RawTypeArguments* TypeArray::InstantiateFrom( 2452 RawTypeArguments* TypeArray::InstantiateFrom(
2444 const TypeArguments& instantiator_type_arguments, 2453 const TypeArguments& instantiator_type_arguments,
2445 intptr_t offset) const { 2454 intptr_t offset) const {
2446 ASSERT(!IsInstantiated()); 2455 ASSERT(!IsInstantiated());
2447 if (instantiator_type_arguments.IsNull()) {
2448 return TypeArguments::null();
2449 }
2450 if ((offset == 0) && 2456 if ((offset == 0) &&
2451 !instantiator_type_arguments.IsNull() && 2457 !instantiator_type_arguments.IsNull() &&
2452 IsUninstantiatedIdentity() && 2458 IsUninstantiatedIdentity() &&
2453 (instantiator_type_arguments.Length() == Length())) { 2459 (instantiator_type_arguments.Length() == Length())) {
2454 return instantiator_type_arguments.raw(); 2460 return instantiator_type_arguments.raw();
2455 } 2461 }
2456 const intptr_t num_types = Length(); 2462 const intptr_t num_types = Length();
2457 TypeArray& instantiated_array = TypeArray::Handle(TypeArray::New(num_types)); 2463 TypeArray& instantiated_array = TypeArray::Handle(TypeArray::New(num_types));
2458 Type& type = Type::Handle(); 2464 Type& type = Type::Handle();
2459 for (intptr_t i = 0; i < num_types; i++) { 2465 for (intptr_t i = 0; i < num_types; i++) {
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
3129 library.LookupLocalClass(signature)); 3135 library.LookupLocalClass(signature));
3130 if (signature_class.IsNull()) { 3136 if (signature_class.IsNull()) {
3131 const Script& script = Script::Handle(owner_class.script()); 3137 const Script& script = Script::Handle(owner_class.script());
3132 signature_class = Class::NewSignatureClass(signature, 3138 signature_class = Class::NewSignatureClass(signature,
3133 closure_function, 3139 closure_function,
3134 script); 3140 script);
3135 library.AddClass(signature_class); 3141 library.AddClass(signature_class);
3136 } else { 3142 } else {
3137 closure_function.set_signature_class(signature_class); 3143 closure_function.set_signature_class(signature_class);
3138 } 3144 }
3145 const Type& signature_type = Type::Handle(signature_class.SignatureType());
3146 if (!signature_type.IsFinalized()) {
3147 String& errmsg = String::Handle();
3148 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, &errmsg);
3149 ASSERT(errmsg.IsNull());
3150 }
3139 ASSERT(closure_function.signature_class() == signature_class.raw()); 3151 ASSERT(closure_function.signature_class() == signature_class.raw());
3140 set_implicit_closure_function(closure_function); 3152 set_implicit_closure_function(closure_function);
3141 ASSERT(closure_function.IsImplicitClosureFunction()); 3153 ASSERT(closure_function.IsImplicitClosureFunction());
3142 return closure_function.raw(); 3154 return closure_function.raw();
3143 } 3155 }
3144 3156
3145 3157
3146 template<typename T> 3158 template<typename T>
3147 static RawArray* NewArray(const GrowableArray<T*>& objs) { 3159 static RawArray* NewArray(const GrowableArray<T*>& objs) {
3148 Array& a = Array::Handle(Array::New(objs.length(), Heap::kOld)); 3160 Array& a = Array::Handle(Array::New(objs.length(), Heap::kOld));
(...skipping 1706 matching lines...) Expand 10 before | Expand all | Expand 10 after
4855 4867
4856 RawType* Instance::GetType() const { 4868 RawType* Instance::GetType() const {
4857 if (IsNull()) { 4869 if (IsNull()) {
4858 return Type::NullType(); 4870 return Type::NullType();
4859 } 4871 }
4860 const Class& cls = Class::Handle(clazz()); 4872 const Class& cls = Class::Handle(clazz());
4861 TypeArguments& type_arguments = TypeArguments::Handle(); 4873 TypeArguments& type_arguments = TypeArguments::Handle();
4862 if (cls.HasTypeArguments()) { 4874 if (cls.HasTypeArguments()) {
4863 type_arguments = GetTypeArguments(); 4875 type_arguments = GetTypeArguments();
4864 } 4876 }
4865 return Type::NewParameterizedType(cls, type_arguments); 4877 const ParameterizedType& type = ParameterizedType::Handle(
4878 ParameterizedType::New(cls, type_arguments));
4879 type.set_is_finalized();
4880 return type.raw();
4866 } 4881 }
4867 4882
4868 4883
4869 RawTypeArguments* Instance::GetTypeArguments() const { 4884 RawTypeArguments* Instance::GetTypeArguments() const {
4870 const Class& cls = Class::Handle(clazz()); 4885 const Class& cls = Class::Handle(clazz());
4871 intptr_t field_offset = cls.type_arguments_instance_field_offset(); 4886 intptr_t field_offset = cls.type_arguments_instance_field_offset();
4872 ASSERT(field_offset != Class::kNoTypeArguments); 4887 ASSERT(field_offset != Class::kNoTypeArguments);
4873 TypeArguments& type_arguments = TypeArguments::Handle(); 4888 TypeArguments& type_arguments = TypeArguments::Handle();
4874 type_arguments ^= *FieldAddrAtOffset(field_offset); 4889 type_arguments ^= *FieldAddrAtOffset(field_offset);
4875 return type_arguments.raw(); 4890 return type_arguments.raw();
(...skipping 2104 matching lines...) Expand 10 before | Expand all | Expand 10 after
6980 const String& str = String::Handle(pattern()); 6995 const String& str = String::Handle(pattern());
6981 const char* format = "JSRegExp: pattern=%s flags=%s"; 6996 const char* format = "JSRegExp: pattern=%s flags=%s";
6982 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 6997 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
6983 char* chars = reinterpret_cast<char*>( 6998 char* chars = reinterpret_cast<char*>(
6984 Isolate::Current()->current_zone()->Allocate(len + 1)); 6999 Isolate::Current()->current_zone()->Allocate(len + 1));
6985 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 7000 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
6986 return chars; 7001 return chars;
6987 } 7002 }
6988 7003
6989 } // namespace dart 7004 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698