| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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::set_patch_class(const Class& cls) const { |
| 2081 ASSERT(patch_class() == Class::null()); |
| 2082 StorePointer(&raw_ptr()->patch_class_, cls.raw()); |
| 2083 } |
| 2084 |
| 2085 |
| 2030 void Class::AddDirectSubclass(const Class& subclass) const { | 2086 void Class::AddDirectSubclass(const Class& subclass) const { |
| 2031 ASSERT(!subclass.IsNull()); | 2087 ASSERT(!subclass.IsNull()); |
| 2032 ASSERT(subclass.SuperClass() == raw()); | 2088 ASSERT(subclass.SuperClass() == raw()); |
| 2033 // Do not keep track of the direct subclasses of class Object. | 2089 // Do not keep track of the direct subclasses of class Object. |
| 2034 ASSERT(!IsObjectClass()); | 2090 ASSERT(!IsObjectClass()); |
| 2035 GrowableObjectArray& direct_subclasses = | 2091 GrowableObjectArray& direct_subclasses = |
| 2036 GrowableObjectArray::Handle(raw_ptr()->direct_subclasses_); | 2092 GrowableObjectArray::Handle(raw_ptr()->direct_subclasses_); |
| 2037 if (direct_subclasses.IsNull()) { | 2093 if (direct_subclasses.IsNull()) { |
| 2038 direct_subclasses = GrowableObjectArray::New(4, Heap::kOld); | 2094 direct_subclasses = GrowableObjectArray::New(4, Heap::kOld); |
| 2039 StorePointer(&raw_ptr()->direct_subclasses_, direct_subclasses.raw()); | 2095 StorePointer(&raw_ptr()->direct_subclasses_, direct_subclasses.raw()); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2335 if (name.CharAt(j) != accessor_name.CharAt(i)) { | 2391 if (name.CharAt(j) != accessor_name.CharAt(i)) { |
| 2336 return false; | 2392 return false; |
| 2337 } | 2393 } |
| 2338 } | 2394 } |
| 2339 return true; | 2395 return true; |
| 2340 } | 2396 } |
| 2341 | 2397 |
| 2342 | 2398 |
| 2343 RawFunction* Class::LookupFunction(const String& name) const { | 2399 RawFunction* Class::LookupFunction(const String& name) const { |
| 2344 Isolate* isolate = Isolate::Current(); | 2400 Isolate* isolate = Isolate::Current(); |
| 2401 if (EnsureIsFinalized(isolate) != Error::null()) { |
| 2402 return Function::null(); |
| 2403 } |
| 2345 Array& funcs = Array::Handle(isolate, functions()); | 2404 Array& funcs = Array::Handle(isolate, functions()); |
| 2346 if (funcs.IsNull()) { | 2405 if (funcs.IsNull()) { |
| 2347 // This can occur, e.g., for Null classes. | 2406 // This can occur, e.g., for Null classes. |
| 2348 return Function::null(); | 2407 return Function::null(); |
| 2349 } | 2408 } |
| 2350 Function& function = Function::Handle(isolate, Function::null()); | 2409 Function& function = Function::Handle(isolate, Function::null()); |
| 2351 const intptr_t len = funcs.Length(); | 2410 const intptr_t len = funcs.Length(); |
| 2352 if (name.IsSymbol()) { | 2411 if (name.IsSymbol()) { |
| 2353 // Quick Symbol compare. | 2412 // Quick Symbol compare. |
| 2354 NoGCScope no_gc; | 2413 NoGCScope no_gc; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2368 } | 2427 } |
| 2369 } | 2428 } |
| 2370 } | 2429 } |
| 2371 // No function found. | 2430 // No function found. |
| 2372 return Function::null(); | 2431 return Function::null(); |
| 2373 } | 2432 } |
| 2374 | 2433 |
| 2375 | 2434 |
| 2376 RawFunction* Class::LookupFunctionAllowPrivate(const String& name) const { | 2435 RawFunction* Class::LookupFunctionAllowPrivate(const String& name) const { |
| 2377 Isolate* isolate = Isolate::Current(); | 2436 Isolate* isolate = Isolate::Current(); |
| 2437 if (EnsureIsFinalized(isolate) != Error::null()) { |
| 2438 return Function::null(); |
| 2439 } |
| 2378 Array& funcs = Array::Handle(isolate, functions()); | 2440 Array& funcs = Array::Handle(isolate, functions()); |
| 2379 if (funcs.IsNull()) { | 2441 if (funcs.IsNull()) { |
| 2380 // This can occur, e.g., for Null classes. | 2442 // This can occur, e.g., for Null classes. |
| 2381 return Function::null(); | 2443 return Function::null(); |
| 2382 } | 2444 } |
| 2383 Function& function = Function::Handle(isolate, Function::null()); | 2445 Function& function = Function::Handle(isolate, Function::null()); |
| 2384 String& function_name = String::Handle(isolate, String::null()); | 2446 String& function_name = String::Handle(isolate, String::null()); |
| 2385 intptr_t len = funcs.Length(); | 2447 intptr_t len = funcs.Length(); |
| 2386 for (intptr_t i = 0; i < len; i++) { | 2448 for (intptr_t i = 0; i < len; i++) { |
| 2387 function ^= funcs.At(i); | 2449 function ^= funcs.At(i); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2402 | 2464 |
| 2403 RawFunction* Class::LookupSetterFunction(const String& name) const { | 2465 RawFunction* Class::LookupSetterFunction(const String& name) const { |
| 2404 return LookupAccessorFunction(kSetterPrefix, kSetterPrefixLength, name); | 2466 return LookupAccessorFunction(kSetterPrefix, kSetterPrefixLength, name); |
| 2405 } | 2467 } |
| 2406 | 2468 |
| 2407 | 2469 |
| 2408 RawFunction* Class::LookupAccessorFunction(const char* prefix, | 2470 RawFunction* Class::LookupAccessorFunction(const char* prefix, |
| 2409 intptr_t prefix_length, | 2471 intptr_t prefix_length, |
| 2410 const String& name) const { | 2472 const String& name) const { |
| 2411 Isolate* isolate = Isolate::Current(); | 2473 Isolate* isolate = Isolate::Current(); |
| 2474 if (EnsureIsFinalized(isolate) != Error::null()) { |
| 2475 return Function::null(); |
| 2476 } |
| 2412 Array& funcs = Array::Handle(isolate, functions()); | 2477 Array& funcs = Array::Handle(isolate, functions()); |
| 2413 Function& function = Function::Handle(isolate, Function::null()); | 2478 Function& function = Function::Handle(isolate, Function::null()); |
| 2414 String& function_name = String::Handle(isolate, String::null()); | 2479 String& function_name = String::Handle(isolate, String::null()); |
| 2415 intptr_t len = funcs.Length(); | 2480 intptr_t len = funcs.Length(); |
| 2416 for (intptr_t i = 0; i < len; i++) { | 2481 for (intptr_t i = 0; i < len; i++) { |
| 2417 function ^= funcs.At(i); | 2482 function ^= funcs.At(i); |
| 2418 function_name ^= function.name(); | 2483 function_name ^= function.name(); |
| 2419 if (MatchesAccessorName(function_name, prefix, prefix_length, name)) { | 2484 if (MatchesAccessorName(function_name, prefix, prefix_length, name)) { |
| 2420 return function.raw(); | 2485 return function.raw(); |
| 2421 } | 2486 } |
| 2422 } | 2487 } |
| 2423 | 2488 |
| 2424 // No function found. | 2489 // No function found. |
| 2425 return Function::null(); | 2490 return Function::null(); |
| 2426 } | 2491 } |
| 2427 | 2492 |
| 2428 | 2493 |
| 2429 RawFunction* Class::LookupFunctionAtToken(intptr_t token_pos) const { | 2494 RawFunction* Class::LookupFunctionAtToken(intptr_t token_pos) const { |
| 2430 // TODO(hausner): we can shortcut the negative case if we knew the | 2495 // TODO(hausner): we can shortcut the negative case if we knew the |
| 2431 // beginning and end token position of the class. | 2496 // beginning and end token position of the class. |
| 2432 Function& func = Function::Handle(); | 2497 Isolate* isolate = Isolate::Current(); |
| 2498 if (EnsureIsFinalized(isolate) != Error::null()) { |
| 2499 return Function::null(); |
| 2500 } |
| 2501 Function& func = Function::Handle(isolate); |
| 2433 func = LookupClosureFunction(token_pos); | 2502 func = LookupClosureFunction(token_pos); |
| 2434 if (!func.IsNull()) { | 2503 if (!func.IsNull()) { |
| 2435 return func.raw(); | 2504 return func.raw(); |
| 2436 } | 2505 } |
| 2437 Array& funcs = Array::Handle(functions()); | 2506 Array& funcs = Array::Handle(isolate, functions()); |
| 2438 intptr_t len = funcs.Length(); | 2507 intptr_t len = funcs.Length(); |
| 2439 for (intptr_t i = 0; i < len; i++) { | 2508 for (intptr_t i = 0; i < len; i++) { |
| 2440 func ^= funcs.At(i); | 2509 func ^= funcs.At(i); |
| 2441 if ((func.token_pos() <= token_pos) && | 2510 if ((func.token_pos() <= token_pos) && |
| 2442 (token_pos <= func.end_token_pos())) { | 2511 (token_pos <= func.end_token_pos())) { |
| 2443 return func.raw(); | 2512 return func.raw(); |
| 2444 } | 2513 } |
| 2445 } | 2514 } |
| 2446 // No function found. | 2515 // No function found. |
| 2447 return Function::null(); | 2516 return Function::null(); |
| 2448 } | 2517 } |
| 2449 | 2518 |
| 2450 | 2519 |
| 2451 RawField* Class::LookupInstanceField(const String& name) const { | 2520 RawField* Class::LookupInstanceField(const String& name) const { |
| 2521 Isolate* isolate = Isolate::Current(); |
| 2522 if (EnsureIsFinalized(isolate) != Error::null()) { |
| 2523 return Field::null(); |
| 2524 } |
| 2452 ASSERT(is_finalized()); | 2525 ASSERT(is_finalized()); |
| 2453 const Field& field = Field::Handle(LookupField(name)); | 2526 const Field& field = Field::Handle(isolate, LookupField(name)); |
| 2454 if (!field.IsNull()) { | 2527 if (!field.IsNull()) { |
| 2455 if (field.is_static()) { | 2528 if (field.is_static()) { |
| 2456 // Name matches but it is not of the correct kind, return NULL. | 2529 // Name matches but it is not of the correct kind, return NULL. |
| 2457 return Field::null(); | 2530 return Field::null(); |
| 2458 } | 2531 } |
| 2459 return field.raw(); | 2532 return field.raw(); |
| 2460 } | 2533 } |
| 2461 // No field found. | 2534 // No field found. |
| 2462 return Field::null(); | 2535 return Field::null(); |
| 2463 } | 2536 } |
| 2464 | 2537 |
| 2465 | 2538 |
| 2466 RawField* Class::LookupStaticField(const String& name) const { | 2539 RawField* Class::LookupStaticField(const String& name) const { |
| 2540 Isolate* isolate = Isolate::Current(); |
| 2541 if (EnsureIsFinalized(isolate) != Error::null()) { |
| 2542 return Field::null(); |
| 2543 } |
| 2467 ASSERT(is_finalized()); | 2544 ASSERT(is_finalized()); |
| 2468 const Field& field = Field::Handle(LookupField(name)); | 2545 const Field& field = Field::Handle(isolate, LookupField(name)); |
| 2469 if (!field.IsNull()) { | 2546 if (!field.IsNull()) { |
| 2470 if (!field.is_static()) { | 2547 if (!field.is_static()) { |
| 2471 // Name matches but it is not of the correct kind, return NULL. | 2548 // Name matches but it is not of the correct kind, return NULL. |
| 2472 return Field::null(); | 2549 return Field::null(); |
| 2473 } | 2550 } |
| 2474 return field.raw(); | 2551 return field.raw(); |
| 2475 } | 2552 } |
| 2476 // No field found. | 2553 // No field found. |
| 2477 return Field::null(); | 2554 return Field::null(); |
| 2478 } | 2555 } |
| 2479 | 2556 |
| 2480 | 2557 |
| 2481 RawField* Class::LookupField(const String& name) const { | 2558 RawField* Class::LookupField(const String& name) const { |
| 2482 Isolate* isolate = Isolate::Current(); | 2559 Isolate* isolate = Isolate::Current(); |
| 2560 if (EnsureIsFinalized(isolate) != Error::null()) { |
| 2561 return Field::null(); |
| 2562 } |
| 2483 const Array& flds = Array::Handle(isolate, fields()); | 2563 const Array& flds = Array::Handle(isolate, fields()); |
| 2484 Field& field = Field::Handle(isolate, Field::null()); | 2564 Field& field = Field::Handle(isolate, Field::null()); |
| 2485 String& field_name = String::Handle(isolate, String::null()); | 2565 String& field_name = String::Handle(isolate, String::null()); |
| 2486 intptr_t len = flds.Length(); | 2566 intptr_t len = flds.Length(); |
| 2487 for (intptr_t i = 0; i < len; i++) { | 2567 for (intptr_t i = 0; i < len; i++) { |
| 2488 field ^= flds.At(i); | 2568 field ^= flds.At(i); |
| 2489 field_name ^= field.name(); | 2569 field_name ^= field.name(); |
| 2490 if (String::EqualsIgnoringPrivateKey(field_name, name)) { | 2570 if (String::EqualsIgnoringPrivateKey(field_name, name)) { |
| 2491 return field.raw(); | 2571 return field.raw(); |
| 2492 } | 2572 } |
| (...skipping 4370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6863 Error& error = Error::Handle(); | 6943 Error& error = Error::Handle(); |
| 6864 const GrowableObjectArray& libs = GrowableObjectArray::Handle( | 6944 const GrowableObjectArray& libs = GrowableObjectArray::Handle( |
| 6865 Isolate::Current()->object_store()->libraries()); | 6945 Isolate::Current()->object_store()->libraries()); |
| 6866 Library& lib = Library::Handle(); | 6946 Library& lib = Library::Handle(); |
| 6867 Class& cls = Class::Handle(); | 6947 Class& cls = Class::Handle(); |
| 6868 for (int i = 0; i < libs.Length(); i++) { | 6948 for (int i = 0; i < libs.Length(); i++) { |
| 6869 lib ^= libs.At(i); | 6949 lib ^= libs.At(i); |
| 6870 ClassDictionaryIterator it(lib); | 6950 ClassDictionaryIterator it(lib); |
| 6871 while (it.HasNext()) { | 6951 while (it.HasNext()) { |
| 6872 cls = it.GetNextClass(); | 6952 cls = it.GetNextClass(); |
| 6953 error = cls.EnsureIsFinalized(Isolate::Current()); |
| 6954 if (!error.IsNull()) { |
| 6955 return error.raw(); |
| 6956 } |
| 6873 error = Compiler::CompileAllFunctions(cls); | 6957 error = Compiler::CompileAllFunctions(cls); |
| 6874 if (!error.IsNull()) { | 6958 if (!error.IsNull()) { |
| 6875 return error.raw(); | 6959 return error.raw(); |
| 6876 } | 6960 } |
| 6877 } | 6961 } |
| 6878 Array& anon_classes = Array::Handle(lib.raw_ptr()->anonymous_classes_); | 6962 Array& anon_classes = Array::Handle(lib.raw_ptr()->anonymous_classes_); |
| 6879 for (int i = 0; i < lib.raw_ptr()->num_anonymous_; i++) { | 6963 for (int i = 0; i < lib.raw_ptr()->num_anonymous_; i++) { |
| 6880 cls ^= anon_classes.At(i); | 6964 cls ^= anon_classes.At(i); |
| 6881 error = Compiler::CompileAllFunctions(cls); | 6965 error = Compiler::CompileAllFunctions(cls); |
| 6882 if (!error.IsNull()) { | 6966 if (!error.IsNull()) { |
| (...skipping 2264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9147 } | 9231 } |
| 9148 return true; | 9232 return true; |
| 9149 } | 9233 } |
| 9150 cls = cls.SuperClass(); | 9234 cls = cls.SuperClass(); |
| 9151 } while (!cls.IsNull()); | 9235 } while (!cls.IsNull()); |
| 9152 return false; | 9236 return false; |
| 9153 } | 9237 } |
| 9154 | 9238 |
| 9155 | 9239 |
| 9156 RawInstance* Instance::New(const Class& cls, Heap::Space space) { | 9240 RawInstance* Instance::New(const Class& cls, Heap::Space space) { |
| 9157 Instance& result = Instance::Handle(); | 9241 Isolate* isolate = Isolate::Current(); |
| 9242 if (cls.EnsureIsFinalized(isolate) != Error::null()) { |
| 9243 return Instance::null(); |
| 9244 } |
| 9245 Instance& result = Instance::Handle(isolate); |
| 9158 { | 9246 { |
| 9159 intptr_t instance_size = cls.instance_size(); | 9247 intptr_t instance_size = cls.instance_size(); |
| 9160 ASSERT(instance_size > 0); | 9248 ASSERT(instance_size > 0); |
| 9161 RawObject* raw = Object::Allocate(cls.id(), instance_size, space); | 9249 RawObject* raw = Object::Allocate(cls.id(), instance_size, space); |
| 9162 NoGCScope no_gc; | 9250 NoGCScope no_gc; |
| 9163 result ^= raw; | 9251 result ^= raw; |
| 9164 } | 9252 } |
| 9165 return result.raw(); | 9253 return result.raw(); |
| 9166 } | 9254 } |
| 9167 | 9255 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9351 // but use actual vector. | 9439 // but use actual vector. |
| 9352 num_type_params = num_args; | 9440 num_type_params = num_args; |
| 9353 } else { | 9441 } else { |
| 9354 ASSERT(num_args == 0); // Type is raw. | 9442 ASSERT(num_args == 0); // Type is raw. |
| 9355 // No need to fill up with "dynamic". | 9443 // No need to fill up with "dynamic". |
| 9356 num_type_params = 0; | 9444 num_type_params = 0; |
| 9357 } | 9445 } |
| 9358 } else { | 9446 } else { |
| 9359 // The actual type argument vector can be longer than necessary, because | 9447 // The actual type argument vector can be longer than necessary, because |
| 9360 // of type optimizations. | 9448 // of type optimizations. |
| 9361 if (IsFinalized() && cls.is_finalized()) { | 9449 if (IsFinalized() && cls.is_type_finalized()) { |
| 9362 first_type_param_index = cls.NumTypeArguments() - num_type_params; | 9450 first_type_param_index = cls.NumTypeArguments() - num_type_params; |
| 9363 } else { | 9451 } else { |
| 9364 first_type_param_index = num_args - num_type_params; | 9452 first_type_param_index = num_args - num_type_params; |
| 9365 } | 9453 } |
| 9366 } | 9454 } |
| 9367 if (cls.IsSignatureClass()) { | 9455 if (cls.IsSignatureClass()) { |
| 9368 // We may be reporting an error about a malformed function type. In that | 9456 // 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. | 9457 // case, avoid instantiating the signature, since it may lead to cycles. |
| 9370 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { | 9458 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { |
| 9371 return class_name.raw(); | 9459 return class_name.raw(); |
| (...skipping 3869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13241 } | 13329 } |
| 13242 return result.raw(); | 13330 return result.raw(); |
| 13243 } | 13331 } |
| 13244 | 13332 |
| 13245 | 13333 |
| 13246 const char* WeakProperty::ToCString() const { | 13334 const char* WeakProperty::ToCString() const { |
| 13247 return "_WeakProperty"; | 13335 return "_WeakProperty"; |
| 13248 } | 13336 } |
| 13249 | 13337 |
| 13250 } // namespace dart | 13338 } // namespace dart |
| OLD | NEW |