OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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/weak_code.h" | 5 #include "vm/weak_code.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 | 8 |
9 #include "vm/code_patcher.h" | 9 #include "vm/code_patcher.h" |
10 #include "vm/object.h" | 10 #include "vm/object.h" |
11 #include "vm/runtime_entry.h" | 11 #include "vm/runtime_entry.h" |
12 #include "vm/stack_frame.h" | 12 #include "vm/stack_frame.h" |
13 | 13 |
14 namespace dart { | 14 namespace dart { |
15 | 15 |
16 bool WeakCodeReferences::HasCodes() const { | 16 bool WeakCodeReferences::HasCodes() const { |
17 return !array_.IsNull() && (array_.Length() > 0); | 17 return !array_.IsNull() && (array_.Length() > 0); |
18 } | 18 } |
19 | 19 |
20 | |
21 void WeakCodeReferences::Register(const Code& value) { | 20 void WeakCodeReferences::Register(const Code& value) { |
22 if (!array_.IsNull()) { | 21 if (!array_.IsNull()) { |
23 // Try to find and reuse cleared WeakProperty to avoid allocating new one. | 22 // Try to find and reuse cleared WeakProperty to avoid allocating new one. |
24 WeakProperty& weak_property = WeakProperty::Handle(); | 23 WeakProperty& weak_property = WeakProperty::Handle(); |
25 for (intptr_t i = 0; i < array_.Length(); i++) { | 24 for (intptr_t i = 0; i < array_.Length(); i++) { |
26 weak_property ^= array_.At(i); | 25 weak_property ^= array_.At(i); |
27 if (weak_property.key() == Code::null()) { | 26 if (weak_property.key() == Code::null()) { |
28 // Empty property found. Reuse it. | 27 // Empty property found. Reuse it. |
29 weak_property.set_key(value); | 28 weak_property.set_key(value); |
30 return; | 29 return; |
31 } | 30 } |
32 } | 31 } |
33 } | 32 } |
34 | 33 |
35 const WeakProperty& weak_property = | 34 const WeakProperty& weak_property = |
36 WeakProperty::Handle(WeakProperty::New(Heap::kOld)); | 35 WeakProperty::Handle(WeakProperty::New(Heap::kOld)); |
37 weak_property.set_key(value); | 36 weak_property.set_key(value); |
38 | 37 |
39 intptr_t length = array_.IsNull() ? 0 : array_.Length(); | 38 intptr_t length = array_.IsNull() ? 0 : array_.Length(); |
40 const Array& new_array = | 39 const Array& new_array = |
41 Array::Handle(Array::Grow(array_, length + 1, Heap::kOld)); | 40 Array::Handle(Array::Grow(array_, length + 1, Heap::kOld)); |
42 new_array.SetAt(length, weak_property); | 41 new_array.SetAt(length, weak_property); |
43 UpdateArrayTo(new_array); | 42 UpdateArrayTo(new_array); |
44 } | 43 } |
45 | 44 |
46 | |
47 bool WeakCodeReferences::IsOptimizedCode(const Array& dependent_code, | 45 bool WeakCodeReferences::IsOptimizedCode(const Array& dependent_code, |
48 const Code& code) { | 46 const Code& code) { |
49 if (!code.is_optimized()) { | 47 if (!code.is_optimized()) { |
50 return false; | 48 return false; |
51 } | 49 } |
52 WeakProperty& weak_property = WeakProperty::Handle(); | 50 WeakProperty& weak_property = WeakProperty::Handle(); |
53 for (intptr_t i = 0; i < dependent_code.Length(); i++) { | 51 for (intptr_t i = 0; i < dependent_code.Length(); i++) { |
54 weak_property ^= dependent_code.At(i); | 52 weak_property ^= dependent_code.At(i); |
55 if (code.raw() == weak_property.key()) { | 53 if (code.raw() == weak_property.key()) { |
56 return true; | 54 return true; |
57 } | 55 } |
58 } | 56 } |
59 return false; | 57 return false; |
60 } | 58 } |
61 | 59 |
62 | |
63 void WeakCodeReferences::DisableCode() { | 60 void WeakCodeReferences::DisableCode() { |
64 Thread* thread = Thread::Current(); | 61 Thread* thread = Thread::Current(); |
65 const Array& code_objects = Array::Handle(thread->zone(), array_.raw()); | 62 const Array& code_objects = Array::Handle(thread->zone(), array_.raw()); |
66 if (code_objects.IsNull()) { | 63 if (code_objects.IsNull()) { |
67 return; | 64 return; |
68 } | 65 } |
69 ASSERT(!FLAG_precompiled_runtime); | 66 ASSERT(!FLAG_precompiled_runtime); |
70 UpdateArrayTo(Object::null_array()); | 67 UpdateArrayTo(Object::null_array()); |
71 // Disable all code on stack. | 68 // Disable all code on stack. |
72 Code& code = Code::Handle(); | 69 Code& code = Code::Handle(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // Make non-OSR code non-entrant. | 125 // Make non-OSR code non-entrant. |
129 if (!code.IsDisabled()) { | 126 if (!code.IsDisabled()) { |
130 ReportSwitchingCode(code); | 127 ReportSwitchingCode(code); |
131 code.DisableDartCode(); | 128 code.DisableDartCode(); |
132 } | 129 } |
133 } | 130 } |
134 } | 131 } |
135 } | 132 } |
136 | 133 |
137 } // namespace dart | 134 } // namespace dart |
OLD | NEW |