Skip to content

[JDK-8359814] Adapt JDK-8351268: [JVMCI] Enhance JVMCI by leveraging modern Java features #11452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: galahad
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import jdk.graal.compiler.debug.GlobalMetrics;
Expand Down Expand Up @@ -234,7 +235,7 @@ private static long hashConstantOopFields(JNIEnv jniEnv,
JVMCIBackend backend = runtime.getHostJVMCIBackend();
ConstantReflectionProvider constantReflection = backend.getConstantReflection();
HotSpotResolvedJavaType type = runtime.unhand(HotSpotResolvedJavaType.class, typeHandle);
ResolvedJavaField[] staticFields = type.getStaticFields();
List<? extends ResolvedJavaField> staticFields = type.getStaticFields();
JavaConstant receiver = null;
long hash = 13;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.graalvm.nativeimage.c.type.CCharPointer;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;

Expand Down Expand Up @@ -156,10 +157,10 @@ public boolean isValueType(ResolvedJavaType type) {
public ConstantFieldInfo getConstantFieldInfo(ResolvedJavaField field) {
ResolvedJavaType enclosingType = field.getDeclaringClass();
boolean isStatic = field.isStatic();
ResolvedJavaField[] declaredFields = isStatic ? enclosingType.getStaticFields() : enclosingType.getInstanceFields(false);
List<? extends ResolvedJavaField> declaredFields = isStatic ? enclosingType.getStaticFields() : enclosingType.getInstanceFields(false);
int fieldIndex = -1;
for (int i = 0; i < declaredFields.length; i++) {
if (field.equals(declaredFields[i])) {
for (int i = 0; i < declaredFields.size(); i++) {
if (field.equals(declaredFields.get(i))) {
fieldIndex = i;
break;
}
Expand All @@ -170,7 +171,7 @@ public ConstantFieldInfo getConstantFieldInfo(ResolvedJavaField field) {
isStatic ? "Static" : "Instance",
field,
enclosingType,
Arrays.toString(declaredFields)));
declaredFields));
}
long typeHandle = HotSpotJVMCIRuntime.runtime().translate(enclosingType);
int rawValue = HSTruffleCompilerRuntimeGen.callGetConstantFieldInfo(calls, env(), getHandle(), typeHandle, isStatic, fieldIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import jdk.graal.compiler.phases.tiers.HighTierContext;
import jdk.vm.ci.meta.JavaKind;

import java.util.List;

public class KillWithUnusedFloatingInputsBenchmark extends GraalBenchmark {

@Benchmark
Expand Down Expand Up @@ -152,7 +154,7 @@ private void modifyGraph(StructuredGraph g) {
}

for (int j = 0; j < sizeParam; j++) {
FrameState fs = fb.create(1, null, false, kinds, vals);
FrameState fs = fb.create(1, null, false, List.of(kinds), vals);
g.addOrUnique(fs);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ private void disassembleClasses(List<Class<?>> classes) {
BytecodeDisassembler disassembler = new BytecodeDisassembler(multiline, newLine, format, f);

ResolvedJavaType type = getMetaAccess().lookupJavaType(c);
ResolvedJavaMethod[] methods = type.getDeclaredMethods();
for (ResolvedJavaMethod m : methods) {
for (ResolvedJavaMethod m : type.getDeclaredMethods()) {
int codeSize = m.getCodeSize();
String dis = disassembler.disassemble(m);
if (codeSize <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ public static void runTest(InvariantsTool tool) {
ResolvedJavaType type = metaAccess.lookupJavaType(c);
List<ResolvedJavaMethod> methods = new ArrayList<>();
try {
methods.addAll(Arrays.asList(type.getDeclaredMethods(false)));
methods.addAll(Arrays.asList(type.getDeclaredConstructors(false)));
methods.addAll(type.getDeclaredMethods(false));
methods.addAll(type.getDeclaredConstructors(false));
} catch (Throwable e) {
errors.add(String.format("Error while checking %s:%n%s", className, printStackTraceToString(e)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,10 +918,10 @@ protected Result executeActual(OptionValues options, ResolvedJavaMethod method,
}

protected void checkArgs(ResolvedJavaMethod method, Object[] args) {
JavaType[] sig = method.toParameterTypes();
Assert.assertEquals(sig.length, args.length);
List<JavaType> sig = method.toParameterTypes();
Assert.assertEquals(sig.size(), args.length);
for (int i = 0; i < args.length; i++) {
JavaType javaType = sig[i];
JavaType javaType = sig.get(i);
JavaKind kind = javaType.getJavaKind();
Object arg = args[i];
if (kind == JavaKind.Object) {
Expand Down Expand Up @@ -1617,12 +1617,12 @@ protected void bindArguments(StructuredGraph graph, Object[] argsToBind) {
ResolvedJavaMethod m = graph.method();
Object receiver = isStatic(m.getModifiers()) ? null : this;
Object[] args = argsWithReceiver(receiver, argsToBind);
JavaType[] parameterTypes = m.toParameterTypes();
assert parameterTypes.length == args.length;
List<JavaType> parameterTypes = m.toParameterTypes();
assert parameterTypes.size() == args.length;
for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
Object arg = args[param.index()];
if (arg != NO_BIND) {
JavaConstant c = getSnippetReflection().forBoxed(parameterTypes[param.index()].getJavaKind(), arg);
JavaConstant c = getSnippetReflection().forBoxed(parameterTypes.get(param.index()).getJavaKind(), arg);
ConstantNode replacement = ConstantNode.forConstant(c, getMetaAccess(), graph);
param.replaceAtUsages(replacement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import jdk.graal.compiler.options.OptionValues;

import java.util.Collections;
import java.util.List;
import java.util.Set;

import static java.lang.reflect.Modifier.isStatic;
Expand All @@ -50,8 +51,8 @@ protected void bindArguments(StructuredGraph graph, Object[] argsToBind) {
ResolvedJavaMethod m = graph.method();
Object receiver = isStatic(m.getModifiers()) ? null : this;
Object[] args = argsWithReceiver(receiver, argsToBind);
JavaType[] parameterTypes = m.toParameterTypes();
assert parameterTypes.length == args.length;
List<JavaType> parameterTypes = m.toParameterTypes();
assert parameterTypes.size() == args.length;
for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
Object arg = args[param.index()];
if (arg == NO_BIND) {
Expand All @@ -63,7 +64,7 @@ protected void bindArguments(StructuredGraph graph, Object[] argsToBind) {
param.replaceAtUsages(replacement, n -> n != replacement);
}
} else {
JavaConstant c = getSnippetReflection().forBoxed(parameterTypes[param.index()].getJavaKind(), arg);
JavaConstant c = getSnippetReflection().forBoxed(parameterTypes.get(param.index()).getJavaKind(), arg);
ConstantNode replacement = ConstantNode.forConstant(c, getMetaAccess(), graph);
param.replaceAtUsages(replacement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,18 @@ private void testTypeProfile(String testSnippet, int bci) {
ProfilingInfo info = profile(testSnippet, "ABC");
JavaTypeProfile typeProfile = info.getTypeProfile(bci);
Assert.assertEquals(0.0, typeProfile.getNotRecordedProbability(), DELTA);
Assert.assertEquals(1, typeProfile.getTypes().length);
Assert.assertEquals(stringType, typeProfile.getTypes()[0].getType());
Assert.assertEquals(1.0, typeProfile.getTypes()[0].getProbability(), DELTA);
Assert.assertEquals(1, typeProfile.getTypes().size());
Assert.assertEquals(stringType, typeProfile.getTypes().getFirst().getType());
Assert.assertEquals(1.0, typeProfile.getTypes().getFirst().getProbability(), DELTA);

continueProfiling(testSnippet, new StringBuilder());
typeProfile = info.getTypeProfile(bci);
Assert.assertEquals(0.0, typeProfile.getNotRecordedProbability(), DELTA);
Assert.assertEquals(2, typeProfile.getTypes().length);
Assert.assertEquals(stringType, typeProfile.getTypes()[0].getType());
Assert.assertEquals(stringBuilderType, typeProfile.getTypes()[1].getType());
Assert.assertEquals(0.5, typeProfile.getTypes()[0].getProbability(), DELTA);
Assert.assertEquals(0.5, typeProfile.getTypes()[1].getProbability(), DELTA);
Assert.assertEquals(2, typeProfile.getTypes().size());
Assert.assertEquals(stringType, typeProfile.getTypes().getFirst().getType());
Assert.assertEquals(stringBuilderType, typeProfile.getTypes().get(1).getType());
Assert.assertEquals(0.5, typeProfile.getTypes().getFirst().getProbability(), DELTA);
Assert.assertEquals(0.5, typeProfile.getTypes().get(1).getProbability(), DELTA);

resetProfile(testSnippet);
typeProfile = info.getTypeProfile(bci);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.lang.reflect.MalformedParametersException;
import java.lang.reflect.Method;
import java.util.List;

import jdk.graal.compiler.graph.Node;
import jdk.graal.compiler.nodes.StructuredGraph;
Expand Down Expand Up @@ -62,13 +63,11 @@ protected void verify(StructuredGraph graph, CoreProviders context) {
boolean hasTool = false;
try {
ResolvedJavaMethod method = graph.method();
Parameter[] parameters = method.getParameters();
if (parameters != null) {
for (ResolvedJavaMethod.Parameter parameter : parameters) {
if (parameter.getType().getName().equals(canonicalizerToolClass.getName())) {
hasTool = true;
break;
}
List<Parameter> parameters = method.getParameters();
for (ResolvedJavaMethod.Parameter parameter : parameters) {
if (parameter.getType().getName().equals(canonicalizerToolClass.getName())) {
hasTool = true;
break;
}
}
} catch (MalformedParametersException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.ResolvedJavaType;

import java.util.List;

/**
* Verifies that code which uses {@link Node} implementing {@link IterableNodeType} uses
* {@link StructuredGraph#getNodes(NodeClass)} and not {@linkplain NodeIterable#filter(Class)} to
Expand All @@ -63,18 +65,17 @@ protected void verify(StructuredGraph graph, CoreProviders context) {
if (receiver instanceof Invoke) {
CallTargetNode receiverCallTarget = ((Invoke) receiver).callTarget();
ResolvedJavaMethod receiverMethod = receiverCallTarget.targetMethod();
if (receiverMethod.getDeclaringClass().equals(graphType) && receiverMethod.getName().equals("getNodes") && receiverMethod.getParameters().length == 0) {
if (receiverMethod.getDeclaringClass().equals(graphType) && receiverMethod.getName().equals("getNodes") && receiverMethod.getParameters().isEmpty()) {
ResolvedJavaMethod callee = t.targetMethod();
if (callee.getDeclaringClass().equals(nodeIterableType)) {
if (callee.getName().equals("filter")) {
ResolvedJavaMethod.Parameter[] params = callee.getParameters();
if (params.length == 1 && params[0].getType().equals(classType)) {
List<ResolvedJavaMethod.Parameter> params = callee.getParameters();
if (params.size() == 1 && params.getFirst().getType().equals(classType)) {
// call to filter
ValueNode v = t.arguments().get(1);
ResolvedJavaType javaType = v.stamp(NodeView.DEFAULT).javaType(metaAccess);
assert classType.isAssignableFrom(javaType) : "Need to have a class type parameter.";
if (v instanceof ConstantNode) {
ConstantNode c = (ConstantNode) v;
if (v instanceof ConstantNode c) {
javaType = context.getConstantReflection().asJavaType(c.asConstant());
if (iterableNodeType.isAssignableFrom(javaType)) {
throw new VerificationError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected void verify(StructuredGraph graph, CoreProviders context) {
}
}
}
boolean[] specialParameters = new boolean[method.getParameters().length];
boolean[] specialParameters = new boolean[method.getParameters().size()];
Annotation[][] parameterAnnotations = graph.method().getParameterAnnotations();
for (int i = 0; i < parameterAnnotations.length; i++) {
for (Annotation a : parameterAnnotations[i]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected void verify(StructuredGraph graph, CoreProviders context) {
for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) {
ResolvedJavaMethod callee = t.targetMethod();
if (callee.getDeclaringClass().equals(stringType)) {
if (callee.getParameters().length > 0) {
if (!callee.getParameters().isEmpty()) {
continue;
}
String calleeName = callee.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package jdk.graal.compiler.core.test.ea;

import java.nio.ByteBuffer;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -60,8 +61,8 @@ protected void testEscapeAnalysis(String snippet, JavaConstant expectedConstantR
// Check that a compiled version of this method returns the same value if we expect a
// constant result.
ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
JavaKind[] javaKinds = method.getSignature().toParameterKinds(false);
Object[] args = new Object[javaKinds.length];
List<JavaKind> javaKinds = method.getSignature().toParameterKinds(false);
Object[] args = new Object[javaKinds.size()];
int i = 0;
for (JavaKind k : javaKinds) {
args[i++] = JavaConstant.defaultForKind(k).asBoxedPrimitive();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import jdk.vm.ci.meta.JavaType;
import jdk.vm.ci.meta.ResolvedJavaMethod;

import java.util.List;

public class InstalledCodeExecuteHelperTest extends GraalCompilerTest {

private static final int ITERATIONS = 100000;
Expand Down Expand Up @@ -84,11 +86,11 @@ protected StructuredGraph parse(Builder builder, PhaseSuite<HighTierContext> gra
ResolvedJavaMethod m = graph.method();
Object receiver = isStatic(m.getModifiers()) ? null : this;
Object[] args = argsWithReceiver(receiver, argsToBind);
JavaType[] parameterTypes = m.toParameterTypes();
assert parameterTypes.length == args.length;
List<JavaType> parameterTypes = m.toParameterTypes();
assert parameterTypes.size() == args.length;
for (int i = 0; i < argsToBind.length; i++) {
ParameterNode param = graph.getParameter(i);
JavaConstant c = getSnippetReflection().forBoxed(parameterTypes[i].getJavaKind(), argsToBind[i]);
JavaConstant c = getSnippetReflection().forBoxed(parameterTypes.get(i).getJavaKind(), argsToBind[i]);
ConstantNode replacement = ConstantNode.forConstant(c, getMetaAccess(), graph);
param.replaceAtUsages(replacement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static java.lang.reflect.Modifier.isStatic;

Expand Down Expand Up @@ -106,12 +107,12 @@ protected StructuredGraph parse(StructuredGraph.Builder builder, PhaseSuite<High
ResolvedJavaMethod m = graph.method();
Object receiver = isStatic(m.getModifiers()) ? null : this;
Object[] args = argsWithReceiver(receiver, argsToBind);
JavaType[] parameterTypes = m.toParameterTypes();
assert parameterTypes.length == args.length;
List<JavaType> parameterTypes = m.toParameterTypes();
assert parameterTypes.size() == args.length;
for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
int index = param.index();
if (args[index] != null) {
JavaConstant c = getSnippetReflection().forBoxed(parameterTypes[index].getJavaKind(), args[index]);
JavaConstant c = getSnippetReflection().forBoxed(parameterTypes.get(index).getJavaKind(), args[index]);
ConstantNode replacement = ConstantNode.forConstant(c, getMetaAccess(), graph);
param.replaceAtUsages(replacement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.List;

import org.junit.Assert;

Expand Down Expand Up @@ -104,12 +105,12 @@ protected void testWithNativeExcept(ResolvedJavaMethod method, Object receiver,
ByteBuffer[] byteBuffers = new ByteBuffer[2];
int nByteBuffers = 0;
try {
ResolvedJavaMethod.Parameter[] parameters = method.getParameters();
Assert.assertTrue(parameters.length <= 64);
for (int i = 0; i < parameters.length; i++) {
if (parameters[i].getType().getName().equals("[B") && (ignore & (1L << i)) == 0) {
List<ResolvedJavaMethod.Parameter> parameters = method.getParameters();
Assert.assertTrue(parameters.size() <= 64);
for (int i = 0; i < parameters.size(); i++) {
if (parameters.get(i).getType().getName().equals("[B") && (ignore & (1L << i)) == 0) {
Assert.assertTrue(argsWithNative[i].toString(), argsWithNative[i] instanceof byte[]);
Assert.assertEquals("J", parameters[i + 1].getType().getName());
Assert.assertEquals("J", parameters.get(i + 1).getType().getName());
byte[] array = (byte[]) argsWithNative[i];
byteBuffers[nByteBuffers] = ByteBuffer.allocateDirect(array.length);
long bufferAddress = getBufferAddress(byteBuffers[nByteBuffers++]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import jdk.vm.ci.meta.LocalVariableTable;
import jdk.vm.ci.meta.ResolvedJavaMethod;

import java.util.List;

/**
* An interface for accessing the bytecode properties of a {@link ResolvedJavaMethod} that allows
* for different properties than those returned by {@link ResolvedJavaMethod}. Since the bytecode
Expand Down Expand Up @@ -60,7 +62,7 @@ public interface Bytecode {

StackTraceElement asStackTraceElement(int bci);

ExceptionHandler[] getExceptionHandlers();
List<ExceptionHandler> getExceptionHandlers();

/**
* Gets the {@link BytecodeProvider} from which this object was acquired.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package jdk.graal.compiler.bytecode;

import java.util.List;
import java.util.Objects;

import jdk.vm.ci.meta.ConstantPool;
Expand Down Expand Up @@ -96,7 +97,7 @@ public LocalVariableTable getLocalVariableTable() {
}

@Override
public ExceptionHandler[] getExceptionHandlers() {
public List<ExceptionHandler> getExceptionHandlers() {
return method.getExceptionHandlers();
}

Expand Down
Loading
Loading