|
29 | 29 | import java.util.Collection; |
30 | 30 | import java.util.Comparator; |
31 | 31 | import java.util.Deque; |
32 | | -import java.util.IdentityHashMap; |
| 32 | +import java.util.HashMap; |
33 | 33 | import java.util.Map; |
34 | 34 | import java.util.concurrent.ConcurrentLinkedDeque; |
35 | 35 | import java.util.concurrent.atomic.AtomicInteger; |
@@ -304,12 +304,11 @@ public void scanConstant(JavaConstant value, ScanReason reason) { |
304 | 304 | return; |
305 | 305 | } |
306 | 306 | 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) { |
309 | 308 | try { |
310 | 309 | scanningObserver.forScannedConstant(unwrappedValue, reason); |
311 | 310 | } finally { |
312 | | - scannedObjects.release(valueObj); |
| 311 | + scannedObjects.release(unwrappedValue); |
313 | 312 | WorklistEntry worklistEntry = new WorklistEntry(unwrappedValue, reason); |
314 | 313 | if (executor != null) { |
315 | 314 | executor.execute(debug -> doScan(worklistEntry)); |
@@ -786,12 +785,16 @@ public static final class ReusableSet { |
786 | 785 | /** |
787 | 786 | * The storage of atomic integers. During analysis the constant count for rather large |
788 | 787 | * 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. |
789 | 792 | */ |
790 | | - private final IdentityHashMap<Object, AtomicInteger> store = new IdentityHashMap<>(65536); |
| 793 | + private final HashMap<JavaConstant, AtomicInteger> store = new HashMap<>(65536); |
791 | 794 | private int sequence = 0; |
792 | 795 |
|
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; |
795 | 798 | AtomicInteger i = map.get(object); |
796 | 799 | int seq = this.sequence; |
797 | 800 | int inflightSequence = seq - 1; |
@@ -824,14 +827,14 @@ public Object putAndAcquire(Object object) { |
824 | 827 | } |
825 | 828 | } |
826 | 829 |
|
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); |
830 | 833 | if (i == null) { |
831 | 834 | // We have missed a value likely someone else has updated the map at the same time. |
832 | 835 | // Now synchronize |
833 | 836 | synchronized (map) { |
834 | | - i = map.get(o); |
| 837 | + i = map.get(object); |
835 | 838 | } |
836 | 839 | } |
837 | 840 | i.set(sequence); |
|
0 commit comments