< 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,10 +62,11 @@
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,11 +169,11 @@
* per snippet and then cached.
*/
public abstract static class SnippetInfo {
protected final ResolvedJavaMethod method;
- protected ResolvedJavaMethod original;
+ protected final ResolvedJavaMethod original;
protected final LocationIdentity[] privateLocations;
protected final Object receiver;
public Object getReceiver() {
return receiver;
@@ -267,12 +268,13 @@
*/
private final CounterKey instantiationCounter;
protected abstract Lazy lazy();
- protected SnippetInfo(ResolvedJavaMethod method, LocationIdentity[] privateLocations, Object receiver) {
+ 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,14 +285,10 @@
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) {
@@ -316,12 +314,12 @@
}
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);
+ protected LazySnippetInfo(ResolvedJavaMethod method, ResolvedJavaMethod original, LocationIdentity[] privateLocations, Object receiver) {
+ super(method, original, privateLocations, receiver);
}
@Override
protected Lazy lazy() {
if (lazy.get() == null) {
@@ -332,12 +330,12 @@
}
protected static class EagerSnippetInfo extends SnippetInfo {
protected final Lazy lazy;
- protected EagerSnippetInfo(ResolvedJavaMethod method, LocationIdentity[] privateLocations, Object receiver) {
- super(method, privateLocations, receiver);
+ protected EagerSnippetInfo(ResolvedJavaMethod method, ResolvedJavaMethod original, LocationIdentity[] privateLocations, Object receiver) {
+ super(method, original, privateLocations, receiver);
lazy = new Lazy(method);
}
@Override
protected Lazy lazy() {
@@ -640,32 +638,49 @@
}
}
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, 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}.
+ * exactly one snippet method in {@code declaringClass} with a given name.
*/
- protected SnippetInfo snippet(Class<? extends Snippets> declaringClass, String methodName, Object receiver, LocationIdentity... initialPrivateLocations) {
+ protected SnippetInfo snippet(Class<? extends Snippets> declaringClass, String methodName, ResolvedJavaMethod original, 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));
+ 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, privateLocations, receiver);
+ return new EagerSnippetInfo(javaMethod, original, privateLocations, receiver);
} else {
- return new LazySnippetInfo(javaMethod, privateLocations, receiver);
+ return new LazySnippetInfo(javaMethod, original, privateLocations, receiver);
}
}
static final AtomicInteger nextSnippetTemplateId = new AtomicInteger();
@@ -1036,11 +1051,11 @@
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);
+ new CanonicalizerPhase().applyIncremental(snippetCopy, phaseContext, mark, false);
loop.deleteUnusedNodes();
}
GraphUtil.removeFixedWithUnusedInputs(explodeLoop);
exploded = true;
}
< prev index next >