Chromium Code Reviews| 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(); | |
| 368 cls.set_is_parsed(); | |
| 366 cls.raw_ptr()->type_arguments_field_offset_in_words_ = | 369 cls.raw_ptr()->type_arguments_field_offset_in_words_ = |
| 367 Class::kNoTypeArguments; | 370 Class::kNoTypeArguments; |
| 368 cls.raw_ptr()->num_native_fields_ = 0; | 371 cls.raw_ptr()->num_native_fields_ = 0; |
| 369 cls.InitEmptyFields(); | 372 cls.InitEmptyFields(); |
| 370 isolate->class_table()->Register(cls); | 373 isolate->class_table()->Register(cls); |
| 371 } | 374 } |
| 372 | 375 |
| 373 // Allocate and initialize the null class. | 376 // Allocate and initialize the null class. |
| 374 cls = Class::New<Instance>(kNullCid); | 377 cls = Class::New<Instance>(kNullCid); |
| 375 cls.set_is_finalized(); | 378 cls.set_is_finalized(); |
| 379 cls.set_is_type_finalized(); | |
| 380 cls.set_is_parsed(); | |
| 376 null_class_ = cls.raw(); | 381 null_class_ = cls.raw(); |
| 377 | 382 |
| 378 // Allocate and initialize the free list element class. | 383 // Allocate and initialize the free list element class. |
| 379 cls = Class::New<FreeListElement::FakeInstance>(kFreeListElement); | 384 cls = Class::New<FreeListElement::FakeInstance>(kFreeListElement); |
| 380 cls.set_is_finalized(); | 385 cls.set_is_finalized(); |
| 386 cls.set_is_type_finalized(); | |
| 387 cls.set_is_parsed(); | |
| 381 | 388 |
| 382 // Allocate and initialize the sentinel values of Null class. | 389 // Allocate and initialize the sentinel values of Null class. |
| 383 { | 390 { |
| 384 *sentinel_ ^= | 391 *sentinel_ ^= |
| 385 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); | 392 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); |
| 386 | 393 |
| 387 *transition_sentinel_ ^= | 394 *transition_sentinel_ ^= |
| 388 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); | 395 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); |
| 389 } | 396 } |
| 390 | 397 |
| 391 // Allocate and initialize optimizing compiler constants. | 398 // Allocate and initialize optimizing compiler constants. |
| 392 { | 399 { |
| 393 *unknown_constant_ ^= | 400 *unknown_constant_ ^= |
| 394 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); | 401 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); |
| 395 *non_constant_ ^= | 402 *non_constant_ ^= |
| 396 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); | 403 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); |
| 397 } | 404 } |
| 398 | 405 |
| 399 cls = Class::New<Instance>(kDynamicCid); | 406 cls = Class::New<Instance>(kDynamicCid); |
| 400 cls.set_is_finalized(); | 407 cls.set_is_finalized(); |
| 408 cls.set_is_type_finalized(); | |
| 409 cls.set_is_parsed(); | |
| 401 cls.set_is_abstract(); | 410 cls.set_is_abstract(); |
| 402 dynamic_class_ = cls.raw(); | 411 dynamic_class_ = cls.raw(); |
| 403 | 412 |
| 404 // Allocate the remaining VM internal classes. | 413 // Allocate the remaining VM internal classes. |
| 405 cls = Class::New<UnresolvedClass>(); | 414 cls = Class::New<UnresolvedClass>(); |
| 406 unresolved_class_class_ = cls.raw(); | 415 unresolved_class_class_ = cls.raw(); |
| 407 | 416 |
| 408 cls = Class::New<Instance>(kVoidCid); | 417 cls = Class::New<Instance>(kVoidCid); |
| 409 cls.set_is_finalized(); | 418 cls.set_is_finalized(); |
| 419 cls.set_is_type_finalized(); | |
| 420 cls.set_is_parsed(); | |
| 410 void_class_ = cls.raw(); | 421 void_class_ = cls.raw(); |
| 411 | 422 |
| 412 cls = Class::New<TypeArguments>(); | 423 cls = Class::New<TypeArguments>(); |
| 413 type_arguments_class_ = cls.raw(); | 424 type_arguments_class_ = cls.raw(); |
| 414 | 425 |
| 415 cls = Class::New<InstantiatedTypeArguments>(); | 426 cls = Class::New<InstantiatedTypeArguments>(); |
| 416 instantiated_type_arguments_class_ = cls.raw(); | 427 instantiated_type_arguments_class_ = cls.raw(); |
| 417 | 428 |
| 418 cls = Class::New<PatchClass>(); | 429 cls = Class::New<PatchClass>(); |
| 419 patch_class_class_ = cls.raw(); | 430 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); | 998 RegisterClass(cls, Symbols::Double(), core_lib); |
| 988 cls.set_is_prefinalized(); | 999 cls.set_is_prefinalized(); |
| 989 pending_classes.Add(cls, Heap::kOld); | 1000 pending_classes.Add(cls, Heap::kOld); |
| 990 type = Type::NewNonParameterizedType(cls); | 1001 type = Type::NewNonParameterizedType(cls); |
| 991 object_store->set_double_type(type); | 1002 object_store->set_double_type(type); |
| 992 | 1003 |
| 993 name = Symbols::New("String"); | 1004 name = Symbols::New("String"); |
| 994 cls = Class::New<Instance>(kIllegalCid); | 1005 cls = Class::New<Instance>(kIllegalCid); |
| 995 cls.set_is_prefinalized(); | 1006 cls.set_is_prefinalized(); |
| 996 RegisterClass(cls, name, core_lib); | 1007 RegisterClass(cls, name, core_lib); |
| 1008 cls.set_is_prefinalized(); | |
| 997 pending_classes.Add(cls, Heap::kOld); | 1009 pending_classes.Add(cls, Heap::kOld); |
| 998 type = Type::NewNonParameterizedType(cls); | 1010 type = Type::NewNonParameterizedType(cls); |
| 999 object_store->set_string_type(type); | 1011 object_store->set_string_type(type); |
| 1000 | 1012 |
| 1001 cls = Class::New<Instance>(kIllegalCid); | 1013 cls = Class::New<Instance>(kIllegalCid); |
| 1002 RegisterClass(cls, Symbols::List(), core_lib); | 1014 RegisterClass(cls, Symbols::List(), core_lib); |
| 1003 cls.set_is_prefinalized(); | 1015 cls.set_is_prefinalized(); |
| 1004 pending_classes.Add(cls, Heap::kOld); | 1016 pending_classes.Add(cls, Heap::kOld); |
| 1005 object_store->set_list_class(cls); | 1017 object_store->set_list_class(cls); |
| 1006 | 1018 |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1536 | 1548 |
| 1537 void Class::set_class_state(RawClass::ClassState state) const { | 1549 void Class::set_class_state(RawClass::ClassState state) const { |
| 1538 ASSERT((state == RawClass::kAllocated) || | 1550 ASSERT((state == RawClass::kAllocated) || |
| 1539 (state == RawClass::kPreFinalized) || | 1551 (state == RawClass::kPreFinalized) || |
| 1540 (state == RawClass::kFinalized)); | 1552 (state == RawClass::kFinalized)); |
| 1541 set_state_bits(StateBits::update(state, raw_ptr()->state_bits_)); | 1553 set_state_bits(StateBits::update(state, raw_ptr()->state_bits_)); |
| 1542 } | 1554 } |
| 1543 | 1555 |
| 1544 | 1556 |
| 1545 void Class::set_state_bits(intptr_t bits) const { | 1557 void Class::set_state_bits(intptr_t bits) const { |
| 1546 raw_ptr()->state_bits_ = static_cast<uint8_t>(bits); | 1558 raw_ptr()->state_bits_ = static_cast<uint16_t>(bits); |
| 1547 } | 1559 } |
| 1548 | 1560 |
| 1549 | 1561 |
| 1550 void Class::set_library(const Library& value) const { | 1562 void Class::set_library(const Library& value) const { |
| 1551 StorePointer(&raw_ptr()->library_, value.raw()); | 1563 StorePointer(&raw_ptr()->library_, value.raw()); |
| 1552 } | 1564 } |
| 1553 | 1565 |
| 1554 | 1566 |
| 1555 void Class::set_type_parameters(const TypeArguments& value) const { | 1567 void Class::set_type_parameters(const TypeArguments& value) const { |
| 1556 StorePointer(&raw_ptr()->type_parameters_, value.raw()); | 1568 StorePointer(&raw_ptr()->type_parameters_, value.raw()); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1582 const Class& superclass = Class::Handle(cls.SuperClass()); | 1594 const Class& superclass = Class::Handle(cls.SuperClass()); |
| 1583 // Object is its own super class during bootstrap. | 1595 // Object is its own super class during bootstrap. |
| 1584 if (!superclass.IsNull() && (superclass.raw() != raw())) { | 1596 if (!superclass.IsNull() && (superclass.raw() != raw())) { |
| 1585 num_type_args += superclass.NumTypeArguments(); | 1597 num_type_args += superclass.NumTypeArguments(); |
| 1586 } | 1598 } |
| 1587 return num_type_args; | 1599 return num_type_args; |
| 1588 } | 1600 } |
| 1589 | 1601 |
| 1590 | 1602 |
| 1591 bool Class::HasTypeArguments() const { | 1603 bool Class::HasTypeArguments() const { |
| 1592 if (!IsSignatureClass() && (is_finalized() || is_prefinalized())) { | 1604 if (!IsSignatureClass() && (is_type_finalized() || is_prefinalized())) { |
| 1593 // More efficient than calling NumTypeArguments(). | 1605 // More efficient than calling NumTypeArguments(). |
| 1594 return type_arguments_field_offset() != kNoTypeArguments; | 1606 return type_arguments_field_offset() != kNoTypeArguments; |
| 1595 } else { | 1607 } else { |
| 1596 // No need to check NumTypeArguments() if class has type parameters. | 1608 // No need to check NumTypeArguments() if class has type parameters. |
| 1597 return (NumTypeParameters() > 0) || (NumTypeArguments() > 0); | 1609 return (NumTypeParameters() > 0) || (NumTypeArguments() > 0); |
| 1598 } | 1610 } |
| 1599 } | 1611 } |
| 1600 | 1612 |
| 1601 | 1613 |
| 1602 RawClass* Class::SuperClass() const { | 1614 RawClass* Class::SuperClass() const { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1776 } | 1788 } |
| 1777 SetFields(new_list); | 1789 SetFields(new_list); |
| 1778 | 1790 |
| 1779 // The functions and fields in the patch class are no longer needed. | 1791 // The functions and fields in the patch class are no longer needed. |
| 1780 patch.SetFunctions(Object::empty_array()); | 1792 patch.SetFunctions(Object::empty_array()); |
| 1781 patch.SetFields(Object::empty_array()); | 1793 patch.SetFields(Object::empty_array()); |
| 1782 return NULL; | 1794 return NULL; |
| 1783 } | 1795 } |
| 1784 | 1796 |
| 1785 | 1797 |
| 1798 // Ensure that top level parsing of the class has been done. | |
| 1799 RawError* Class::EnsureIsParsed(Isolate* isolate) const { | |
| 1800 if (!is_parsed()) { | |
| 1801 ASSERT(isolate != NULL); | |
| 1802 const Error& error = Error::Handle(isolate, Compiler::ParseClass(*this)); | |
| 1803 if (!error.IsNull() && (isolate->long_jump_base() != NULL)) { | |
| 1804 isolate->long_jump_base()->Jump(1, error); | |
| 1805 UNREACHABLE(); | |
| 1806 } | |
| 1807 return error.raw(); | |
| 1808 } | |
| 1809 return Error::null(); | |
| 1810 } | |
| 1811 | |
| 1812 | |
| 1786 void Class::SetFields(const Array& value) const { | 1813 void Class::SetFields(const Array& value) const { |
| 1787 ASSERT(!value.IsNull()); | 1814 ASSERT(!value.IsNull()); |
| 1788 #if defined(DEBUG) | 1815 #if defined(DEBUG) |
| 1789 // Verify that all the fields in the array have this class as owner. | 1816 // Verify that all the fields in the array have this class as owner. |
| 1790 Field& field = Field::Handle(); | 1817 Field& field = Field::Handle(); |
| 1791 intptr_t len = value.Length(); | 1818 intptr_t len = value.Length(); |
| 1792 for (intptr_t i = 0; i < len; i++) { | 1819 for (intptr_t i = 0; i < len; i++) { |
| 1793 field ^= value.At(i); | 1820 field ^= value.At(i); |
| 1794 ASSERT(field.owner() == raw()); | 1821 ASSERT(field.owner() == raw()); |
| 1795 } | 1822 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1841 const Function& signature_function, | 1868 const Function& signature_function, |
| 1842 const Script& script, | 1869 const Script& script, |
| 1843 intptr_t token_pos) { | 1870 intptr_t token_pos) { |
| 1844 const Class& result = Class::Handle(New(name, script, token_pos)); | 1871 const Class& result = Class::Handle(New(name, script, token_pos)); |
| 1845 const Type& super_type = Type::Handle(Type::ObjectType()); | 1872 const Type& super_type = Type::Handle(Type::ObjectType()); |
| 1846 ASSERT(!super_type.IsNull()); | 1873 ASSERT(!super_type.IsNull()); |
| 1847 // Instances of a signature class can only be closures. | 1874 // Instances of a signature class can only be closures. |
| 1848 result.set_instance_size(Closure::InstanceSize()); | 1875 result.set_instance_size(Closure::InstanceSize()); |
| 1849 result.set_next_field_offset(Closure::InstanceSize()); | 1876 result.set_next_field_offset(Closure::InstanceSize()); |
| 1850 result.set_super_type(super_type); | 1877 result.set_super_type(super_type); |
| 1878 result.set_is_parsed(); | |
| 1851 result.set_type_arguments_field_offset(Closure::type_arguments_offset()); | 1879 result.set_type_arguments_field_offset(Closure::type_arguments_offset()); |
| 1852 // Implements interface "Function". | 1880 // Implements interface "Function". |
| 1853 const Type& function_type = Type::Handle(Type::Function()); | 1881 const Type& function_type = Type::Handle(Type::Function()); |
| 1854 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); | 1882 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); |
| 1855 interfaces.SetAt(0, function_type); | 1883 interfaces.SetAt(0, function_type); |
| 1856 result.set_interfaces(interfaces); | 1884 result.set_interfaces(interfaces); |
| 1857 if (!signature_function.IsNull()) { | 1885 if (!signature_function.IsNull()) { |
| 1858 result.PatchSignatureFunction(signature_function); | 1886 result.PatchSignatureFunction(signature_function); |
| 1859 } | 1887 } |
| 1860 return result.raw(); | 1888 return result.raw(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1901 cls.SetFunctions(Object::empty_array()); | 1929 cls.SetFunctions(Object::empty_array()); |
| 1902 // Set super class to Object. | 1930 // Set super class to Object. |
| 1903 cls.set_super_type(Type::Handle(Type::ObjectType())); | 1931 cls.set_super_type(Type::Handle(Type::ObjectType())); |
| 1904 // Compute instance size. First word contains a pointer to a properly | 1932 // Compute instance size. First word contains a pointer to a properly |
| 1905 // sized typed array once the first native field has been set. | 1933 // sized typed array once the first native field has been set. |
| 1906 intptr_t instance_size = sizeof(RawObject) + kWordSize; | 1934 intptr_t instance_size = sizeof(RawObject) + kWordSize; |
| 1907 cls.set_instance_size(RoundedAllocationSize(instance_size)); | 1935 cls.set_instance_size(RoundedAllocationSize(instance_size)); |
| 1908 cls.set_next_field_offset(instance_size); | 1936 cls.set_next_field_offset(instance_size); |
| 1909 cls.set_num_native_fields(field_count); | 1937 cls.set_num_native_fields(field_count); |
| 1910 cls.set_is_finalized(); | 1938 cls.set_is_finalized(); |
| 1939 cls.set_is_type_finalized(); | |
| 1940 cls.set_is_parsed(); | |
| 1911 library.AddClass(cls); | 1941 library.AddClass(cls); |
| 1912 return cls.raw(); | 1942 return cls.raw(); |
| 1913 } else { | 1943 } else { |
| 1914 return Class::null(); | 1944 return Class::null(); |
| 1915 } | 1945 } |
| 1916 } | 1946 } |
| 1917 | 1947 |
| 1918 | 1948 |
| 1919 RawClass* Class::NewStringClass(intptr_t class_id) { | 1949 RawClass* Class::NewStringClass(intptr_t class_id) { |
| 1920 intptr_t instance_size; | 1950 intptr_t instance_size; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1987 void Class::set_is_implemented() const { | 2017 void Class::set_is_implemented() const { |
| 1988 set_state_bits(ImplementedBit::update(true, raw_ptr()->state_bits_)); | 2018 set_state_bits(ImplementedBit::update(true, raw_ptr()->state_bits_)); |
| 1989 } | 2019 } |
| 1990 | 2020 |
| 1991 | 2021 |
| 1992 void Class::set_is_abstract() const { | 2022 void Class::set_is_abstract() const { |
| 1993 set_state_bits(AbstractBit::update(true, raw_ptr()->state_bits_)); | 2023 set_state_bits(AbstractBit::update(true, raw_ptr()->state_bits_)); |
| 1994 } | 2024 } |
| 1995 | 2025 |
| 1996 | 2026 |
| 2027 void Class::set_is_type_finalized() const { | |
| 2028 set_state_bits(TypeFinalizedBit::update(true, raw_ptr()->state_bits_)); | |
| 2029 } | |
| 2030 | |
| 2031 | |
| 2032 void Class::set_is_patch() const { | |
| 2033 set_state_bits(PatchBit::update(true, raw_ptr()->state_bits_)); | |
| 2034 } | |
| 2035 | |
| 2036 | |
| 2037 void Class::set_is_parsed() const { | |
| 2038 set_state_bits(ParsedBit::update(true, raw_ptr()->state_bits_)); | |
| 2039 } | |
| 2040 | |
| 2041 | |
| 2042 void Class::set_is_synthesized_class() const { | |
| 2043 set_state_bits(SynthesizedClassBit::update(true, raw_ptr()->state_bits_)); | |
| 2044 } | |
| 2045 | |
| 2046 | |
| 1997 void Class::set_is_const() const { | 2047 void Class::set_is_const() const { |
| 1998 set_state_bits(ConstBit::update(true, raw_ptr()->state_bits_)); | 2048 set_state_bits(ConstBit::update(true, raw_ptr()->state_bits_)); |
| 1999 } | 2049 } |
| 2000 | 2050 |
| 2001 | 2051 |
| 2002 void Class::set_is_finalized() const { | 2052 void Class::set_is_finalized() const { |
| 2003 ASSERT(!is_finalized()); | 2053 ASSERT(!is_finalized()); |
| 2004 set_state_bits(StateBits::update(RawClass::kFinalized, | 2054 set_state_bits(StateBits::update(RawClass::kFinalized, |
| 2005 raw_ptr()->state_bits_)); | 2055 raw_ptr()->state_bits_)); |
| 2006 } | 2056 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 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 Loading... | |
| 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 (EnsureIsParsed(isolate) != Error::null()) { | |
|
hausner
2013/05/21 20:07:30
How do errors during parsing get propagated to the
siva
2013/05/23 00:54:31
The function EnsureIsParsed does a Longjump on err
| |
| 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 Loading... | |
| 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 (EnsureIsParsed(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 Loading... | |
| 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 (EnsureIsParsed(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 (EnsureIsParsed(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 (EnsureIsParsed(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 (EnsureIsParsed(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 (EnsureIsParsed(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 4396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6889 Error& error = Error::Handle(); | 6975 Error& error = Error::Handle(); |
| 6890 const GrowableObjectArray& libs = GrowableObjectArray::Handle( | 6976 const GrowableObjectArray& libs = GrowableObjectArray::Handle( |
| 6891 Isolate::Current()->object_store()->libraries()); | 6977 Isolate::Current()->object_store()->libraries()); |
| 6892 Library& lib = Library::Handle(); | 6978 Library& lib = Library::Handle(); |
| 6893 Class& cls = Class::Handle(); | 6979 Class& cls = Class::Handle(); |
| 6894 for (int i = 0; i < libs.Length(); i++) { | 6980 for (int i = 0; i < libs.Length(); i++) { |
| 6895 lib ^= libs.At(i); | 6981 lib ^= libs.At(i); |
| 6896 ClassDictionaryIterator it(lib); | 6982 ClassDictionaryIterator it(lib); |
| 6897 while (it.HasNext()) { | 6983 while (it.HasNext()) { |
| 6898 cls = it.GetNextClass(); | 6984 cls = it.GetNextClass(); |
| 6985 error = cls.EnsureIsParsed(Isolate::Current()); | |
| 6986 if (!error.IsNull()) { | |
| 6987 return error.raw(); | |
| 6988 } | |
| 6899 error = Compiler::CompileAllFunctions(cls); | 6989 error = Compiler::CompileAllFunctions(cls); |
| 6900 if (!error.IsNull()) { | 6990 if (!error.IsNull()) { |
| 6901 return error.raw(); | 6991 return error.raw(); |
| 6902 } | 6992 } |
| 6903 } | 6993 } |
| 6904 Array& anon_classes = Array::Handle(lib.raw_ptr()->anonymous_classes_); | 6994 Array& anon_classes = Array::Handle(lib.raw_ptr()->anonymous_classes_); |
| 6905 for (int i = 0; i < lib.raw_ptr()->num_anonymous_; i++) { | 6995 for (int i = 0; i < lib.raw_ptr()->num_anonymous_; i++) { |
| 6906 cls ^= anon_classes.At(i); | 6996 cls ^= anon_classes.At(i); |
| 6907 error = Compiler::CompileAllFunctions(cls); | 6997 error = Compiler::CompileAllFunctions(cls); |
| 6908 if (!error.IsNull()) { | 6998 if (!error.IsNull()) { |
| (...skipping 2264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9173 } | 9263 } |
| 9174 return true; | 9264 return true; |
| 9175 } | 9265 } |
| 9176 cls = cls.SuperClass(); | 9266 cls = cls.SuperClass(); |
| 9177 } while (!cls.IsNull()); | 9267 } while (!cls.IsNull()); |
| 9178 return false; | 9268 return false; |
| 9179 } | 9269 } |
| 9180 | 9270 |
| 9181 | 9271 |
| 9182 RawInstance* Instance::New(const Class& cls, Heap::Space space) { | 9272 RawInstance* Instance::New(const Class& cls, Heap::Space space) { |
| 9183 Instance& result = Instance::Handle(); | 9273 Isolate* isolate = Isolate::Current(); |
| 9274 if (cls.EnsureIsParsed(isolate) != Error::null()) { | |
| 9275 return Instance::null(); | |
| 9276 } | |
| 9277 Instance& result = Instance::Handle(isolate); | |
| 9184 { | 9278 { |
| 9185 intptr_t instance_size = cls.instance_size(); | 9279 intptr_t instance_size = cls.instance_size(); |
| 9186 ASSERT(instance_size > 0); | 9280 ASSERT(instance_size > 0); |
| 9187 RawObject* raw = Object::Allocate(cls.id(), instance_size, space); | 9281 RawObject* raw = Object::Allocate(cls.id(), instance_size, space); |
| 9188 NoGCScope no_gc; | 9282 NoGCScope no_gc; |
| 9189 result ^= raw; | 9283 result ^= raw; |
| 9190 } | 9284 } |
| 9191 return result.raw(); | 9285 return result.raw(); |
| 9192 } | 9286 } |
| 9193 | 9287 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9377 // but use actual vector. | 9471 // but use actual vector. |
| 9378 num_type_params = num_args; | 9472 num_type_params = num_args; |
| 9379 } else { | 9473 } else { |
| 9380 ASSERT(num_args == 0); // Type is raw. | 9474 ASSERT(num_args == 0); // Type is raw. |
| 9381 // No need to fill up with "dynamic". | 9475 // No need to fill up with "dynamic". |
| 9382 num_type_params = 0; | 9476 num_type_params = 0; |
| 9383 } | 9477 } |
| 9384 } else { | 9478 } else { |
| 9385 // The actual type argument vector can be longer than necessary, because | 9479 // The actual type argument vector can be longer than necessary, because |
| 9386 // of type optimizations. | 9480 // of type optimizations. |
| 9387 if (IsFinalized() && cls.is_finalized()) { | 9481 if (IsFinalized() && cls.is_type_finalized()) { |
| 9388 first_type_param_index = cls.NumTypeArguments() - num_type_params; | 9482 first_type_param_index = cls.NumTypeArguments() - num_type_params; |
| 9389 } else { | 9483 } else { |
| 9390 first_type_param_index = num_args - num_type_params; | 9484 first_type_param_index = num_args - num_type_params; |
| 9391 } | 9485 } |
| 9392 } | 9486 } |
| 9393 if (cls.IsSignatureClass()) { | 9487 if (cls.IsSignatureClass()) { |
| 9394 // We may be reporting an error about a malformed function type. In that | 9488 // We may be reporting an error about a malformed function type. In that |
| 9395 // case, avoid instantiating the signature, since it may lead to cycles. | 9489 // case, avoid instantiating the signature, since it may lead to cycles. |
| 9396 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { | 9490 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { |
| 9397 return class_name.raw(); | 9491 return class_name.raw(); |
| (...skipping 3869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13267 } | 13361 } |
| 13268 return result.raw(); | 13362 return result.raw(); |
| 13269 } | 13363 } |
| 13270 | 13364 |
| 13271 | 13365 |
| 13272 const char* WeakProperty::ToCString() const { | 13366 const char* WeakProperty::ToCString() const { |
| 13273 return "_WeakProperty"; | 13367 return "_WeakProperty"; |
| 13274 } | 13368 } |
| 13275 | 13369 |
| 13276 } // namespace dart | 13370 } // namespace dart |
| OLD | NEW |