< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/SnippetTemplate.java

Print this page

        

*** 62,71 **** --- 62,72 ---- import org.graalvm.compiler.core.common.GraalOptions; import org.graalvm.compiler.core.common.type.Stamp; import org.graalvm.compiler.core.common.type.StampFactory; import org.graalvm.compiler.core.common.type.StampPair; import org.graalvm.compiler.core.common.type.TypeReference; + import org.graalvm.compiler.debug.Assertions; import org.graalvm.compiler.debug.CounterKey; import org.graalvm.compiler.debug.DebugCloseable; import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.debug.DebugContext.Description; import org.graalvm.compiler.debug.DebugHandlersFactory;
*** 168,178 **** * per snippet and then cached. */ public abstract static class SnippetInfo { protected final ResolvedJavaMethod method; ! protected ResolvedJavaMethod original; protected final LocationIdentity[] privateLocations; protected final Object receiver; public Object getReceiver() { return receiver; --- 169,179 ---- * per snippet and then cached. */ public abstract static class SnippetInfo { protected final ResolvedJavaMethod method; ! protected final ResolvedJavaMethod original; protected final LocationIdentity[] privateLocations; protected final Object receiver; public Object getReceiver() { return receiver;
*** 267,278 **** */ private final CounterKey instantiationCounter; protected abstract Lazy lazy(); ! protected SnippetInfo(ResolvedJavaMethod method, LocationIdentity[] privateLocations, Object receiver) { this.method = method; this.privateLocations = privateLocations; instantiationCounter = DebugContext.counter("SnippetInstantiationCount[%s]", method.getName()); instantiationTimer = DebugContext.timer("SnippetInstantiationTime[%s]", method.getName()); this.receiver = receiver; } --- 268,280 ---- */ private final CounterKey instantiationCounter; protected abstract Lazy lazy(); ! protected SnippetInfo(ResolvedJavaMethod method, ResolvedJavaMethod original, LocationIdentity[] privateLocations, Object receiver) { this.method = method; + this.original = original; this.privateLocations = privateLocations; instantiationCounter = DebugContext.counter("SnippetInstantiationCount[%s]", method.getName()); instantiationTimer = DebugContext.timer("SnippetInstantiationTime[%s]", method.getName()); this.receiver = receiver; }
*** 283,296 **** public int getParameterCount() { return lazy().constantParameters.length; } - public void setOriginalMethod(ResolvedJavaMethod original) { - this.original = original; - } - public boolean isConstantParameter(int paramIdx) { return lazy().constantParameters[paramIdx]; } public boolean isVarargsParameter(int paramIdx) { --- 285,294 ----
*** 316,327 **** } protected static class LazySnippetInfo extends SnippetInfo { protected final AtomicReference<Lazy> lazy = new AtomicReference<>(null); ! protected LazySnippetInfo(ResolvedJavaMethod method, LocationIdentity[] privateLocations, Object receiver) { ! super(method, privateLocations, receiver); } @Override protected Lazy lazy() { if (lazy.get() == null) { --- 314,325 ---- } protected static class LazySnippetInfo extends SnippetInfo { protected final AtomicReference<Lazy> lazy = new AtomicReference<>(null); ! protected LazySnippetInfo(ResolvedJavaMethod method, ResolvedJavaMethod original, LocationIdentity[] privateLocations, Object receiver) { ! super(method, original, privateLocations, receiver); } @Override protected Lazy lazy() { if (lazy.get() == null) {
*** 332,343 **** } protected static class EagerSnippetInfo extends SnippetInfo { protected final Lazy lazy; ! protected EagerSnippetInfo(ResolvedJavaMethod method, LocationIdentity[] privateLocations, Object receiver) { ! super(method, privateLocations, receiver); lazy = new Lazy(method); } @Override protected Lazy lazy() { --- 330,341 ---- } protected static class EagerSnippetInfo extends SnippetInfo { protected final Lazy lazy; ! protected EagerSnippetInfo(ResolvedJavaMethod method, ResolvedJavaMethod original, LocationIdentity[] privateLocations, Object receiver) { ! super(method, original, privateLocations, receiver); lazy = new Lazy(method); } @Override protected Lazy lazy() {
*** 640,671 **** } } return null; } protected SnippetInfo snippet(Class<? extends Snippets> declaringClass, String methodName, LocationIdentity... initialPrivateLocations) { ! return snippet(declaringClass, methodName, null, initialPrivateLocations); } /** * Finds the unique method in {@code declaringClass} named {@code methodName} annotated by * {@link Snippet} and returns a {@link SnippetInfo} value describing it. There must be ! * exactly one snippet method in {@code declaringClass}. */ ! protected SnippetInfo snippet(Class<? extends Snippets> declaringClass, String methodName, Object receiver, LocationIdentity... initialPrivateLocations) { assert methodName != null; ! Method method = findMethod(declaringClass, methodName, null); ! assert method != null : "did not find @" + Snippet.class.getSimpleName() + " method in " + declaringClass + " named " + methodName; ! assert method.getAnnotation(Snippet.class) != null : method + " must be annotated with @" + Snippet.class.getSimpleName(); ! assert findMethod(declaringClass, methodName, method) == null : "found more than one method named " + methodName + " in " + declaringClass; ! ResolvedJavaMethod javaMethod = providers.getMetaAccess().lookupJavaMethod(method); ! providers.getReplacements().registerSnippet(javaMethod, GraalOptions.TrackNodeSourcePosition.getValue(options)); LocationIdentity[] privateLocations = GraalOptions.SnippetCounters.getValue(options) ? SnippetCounterNode.addSnippetCounters(initialPrivateLocations) : initialPrivateLocations; if (GraalOptions.EagerSnippets.getValue(options)) { ! return new EagerSnippetInfo(javaMethod, privateLocations, receiver); } else { ! return new LazySnippetInfo(javaMethod, privateLocations, receiver); } } static final AtomicInteger nextSnippetTemplateId = new AtomicInteger(); --- 638,686 ---- } } return null; } + public static ResolvedJavaMethod findMethod(MetaAccessProvider metaAccess, Class<?> declaringClass, String methodName) { + ResolvedJavaType type = metaAccess.lookupJavaType(declaringClass); + ResolvedJavaMethod result = null; + for (ResolvedJavaMethod m : type.getDeclaredMethods()) { + if (m.getName().equals(methodName)) { + if (!Assertions.assertionsEnabled()) { + return m; + } else { + assert result == null : "multiple definitions found"; + result = m; + } + } + } + if (result == null) { + throw new GraalError("Could not find method in " + declaringClass + " named " + methodName); + } + return result; + } + protected SnippetInfo snippet(Class<? extends Snippets> declaringClass, String methodName, LocationIdentity... initialPrivateLocations) { ! return snippet(declaringClass, methodName, null, null, initialPrivateLocations); } /** * Finds the unique method in {@code declaringClass} named {@code methodName} annotated by * {@link Snippet} and returns a {@link SnippetInfo} value describing it. There must be ! * exactly one snippet method in {@code declaringClass} with a given name. */ ! protected SnippetInfo snippet(Class<? extends Snippets> declaringClass, String methodName, ResolvedJavaMethod original, Object receiver, LocationIdentity... initialPrivateLocations) { assert methodName != null; ! ResolvedJavaMethod javaMethod = findMethod(providers.getMetaAccess(), declaringClass, methodName); ! assert javaMethod != null : "did not find @" + Snippet.class.getSimpleName() + " method in " + declaringClass + " named " + methodName; ! assert javaMethod.getAnnotation(Snippet.class) != null : javaMethod + " must be annotated with @" + Snippet.class.getSimpleName(); ! providers.getReplacements().registerSnippet(javaMethod, original, receiver, GraalOptions.TrackNodeSourcePosition.getValue(options)); LocationIdentity[] privateLocations = GraalOptions.SnippetCounters.getValue(options) ? SnippetCounterNode.addSnippetCounters(initialPrivateLocations) : initialPrivateLocations; if (GraalOptions.EagerSnippets.getValue(options)) { ! return new EagerSnippetInfo(javaMethod, original, privateLocations, receiver); } else { ! return new LazySnippetInfo(javaMethod, original, privateLocations, receiver); } } static final AtomicInteger nextSnippetTemplateId = new AtomicInteger();
*** 1036,1046 **** LoopBeginNode loopBegin = explodeLoop.findLoopBegin(); if (loopBegin != null) { LoopEx loop = new LoopsData(snippetCopy).loop(loopBegin); Mark mark = snippetCopy.getMark(); LoopTransformations.fullUnroll(loop, phaseContext, new CanonicalizerPhase()); ! new CanonicalizerPhase().applyIncremental(snippetCopy, phaseContext, mark); loop.deleteUnusedNodes(); } GraphUtil.removeFixedWithUnusedInputs(explodeLoop); exploded = true; } --- 1051,1061 ---- LoopBeginNode loopBegin = explodeLoop.findLoopBegin(); if (loopBegin != null) { LoopEx loop = new LoopsData(snippetCopy).loop(loopBegin); Mark mark = snippetCopy.getMark(); LoopTransformations.fullUnroll(loop, phaseContext, new CanonicalizerPhase()); ! new CanonicalizerPhase().applyIncremental(snippetCopy, phaseContext, mark, false); loop.deleteUnusedNodes(); } GraphUtil.removeFixedWithUnusedInputs(explodeLoop); exploded = true; }
< prev index next >