OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/class_finalizer.h" | 5 #include "vm/class_finalizer.h" |
6 | 6 |
7 #include "vm/flags.h" | 7 #include "vm/flags.h" |
8 #include "vm/heap.h" | 8 #include "vm/heap.h" |
9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
10 #include "vm/longjump.h" | 10 #include "vm/longjump.h" |
(...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1656 test2 = test2.SuperClass(); | 1656 test2 = test2.SuperClass(); |
1657 if (!test2.IsNull()) { | 1657 if (!test2.IsNull()) { |
1658 test2 = test2.SuperClass(); | 1658 test2 = test2.SuperClass(); |
1659 } | 1659 } |
1660 } | 1660 } |
1661 // No cycles. | 1661 // No cycles. |
1662 return true; | 1662 return true; |
1663 } | 1663 } |
1664 | 1664 |
1665 | 1665 |
1666 // Helper function called by IsAliasCycleFree. | |
1667 bool ClassFinalizer::IsParameterTypeCycleFree( | |
1668 const Class& cls, | |
1669 const AbstractType& type, | |
1670 GrowableArray<intptr_t>* visited) { | |
srdjan
2013/07/23 22:56:34
ASSERT(visited != NULL).
regis
2013/07/23 23:14:35
Done.
| |
1671 ResolveType(cls, type, kCanonicalize); | |
1672 if (type.IsType() && !type.IsMalformed()) { | |
1673 const Class& type_class = Class::Handle(type.type_class()); | |
1674 if (!type_class.is_type_finalized() && | |
1675 type_class.IsSignatureClass() && | |
1676 !IsAliasCycleFree(type_class, visited)) { | |
1677 return false; | |
1678 } | |
1679 const AbstractTypeArguments& type_args = AbstractTypeArguments::Handle( | |
1680 type.arguments()); | |
1681 if (!type_args.IsNull()) { | |
1682 AbstractType& type_arg = AbstractType::Handle(); | |
1683 for (intptr_t i = 0; i < type_args.Length(); i++) { | |
1684 type_arg = type_args.TypeAt(i); | |
1685 if (!IsParameterTypeCycleFree(cls, type_arg, visited)) { | |
1686 return false; | |
1687 } | |
1688 } | |
1689 } | |
1690 } | |
1691 return true; | |
1692 } | |
1693 | |
1694 | |
1666 // Returns false if the function type alias illegally refers to itself. | 1695 // Returns false if the function type alias illegally refers to itself. |
1667 bool ClassFinalizer::IsAliasCycleFree(const Class& cls, | 1696 bool ClassFinalizer::IsAliasCycleFree(const Class& cls, |
1668 GrowableArray<intptr_t>* visited) { | 1697 GrowableArray<intptr_t>* visited) { |
1669 ASSERT(cls.IsSignatureClass()); | 1698 ASSERT(cls.IsSignatureClass()); |
1670 ASSERT(!cls.is_type_finalized()); | 1699 ASSERT(!cls.is_type_finalized()); |
1671 ASSERT(visited != NULL); | 1700 ASSERT(visited != NULL); |
1672 const intptr_t cls_index = cls.id(); | 1701 const intptr_t cls_index = cls.id(); |
1673 for (int i = 0; i < visited->length(); i++) { | 1702 for (int i = 0; i < visited->length(); i++) { |
1674 if ((*visited)[i] == cls_index) { | 1703 if ((*visited)[i] == cls_index) { |
1675 // We have already visited alias 'cls'. We found a cycle. | 1704 // We have already visited alias 'cls'. We found a cycle. |
1676 return false; | 1705 return false; |
1677 } | 1706 } |
1678 } | 1707 } |
1679 | 1708 |
1680 // Visit the result type and parameter types of this signature type. | 1709 // Visit the result type and parameter types of this signature type. |
1681 visited->Add(cls.id()); | 1710 visited->Add(cls.id()); |
1682 const Function& function = Function::Handle(cls.signature_function()); | 1711 const Function& function = Function::Handle(cls.signature_function()); |
1683 // Check class of result type. | 1712 // Check class of result type. |
1684 AbstractType& type = AbstractType::Handle(function.result_type()); | 1713 AbstractType& type = AbstractType::Handle(function.result_type()); |
1685 ResolveType(cls, type, kCanonicalize); | 1714 if (!IsParameterTypeCycleFree(cls, type, visited)) { |
1686 if (type.IsType() && !type.IsMalformed()) { | 1715 return false; |
1687 const Class& type_class = Class::Handle(type.type_class()); | |
1688 if (!type_class.is_type_finalized() && | |
1689 type_class.IsSignatureClass() && | |
1690 !IsAliasCycleFree(type_class, visited)) { | |
1691 return false; | |
1692 } | |
1693 } | 1716 } |
1694 // Check classes of formal parameter types. | 1717 // Check classes of formal parameter types. |
1695 const intptr_t num_parameters = function.NumParameters(); | 1718 const intptr_t num_parameters = function.NumParameters(); |
1696 for (intptr_t i = 0; i < num_parameters; i++) { | 1719 for (intptr_t i = 0; i < num_parameters; i++) { |
1697 type = function.ParameterTypeAt(i); | 1720 type = function.ParameterTypeAt(i); |
1698 ResolveType(cls, type, kCanonicalize); | 1721 if (!IsParameterTypeCycleFree(cls, type, visited)) { |
1699 if (type.IsType() && !type.IsMalformed()) { | 1722 return false; |
1700 const Class& type_class = Class::Handle(type.type_class()); | |
1701 if (!type_class.is_type_finalized() && | |
1702 type_class.IsSignatureClass() && | |
1703 !IsAliasCycleFree(type_class, visited)) { | |
1704 return false; | |
1705 } | |
1706 } | 1723 } |
1707 } | 1724 } |
1708 visited->RemoveLast(); | 1725 visited->RemoveLast(); |
1709 return true; | 1726 return true; |
1710 } | 1727 } |
1711 | 1728 |
1712 | 1729 |
1713 void ClassFinalizer::CollectTypeArguments(const Class& cls, | 1730 void ClassFinalizer::CollectTypeArguments(const Class& cls, |
1714 const Type& type, | 1731 const Type& type, |
1715 const GrowableObjectArray& collected_args) { | 1732 const GrowableObjectArray& collected_args) { |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2169 expected_name ^= String::New("_offset"); | 2186 expected_name ^= String::New("_offset"); |
2170 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); | 2187 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); |
2171 field ^= fields_array.At(2); | 2188 field ^= fields_array.At(2); |
2172 ASSERT(field.Offset() == TypedDataView::length_offset()); | 2189 ASSERT(field.Offset() == TypedDataView::length_offset()); |
2173 name ^= field.name(); | 2190 name ^= field.name(); |
2174 ASSERT(name.Equals("length")); | 2191 ASSERT(name.Equals("length")); |
2175 #endif | 2192 #endif |
2176 } | 2193 } |
2177 | 2194 |
2178 } // namespace dart | 2195 } // namespace dart |
OLD | NEW |