src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/TraceAllocationPhase.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/TraceAllocationPhase.java

Print this page




  27 import org.graalvm.compiler.core.common.alloc.TraceBuilderResult;
  28 import org.graalvm.compiler.debug.Debug;
  29 import org.graalvm.compiler.debug.Debug.Scope;
  30 import org.graalvm.compiler.debug.DebugCloseable;
  31 import org.graalvm.compiler.debug.DebugCounter;
  32 import org.graalvm.compiler.debug.DebugMemUseTracker;
  33 import org.graalvm.compiler.debug.DebugTimer;
  34 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
  35 import org.graalvm.compiler.lir.gen.LIRGeneratorTool.MoveFactory;
  36 import org.graalvm.compiler.lir.phases.LIRPhase;
  37 import org.graalvm.compiler.lir.phases.LIRPhase.LIRPhaseStatistics;
  38 
  39 import jdk.vm.ci.code.TargetDescription;
  40 
  41 public abstract class TraceAllocationPhase<C extends TraceAllocationPhase.TraceAllocationContext> {
  42 
  43     public static class TraceAllocationContext {
  44         public final MoveFactory spillMoveFactory;
  45         public final RegisterAllocationConfig registerAllocationConfig;
  46         public final TraceBuilderResult resultTraces;

  47 
  48         public TraceAllocationContext(MoveFactory spillMoveFactory, RegisterAllocationConfig registerAllocationConfig, TraceBuilderResult resultTraces) {
  49             this.spillMoveFactory = spillMoveFactory;
  50             this.registerAllocationConfig = registerAllocationConfig;
  51             this.resultTraces = resultTraces;

  52         }
  53     }
  54 
  55     /**
  56      * Records time spent within {@link #apply}.
  57      */
  58     private final DebugTimer timer;
  59 
  60     /**
  61      * Records memory usage within {@link #apply}.
  62      */
  63     private final DebugMemUseTracker memUseTracker;
  64 
  65     /**
  66      * Records the number of traces allocated with this phase.
  67      */
  68     private final DebugCounter allocatedTraces;
  69 
  70     private static final class AllocationStatistics {
  71         private final DebugCounter allocatedTraces;
  72 
  73         private AllocationStatistics(Class<?> clazz) {
  74             allocatedTraces = Debug.counter("TraceRA[%s]", clazz);
  75         }
  76     }
  77 
  78     private static final ClassValue<AllocationStatistics> counterClassValue = new ClassValue<AllocationStatistics>() {
  79         @Override
  80         protected AllocationStatistics computeValue(Class<?> c) {
  81             return new AllocationStatistics(c);
  82         }
  83     };
  84 




  85     public TraceAllocationPhase() {
  86         LIRPhaseStatistics statistics = LIRPhase.statisticsClassValue.get(getClass());
  87         timer = statistics.timer;
  88         memUseTracker = statistics.memUseTracker;
  89         allocatedTraces = counterClassValue.get(getClass()).allocatedTraces;
  90     }
  91 
  92     public final CharSequence getName() {
  93         return LIRPhase.createName(getClass());
  94     }
  95 
  96     @Override
  97     public final String toString() {
  98         return getName().toString();
  99     }
 100 
 101     public final void apply(TargetDescription target, LIRGenerationResult lirGenRes, Trace trace, C context) {
 102         apply(target, lirGenRes, trace, context, true);
 103     }
 104 
 105     @SuppressWarnings("try")
 106     public final void apply(TargetDescription target, LIRGenerationResult lirGenRes, Trace trace, C context, boolean dumpTrace) {
 107         try (Scope s = Debug.scope(getName(), this)) {
 108             try (DebugCloseable a = timer.start(); DebugCloseable c = memUseTracker.start()) {
 109                 if (dumpTrace && Debug.isDumpEnabled(TraceBuilderPhase.TRACE_DUMP_LEVEL + 1)) {


  27 import org.graalvm.compiler.core.common.alloc.TraceBuilderResult;
  28 import org.graalvm.compiler.debug.Debug;
  29 import org.graalvm.compiler.debug.Debug.Scope;
  30 import org.graalvm.compiler.debug.DebugCloseable;
  31 import org.graalvm.compiler.debug.DebugCounter;
  32 import org.graalvm.compiler.debug.DebugMemUseTracker;
  33 import org.graalvm.compiler.debug.DebugTimer;
  34 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
  35 import org.graalvm.compiler.lir.gen.LIRGeneratorTool.MoveFactory;
  36 import org.graalvm.compiler.lir.phases.LIRPhase;
  37 import org.graalvm.compiler.lir.phases.LIRPhase.LIRPhaseStatistics;
  38 
  39 import jdk.vm.ci.code.TargetDescription;
  40 
  41 public abstract class TraceAllocationPhase<C extends TraceAllocationPhase.TraceAllocationContext> {
  42 
  43     public static class TraceAllocationContext {
  44         public final MoveFactory spillMoveFactory;
  45         public final RegisterAllocationConfig registerAllocationConfig;
  46         public final TraceBuilderResult resultTraces;
  47         public final GlobalLivenessInfo livenessInfo;
  48 
  49         public TraceAllocationContext(MoveFactory spillMoveFactory, RegisterAllocationConfig registerAllocationConfig, TraceBuilderResult resultTraces, GlobalLivenessInfo livenessInfo) {
  50             this.spillMoveFactory = spillMoveFactory;
  51             this.registerAllocationConfig = registerAllocationConfig;
  52             this.resultTraces = resultTraces;
  53             this.livenessInfo = livenessInfo;
  54         }
  55     }
  56 
  57     /**
  58      * Records time spent within {@link #apply}.
  59      */
  60     private final DebugTimer timer;
  61 
  62     /**
  63      * Records memory usage within {@link #apply}.
  64      */
  65     private final DebugMemUseTracker memUseTracker;
  66 
  67     /**
  68      * Records the number of traces allocated with this phase.
  69      */
  70     private final DebugCounter allocatedTraces;
  71 
  72     public static final class AllocationStatistics {
  73         private final DebugCounter allocatedTraces;
  74 
  75         public AllocationStatistics(Class<?> clazz) {
  76             allocatedTraces = Debug.counter("TraceRA[%s]", clazz);
  77         }
  78     }
  79 
  80     private static final ClassValue<AllocationStatistics> counterClassValue = new ClassValue<AllocationStatistics>() {
  81         @Override
  82         protected AllocationStatistics computeValue(Class<?> c) {
  83             return new AllocationStatistics(c);
  84         }
  85     };
  86 
  87     private static AllocationStatistics getAllocationStatistics(Class<?> c) {
  88         return counterClassValue.get(c);
  89     }
  90 
  91     public TraceAllocationPhase() {
  92         LIRPhaseStatistics statistics = LIRPhase.getLIRPhaseStatistics(getClass());
  93         timer = statistics.timer;
  94         memUseTracker = statistics.memUseTracker;
  95         allocatedTraces = getAllocationStatistics(getClass()).allocatedTraces;
  96     }
  97 
  98     public final CharSequence getName() {
  99         return LIRPhase.createName(getClass());
 100     }
 101 
 102     @Override
 103     public final String toString() {
 104         return getName().toString();
 105     }
 106 
 107     public final void apply(TargetDescription target, LIRGenerationResult lirGenRes, Trace trace, C context) {
 108         apply(target, lirGenRes, trace, context, true);
 109     }
 110 
 111     @SuppressWarnings("try")
 112     public final void apply(TargetDescription target, LIRGenerationResult lirGenRes, Trace trace, C context, boolean dumpTrace) {
 113         try (Scope s = Debug.scope(getName(), this)) {
 114             try (DebugCloseable a = timer.start(); DebugCloseable c = memUseTracker.start()) {
 115                 if (dumpTrace && Debug.isDumpEnabled(TraceBuilderPhase.TRACE_DUMP_LEVEL + 1)) {
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/trace/TraceAllocationPhase.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File