Chromium Code Reviews| Index: runtime/vm/weak_code.cc |
| diff --git a/runtime/vm/weak_code.cc b/runtime/vm/weak_code.cc |
| index c7e12d14c5b7156463feacf0c06c6a9ab3a6a2f4..3b771f4bbced045de0c2810fb3757dc719ffab07 100644 |
| --- a/runtime/vm/weak_code.cc |
| +++ b/runtime/vm/weak_code.cc |
| @@ -22,8 +22,12 @@ void WeakCodeReferences::Register(const Code& value) { |
| if (!array_.IsNull()) { |
| // Try to find and reuse cleared WeakProperty to avoid allocating new one. |
|
Vyacheslav Egorov (Google)
2017/04/10 10:59:28
You need to amend the comment because the code bel
erikcorry
2017/04/19 15:06:41
Moved to different CL
|
| WeakProperty& weak_property = WeakProperty::Handle(); |
| - for (intptr_t i = 0; i < array_.Length(); i++) { |
| + for (intptr_t i = array_.Length() - 1; i >= 0; i--) { |
| weak_property ^= array_.At(i); |
| + if (weak_property.raw() == WeakProperty::null()) { |
| + weak_property ^= WeakProperty::New(Heap::kOld); |
| + array_.SetAt(i, weak_property); |
| + } |
| if (weak_property.key() == Code::null()) { |
| // Empty property found. Reuse it. |
| weak_property.set_key(value); |
| @@ -37,8 +41,8 @@ void WeakCodeReferences::Register(const Code& value) { |
| weak_property.set_key(value); |
| intptr_t length = array_.IsNull() ? 0 : array_.Length(); |
| - const Array& new_array = |
| - Array::Handle(Array::Grow(array_, length + 1, Heap::kOld)); |
| + const Array& new_array = Array::Handle( |
| + Array::Grow(array_, length + 1 + (length >> 2), Heap::kOld)); |
| new_array.SetAt(length, weak_property); |
| UpdateArrayTo(new_array); |
| } |
| @@ -52,7 +56,8 @@ bool WeakCodeReferences::IsOptimizedCode(const Array& dependent_code, |
| WeakProperty& weak_property = WeakProperty::Handle(); |
| for (intptr_t i = 0; i < dependent_code.Length(); i++) { |
| weak_property ^= dependent_code.At(i); |
| - if (code.raw() == weak_property.key()) { |
| + if (weak_property.raw() != WeakProperty::null() && |
| + code.raw() == weak_property.key()) { |
| return true; |
| } |
| } |
| @@ -88,6 +93,9 @@ void WeakCodeReferences::DisableCode() { |
| Function& function = Function::Handle(); |
| for (intptr_t i = 0; i < code_objects.Length(); i++) { |
| weak_property ^= code_objects.At(i); |
| + if (weak_property.raw() == WeakProperty::null()) { |
| + continue; |
| + } |
| code ^= weak_property.key(); |
| if (code.IsNull()) { |
| // Code was garbage collected already. |