Skip to content

Commit d1cb3d1

Browse files
committed
Changes to preserve kept list while running markers.
1 parent 5267aaf commit d1cb3d1

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/main/java/org/truffleruby/core/MarkingService.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public ReferenceProcessingService<MarkerReference> service() {
8484
private final ThreadLocal<Deque<ArrayList<Object>>> stackPreservation = ThreadLocal.withInitial(() -> new ArrayDeque<>());
8585

8686
private Object[] keptObjects;
87+
private Object[] oldKeptObjects = null;
8788

8889
private int counter = 0;
8990

@@ -94,25 +95,24 @@ public MarkingService(RubyContext context, ReferenceProcessor referenceProcessor
9495
}
9596

9697
public void keepObject(Object object) {
97-
Object[] oldKeptObjects = addToKeptObjects(object);
98-
if (oldKeptObjects != null) {
98+
if (addToKeptObjects(object)) {
9999
runAllMarkers();
100100
}
101101
}
102102

103-
private synchronized Object[] addToKeptObjects(Object object) {
103+
private synchronized boolean addToKeptObjects(Object object) {
104104
final ArrayList<Object> keepList = stackPreservation.get().peekFirst();
105105
if (keepList != null) {
106106
keepList.add(object);
107107
}
108108
keptObjects[counter++] = object;
109109
if (counter == cacheSize) {
110110
counter = 0;
111-
Object[] tmp = keptObjects;
111+
oldKeptObjects = keptObjects;
112112
keptObjects = new Object[cacheSize];
113-
return tmp;
113+
return true;
114114
}
115-
return null;
115+
return false;
116116
}
117117

118118
@TruffleBoundary
@@ -126,8 +126,7 @@ public void popStackPreservationFrame() {
126126
}
127127

128128
public synchronized void runMarkersAndDropKeptList() {
129-
@SuppressWarnings("unused")
130-
Object[] tmp = keptObjects;
129+
oldKeptObjects = keptObjects;
131130
keptObjects = new Object[cacheSize];
132131
runAllMarkers();
133132
}
@@ -143,6 +142,7 @@ private synchronized void runAllMarkers() {
143142
}
144143
currentMarker = nextMarker;
145144
}
145+
oldKeptObjects = null;
146146
}
147147

148148
public void addMarker(DynamicObject object, MarkerAction action) {

0 commit comments

Comments
 (0)