Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 06c4a4b7563ceff3d06f97e932704fc326c26bf5..f852f4d7c8197df97e26d6f041056c8a5af408e5 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -12061,8 +12061,17 @@ void DependentCode::AddToDependentICList(Handle<Code> stub) { |
DisallowHeapAllocation no_heap_allocation; |
GroupStartIndexes starts(this); |
int i = starts.at(kWeakICGroup); |
- stub->set_next_code_link(object_at(i)); |
- set_object_at(i, *stub); |
+ Object* head = object_at(i); |
+ // Try to insert the stub after the head of the list to minimize number of |
+ // writes to the DependentCode array, since a write to the array can make it |
+ // strong if it was alread marked by incremental marker. |
+ if (head->IsCode()) { |
+ stub->set_next_code_link(Code::cast(head)->next_code_link()); |
+ Code::cast(head)->set_next_code_link(*stub); |
+ } else { |
+ stub->set_next_code_link(head); |
+ set_object_at(i, *stub); |
+ } |
} |