Skip to content

Commit f9bbcfd

Browse files
committed
[GR-73410] Update ObjectScanner#scanConstant and ObjectScanner.ReusableSet for Terminus
PullRequest: graal/23276
2 parents 4eea506 + d726ffe commit f9bbcfd

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/ObjectScanner.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import java.util.Collection;
3030
import java.util.Comparator;
3131
import java.util.Deque;
32-
import java.util.IdentityHashMap;
32+
import java.util.HashMap;
3333
import java.util.Map;
3434
import java.util.concurrent.ConcurrentLinkedDeque;
3535
import java.util.concurrent.atomic.AtomicInteger;
@@ -304,12 +304,11 @@ public void scanConstant(JavaConstant value, ScanReason reason) {
304304
return;
305305
}
306306
JavaConstant unwrappedValue = maybeUnwrap(value);
307-
Object valueObj = unwrappedValue instanceof ImageHeapConstant ? unwrappedValue : constantAsObject(bb, unwrappedValue);
308-
if (scannedObjects.putAndAcquire(valueObj) == null) {
307+
if (scannedObjects.putAndAcquire(unwrappedValue) == null) {
309308
try {
310309
scanningObserver.forScannedConstant(unwrappedValue, reason);
311310
} finally {
312-
scannedObjects.release(valueObj);
311+
scannedObjects.release(unwrappedValue);
313312
WorklistEntry worklistEntry = new WorklistEntry(unwrappedValue, reason);
314313
if (executor != null) {
315314
executor.execute(debug -> doScan(worklistEntry));
@@ -786,12 +785,16 @@ public static final class ReusableSet {
786785
/**
787786
* The storage of atomic integers. During analysis the constant count for rather large
788787
* programs such as the JS interpreter are 90k objects. Hence we use 64k as a good start.
788+
* <p/>
789+
* The specification of {@link Object#equals(Object)} and {@link Object#hashCode()}} for
790+
* {@link JavaConstant} states that they are based on the identity of the wrapped object,
791+
* thus we can use {@link JavaConstant} as keys here.
789792
*/
790-
private final IdentityHashMap<Object, AtomicInteger> store = new IdentityHashMap<>(65536);
793+
private final HashMap<JavaConstant, AtomicInteger> store = new HashMap<>(65536);
791794
private int sequence = 0;
792795

793-
public Object putAndAcquire(Object object) {
794-
IdentityHashMap<Object, AtomicInteger> map = this.store;
796+
public Object putAndAcquire(JavaConstant object) {
797+
Map<JavaConstant, AtomicInteger> map = this.store;
795798
AtomicInteger i = map.get(object);
796799
int seq = this.sequence;
797800
int inflightSequence = seq - 1;
@@ -824,14 +827,14 @@ public Object putAndAcquire(Object object) {
824827
}
825828
}
826829

827-
public void release(Object o) {
828-
IdentityHashMap<Object, AtomicInteger> map = this.store;
829-
AtomicInteger i = map.get(o);
830+
public void release(JavaConstant object) {
831+
Map<JavaConstant, AtomicInteger> map = this.store;
832+
AtomicInteger i = map.get(object);
830833
if (i == null) {
831834
// We have missed a value likely someone else has updated the map at the same time.
832835
// Now synchronize
833836
synchronized (map) {
834-
i = map.get(o);
837+
i = map.get(object);
835838
}
836839
}
837840
i.set(sequence);

0 commit comments

Comments
 (0)