| 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/code_generator.h" | 7 #include "vm/code_generator.h" |
| 8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
| 9 #include "vm/heap.h" | 9 #include "vm/heap.h" |
| 10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 const GrowableObjectArray& classes = | 29 const GrowableObjectArray& classes = |
| 30 GrowableObjectArray::Handle(object_store->pending_classes()); | 30 GrowableObjectArray::Handle(object_store->pending_classes()); |
| 31 return classes.Length() == 0; | 31 return classes.Length() == 0; |
| 32 } | 32 } |
| 33 | 33 |
| 34 | 34 |
| 35 // Removes optimized code once we load more classes, since --use_cha based | 35 // Removes optimized code once we load more classes, since --use_cha based |
| 36 // optimizations may have become invalid. | 36 // optimizations may have become invalid. |
| 37 // Only methods which owner classes where subclasses can be invalid. | 37 // Only methods which owner classes where subclasses can be invalid. |
| 38 // TODO(srdjan): Be even more precise by recording the exact CHA optimization. | 38 // TODO(srdjan): Be even more precise by recording the exact CHA optimization. |
| 39 static void RemoveOptimizedCode( | 39 static void RemoveCHAOptimizedCode( |
| 40 const GrowableArray<intptr_t>& added_subclass_to_cids) { | 40 const GrowableArray<intptr_t>& added_subclass_to_cids) { |
| 41 ASSERT(FLAG_use_cha); | 41 ASSERT(FLAG_use_cha); |
| 42 if (added_subclass_to_cids.is_empty()) return; | 42 if (added_subclass_to_cids.is_empty()) return; |
| 43 // Deoptimize all live frames. | |
| 44 DeoptimizeIfOwner(added_subclass_to_cids); | |
| 45 // Switch all functions' code to unoptimized. | 43 // Switch all functions' code to unoptimized. |
| 46 const ClassTable& class_table = *Isolate::Current()->class_table(); | 44 const ClassTable& class_table = *Isolate::Current()->class_table(); |
| 47 Class& cls = Class::Handle(); | 45 Class& cls = Class::Handle(); |
| 48 Array& array = Array::Handle(); | |
| 49 Function& function = Function::Handle(); | |
| 50 for (intptr_t i = 0; i < added_subclass_to_cids.length(); i++) { | 46 for (intptr_t i = 0; i < added_subclass_to_cids.length(); i++) { |
| 51 intptr_t cid = added_subclass_to_cids[i]; | 47 intptr_t cid = added_subclass_to_cids[i]; |
| 52 cls = class_table.At(cid); | 48 cls = class_table.At(cid); |
| 53 ASSERT(!cls.IsNull()); | 49 ASSERT(!cls.IsNull()); |
| 54 array = cls.functions(); | 50 cls.DisableCHAOptimizedCode(); |
| 55 const intptr_t num_functions = array.IsNull() ? 0 : array.Length(); | |
| 56 for (intptr_t f = 0; f < num_functions; f++) { | |
| 57 function ^= array.At(f); | |
| 58 ASSERT(!function.IsNull()); | |
| 59 if (function.HasOptimizedCode()) { | |
| 60 function.SwitchToUnoptimizedCode(); | |
| 61 } | |
| 62 } | |
| 63 } | 51 } |
| 64 } | 52 } |
| 65 | 53 |
| 66 | 54 |
| 67 void AddSuperType(const AbstractType& type, | 55 void AddSuperType(const AbstractType& type, |
| 68 GrowableArray<intptr_t>* finalized_super_classes) { | 56 GrowableArray<intptr_t>* finalized_super_classes) { |
| 69 ASSERT(type.HasResolvedTypeClass()); | 57 ASSERT(type.HasResolvedTypeClass()); |
| 70 ASSERT(!type.IsDynamicType()); | 58 ASSERT(!type.IsDynamicType()); |
| 71 if (type.IsObjectType()) { | 59 if (type.IsObjectType()) { |
| 72 return; | 60 return; |
| (...skipping 2115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2188 ASSERT(cls.IsTopLevel() || | 2176 ASSERT(cls.IsTopLevel() || |
| 2189 cls.IsSignatureClass() || | 2177 cls.IsSignatureClass() || |
| 2190 (Array::Handle(cls.functions()).Length() > 0)); | 2178 (Array::Handle(cls.functions()).Length() > 0)); |
| 2191 // Resolve and finalize all member types. | 2179 // Resolve and finalize all member types. |
| 2192 ResolveAndFinalizeMemberTypes(cls); | 2180 ResolveAndFinalizeMemberTypes(cls); |
| 2193 // Run additional checks after all types are finalized. | 2181 // Run additional checks after all types are finalized. |
| 2194 if (cls.is_const()) { | 2182 if (cls.is_const()) { |
| 2195 CheckForLegalConstClass(cls); | 2183 CheckForLegalConstClass(cls); |
| 2196 } | 2184 } |
| 2197 if (FLAG_use_cha) { | 2185 if (FLAG_use_cha) { |
| 2198 RemoveOptimizedCode(added_subclass_to_cids); | 2186 RemoveCHAOptimizedCode(added_subclass_to_cids); |
| 2199 } | 2187 } |
| 2200 } | 2188 } |
| 2201 | 2189 |
| 2202 | 2190 |
| 2203 bool ClassFinalizer::IsSuperCycleFree(const Class& cls) { | 2191 bool ClassFinalizer::IsSuperCycleFree(const Class& cls) { |
| 2204 Class& test1 = Class::Handle(cls.raw()); | 2192 Class& test1 = Class::Handle(cls.raw()); |
| 2205 Class& test2 = Class::Handle(cls.SuperClass()); | 2193 Class& test2 = Class::Handle(cls.SuperClass()); |
| 2206 // A finalized class has been checked for cycles. | 2194 // A finalized class has been checked for cycles. |
| 2207 // Using the hare and tortoise algorithm for locating cycles. | 2195 // Using the hare and tortoise algorithm for locating cycles. |
| 2208 while (!test1.is_type_finalized() && | 2196 while (!test1.is_type_finalized() && |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2908 expected_name ^= String::New("_offset"); | 2896 expected_name ^= String::New("_offset"); |
| 2909 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); | 2897 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); |
| 2910 field ^= fields_array.At(2); | 2898 field ^= fields_array.At(2); |
| 2911 ASSERT(field.Offset() == TypedDataView::length_offset()); | 2899 ASSERT(field.Offset() == TypedDataView::length_offset()); |
| 2912 name ^= field.name(); | 2900 name ^= field.name(); |
| 2913 ASSERT(name.Equals("length")); | 2901 ASSERT(name.Equals("length")); |
| 2914 #endif | 2902 #endif |
| 2915 } | 2903 } |
| 2916 | 2904 |
| 2917 } // namespace dart | 2905 } // namespace dart |
| OLD | NEW |