| 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/cha.h" | 5 #include "vm/cha.h" |
| 6 #include "vm/class_table.h" | 6 #include "vm/class_table.h" |
| 7 #include "vm/flags.h" | 7 #include "vm/flags.h" |
| 8 #include "vm/freelist.h" | 8 #include "vm/freelist.h" |
| 9 #include "vm/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/raw_object.h" | 10 #include "vm/raw_object.h" |
| 11 #include "vm/visitor.h" | 11 #include "vm/visitor.h" |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 | 14 |
| 15 void CHA::AddToLeafClasses(const Class& cls) { | 15 void CHA::AddToLeafClasses(const Class& cls) { |
| 16 for (intptr_t i = 0; i < leaf_classes_.length(); i++) { | 16 for (intptr_t i = 0; i < leaf_classes_.length(); i++) { |
| 17 if (leaf_classes_[i]->raw() == cls.raw()) { | 17 if (leaf_classes_[i]->raw() == cls.raw()) { |
| 18 return; | 18 return; |
| 19 } | 19 } |
| 20 } | 20 } |
| 21 leaf_classes_.Add(&Class::ZoneHandle(isolate_, cls.raw())); | 21 leaf_classes_.Add(&Class::ZoneHandle(thread_->zone(), cls.raw())); |
| 22 } | 22 } |
| 23 | 23 |
| 24 | 24 |
| 25 bool CHA::HasSubclasses(const Class& cls) { | 25 bool CHA::HasSubclasses(const Class& cls) { |
| 26 ASSERT(!cls.IsNull()); | 26 ASSERT(!cls.IsNull()); |
| 27 ASSERT(cls.id() >= kInstanceCid); | 27 ASSERT(cls.id() >= kInstanceCid); |
| 28 // Can't track dependencies for classes on the VM heap since those are | 28 // Can't track dependencies for classes on the VM heap since those are |
| 29 // read-only. | 29 // read-only. |
| 30 // TODO(fschneider): Enable tracking of CHA dependent code for VM heap | 30 // TODO(fschneider): Enable tracking of CHA dependent code for VM heap |
| 31 // classes. | 31 // classes. |
| 32 if (cls.InVMHeap()) return true; | 32 if (cls.InVMHeap()) return true; |
| 33 | 33 |
| 34 if (cls.IsObjectClass()) { | 34 if (cls.IsObjectClass()) { |
| 35 // Class Object has subclasses, although we do not keep track of them. | 35 // Class Object has subclasses, although we do not keep track of them. |
| 36 return true; | 36 return true; |
| 37 } | 37 } |
| 38 const GrowableObjectArray& direct_subclasses = | 38 const GrowableObjectArray& direct_subclasses = |
| 39 GrowableObjectArray::Handle(isolate_, cls.direct_subclasses()); | 39 GrowableObjectArray::Handle(thread_->zone(), cls.direct_subclasses()); |
| 40 bool result = | 40 bool result = |
| 41 !direct_subclasses.IsNull() && (direct_subclasses.Length() > 0); | 41 !direct_subclasses.IsNull() && (direct_subclasses.Length() > 0); |
| 42 if (!result) { | 42 if (!result) { |
| 43 AddToLeafClasses(cls); | 43 AddToLeafClasses(cls); |
| 44 } | 44 } |
| 45 return result; | 45 return result; |
| 46 } | 46 } |
| 47 | 47 |
| 48 | 48 |
| 49 bool CHA::HasSubclasses(intptr_t cid) { | 49 bool CHA::HasSubclasses(intptr_t cid) { |
| 50 const ClassTable& class_table = *isolate_->class_table(); | 50 const ClassTable& class_table = *thread_->isolate()->class_table(); |
| 51 Class& cls = Class::Handle(isolate_, class_table.At(cid)); | 51 Class& cls = Class::Handle(thread_->zone(), class_table.At(cid)); |
| 52 return HasSubclasses(cls); | 52 return HasSubclasses(cls); |
| 53 } | 53 } |
| 54 | 54 |
| 55 | 55 |
| 56 bool CHA::IsImplemented(const Class& cls) { | 56 bool CHA::IsImplemented(const Class& cls) { |
| 57 // Signature classes have different type checking rules. | 57 // Signature classes have different type checking rules. |
| 58 ASSERT(!cls.IsSignatureClass()); | 58 ASSERT(!cls.IsSignatureClass()); |
| 59 // Can't track dependencies for classes on the VM heap since those are | 59 // Can't track dependencies for classes on the VM heap since those are |
| 60 // read-only. | 60 // read-only. |
| 61 // TODO(fschneider): Enable tracking of CHA dependent code for VM heap | 61 // TODO(fschneider): Enable tracking of CHA dependent code for VM heap |
| 62 // classes. | 62 // classes. |
| 63 if (cls.InVMHeap()) return true; | 63 if (cls.InVMHeap()) return true; |
| 64 | 64 |
| 65 bool result = cls.is_implemented(); | 65 bool result = cls.is_implemented(); |
| 66 if (!result) { | 66 if (!result) { |
| 67 AddToLeafClasses(cls); | 67 AddToLeafClasses(cls); |
| 68 } | 68 } |
| 69 return result; | 69 return result; |
| 70 } | 70 } |
| 71 | 71 |
| 72 | 72 |
| 73 bool CHA::HasOverride(const Class& cls, const String& function_name) { | 73 bool CHA::HasOverride(const Class& cls, const String& function_name) { |
| 74 const GrowableObjectArray& cls_direct_subclasses = | 74 const GrowableObjectArray& cls_direct_subclasses = |
| 75 GrowableObjectArray::Handle(isolate_, cls.direct_subclasses()); | 75 GrowableObjectArray::Handle(thread_->zone(), cls.direct_subclasses()); |
| 76 // Subclasses of Object are not tracked by CHA. Safely assume that overrides | 76 // Subclasses of Object are not tracked by CHA. Safely assume that overrides |
| 77 // exist. | 77 // exist. |
| 78 if (cls.IsObjectClass()) { | 78 if (cls.IsObjectClass()) { |
| 79 return true; | 79 return true; |
| 80 } | 80 } |
| 81 | 81 |
| 82 if (cls_direct_subclasses.IsNull()) { | 82 if (cls_direct_subclasses.IsNull()) { |
| 83 AddToLeafClasses(cls); | 83 AddToLeafClasses(cls); |
| 84 return false; | 84 return false; |
| 85 } | 85 } |
| 86 Class& direct_subclass = Class::Handle(isolate_); | 86 Class& direct_subclass = Class::Handle(thread_->zone()); |
| 87 for (intptr_t i = 0; i < cls_direct_subclasses.Length(); i++) { | 87 for (intptr_t i = 0; i < cls_direct_subclasses.Length(); i++) { |
| 88 direct_subclass ^= cls_direct_subclasses.At(i); | 88 direct_subclass ^= cls_direct_subclasses.At(i); |
| 89 // Unfinalized classes are treated as non-existent for CHA purposes, | 89 // Unfinalized classes are treated as non-existent for CHA purposes, |
| 90 // as that means that no instance of that class exists at runtime. | 90 // as that means that no instance of that class exists at runtime. |
| 91 if (direct_subclass.is_finalized() && | 91 if (direct_subclass.is_finalized() && |
| 92 (direct_subclass.LookupDynamicFunction(function_name) != | 92 (direct_subclass.LookupDynamicFunction(function_name) != |
| 93 Function::null())) { | 93 Function::null())) { |
| 94 return true; | 94 return true; |
| 95 } | 95 } |
| 96 if (HasOverride(direct_subclass, function_name)) { | 96 if (HasOverride(direct_subclass, function_name)) { |
| 97 return true; | 97 return true; |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 AddToLeafClasses(cls); | 100 AddToLeafClasses(cls); |
| 101 return false; | 101 return false; |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace dart | 104 } // namespace dart |
| OLD | NEW |