< prev index next >

src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotSpeculationLog.java

Print this page

        

@@ -49,31 +49,40 @@
 
     /** All speculations that have caused a deoptimization. */
     private Set<SpeculationReason> failedSpeculations;
 
     /** Strong references to all reasons embedded in the current nmethod. */
-    private Map<Long, SpeculationReason> speculations;
+    private HashMap<SpeculationReason, JavaConstant> speculations;
 
     private long currentSpeculationID;
 
     @Override
     public synchronized void collectFailedSpeculations() {
         if (lastFailed != 0) {
             if (failedSpeculations == null) {
                 failedSpeculations = new HashSet<>(2);
             }
             if (speculations != null) {
-                SpeculationReason lastFailedSpeculation = speculations.get(lastFailed);
+                SpeculationReason lastFailedSpeculation = lookupSpeculation(this.lastFailed);
                 if (lastFailedSpeculation != null) {
                     failedSpeculations.add(lastFailedSpeculation);
                 }
                 lastFailed = 0;
                 speculations = null;
             }
         }
     }
 
+    private SpeculationReason lookupSpeculation(long value) {
+        for (Map.Entry<SpeculationReason, JavaConstant> entry : speculations.entrySet()) {
+            if (value == entry.getValue().asLong()) {
+                return entry.getKey();
+            }
+        }
+        return null;
+    }
+
     @Override
     public synchronized boolean maySpeculate(SpeculationReason reason) {
         if (failedSpeculations != null && failedSpeculations.contains(reason)) {
             return false;
         }

@@ -83,12 +92,16 @@
     @Override
     public synchronized Speculation speculate(SpeculationReason reason) {
         if (speculations == null) {
             speculations = new HashMap<>();
         }
-        speculations.put(++currentSpeculationID, reason);
-        return new HotSpotSpeculation(reason, JavaConstant.forLong(currentSpeculationID));
+        JavaConstant id = speculations.get(reason);
+        if (id == null) {
+            id = JavaConstant.forLong(++currentSpeculationID);
+            speculations.put(reason, id);
+        }
+        return new HotSpotSpeculation(reason, id);
     }
 
     @Override
     public synchronized boolean hasSpeculations() {
         return speculations != null && !speculations.isEmpty();

@@ -97,10 +110,10 @@
     @Override
     public synchronized Speculation lookupSpeculation(JavaConstant constant) {
         if (constant.isDefaultForKind()) {
             return NO_SPECULATION;
         }
-        SpeculationReason reason = speculations.get(constant.asLong());
+        SpeculationReason reason = lookupSpeculation(constant.asLong());
         assert reason != null : "Speculation should have been registered";
         return new HotSpotSpeculation(reason, constant);
     }
 }
< prev index next >