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

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

Issue 14820028: Delay Class parsing until the class is actually used. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 11 matching lines...) Expand all
22 #include "vm/datastream.h" 22 #include "vm/datastream.h"
23 #include "vm/debugger.h" 23 #include "vm/debugger.h"
24 #include "vm/deopt_instructions.h" 24 #include "vm/deopt_instructions.h"
25 #include "vm/double_conversion.h" 25 #include "vm/double_conversion.h"
26 #include "vm/exceptions.h" 26 #include "vm/exceptions.h"
27 #include "vm/flow_graph_builder.h" 27 #include "vm/flow_graph_builder.h"
28 #include "vm/growable_array.h" 28 #include "vm/growable_array.h"
29 #include "vm/heap.h" 29 #include "vm/heap.h"
30 #include "vm/intermediate_language.h" 30 #include "vm/intermediate_language.h"
31 #include "vm/intrinsifier.h" 31 #include "vm/intrinsifier.h"
32 #include "vm/longjump.h"
32 #include "vm/object_store.h" 33 #include "vm/object_store.h"
33 #include "vm/parser.h" 34 #include "vm/parser.h"
34 #include "vm/runtime_entry.h" 35 #include "vm/runtime_entry.h"
35 #include "vm/scopes.h" 36 #include "vm/scopes.h"
36 #include "vm/stack_frame.h" 37 #include "vm/stack_frame.h"
37 #include "vm/symbols.h" 38 #include "vm/symbols.h"
38 #include "vm/timer.h" 39 #include "vm/timer.h"
39 #include "vm/unicode.h" 40 #include "vm/unicode.h"
40 41
41 namespace dart { 42 namespace dart {
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 // Initialization from Class::New<Class>. 357 // Initialization from Class::New<Class>.
357 // Directly set raw_ to break a circular dependency: SetRaw will attempt 358 // Directly set raw_ to break a circular dependency: SetRaw will attempt
358 // to lookup class class in the class table where it is not registered yet. 359 // to lookup class class in the class table where it is not registered yet.
359 cls.raw_ = class_class_; 360 cls.raw_ = class_class_;
360 cls.set_handle_vtable(fake.vtable()); 361 cls.set_handle_vtable(fake.vtable());
361 cls.set_instance_size(Class::InstanceSize()); 362 cls.set_instance_size(Class::InstanceSize());
362 cls.set_next_field_offset(Class::InstanceSize()); 363 cls.set_next_field_offset(Class::InstanceSize());
363 cls.set_id(Class::kClassId); 364 cls.set_id(Class::kClassId);
364 cls.raw_ptr()->state_bits_ = 0; 365 cls.raw_ptr()->state_bits_ = 0;
365 cls.set_is_finalized(); 366 cls.set_is_finalized();
367 cls.set_is_type_finalized();
366 cls.raw_ptr()->type_arguments_field_offset_in_words_ = 368 cls.raw_ptr()->type_arguments_field_offset_in_words_ =
367 Class::kNoTypeArguments; 369 Class::kNoTypeArguments;
368 cls.raw_ptr()->num_native_fields_ = 0; 370 cls.raw_ptr()->num_native_fields_ = 0;
369 cls.InitEmptyFields(); 371 cls.InitEmptyFields();
370 isolate->class_table()->Register(cls); 372 isolate->class_table()->Register(cls);
371 } 373 }
372 374
373 // Allocate and initialize the null class. 375 // Allocate and initialize the null class.
374 cls = Class::New<Instance>(kNullCid); 376 cls = Class::New<Instance>(kNullCid);
375 cls.set_is_finalized(); 377 cls.set_is_finalized();
378 cls.set_is_type_finalized();
376 null_class_ = cls.raw(); 379 null_class_ = cls.raw();
377 380
378 // Allocate and initialize the free list element class. 381 // Allocate and initialize the free list element class.
379 cls = Class::New<FreeListElement::FakeInstance>(kFreeListElement); 382 cls = Class::New<FreeListElement::FakeInstance>(kFreeListElement);
380 cls.set_is_finalized(); 383 cls.set_is_finalized();
384 cls.set_is_type_finalized();
381 385
382 // Allocate and initialize the sentinel values of Null class. 386 // Allocate and initialize the sentinel values of Null class.
383 { 387 {
384 *sentinel_ ^= 388 *sentinel_ ^=
385 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); 389 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld);
386 390
387 *transition_sentinel_ ^= 391 *transition_sentinel_ ^=
388 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); 392 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld);
389 } 393 }
390 394
391 // Allocate and initialize optimizing compiler constants. 395 // Allocate and initialize optimizing compiler constants.
392 { 396 {
393 *unknown_constant_ ^= 397 *unknown_constant_ ^=
394 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); 398 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld);
395 *non_constant_ ^= 399 *non_constant_ ^=
396 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); 400 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld);
397 } 401 }
398 402
399 cls = Class::New<Instance>(kDynamicCid); 403 cls = Class::New<Instance>(kDynamicCid);
400 cls.set_is_finalized(); 404 cls.set_is_finalized();
405 cls.set_is_type_finalized();
401 cls.set_is_abstract(); 406 cls.set_is_abstract();
402 dynamic_class_ = cls.raw(); 407 dynamic_class_ = cls.raw();
403 408
404 // Allocate the remaining VM internal classes. 409 // Allocate the remaining VM internal classes.
405 cls = Class::New<UnresolvedClass>(); 410 cls = Class::New<UnresolvedClass>();
406 unresolved_class_class_ = cls.raw(); 411 unresolved_class_class_ = cls.raw();
407 412
408 cls = Class::New<Instance>(kVoidCid); 413 cls = Class::New<Instance>(kVoidCid);
409 cls.set_is_finalized(); 414 cls.set_is_finalized();
415 cls.set_is_type_finalized();
410 void_class_ = cls.raw(); 416 void_class_ = cls.raw();
411 417
412 cls = Class::New<TypeArguments>(); 418 cls = Class::New<TypeArguments>();
413 type_arguments_class_ = cls.raw(); 419 type_arguments_class_ = cls.raw();
414 420
415 cls = Class::New<InstantiatedTypeArguments>(); 421 cls = Class::New<InstantiatedTypeArguments>();
416 instantiated_type_arguments_class_ = cls.raw(); 422 instantiated_type_arguments_class_ = cls.raw();
417 423
418 cls = Class::New<PatchClass>(); 424 cls = Class::New<PatchClass>();
419 patch_class_class_ = cls.raw(); 425 patch_class_class_ = cls.raw();
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 RegisterClass(cls, Symbols::Double(), core_lib); 993 RegisterClass(cls, Symbols::Double(), core_lib);
988 cls.set_is_prefinalized(); 994 cls.set_is_prefinalized();
989 pending_classes.Add(cls, Heap::kOld); 995 pending_classes.Add(cls, Heap::kOld);
990 type = Type::NewNonParameterizedType(cls); 996 type = Type::NewNonParameterizedType(cls);
991 object_store->set_double_type(type); 997 object_store->set_double_type(type);
992 998
993 name = Symbols::New("String"); 999 name = Symbols::New("String");
994 cls = Class::New<Instance>(kIllegalCid); 1000 cls = Class::New<Instance>(kIllegalCid);
995 cls.set_is_prefinalized(); 1001 cls.set_is_prefinalized();
996 RegisterClass(cls, name, core_lib); 1002 RegisterClass(cls, name, core_lib);
1003 cls.set_is_prefinalized();
997 pending_classes.Add(cls, Heap::kOld); 1004 pending_classes.Add(cls, Heap::kOld);
998 type = Type::NewNonParameterizedType(cls); 1005 type = Type::NewNonParameterizedType(cls);
999 object_store->set_string_type(type); 1006 object_store->set_string_type(type);
1000 1007
1001 cls = Class::New<Instance>(kIllegalCid); 1008 cls = Class::New<Instance>(kIllegalCid);
1002 RegisterClass(cls, Symbols::List(), core_lib); 1009 RegisterClass(cls, Symbols::List(), core_lib);
1003 cls.set_is_prefinalized(); 1010 cls.set_is_prefinalized();
1004 pending_classes.Add(cls, Heap::kOld); 1011 pending_classes.Add(cls, Heap::kOld);
1005 object_store->set_list_class(cls); 1012 object_store->set_list_class(cls);
1006 1013
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 1543
1537 void Class::set_class_state(RawClass::ClassState state) const { 1544 void Class::set_class_state(RawClass::ClassState state) const {
1538 ASSERT((state == RawClass::kAllocated) || 1545 ASSERT((state == RawClass::kAllocated) ||
1539 (state == RawClass::kPreFinalized) || 1546 (state == RawClass::kPreFinalized) ||
1540 (state == RawClass::kFinalized)); 1547 (state == RawClass::kFinalized));
1541 set_state_bits(StateBits::update(state, raw_ptr()->state_bits_)); 1548 set_state_bits(StateBits::update(state, raw_ptr()->state_bits_));
1542 } 1549 }
1543 1550
1544 1551
1545 void Class::set_state_bits(intptr_t bits) const { 1552 void Class::set_state_bits(intptr_t bits) const {
1546 raw_ptr()->state_bits_ = static_cast<uint8_t>(bits); 1553 raw_ptr()->state_bits_ = static_cast<uint16_t>(bits);
1547 } 1554 }
1548 1555
1549 1556
1550 void Class::set_library(const Library& value) const { 1557 void Class::set_library(const Library& value) const {
1551 StorePointer(&raw_ptr()->library_, value.raw()); 1558 StorePointer(&raw_ptr()->library_, value.raw());
1552 } 1559 }
1553 1560
1554 1561
1555 void Class::set_type_parameters(const TypeArguments& value) const { 1562 void Class::set_type_parameters(const TypeArguments& value) const {
1556 StorePointer(&raw_ptr()->type_parameters_, value.raw()); 1563 StorePointer(&raw_ptr()->type_parameters_, value.raw());
(...skipping 25 matching lines...) Expand all
1582 const Class& superclass = Class::Handle(cls.SuperClass()); 1589 const Class& superclass = Class::Handle(cls.SuperClass());
1583 // Object is its own super class during bootstrap. 1590 // Object is its own super class during bootstrap.
1584 if (!superclass.IsNull() && (superclass.raw() != raw())) { 1591 if (!superclass.IsNull() && (superclass.raw() != raw())) {
1585 num_type_args += superclass.NumTypeArguments(); 1592 num_type_args += superclass.NumTypeArguments();
1586 } 1593 }
1587 return num_type_args; 1594 return num_type_args;
1588 } 1595 }
1589 1596
1590 1597
1591 bool Class::HasTypeArguments() const { 1598 bool Class::HasTypeArguments() const {
1592 if (!IsSignatureClass() && (is_finalized() || is_prefinalized())) { 1599 if (!IsSignatureClass() && (is_type_finalized() || is_prefinalized())) {
1593 // More efficient than calling NumTypeArguments(). 1600 // More efficient than calling NumTypeArguments().
1594 return type_arguments_field_offset() != kNoTypeArguments; 1601 return type_arguments_field_offset() != kNoTypeArguments;
1595 } else { 1602 } else {
1596 // No need to check NumTypeArguments() if class has type parameters. 1603 // No need to check NumTypeArguments() if class has type parameters.
1597 return (NumTypeParameters() > 0) || (NumTypeArguments() > 0); 1604 return (NumTypeParameters() > 0) || (NumTypeArguments() > 0);
1598 } 1605 }
1599 } 1606 }
1600 1607
1601 1608
1602 RawClass* Class::SuperClass() const { 1609 RawClass* Class::SuperClass() const {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 } 1783 }
1777 SetFields(new_list); 1784 SetFields(new_list);
1778 1785
1779 // The functions and fields in the patch class are no longer needed. 1786 // The functions and fields in the patch class are no longer needed.
1780 patch.SetFunctions(Object::empty_array()); 1787 patch.SetFunctions(Object::empty_array());
1781 patch.SetFields(Object::empty_array()); 1788 patch.SetFields(Object::empty_array());
1782 return NULL; 1789 return NULL;
1783 } 1790 }
1784 1791
1785 1792
1793 // Ensure that top level parsing of the class has been done.
1794 RawError* Class::EnsureIsFinalized(Isolate* isolate) const {
1795 // Finalized classes have already been parsed.
1796 if (is_finalized()) {
1797 return Error::null();
1798 }
1799 ASSERT(isolate != NULL);
1800 const Error& error = Error::Handle(isolate, Compiler::CompileClass(*this));
1801 if (!error.IsNull() && (isolate->long_jump_base() != NULL)) {
1802 isolate->long_jump_base()->Jump(1, error);
1803 UNREACHABLE();
1804 }
1805 return error.raw();
1806 }
1807
1808
1786 void Class::SetFields(const Array& value) const { 1809 void Class::SetFields(const Array& value) const {
1787 ASSERT(!value.IsNull()); 1810 ASSERT(!value.IsNull());
1788 #if defined(DEBUG) 1811 #if defined(DEBUG)
1789 // Verify that all the fields in the array have this class as owner. 1812 // Verify that all the fields in the array have this class as owner.
1790 Field& field = Field::Handle(); 1813 Field& field = Field::Handle();
1791 intptr_t len = value.Length(); 1814 intptr_t len = value.Length();
1792 for (intptr_t i = 0; i < len; i++) { 1815 for (intptr_t i = 0; i < len; i++) {
1793 field ^= value.At(i); 1816 field ^= value.At(i);
1794 ASSERT(field.owner() == raw()); 1817 ASSERT(field.owner() == raw());
1795 } 1818 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1841 const Function& signature_function, 1864 const Function& signature_function,
1842 const Script& script, 1865 const Script& script,
1843 intptr_t token_pos) { 1866 intptr_t token_pos) {
1844 const Class& result = Class::Handle(New(name, script, token_pos)); 1867 const Class& result = Class::Handle(New(name, script, token_pos));
1845 const Type& super_type = Type::Handle(Type::ObjectType()); 1868 const Type& super_type = Type::Handle(Type::ObjectType());
1846 ASSERT(!super_type.IsNull()); 1869 ASSERT(!super_type.IsNull());
1847 // Instances of a signature class can only be closures. 1870 // Instances of a signature class can only be closures.
1848 result.set_instance_size(Closure::InstanceSize()); 1871 result.set_instance_size(Closure::InstanceSize());
1849 result.set_next_field_offset(Closure::InstanceSize()); 1872 result.set_next_field_offset(Closure::InstanceSize());
1850 result.set_super_type(super_type); 1873 result.set_super_type(super_type);
1874 result.set_is_synthesized_class();
1851 result.set_type_arguments_field_offset(Closure::type_arguments_offset()); 1875 result.set_type_arguments_field_offset(Closure::type_arguments_offset());
1852 // Implements interface "Function". 1876 // Implements interface "Function".
1853 const Type& function_type = Type::Handle(Type::Function()); 1877 const Type& function_type = Type::Handle(Type::Function());
1854 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); 1878 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld));
1855 interfaces.SetAt(0, function_type); 1879 interfaces.SetAt(0, function_type);
1856 result.set_interfaces(interfaces); 1880 result.set_interfaces(interfaces);
1857 if (!signature_function.IsNull()) { 1881 if (!signature_function.IsNull()) {
1858 result.PatchSignatureFunction(signature_function); 1882 result.PatchSignatureFunction(signature_function);
1859 } 1883 }
1860 return result.raw(); 1884 return result.raw();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 cls.SetFunctions(Object::empty_array()); 1925 cls.SetFunctions(Object::empty_array());
1902 // Set super class to Object. 1926 // Set super class to Object.
1903 cls.set_super_type(Type::Handle(Type::ObjectType())); 1927 cls.set_super_type(Type::Handle(Type::ObjectType()));
1904 // Compute instance size. First word contains a pointer to a properly 1928 // Compute instance size. First word contains a pointer to a properly
1905 // sized typed array once the first native field has been set. 1929 // sized typed array once the first native field has been set.
1906 intptr_t instance_size = sizeof(RawObject) + kWordSize; 1930 intptr_t instance_size = sizeof(RawObject) + kWordSize;
1907 cls.set_instance_size(RoundedAllocationSize(instance_size)); 1931 cls.set_instance_size(RoundedAllocationSize(instance_size));
1908 cls.set_next_field_offset(instance_size); 1932 cls.set_next_field_offset(instance_size);
1909 cls.set_num_native_fields(field_count); 1933 cls.set_num_native_fields(field_count);
1910 cls.set_is_finalized(); 1934 cls.set_is_finalized();
1935 cls.set_is_type_finalized();
1911 library.AddClass(cls); 1936 library.AddClass(cls);
1912 return cls.raw(); 1937 return cls.raw();
1913 } else { 1938 } else {
1914 return Class::null(); 1939 return Class::null();
1915 } 1940 }
1916 } 1941 }
1917 1942
1918 1943
1919 RawClass* Class::NewStringClass(intptr_t class_id) { 1944 RawClass* Class::NewStringClass(intptr_t class_id) {
1920 intptr_t instance_size; 1945 intptr_t instance_size;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1987 void Class::set_is_implemented() const { 2012 void Class::set_is_implemented() const {
1988 set_state_bits(ImplementedBit::update(true, raw_ptr()->state_bits_)); 2013 set_state_bits(ImplementedBit::update(true, raw_ptr()->state_bits_));
1989 } 2014 }
1990 2015
1991 2016
1992 void Class::set_is_abstract() const { 2017 void Class::set_is_abstract() const {
1993 set_state_bits(AbstractBit::update(true, raw_ptr()->state_bits_)); 2018 set_state_bits(AbstractBit::update(true, raw_ptr()->state_bits_));
1994 } 2019 }
1995 2020
1996 2021
2022 void Class::set_is_type_finalized() const {
2023 set_state_bits(TypeFinalizedBit::update(true, raw_ptr()->state_bits_));
2024 }
2025
2026
2027 void Class::set_is_patch() const {
2028 set_state_bits(PatchBit::update(true, raw_ptr()->state_bits_));
2029 }
2030
2031
2032 void Class::set_is_synthesized_class() const {
2033 set_state_bits(SynthesizedClassBit::update(true, raw_ptr()->state_bits_));
2034 }
2035
2036
1997 void Class::set_is_const() const { 2037 void Class::set_is_const() const {
1998 set_state_bits(ConstBit::update(true, raw_ptr()->state_bits_)); 2038 set_state_bits(ConstBit::update(true, raw_ptr()->state_bits_));
1999 } 2039 }
2000 2040
2001 2041
2002 void Class::set_is_finalized() const { 2042 void Class::set_is_finalized() const {
2003 ASSERT(!is_finalized()); 2043 ASSERT(!is_finalized());
2004 set_state_bits(StateBits::update(RawClass::kFinalized, 2044 set_state_bits(StateBits::update(RawClass::kFinalized,
2005 raw_ptr()->state_bits_)); 2045 raw_ptr()->state_bits_));
2006 } 2046 }
2007 2047
2008 2048
2009 void Class::set_is_prefinalized() const { 2049 void Class::set_is_prefinalized() const {
2010 ASSERT(!is_finalized()); 2050 ASSERT(!is_finalized());
2011 set_state_bits(StateBits::update(RawClass::kPreFinalized, 2051 set_state_bits(StateBits::update(RawClass::kPreFinalized,
2012 raw_ptr()->state_bits_)); 2052 raw_ptr()->state_bits_));
2013 } 2053 }
2014 2054
2015 2055
2056 void Class::set_is_marked_for_parsing() const {
2057 set_state_bits(MarkedForParsingBit::update(true, raw_ptr()->state_bits_));
2058 }
2059
2060
2061 void Class::reset_is_marked_for_parsing() const {
2062 set_state_bits(MarkedForParsingBit::update(false, raw_ptr()->state_bits_));
2063 }
2064
2065
2016 void Class::set_interfaces(const Array& value) const { 2066 void Class::set_interfaces(const Array& value) const {
2017 // Verification and resolving of interfaces occurs in finalizer. 2067 // Verification and resolving of interfaces occurs in finalizer.
2018 ASSERT(!value.IsNull()); 2068 ASSERT(!value.IsNull());
2019 StorePointer(&raw_ptr()->interfaces_, value.raw()); 2069 StorePointer(&raw_ptr()->interfaces_, value.raw());
2020 } 2070 }
2021 2071
2022 2072
2023 void Class::set_mixin(const Type& value) const { 2073 void Class::set_mixin(const Type& value) const {
2024 // Resolution and application of mixin type occurs in finalizer. 2074 // Resolution and application of mixin type occurs in finalizer.
2025 ASSERT(!value.IsNull()); 2075 ASSERT(!value.IsNull());
2026 StorePointer(&raw_ptr()->mixin_, value.raw()); 2076 StorePointer(&raw_ptr()->mixin_, value.raw());
2027 } 2077 }
2028 2078
2029 2079
2080 void Class::add_patch_class(const Class& patch_class) const {
2081 ASSERT(!patch_class.IsNull());
2082 GrowableObjectArray& patch_classes = GrowableObjectArray::Handle();
2083 patch_classes ^= raw_ptr()->patch_classes_;
2084 if (patch_classes.IsNull()) {
2085 patch_classes ^= GrowableObjectArray::New(1, Heap::kOld);
2086 StorePointer(&raw_ptr()->patch_classes_, patch_classes.raw());
2087 }
2088 patch_classes.Add(patch_class);
2089 }
2090
2091
2030 void Class::AddDirectSubclass(const Class& subclass) const { 2092 void Class::AddDirectSubclass(const Class& subclass) const {
2031 ASSERT(!subclass.IsNull()); 2093 ASSERT(!subclass.IsNull());
2032 ASSERT(subclass.SuperClass() == raw()); 2094 ASSERT(subclass.SuperClass() == raw());
2033 // Do not keep track of the direct subclasses of class Object. 2095 // Do not keep track of the direct subclasses of class Object.
2034 ASSERT(!IsObjectClass()); 2096 ASSERT(!IsObjectClass());
2035 GrowableObjectArray& direct_subclasses = 2097 GrowableObjectArray& direct_subclasses =
2036 GrowableObjectArray::Handle(raw_ptr()->direct_subclasses_); 2098 GrowableObjectArray::Handle(raw_ptr()->direct_subclasses_);
2037 if (direct_subclasses.IsNull()) { 2099 if (direct_subclasses.IsNull()) {
2038 direct_subclasses = GrowableObjectArray::New(4, Heap::kOld); 2100 direct_subclasses = GrowableObjectArray::New(4, Heap::kOld);
2039 StorePointer(&raw_ptr()->direct_subclasses_, direct_subclasses.raw()); 2101 StorePointer(&raw_ptr()->direct_subclasses_, direct_subclasses.raw());
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
2335 if (name.CharAt(j) != accessor_name.CharAt(i)) { 2397 if (name.CharAt(j) != accessor_name.CharAt(i)) {
2336 return false; 2398 return false;
2337 } 2399 }
2338 } 2400 }
2339 return true; 2401 return true;
2340 } 2402 }
2341 2403
2342 2404
2343 RawFunction* Class::LookupFunction(const String& name) const { 2405 RawFunction* Class::LookupFunction(const String& name) const {
2344 Isolate* isolate = Isolate::Current(); 2406 Isolate* isolate = Isolate::Current();
2407 if (EnsureIsFinalized(isolate) != Error::null()) {
2408 return Function::null();
2409 }
2345 Array& funcs = Array::Handle(isolate, functions()); 2410 Array& funcs = Array::Handle(isolate, functions());
2346 if (funcs.IsNull()) { 2411 if (funcs.IsNull()) {
2347 // This can occur, e.g., for Null classes. 2412 // This can occur, e.g., for Null classes.
2348 return Function::null(); 2413 return Function::null();
2349 } 2414 }
2350 Function& function = Function::Handle(isolate, Function::null()); 2415 Function& function = Function::Handle(isolate, Function::null());
2351 const intptr_t len = funcs.Length(); 2416 const intptr_t len = funcs.Length();
2352 if (name.IsSymbol()) { 2417 if (name.IsSymbol()) {
2353 // Quick Symbol compare. 2418 // Quick Symbol compare.
2354 NoGCScope no_gc; 2419 NoGCScope no_gc;
(...skipping 13 matching lines...) Expand all
2368 } 2433 }
2369 } 2434 }
2370 } 2435 }
2371 // No function found. 2436 // No function found.
2372 return Function::null(); 2437 return Function::null();
2373 } 2438 }
2374 2439
2375 2440
2376 RawFunction* Class::LookupFunctionAllowPrivate(const String& name) const { 2441 RawFunction* Class::LookupFunctionAllowPrivate(const String& name) const {
2377 Isolate* isolate = Isolate::Current(); 2442 Isolate* isolate = Isolate::Current();
2443 if (EnsureIsFinalized(isolate) != Error::null()) {
2444 return Function::null();
2445 }
2378 Array& funcs = Array::Handle(isolate, functions()); 2446 Array& funcs = Array::Handle(isolate, functions());
2379 if (funcs.IsNull()) { 2447 if (funcs.IsNull()) {
2380 // This can occur, e.g., for Null classes. 2448 // This can occur, e.g., for Null classes.
2381 return Function::null(); 2449 return Function::null();
2382 } 2450 }
2383 Function& function = Function::Handle(isolate, Function::null()); 2451 Function& function = Function::Handle(isolate, Function::null());
2384 String& function_name = String::Handle(isolate, String::null()); 2452 String& function_name = String::Handle(isolate, String::null());
2385 intptr_t len = funcs.Length(); 2453 intptr_t len = funcs.Length();
2386 for (intptr_t i = 0; i < len; i++) { 2454 for (intptr_t i = 0; i < len; i++) {
2387 function ^= funcs.At(i); 2455 function ^= funcs.At(i);
(...skipping 14 matching lines...) Expand all
2402 2470
2403 RawFunction* Class::LookupSetterFunction(const String& name) const { 2471 RawFunction* Class::LookupSetterFunction(const String& name) const {
2404 return LookupAccessorFunction(kSetterPrefix, kSetterPrefixLength, name); 2472 return LookupAccessorFunction(kSetterPrefix, kSetterPrefixLength, name);
2405 } 2473 }
2406 2474
2407 2475
2408 RawFunction* Class::LookupAccessorFunction(const char* prefix, 2476 RawFunction* Class::LookupAccessorFunction(const char* prefix,
2409 intptr_t prefix_length, 2477 intptr_t prefix_length,
2410 const String& name) const { 2478 const String& name) const {
2411 Isolate* isolate = Isolate::Current(); 2479 Isolate* isolate = Isolate::Current();
2480 if (EnsureIsFinalized(isolate) != Error::null()) {
2481 return Function::null();
2482 }
2412 Array& funcs = Array::Handle(isolate, functions()); 2483 Array& funcs = Array::Handle(isolate, functions());
2413 Function& function = Function::Handle(isolate, Function::null()); 2484 Function& function = Function::Handle(isolate, Function::null());
2414 String& function_name = String::Handle(isolate, String::null()); 2485 String& function_name = String::Handle(isolate, String::null());
2415 intptr_t len = funcs.Length(); 2486 intptr_t len = funcs.Length();
2416 for (intptr_t i = 0; i < len; i++) { 2487 for (intptr_t i = 0; i < len; i++) {
2417 function ^= funcs.At(i); 2488 function ^= funcs.At(i);
2418 function_name ^= function.name(); 2489 function_name ^= function.name();
2419 if (MatchesAccessorName(function_name, prefix, prefix_length, name)) { 2490 if (MatchesAccessorName(function_name, prefix, prefix_length, name)) {
2420 return function.raw(); 2491 return function.raw();
2421 } 2492 }
2422 } 2493 }
2423 2494
2424 // No function found. 2495 // No function found.
2425 return Function::null(); 2496 return Function::null();
2426 } 2497 }
2427 2498
2428 2499
2429 RawFunction* Class::LookupFunctionAtToken(intptr_t token_pos) const { 2500 RawFunction* Class::LookupFunctionAtToken(intptr_t token_pos) const {
2430 // TODO(hausner): we can shortcut the negative case if we knew the 2501 // TODO(hausner): we can shortcut the negative case if we knew the
2431 // beginning and end token position of the class. 2502 // beginning and end token position of the class.
2432 Function& func = Function::Handle(); 2503 Isolate* isolate = Isolate::Current();
2504 if (EnsureIsFinalized(isolate) != Error::null()) {
2505 return Function::null();
2506 }
2507 Function& func = Function::Handle(isolate);
2433 func = LookupClosureFunction(token_pos); 2508 func = LookupClosureFunction(token_pos);
2434 if (!func.IsNull()) { 2509 if (!func.IsNull()) {
2435 return func.raw(); 2510 return func.raw();
2436 } 2511 }
2437 Array& funcs = Array::Handle(functions()); 2512 Array& funcs = Array::Handle(isolate, functions());
2438 intptr_t len = funcs.Length(); 2513 intptr_t len = funcs.Length();
2439 for (intptr_t i = 0; i < len; i++) { 2514 for (intptr_t i = 0; i < len; i++) {
2440 func ^= funcs.At(i); 2515 func ^= funcs.At(i);
2441 if ((func.token_pos() <= token_pos) && 2516 if ((func.token_pos() <= token_pos) &&
2442 (token_pos <= func.end_token_pos())) { 2517 (token_pos <= func.end_token_pos())) {
2443 return func.raw(); 2518 return func.raw();
2444 } 2519 }
2445 } 2520 }
2446 // No function found. 2521 // No function found.
2447 return Function::null(); 2522 return Function::null();
2448 } 2523 }
2449 2524
2450 2525
2451 RawField* Class::LookupInstanceField(const String& name) const { 2526 RawField* Class::LookupInstanceField(const String& name) const {
2527 Isolate* isolate = Isolate::Current();
2528 if (EnsureIsFinalized(isolate) != Error::null()) {
2529 return Field::null();
2530 }
2452 ASSERT(is_finalized()); 2531 ASSERT(is_finalized());
2453 const Field& field = Field::Handle(LookupField(name)); 2532 const Field& field = Field::Handle(isolate, LookupField(name));
2454 if (!field.IsNull()) { 2533 if (!field.IsNull()) {
2455 if (field.is_static()) { 2534 if (field.is_static()) {
2456 // Name matches but it is not of the correct kind, return NULL. 2535 // Name matches but it is not of the correct kind, return NULL.
2457 return Field::null(); 2536 return Field::null();
2458 } 2537 }
2459 return field.raw(); 2538 return field.raw();
2460 } 2539 }
2461 // No field found. 2540 // No field found.
2462 return Field::null(); 2541 return Field::null();
2463 } 2542 }
2464 2543
2465 2544
2466 RawField* Class::LookupStaticField(const String& name) const { 2545 RawField* Class::LookupStaticField(const String& name) const {
2546 Isolate* isolate = Isolate::Current();
2547 if (EnsureIsFinalized(isolate) != Error::null()) {
2548 return Field::null();
2549 }
2467 ASSERT(is_finalized()); 2550 ASSERT(is_finalized());
2468 const Field& field = Field::Handle(LookupField(name)); 2551 const Field& field = Field::Handle(isolate, LookupField(name));
2469 if (!field.IsNull()) { 2552 if (!field.IsNull()) {
2470 if (!field.is_static()) { 2553 if (!field.is_static()) {
2471 // Name matches but it is not of the correct kind, return NULL. 2554 // Name matches but it is not of the correct kind, return NULL.
2472 return Field::null(); 2555 return Field::null();
2473 } 2556 }
2474 return field.raw(); 2557 return field.raw();
2475 } 2558 }
2476 // No field found. 2559 // No field found.
2477 return Field::null(); 2560 return Field::null();
2478 } 2561 }
2479 2562
2480 2563
2481 RawField* Class::LookupField(const String& name) const { 2564 RawField* Class::LookupField(const String& name) const {
2482 Isolate* isolate = Isolate::Current(); 2565 Isolate* isolate = Isolate::Current();
2566 if (EnsureIsFinalized(isolate) != Error::null()) {
2567 return Field::null();
2568 }
2483 const Array& flds = Array::Handle(isolate, fields()); 2569 const Array& flds = Array::Handle(isolate, fields());
2484 Field& field = Field::Handle(isolate, Field::null()); 2570 Field& field = Field::Handle(isolate, Field::null());
2485 String& field_name = String::Handle(isolate, String::null()); 2571 String& field_name = String::Handle(isolate, String::null());
2486 intptr_t len = flds.Length(); 2572 intptr_t len = flds.Length();
2487 for (intptr_t i = 0; i < len; i++) { 2573 for (intptr_t i = 0; i < len; i++) {
2488 field ^= flds.At(i); 2574 field ^= flds.At(i);
2489 field_name ^= field.name(); 2575 field_name ^= field.name();
2490 if (String::EqualsIgnoringPrivateKey(field_name, name)) { 2576 if (String::EqualsIgnoringPrivateKey(field_name, name)) {
2491 return field.raw(); 2577 return field.raw();
2492 } 2578 }
(...skipping 4370 matching lines...) Expand 10 before | Expand all | Expand 10 after
6863 Error& error = Error::Handle(); 6949 Error& error = Error::Handle();
6864 const GrowableObjectArray& libs = GrowableObjectArray::Handle( 6950 const GrowableObjectArray& libs = GrowableObjectArray::Handle(
6865 Isolate::Current()->object_store()->libraries()); 6951 Isolate::Current()->object_store()->libraries());
6866 Library& lib = Library::Handle(); 6952 Library& lib = Library::Handle();
6867 Class& cls = Class::Handle(); 6953 Class& cls = Class::Handle();
6868 for (int i = 0; i < libs.Length(); i++) { 6954 for (int i = 0; i < libs.Length(); i++) {
6869 lib ^= libs.At(i); 6955 lib ^= libs.At(i);
6870 ClassDictionaryIterator it(lib); 6956 ClassDictionaryIterator it(lib);
6871 while (it.HasNext()) { 6957 while (it.HasNext()) {
6872 cls = it.GetNextClass(); 6958 cls = it.GetNextClass();
6959 error = cls.EnsureIsFinalized(Isolate::Current());
6960 if (!error.IsNull()) {
6961 return error.raw();
6962 }
6873 error = Compiler::CompileAllFunctions(cls); 6963 error = Compiler::CompileAllFunctions(cls);
6874 if (!error.IsNull()) { 6964 if (!error.IsNull()) {
6875 return error.raw(); 6965 return error.raw();
6876 } 6966 }
6877 } 6967 }
6878 Array& anon_classes = Array::Handle(lib.raw_ptr()->anonymous_classes_); 6968 Array& anon_classes = Array::Handle(lib.raw_ptr()->anonymous_classes_);
6879 for (int i = 0; i < lib.raw_ptr()->num_anonymous_; i++) { 6969 for (int i = 0; i < lib.raw_ptr()->num_anonymous_; i++) {
6880 cls ^= anon_classes.At(i); 6970 cls ^= anon_classes.At(i);
6881 error = Compiler::CompileAllFunctions(cls); 6971 error = Compiler::CompileAllFunctions(cls);
6882 if (!error.IsNull()) { 6972 if (!error.IsNull()) {
(...skipping 2264 matching lines...) Expand 10 before | Expand all | Expand 10 after
9147 } 9237 }
9148 return true; 9238 return true;
9149 } 9239 }
9150 cls = cls.SuperClass(); 9240 cls = cls.SuperClass();
9151 } while (!cls.IsNull()); 9241 } while (!cls.IsNull());
9152 return false; 9242 return false;
9153 } 9243 }
9154 9244
9155 9245
9156 RawInstance* Instance::New(const Class& cls, Heap::Space space) { 9246 RawInstance* Instance::New(const Class& cls, Heap::Space space) {
9157 Instance& result = Instance::Handle(); 9247 Isolate* isolate = Isolate::Current();
9248 if (cls.EnsureIsFinalized(isolate) != Error::null()) {
9249 return Instance::null();
9250 }
9251 Instance& result = Instance::Handle(isolate);
9158 { 9252 {
9159 intptr_t instance_size = cls.instance_size(); 9253 intptr_t instance_size = cls.instance_size();
9160 ASSERT(instance_size > 0); 9254 ASSERT(instance_size > 0);
9161 RawObject* raw = Object::Allocate(cls.id(), instance_size, space); 9255 RawObject* raw = Object::Allocate(cls.id(), instance_size, space);
9162 NoGCScope no_gc; 9256 NoGCScope no_gc;
9163 result ^= raw; 9257 result ^= raw;
9164 } 9258 }
9165 return result.raw(); 9259 return result.raw();
9166 } 9260 }
9167 9261
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
9351 // but use actual vector. 9445 // but use actual vector.
9352 num_type_params = num_args; 9446 num_type_params = num_args;
9353 } else { 9447 } else {
9354 ASSERT(num_args == 0); // Type is raw. 9448 ASSERT(num_args == 0); // Type is raw.
9355 // No need to fill up with "dynamic". 9449 // No need to fill up with "dynamic".
9356 num_type_params = 0; 9450 num_type_params = 0;
9357 } 9451 }
9358 } else { 9452 } else {
9359 // The actual type argument vector can be longer than necessary, because 9453 // The actual type argument vector can be longer than necessary, because
9360 // of type optimizations. 9454 // of type optimizations.
9361 if (IsFinalized() && cls.is_finalized()) { 9455 if (IsFinalized() && cls.is_type_finalized()) {
9362 first_type_param_index = cls.NumTypeArguments() - num_type_params; 9456 first_type_param_index = cls.NumTypeArguments() - num_type_params;
9363 } else { 9457 } else {
9364 first_type_param_index = num_args - num_type_params; 9458 first_type_param_index = num_args - num_type_params;
9365 } 9459 }
9366 } 9460 }
9367 if (cls.IsSignatureClass()) { 9461 if (cls.IsSignatureClass()) {
9368 // We may be reporting an error about a malformed function type. In that 9462 // We may be reporting an error about a malformed function type. In that
9369 // case, avoid instantiating the signature, since it may lead to cycles. 9463 // case, avoid instantiating the signature, since it may lead to cycles.
9370 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { 9464 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) {
9371 return class_name.raw(); 9465 return class_name.raw();
(...skipping 3869 matching lines...) Expand 10 before | Expand all | Expand 10 after
13241 } 13335 }
13242 return result.raw(); 13336 return result.raw();
13243 } 13337 }
13244 13338
13245 13339
13246 const char* WeakProperty::ToCString() const { 13340 const char* WeakProperty::ToCString() const {
13247 return "_WeakProperty"; 13341 return "_WeakProperty";
13248 } 13342 }
13249 13343
13250 } // namespace dart 13344 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698