Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gluon-bot committed Sep 30, 2023
2 parents 7a8a59e + 73576b0 commit fbb0987
Show file tree
Hide file tree
Showing 31 changed files with 198 additions and 207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
import jdk.vm.ci.code.BailoutException;
import jdk.vm.ci.code.CodeCacheProvider;
import jdk.vm.ci.code.InstalledCode;
import jdk.vm.ci.code.InvalidInstalledCodeException;
import jdk.vm.ci.code.TargetDescription;
import jdk.vm.ci.meta.Assumptions.Assumption;
import jdk.vm.ci.meta.ConstantReflectionProvider;
Expand Down Expand Up @@ -1321,6 +1322,22 @@ protected Object invoke(ResolvedJavaMethod javaMethod, Object receiver, Object..
return ((Constructor<?>) method).newInstance(applyArgSuppliers(args));
}

protected static Object executeVarargsSafe(InstalledCode code, Object... args) {
try {
return code.executeVarargs(args);
} catch (InvalidInstalledCodeException e) {
throw new RuntimeException(e);
}
}

protected Object invokeSafe(ResolvedJavaMethod method, Object receiver, Object... args) {
try {
return invoke(method, receiver, args);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException e) {
throw new RuntimeException(e);
}
}

/**
* Parses a Java method in {@linkplain GraphBuilderConfiguration#getDefault default} mode to
* produce a graph.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.compiler.debug.DebugDumpScope;
import org.graalvm.compiler.debug.TTY;
import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.nodes.FullInfopointNode;
import org.graalvm.compiler.nodes.Invoke;
import org.graalvm.compiler.nodes.StructuredGraph;
Expand Down Expand Up @@ -306,25 +305,6 @@ private static StructuredGraph assertNotInlined(StructuredGraph graph) {
return assertInGraph(graph, Invoke.class);
}

private static StructuredGraph assertNotInGraph(StructuredGraph graph, Class<?> clazz) {
for (Node node : graph.getNodes()) {
if (clazz.isInstance(node)) {
fail(node.toString());
}
}
return graph;
}

private static StructuredGraph assertInGraph(StructuredGraph graph, Class<?> clazz) {
for (Node node : graph.getNodes()) {
if (clazz.isInstance(node)) {
return graph;
}
}
fail("Graph does not contain a node of class " + clazz.getName());
return graph;
}

private static int[] countMethodInfopoints(StructuredGraph graph) {
int start = 0;
int end = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@
package org.graalvm.compiler.hotspot.test;

import org.graalvm.compiler.api.test.Graal;
import org.graalvm.compiler.bytecode.Bytecode;
import org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode;
import org.graalvm.compiler.core.common.CompilationIdentifier;
import org.graalvm.compiler.core.test.GraalCompilerTest;
import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.compiler.hotspot.HotSpotBackend;
import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
import org.graalvm.compiler.hotspot.HotSpotReplacementsImpl;
import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
import org.graalvm.compiler.nodes.Cancellable;
import org.graalvm.compiler.nodes.StructuredGraph;
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.runtime.RuntimeProvider;
import org.junit.Assume;
Expand Down Expand Up @@ -77,10 +84,24 @@ protected InstalledCode compileAndInstallSubstitution(ResolvedJavaMethod method)
HotSpotProviders providers = rt.getHostBackend().getProviders();
CompilationIdentifier compilationId = runtime().getHostBackend().getCompilationIdentifier(method);
OptionValues options = getInitialOptions();
StructuredGraph graph = providers.getReplacements().getIntrinsicGraph(method, compilationId, getDebugContext(options), AllowAssumptions.YES, null);
StructuredGraph graph = getIntrinsicGraph(method, compilationId, getDebugContext(options), AllowAssumptions.YES, null);
if (graph != null) {
return getCode(method, graph, true, true, graph.getOptions());
}
return null;
}

public StructuredGraph getIntrinsicGraph(ResolvedJavaMethod method, CompilationIdentifier compilationId, DebugContext debug, AllowAssumptions allowAssumptions, Cancellable cancellable) {
GraphBuilderConfiguration.Plugins graphBuilderPlugins = getReplacements().getGraphBuilderPlugins();
InvocationPlugin plugin = graphBuilderPlugins.getInvocationPlugins().lookupInvocation(method, debug.getOptions());
if (plugin != null && !plugin.inlineOnly()) {
assert !plugin.isDecorator() : "lookupInvocation shouldn't return decorator plugins";
Bytecode code = new ResolvedJavaMethodBytecode(method);
OptionValues options = debug.getOptions();
GraphBuilderConfiguration.Plugins plugins = new GraphBuilderConfiguration.Plugins(graphBuilderPlugins);
GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins);
return new HotSpotReplacementsImpl.HotSpotIntrinsicGraphBuilder(options, debug, getProviders(), code, -1, StructuredGraph.AllowAssumptions.YES, config).buildGraph(plugin);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
import org.graalvm.compiler.nodes.java.NewArrayNode;
import org.graalvm.compiler.replacements.arraycopy.ArrayCopyCallNode;
import org.graalvm.compiler.replacements.test.MethodSubstitutionTest;
import org.graalvm.compiler.test.AddExports;
import org.junit.Test;

Expand All @@ -41,7 +40,7 @@
* {@link org.graalvm.compiler.hotspot.meta.HotSpotGraphBuilderPlugins#registerStringPlugins}.
*/
@AddExports({"java.base/java.lang"})
public final class StringUTF16ToBytesGetCharsTest extends MethodSubstitutionTest {
public final class StringUTF16ToBytesGetCharsTest extends HotSpotGraalCompilerTest {

private static final int N = 1000;
private static final int N_OVERFLOW = 10;
Expand All @@ -51,7 +50,7 @@ public void testStringUTF16ToBytes() throws ClassNotFoundException {
Class<?> javaclass = Class.forName("java.lang.StringUTF16");

ResolvedJavaMethod caller = getResolvedJavaMethod(javaclass, "toBytes", char[].class, int.class, int.class);
StructuredGraph graph = getReplacements().getIntrinsicGraph(caller, CompilationIdentifier.INVALID_COMPILATION_ID, getDebugContext(), AllowAssumptions.YES, null);
StructuredGraph graph = getIntrinsicGraph(caller, CompilationIdentifier.INVALID_COMPILATION_ID, getDebugContext(), AllowAssumptions.YES, null);
assertInGraph(graph, NewArrayNode.class);
assertInGraph(graph, ArrayCopyCallNode.class);

Expand Down Expand Up @@ -82,7 +81,7 @@ public void testStringUTF16getChars() throws ClassNotFoundException {
Class<?> javaclass = Class.forName("java.lang.StringUTF16");

ResolvedJavaMethod caller = getResolvedJavaMethod(javaclass, "getChars", byte[].class, int.class, int.class, char[].class, int.class);
StructuredGraph graph = getReplacements().getIntrinsicGraph(caller, CompilationIdentifier.INVALID_COMPILATION_ID, getDebugContext(), AllowAssumptions.YES, null);
StructuredGraph graph = getIntrinsicGraph(caller, CompilationIdentifier.INVALID_COMPILATION_ID, getDebugContext(), AllowAssumptions.YES, null);
assertInGraph(graph, ArrayCopyCallNode.class);

InstalledCode code = getCode(caller, graph);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import org.graalvm.collections.EconomicMap;
import org.graalvm.compiler.api.test.Graal;
import org.graalvm.compiler.core.test.GraalCompilerTest;
import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.compiler.debug.GraalError;
import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
Expand All @@ -52,7 +51,7 @@
/**
* Exercise the compilation of intrinsic method substitutions.
*/
public class TestIntrinsicCompiles extends GraalCompilerTest {
public class TestIntrinsicCompiles extends HotSpotGraalCompilerTest {

@Test
@SuppressWarnings("try")
Expand All @@ -73,7 +72,7 @@ public void test() throws ClassNotFoundException {
ResolvedJavaMethod method = CheckGraalIntrinsics.resolveIntrinsic(getMetaAccess(), intrinsic);
if (!method.isNative()) {
try {
StructuredGraph graph = providers.getReplacements().getIntrinsicGraph(method, INVALID_COMPILATION_ID, debug, AllowAssumptions.YES, null);
StructuredGraph graph = getIntrinsicGraph(method, INVALID_COMPILATION_ID, debug, AllowAssumptions.YES, null);
if (graph != null) {
boolean canCompile = true;
for (ForeignCallNode foreignCall : graph.getNodes().filter(ForeignCallNode.class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.Collections;

import org.graalvm.compiler.core.common.CompilationIdentifier;
import org.graalvm.compiler.core.test.GraalCompilerTest;
import org.graalvm.compiler.hotspot.test.HotSpotGraalCompilerTest;
import org.graalvm.compiler.nodes.StructuredGraph;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.test.AddExports;
Expand All @@ -36,7 +36,7 @@
import jdk.vm.ci.meta.ResolvedJavaMethod;

@AddExports("java.base/java.lang")
public class CountPositivesTest extends GraalCompilerTest {
public class CountPositivesTest extends HotSpotGraalCompilerTest {

protected final String[] testData = new String[]{
"A", "\uFF21", "AB", "A", "a", "Ab", "AA", "\uFF21",
Expand Down Expand Up @@ -91,7 +91,7 @@ public void testStringCoding() throws ClassNotFoundException {

@Override
protected StructuredGraph parseForCompile(ResolvedJavaMethod method, CompilationIdentifier compilationId, OptionValues options) {
StructuredGraph graph = getReplacements().getIntrinsicGraph(method, CompilationIdentifier.INVALID_COMPILATION_ID, getDebugContext(), StructuredGraph.AllowAssumptions.YES, null);
StructuredGraph graph = getIntrinsicGraph(method, CompilationIdentifier.INVALID_COMPILATION_ID, getDebugContext(), StructuredGraph.AllowAssumptions.YES, null);
if (graph != null) {
return graph;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
package org.graalvm.compiler.replacements.test;

import org.graalvm.compiler.core.common.CompilationIdentifier;
import org.graalvm.compiler.core.test.GraalCompilerTest;
import org.graalvm.compiler.hotspot.test.HotSpotGraalCompilerTest;
import org.graalvm.compiler.nodes.StructuredGraph;
import org.graalvm.compiler.test.AddExports;
import org.junit.Test;
Expand All @@ -34,7 +34,7 @@
import jdk.vm.ci.meta.ResolvedJavaMethod;

@AddExports({"java.base/java.lang", "java.base/sun.nio.cs"})
public class EncodeArrayTest extends GraalCompilerTest {
public class EncodeArrayTest extends HotSpotGraalCompilerTest {

protected final String[] testData = new String[]{
"A", "\uFF21", "AB", "A", "a", "Ab", "AA", "\uFF21",
Expand Down Expand Up @@ -68,7 +68,7 @@ private static Result executeCompiledMethod(InstalledCode compiledMethod, Object
public void testStringCodingISO() throws ClassNotFoundException {
Class<?> klass = Class.forName("java.lang.StringCoding");
ResolvedJavaMethod method = getResolvedJavaMethod(klass, "implEncodeISOArray");
StructuredGraph graph = getReplacements().getIntrinsicGraph(method, CompilationIdentifier.INVALID_COMPILATION_ID, getDebugContext(), StructuredGraph.AllowAssumptions.YES, null);
StructuredGraph graph = getIntrinsicGraph(method, CompilationIdentifier.INVALID_COMPILATION_ID, getDebugContext(), StructuredGraph.AllowAssumptions.YES, null);
InstalledCode compiledMethod = getCode(method, graph);

// Caller of the tested method should guarantee the indexes are within the range -- there is
Expand Down Expand Up @@ -101,7 +101,7 @@ public void testStringCodingISO() throws ClassNotFoundException {
public void testStringCodingAscii() throws ClassNotFoundException {
Class<?> klass = Class.forName("java.lang.StringCoding");
ResolvedJavaMethod method = getResolvedJavaMethod(klass, "implEncodeAsciiArray");
StructuredGraph graph = getReplacements().getIntrinsicGraph(method, CompilationIdentifier.INVALID_COMPILATION_ID, getDebugContext(), StructuredGraph.AllowAssumptions.YES, null);
StructuredGraph graph = getIntrinsicGraph(method, CompilationIdentifier.INVALID_COMPILATION_ID, getDebugContext(), StructuredGraph.AllowAssumptions.YES, null);
InstalledCode compiledMethod = getCode(method, graph);

// Caller of the tested method should guarantee the indexes are within the range --
Expand Down Expand Up @@ -134,7 +134,7 @@ public void testStringCodingAscii() throws ClassNotFoundException {
public void testISOEncoding() throws ClassNotFoundException {
Class<?> klass = Class.forName("sun.nio.cs.ISO_8859_1$Encoder");
ResolvedJavaMethod method = getResolvedJavaMethod(klass, "implEncodeISOArray");
StructuredGraph graph = getReplacements().getIntrinsicGraph(method, CompilationIdentifier.INVALID_COMPILATION_ID, getDebugContext(), StructuredGraph.AllowAssumptions.YES, null);
StructuredGraph graph = getIntrinsicGraph(method, CompilationIdentifier.INVALID_COMPILATION_ID, getDebugContext(), StructuredGraph.AllowAssumptions.YES, null);
InstalledCode compiledMethod = getCode(method, graph);

// Caller of the tested method should guarantee the indexes are within the range -- there is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
package org.graalvm.compiler.replacements.test;

import org.graalvm.compiler.core.common.CompilationIdentifier;
import org.graalvm.compiler.core.test.GraalCompilerTest;
import org.graalvm.compiler.hotspot.test.HotSpotGraalCompilerTest;
import org.graalvm.compiler.nodes.StructuredGraph;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.test.AddExports;
Expand All @@ -34,7 +34,7 @@
import jdk.vm.ci.meta.ResolvedJavaMethod;

@AddExports("java.base/java.lang")
public class HasNegativesTest extends GraalCompilerTest {
public class HasNegativesTest extends HotSpotGraalCompilerTest {

protected final String[] testData = new String[]{
"A", "\uFF21", "AB", "A", "a", "Ab", "AA", "\uFF21",
Expand Down Expand Up @@ -72,7 +72,7 @@ public void testStringCoding() throws ClassNotFoundException {

@Override
protected StructuredGraph parseForCompile(ResolvedJavaMethod method, CompilationIdentifier compilationId, OptionValues options) {
StructuredGraph graph = getReplacements().getIntrinsicGraph(method, CompilationIdentifier.INVALID_COMPILATION_ID, getDebugContext(), StructuredGraph.AllowAssumptions.YES, null);
StructuredGraph graph = getIntrinsicGraph(method, CompilationIdentifier.INVALID_COMPILATION_ID, getDebugContext(), StructuredGraph.AllowAssumptions.YES, null);
if (graph != null) {
return graph;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
*/
package org.graalvm.compiler.replacements.test;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;

import org.graalvm.compiler.core.test.GraalCompilerTest;
import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.compiler.graph.Node;
Expand All @@ -41,7 +38,6 @@
import org.graalvm.compiler.replacements.nodes.MacroNode;

import jdk.vm.ci.code.InstalledCode;
import jdk.vm.ci.code.InvalidInstalledCodeException;
import jdk.vm.ci.meta.ResolvedJavaMethod;

/**
Expand Down Expand Up @@ -126,15 +122,6 @@ protected StructuredGraph testGraph(final ResolvedJavaMethod method, String name
}
}

protected static StructuredGraph assertNotInGraph(StructuredGraph graph, Class<?> clazz) {
for (Node node : graph.getNodes()) {
if (clazz.isInstance(node)) {
fail(String.format("found unexpected instance of %s in %s: %s", clazz, graph, node.toString()));
}
}
return graph;
}

protected void testSubstitution(String testMethodName, Class<?> intrinsicClass, Class<?> holder, String methodName, Class<?>[] parameterTypes, boolean optional, boolean forceCompilation,
Object[] args1, Object[] args2) {
ResolvedJavaMethod realMethod = getResolvedJavaMethod(holder, methodName, parameterTypes);
Expand Down Expand Up @@ -162,37 +149,4 @@ protected void testSubstitution(String testMethodName, Class<?> intrinsicClass,
}
}

protected static StructuredGraph assertInGraph(StructuredGraph graph, Class<?>... clazzes) {
for (Node node : graph.getNodes()) {
for (Class<?> clazz : clazzes) {
if (clazz.isInstance(node)) {
return graph;
}
}
}
if (clazzes.length == 1) {
fail("Graph does not contain a node of class " + clazzes[0].getName());
} else {
fail("Graph does not contain a node of one these classes class " + Arrays.toString(clazzes));

}
return graph;
}

protected static Object executeVarargsSafe(InstalledCode code, Object... args) {
try {
return code.executeVarargs(args);
} catch (InvalidInstalledCodeException e) {
throw new RuntimeException(e);
}
}

protected Object invokeSafe(ResolvedJavaMethod method, Object receiver, Object... args) {
try {
return invoke(method, receiver, args);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException e) {
throw new RuntimeException(e);
}
}

}
Loading

0 comments on commit fbb0987

Please sign in to comment.