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




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.lir.alloc.trace;
  24 
  25 import org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig;
  26 import org.graalvm.compiler.core.common.alloc.Trace;
  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(Debug.DETAILED_LEVEL)) {
 116                     Debug.dump(Debug.DETAILED_LEVEL, trace, "Before %s (Trace%s: %s)", getName(), trace.getId(), trace);



 117                 }
 118                 run(target, lirGenRes, trace, context);
 119                 allocatedTraces.increment();
 120                 if (dumpTrace && Debug.isDumpEnabled(Debug.VERBOSE_LEVEL)) {
 121                     Debug.dump(Debug.VERBOSE_LEVEL, trace, "After %s (Trace%s: %s)", getName(), trace.getId(), trace);


 122                 }
 123             }
 124         } catch (Throwable e) {
 125             throw Debug.handle(e);
 126         }
 127     }
 128 
 129     protected abstract void run(TargetDescription target, LIRGenerationResult lirGenRes, Trace trace, C context);
 130 }


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.lir.alloc.trace;
  24 
  25 import org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig;
  26 import org.graalvm.compiler.core.common.alloc.Trace;
  27 import org.graalvm.compiler.core.common.alloc.TraceBuilderResult;
  28 import org.graalvm.compiler.debug.CounterKey;

  29 import org.graalvm.compiler.debug.DebugCloseable;
  30 import org.graalvm.compiler.debug.DebugContext;
  31 import org.graalvm.compiler.debug.MemUseTrackerKey;
  32 import org.graalvm.compiler.debug.TimerKey;
  33 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
  34 import org.graalvm.compiler.lir.gen.LIRGeneratorTool.MoveFactory;
  35 import org.graalvm.compiler.lir.phases.LIRPhase;
  36 import org.graalvm.compiler.lir.phases.LIRPhase.LIRPhaseStatistics;
  37 
  38 import jdk.vm.ci.code.TargetDescription;
  39 
  40 public abstract class TraceAllocationPhase<C extends TraceAllocationPhase.TraceAllocationContext> {
  41 
  42     public static class TraceAllocationContext {
  43         public final MoveFactory spillMoveFactory;
  44         public final RegisterAllocationConfig registerAllocationConfig;
  45         public final TraceBuilderResult resultTraces;
  46         public final GlobalLivenessInfo livenessInfo;
  47 
  48         public TraceAllocationContext(MoveFactory spillMoveFactory, RegisterAllocationConfig registerAllocationConfig, TraceBuilderResult resultTraces, GlobalLivenessInfo livenessInfo) {
  49             this.spillMoveFactory = spillMoveFactory;
  50             this.registerAllocationConfig = registerAllocationConfig;
  51             this.resultTraces = resultTraces;
  52             this.livenessInfo = livenessInfo;
  53         }
  54     }
  55 
  56     /**
  57      * Records time spent within {@link #apply}.
  58      */
  59     private final TimerKey timer;
  60 
  61     /**
  62      * Records memory usage within {@link #apply}.
  63      */
  64     private final MemUseTrackerKey memUseTracker;
  65 
  66     /**
  67      * Records the number of traces allocated with this phase.
  68      */
  69     private final CounterKey allocatedTraces;
  70 
  71     public static final class AllocationStatistics {
  72         private final CounterKey allocatedTraces;
  73 
  74         public AllocationStatistics(Class<?> clazz) {
  75             allocatedTraces = DebugContext.counter("TraceRA[%s]", clazz);
  76         }
  77     }
  78 
  79     private static final ClassValue<AllocationStatistics> counterClassValue = new ClassValue<AllocationStatistics>() {
  80         @Override
  81         protected AllocationStatistics computeValue(Class<?> c) {
  82             return new AllocationStatistics(c);
  83         }
  84     };
  85 
  86     private static AllocationStatistics getAllocationStatistics(Class<?> c) {
  87         return counterClassValue.get(c);
  88     }
  89 
  90     public TraceAllocationPhase() {
  91         LIRPhaseStatistics statistics = LIRPhase.getLIRPhaseStatistics(getClass());
  92         timer = statistics.timer;
  93         memUseTracker = statistics.memUseTracker;
  94         allocatedTraces = getAllocationStatistics(getClass()).allocatedTraces;
  95     }
  96 
  97     public final CharSequence getName() {
  98         return LIRPhase.createName(getClass());
  99     }
 100 
 101     @Override
 102     public final String toString() {
 103         return getName().toString();
 104     }
 105 
 106     public final void apply(TargetDescription target, LIRGenerationResult lirGenRes, Trace trace, C context) {
 107         apply(target, lirGenRes, trace, context, true);
 108     }
 109 
 110     @SuppressWarnings("try")
 111     public final void apply(TargetDescription target, LIRGenerationResult lirGenRes, Trace trace, C context, boolean dumpTrace) {
 112         DebugContext debug = lirGenRes.getLIR().getDebug();
 113         try (DebugContext.Scope s = debug.scope(getName(), this)) {
 114             try (DebugCloseable a = timer.start(debug); DebugCloseable c = memUseTracker.start(debug)) {
 115                 if (dumpTrace) {
 116                     if (debug.isDumpEnabled(DebugContext.DETAILED_LEVEL)) {
 117                         debug.dump(DebugContext.DETAILED_LEVEL, trace, "Before %s (Trace%s: %s)", getName(), trace.getId(), trace);
 118                     }
 119                 }
 120                 run(target, lirGenRes, trace, context);
 121                 allocatedTraces.increment(debug);
 122                 if (dumpTrace) {
 123                     if (debug.isDumpEnabled(DebugContext.VERBOSE_LEVEL)) {
 124                         debug.dump(DebugContext.VERBOSE_LEVEL, trace, "After %s (Trace%s: %s)", getName(), trace.getId(), trace);
 125                     }
 126                 }
 127             }
 128         } catch (Throwable e) {
 129             throw debug.handle(e);
 130         }
 131     }
 132 
 133     protected abstract void run(TargetDescription target, LIRGenerationResult lirGenRes, Trace trace, C context);
 134 }
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