src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/profiling/ProfileSnippets.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.hotspot/src/org/graalvm/compiler/hotspot/replacements/profiling

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/profiling/ProfileSnippets.java

Print this page




  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.hotspot.replacements.profiling;
  24 
  25 import static org.graalvm.compiler.hotspot.GraalHotSpotVMConfig.INJECTED_VMCONFIG;
  26 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.config;
  27 import static org.graalvm.compiler.nodes.extended.BranchProbabilityNode.SLOW_PATH_PROBABILITY;
  28 import static org.graalvm.compiler.nodes.extended.BranchProbabilityNode.probability;
  29 import static org.graalvm.compiler.replacements.SnippetTemplate.DEFAULT_REPLACER;
  30 
  31 import org.graalvm.compiler.api.replacements.Snippet;
  32 import org.graalvm.compiler.api.replacements.Snippet.ConstantParameter;
  33 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;

  34 import org.graalvm.compiler.debug.GraalError;
  35 import org.graalvm.compiler.graph.Node.ConstantNodeParameter;
  36 import org.graalvm.compiler.graph.Node.NodeIntrinsic;
  37 import org.graalvm.compiler.hotspot.HotSpotBackend;
  38 import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
  39 import org.graalvm.compiler.hotspot.nodes.aot.LoadMethodCountersNode;
  40 import org.graalvm.compiler.hotspot.nodes.profiling.ProfileBranchNode;
  41 import org.graalvm.compiler.hotspot.nodes.profiling.ProfileInvokeNode;
  42 import org.graalvm.compiler.hotspot.nodes.profiling.ProfileNode;
  43 import org.graalvm.compiler.hotspot.word.MethodCountersPointer;
  44 import org.graalvm.compiler.nodes.ConstantNode;
  45 import org.graalvm.compiler.nodes.StructuredGraph;
  46 import org.graalvm.compiler.nodes.extended.ForeignCallNode;
  47 import org.graalvm.compiler.nodes.spi.LoweringTool;
  48 import org.graalvm.compiler.nodes.util.GraphUtil;
  49 import org.graalvm.compiler.options.OptionValues;
  50 import org.graalvm.compiler.replacements.SnippetTemplate;
  51 import org.graalvm.compiler.replacements.SnippetTemplate.AbstractTemplates;
  52 import org.graalvm.compiler.replacements.SnippetTemplate.Arguments;
  53 import org.graalvm.compiler.replacements.SnippetTemplate.SnippetInfo;


  79         int counterValue = counters.readInt(config(INJECTED_VMCONFIG).backedgeCounterOffset) + config(INJECTED_VMCONFIG).invocationCounterIncrement;
  80         counters.writeInt(config(INJECTED_VMCONFIG).backedgeCounterOffset, counterValue);
  81         final int frequencyMask = (1 << freqLog) - 1;
  82         if (probability(SLOW_PATH_PROBABILITY, (counterValue & (frequencyMask << config(INJECTED_VMCONFIG).invocationCounterShift)) == 0)) {
  83             methodBackedgeEvent(HotSpotBackend.BACKEDGE_EVENT, counters, bci, targetBci);
  84         }
  85     }
  86 
  87     @Snippet
  88     public static void profileConditionalBackedge(MethodCountersPointer counters, @ConstantParameter int freqLog, boolean branchCondition, int bci, int targetBci) {
  89         if (branchCondition) {
  90             profileBackedge(counters, freqLog, bci, targetBci);
  91         }
  92     }
  93 
  94     public static class Templates extends AbstractTemplates {
  95         private final SnippetInfo profileMethodEntry = snippet(ProfileSnippets.class, "profileMethodEntry");
  96         private final SnippetInfo profileBackedge = snippet(ProfileSnippets.class, "profileBackedge");
  97         private final SnippetInfo profileConditionalBackedge = snippet(ProfileSnippets.class, "profileConditionalBackedge");
  98 
  99         public Templates(OptionValues options, HotSpotProviders providers, TargetDescription target) {
 100             super(options, providers, providers.getSnippetReflection(), target);
 101         }
 102 
 103         public void lower(ProfileNode profileNode, LoweringTool tool) {
 104             StructuredGraph graph = profileNode.graph();
 105             LoadMethodCountersNode counters = graph.unique(new LoadMethodCountersNode(profileNode.getProfiledMethod()));
 106 
 107             if (profileNode instanceof ProfileBranchNode) {
 108                 // Backedge event
 109                 ProfileBranchNode profileBranchNode = (ProfileBranchNode) profileNode;
 110                 SnippetInfo snippet = profileBranchNode.hasCondition() ? profileConditionalBackedge : profileBackedge;
 111                 Arguments args = new Arguments(snippet, graph.getGuardsStage(), tool.getLoweringStage());
 112                 ConstantNode bci = ConstantNode.forInt(profileBranchNode.bci(), graph);
 113                 ConstantNode targetBci = ConstantNode.forInt(profileBranchNode.targetBci(), graph);
 114                 args.add("counters", counters);
 115                 args.addConst("freqLog", profileBranchNode.getNotificationFreqLog());
 116                 if (profileBranchNode.hasCondition()) {
 117                     args.add("branchCondition", profileBranchNode.branchCondition());
 118                 }
 119                 args.add("bci", bci);
 120                 args.add("targetBci", targetBci);
 121 
 122                 SnippetTemplate template = template(args);
 123                 template.instantiate(providers.getMetaAccess(), profileNode, DEFAULT_REPLACER, args);
 124             } else if (profileNode instanceof ProfileInvokeNode) {
 125                 ProfileInvokeNode profileInvokeNode = (ProfileInvokeNode) profileNode;
 126                 // Method invocation event
 127                 Arguments args = new Arguments(profileMethodEntry, graph.getGuardsStage(), tool.getLoweringStage());
 128                 args.add("counters", counters);
 129                 args.addConst("freqLog", profileInvokeNode.getNotificationFreqLog());
 130                 SnippetTemplate template = template(args);
 131                 template.instantiate(providers.getMetaAccess(), profileNode, DEFAULT_REPLACER, args);
 132             } else {
 133                 throw new GraalError("Unsupported profile node type: " + profileNode);
 134             }
 135 
 136             assert profileNode.hasNoUsages();
 137             if (!profileNode.isDeleted()) {
 138                 GraphUtil.killWithUnusedFloatingInputs(profileNode);
 139             }
 140         }
 141     }
 142 }


  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.hotspot.replacements.profiling;
  24 
  25 import static org.graalvm.compiler.hotspot.GraalHotSpotVMConfig.INJECTED_VMCONFIG;
  26 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.config;
  27 import static org.graalvm.compiler.nodes.extended.BranchProbabilityNode.SLOW_PATH_PROBABILITY;
  28 import static org.graalvm.compiler.nodes.extended.BranchProbabilityNode.probability;
  29 import static org.graalvm.compiler.replacements.SnippetTemplate.DEFAULT_REPLACER;
  30 
  31 import org.graalvm.compiler.api.replacements.Snippet;
  32 import org.graalvm.compiler.api.replacements.Snippet.ConstantParameter;
  33 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
  34 import org.graalvm.compiler.debug.DebugHandlersFactory;
  35 import org.graalvm.compiler.debug.GraalError;
  36 import org.graalvm.compiler.graph.Node.ConstantNodeParameter;
  37 import org.graalvm.compiler.graph.Node.NodeIntrinsic;
  38 import org.graalvm.compiler.hotspot.HotSpotBackend;
  39 import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
  40 import org.graalvm.compiler.hotspot.nodes.aot.LoadMethodCountersNode;
  41 import org.graalvm.compiler.hotspot.nodes.profiling.ProfileBranchNode;
  42 import org.graalvm.compiler.hotspot.nodes.profiling.ProfileInvokeNode;
  43 import org.graalvm.compiler.hotspot.nodes.profiling.ProfileNode;
  44 import org.graalvm.compiler.hotspot.word.MethodCountersPointer;
  45 import org.graalvm.compiler.nodes.ConstantNode;
  46 import org.graalvm.compiler.nodes.StructuredGraph;
  47 import org.graalvm.compiler.nodes.extended.ForeignCallNode;
  48 import org.graalvm.compiler.nodes.spi.LoweringTool;
  49 import org.graalvm.compiler.nodes.util.GraphUtil;
  50 import org.graalvm.compiler.options.OptionValues;
  51 import org.graalvm.compiler.replacements.SnippetTemplate;
  52 import org.graalvm.compiler.replacements.SnippetTemplate.AbstractTemplates;
  53 import org.graalvm.compiler.replacements.SnippetTemplate.Arguments;
  54 import org.graalvm.compiler.replacements.SnippetTemplate.SnippetInfo;


  80         int counterValue = counters.readInt(config(INJECTED_VMCONFIG).backedgeCounterOffset) + config(INJECTED_VMCONFIG).invocationCounterIncrement;
  81         counters.writeInt(config(INJECTED_VMCONFIG).backedgeCounterOffset, counterValue);
  82         final int frequencyMask = (1 << freqLog) - 1;
  83         if (probability(SLOW_PATH_PROBABILITY, (counterValue & (frequencyMask << config(INJECTED_VMCONFIG).invocationCounterShift)) == 0)) {
  84             methodBackedgeEvent(HotSpotBackend.BACKEDGE_EVENT, counters, bci, targetBci);
  85         }
  86     }
  87 
  88     @Snippet
  89     public static void profileConditionalBackedge(MethodCountersPointer counters, @ConstantParameter int freqLog, boolean branchCondition, int bci, int targetBci) {
  90         if (branchCondition) {
  91             profileBackedge(counters, freqLog, bci, targetBci);
  92         }
  93     }
  94 
  95     public static class Templates extends AbstractTemplates {
  96         private final SnippetInfo profileMethodEntry = snippet(ProfileSnippets.class, "profileMethodEntry");
  97         private final SnippetInfo profileBackedge = snippet(ProfileSnippets.class, "profileBackedge");
  98         private final SnippetInfo profileConditionalBackedge = snippet(ProfileSnippets.class, "profileConditionalBackedge");
  99 
 100         public Templates(OptionValues options, Iterable<DebugHandlersFactory> factories, HotSpotProviders providers, TargetDescription target) {
 101             super(options, factories, providers, providers.getSnippetReflection(), target);
 102         }
 103 
 104         public void lower(ProfileNode profileNode, LoweringTool tool) {
 105             StructuredGraph graph = profileNode.graph();
 106             LoadMethodCountersNode counters = graph.unique(new LoadMethodCountersNode(profileNode.getProfiledMethod()));
 107 
 108             if (profileNode instanceof ProfileBranchNode) {
 109                 // Backedge event
 110                 ProfileBranchNode profileBranchNode = (ProfileBranchNode) profileNode;
 111                 SnippetInfo snippet = profileBranchNode.hasCondition() ? profileConditionalBackedge : profileBackedge;
 112                 Arguments args = new Arguments(snippet, graph.getGuardsStage(), tool.getLoweringStage());
 113                 ConstantNode bci = ConstantNode.forInt(profileBranchNode.bci(), graph);
 114                 ConstantNode targetBci = ConstantNode.forInt(profileBranchNode.targetBci(), graph);
 115                 args.add("counters", counters);
 116                 args.addConst("freqLog", profileBranchNode.getNotificationFreqLog());
 117                 if (profileBranchNode.hasCondition()) {
 118                     args.add("branchCondition", profileBranchNode.branchCondition());
 119                 }
 120                 args.add("bci", bci);
 121                 args.add("targetBci", targetBci);
 122 
 123                 SnippetTemplate template = template(graph.getDebug(), args);
 124                 template.instantiate(providers.getMetaAccess(), profileNode, DEFAULT_REPLACER, args);
 125             } else if (profileNode instanceof ProfileInvokeNode) {
 126                 ProfileInvokeNode profileInvokeNode = (ProfileInvokeNode) profileNode;
 127                 // Method invocation event
 128                 Arguments args = new Arguments(profileMethodEntry, graph.getGuardsStage(), tool.getLoweringStage());
 129                 args.add("counters", counters);
 130                 args.addConst("freqLog", profileInvokeNode.getNotificationFreqLog());
 131                 SnippetTemplate template = template(graph.getDebug(), args);
 132                 template.instantiate(providers.getMetaAccess(), profileNode, DEFAULT_REPLACER, args);
 133             } else {
 134                 throw new GraalError("Unsupported profile node type: " + profileNode);
 135             }
 136 
 137             assert profileNode.hasNoUsages();
 138             if (!profileNode.isDeleted()) {
 139                 GraphUtil.killWithUnusedFloatingInputs(profileNode);
 140             }
 141         }
 142     }
 143 }
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/profiling/ProfileSnippets.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File