< prev index next >

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

Print this page

        

*** 20,34 **** * or visit www.oracle.com if you need additional information or have any * questions. */ package jdk.vm.ci.hotspot; ! import jdk.vm.ci.meta.*; ! public class HotSpotSpeculationLog extends SpeculationLog { @Override ! public JavaConstant speculate(Object reason) { ! addSpeculation(reason); return HotSpotObjectConstantImpl.forObject(reason); } } --- 20,84 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ package jdk.vm.ci.hotspot; ! import java.util.Collection; ! import java.util.HashSet; ! import java.util.Set; ! import java.util.concurrent.ConcurrentLinkedQueue; ! import jdk.vm.ci.meta.JavaConstant; ! import jdk.vm.ci.meta.SpeculationLog; ! ! public class HotSpotSpeculationLog implements SpeculationLog { ! ! /** Written by the C++ code that performs deoptimization. */ ! private volatile Object lastFailed; ! ! /** All speculations that have been a deoptimization reason. */ ! private Set<SpeculationReason> failedSpeculations; ! ! /** Strong references to all reasons embededded in the current nmethod. */ ! private volatile Collection<SpeculationReason> speculations; ! ! @Override ! public synchronized void collectFailedSpeculations() { ! if (lastFailed != null) { ! if (failedSpeculations == null) { ! failedSpeculations = new HashSet<>(2); ! } ! failedSpeculations.add((SpeculationReason) lastFailed); ! lastFailed = null; ! speculations = null; ! } ! } @Override ! public boolean maySpeculate(SpeculationReason reason) { ! if (failedSpeculations != null && failedSpeculations.contains(reason)) { ! return false; ! } ! return true; ! } ! ! @Override ! public JavaConstant speculate(SpeculationReason reason) { ! assert maySpeculate(reason); ! ! /* ! * Objects referenced from nmethods are weak references. We need a strong reference to the ! * reason objects that are embedded in nmethods, so we add them to the speculations ! * collection. ! */ ! if (speculations == null) { ! synchronized (this) { ! if (speculations == null) { ! speculations = new ConcurrentLinkedQueue<>(); ! } ! } ! } ! speculations.add(reason); ! return HotSpotObjectConstantImpl.forObject(reason); } }
< prev index next >