Skip to content
Merged
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 @@ -57,7 +57,7 @@ public void ensureAllGraalDirectivesIntrinsified() {
}

ResolvedJavaType directives = getMetaAccess().lookupJavaType(GraalDirectives.class);
for (ResolvedJavaMethod method : directives.getDeclaredMethods()) {
for (ResolvedJavaMethod method : directives.getDeclaredMethods(false)) {
if (method.isStatic()) {
// A method's descriptor includes the return type, which we must drop so we can
// compare to the binding strings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public static void runTest(InvariantsTool tool) {
if (errors.isEmpty()) {
// Order outer classes before the inner classes
classNames.sort((String a, String b) -> a.compareTo(b));
List<Class<?>> classes = loadClasses(tool, classNames);
List<Class<?>> classes = loadClasses(tool, metaAccess, classNames);
for (Class<?> c : classes) {
String className = c.getName();
executor.execute(() -> {
Expand All @@ -390,8 +390,8 @@ public static void runTest(InvariantsTool tool) {
ResolvedJavaType type = metaAccess.lookupJavaType(c);
List<ResolvedJavaMethod> methods = new ArrayList<>();
try {
methods.addAll(Arrays.asList(type.getDeclaredMethods()));
methods.addAll(Arrays.asList(type.getDeclaredConstructors()));
methods.addAll(Arrays.asList(type.getDeclaredMethods(false)));
methods.addAll(Arrays.asList(type.getDeclaredConstructors(false)));
} catch (Throwable e) {
errors.add(String.format("Error while checking %s:%n%s", className, printStackTraceToString(e)));
}
Expand Down Expand Up @@ -542,14 +542,22 @@ private static boolean isONNX(String className) {
return className.contains("ai.onnxruntime");
}

private static List<Class<?>> loadClasses(InvariantsTool tool, List<String> classNames) {
private static List<Class<?>> loadClasses(InvariantsTool tool, MetaAccessProvider metaAccess, List<String> classNames) {
List<Class<?>> classes = new ArrayList<>(classNames.size());
for (String className : classNames) {
if (!tool.shouldLoadClass(className)) {
continue;
}
try {
Class<?> c = Class.forName(className, false, CheckGraalInvariants.class.getClassLoader());

/*
* Ensure all types are linked eagerly, so that we can access the bytecode of all
* methods.
*/
ResolvedJavaType type = metaAccess.lookupJavaType(c);
type.link();

if (Node.class.isAssignableFrom(c)) {
/*
* Eagerly initialize Node classes because the VerifyNodeCosts checker will
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected void verify(StructuredGraph graph, CoreProviders context) {
Class<?> receiverClass = (Class<?>) KNOWN_PROFILE_INTRINSICS[i];
String methodName = (String) KNOWN_PROFILE_INTRINSICS[i + 1];
ResolvedJavaType type = context.getMetaAccess().lookupJavaType(receiverClass);
for (ResolvedJavaMethod typeMethod : type.getDeclaredMethods()) {
for (ResolvedJavaMethod typeMethod : type.getDeclaredMethods(false)) {
if (typeMethod.getName().contains(methodName)) {
knownIntrinsicMethods.add(typeMethod);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ public ResolvedJavaMethod resolve(ResolvedJavaType accessingClass) {
if (resolvedType == null) {
throw new NoClassDefFoundError("Can't resolve " + type.getName() + " with " + accessingClass.getName());
}
for (ResolvedJavaMethod method : methodName.equals("<init>") ? resolvedType.getDeclaredConstructors() : resolvedType.getDeclaredMethods()) {
for (ResolvedJavaMethod method : methodName.equals("<init>") ? resolvedType.getDeclaredConstructors(false) : resolvedType.getDeclaredMethods(false)) {
if (method.getName().equals(methodName) && method.getSignature().toMethodDescriptor().equals(signature)) {
return method;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.List;
import java.util.Objects;

import org.graalvm.compiler.debug.GraalError;

import jdk.vm.ci.meta.Assumptions;
import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.JavaKind;
Expand Down Expand Up @@ -144,6 +146,10 @@ public boolean isInitialized() {
public void initialize() {
}

@Override
public void link() {
}

@Override
public boolean isLinked() {
throw new UnsupportedOperationException();
Expand Down Expand Up @@ -294,11 +300,22 @@ public ResolvedJavaType getEnclosingType() {

@Override
public ResolvedJavaMethod[] getDeclaredConstructors() {
return getDeclaredConstructors(true);
}

@Override
public ResolvedJavaMethod[] getDeclaredConstructors(boolean forceLink) {
throw new UnsupportedOperationException();
}

@Override
public ResolvedJavaMethod[] getDeclaredMethods() {
return getDeclaredMethods(true);
}

@Override
public ResolvedJavaMethod[] getDeclaredMethods(boolean forceLink) {
GraalError.guarantee(forceLink == false, "only use getDeclaredMethods without forcing to link, because linking can throw LinkageError");
if (methods == null) {
return new ResolvedJavaMethod[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ protected final StructuredGraph getGraph(DebugContext debug, CompilationIdentifi
private ResolvedJavaMethod getGraphMethod() {
ResolvedJavaMethod thisMethod = null;
MetaAccessProvider metaAccess = providers.getMetaAccess();
for (ResolvedJavaMethod method : metaAccess.lookupJavaType(AbstractForeignCallStub.class).getDeclaredMethods()) {
for (ResolvedJavaMethod method : metaAccess.lookupJavaType(AbstractForeignCallStub.class).getDeclaredMethods(false)) {
if (method.getName().equals("getGraph")) {
if (thisMethod == null) {
thisMethod = method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private LambdaUtils() {
@SuppressWarnings("try")
public static String findStableLambdaName(ClassInitializationPlugin cip, Providers providers, ResolvedJavaType lambdaType, OptionValues options, DebugContext debug, Object ctx)
throws RuntimeException {
ResolvedJavaMethod[] lambdaProxyMethods = Arrays.stream(lambdaType.getDeclaredMethods()).filter(m -> !m.isBridge() && m.isPublic()).toArray(ResolvedJavaMethod[]::new);
ResolvedJavaMethod[] lambdaProxyMethods = Arrays.stream(lambdaType.getDeclaredMethods(false)).filter(m -> !m.isBridge() && m.isPublic()).toArray(ResolvedJavaMethod[]::new);
/*
* Take only the first method to build a graph, because the graph for all other methods will
* be the same.
Expand All @@ -125,7 +125,7 @@ public static String findStableLambdaName(ClassInitializationPlugin cip, Provide
if (invokedMethods.isEmpty()) {
StringBuilder sb = new StringBuilder();
sb.append("Lambda without a target invoke: ").append(lambdaType.toClassName());
for (ResolvedJavaMethod m : lambdaType.getDeclaredMethods()) {
for (ResolvedJavaMethod m : lambdaType.getDeclaredMethods(false)) {
sb.append("\n Method: ").append(m);
}
throw new JVMCIError(sb.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ public static Method resolveMethod(Class<?> declaringClass, InvocationPlugin plu
* {@link ResolvedJavaType} and {@link ResolvedJavaMethod}.
*/
public static ResolvedJavaMethod resolveJavaMethod(ResolvedJavaType declaringClass, InvocationPlugin plugin) {
ResolvedJavaMethod[] methods = declaringClass.getDeclaredMethods();
ResolvedJavaMethod[] methods = declaringClass.getDeclaredMethods(false);
if (plugin.name.equals("<init>")) {
for (ResolvedJavaMethod m : methods) {
if (m.getName().equals("<init>") && m.getSignature().toMethodDescriptor().startsWith(plugin.argumentsDescriptor)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public InvokeNode createInvoke(Class<?> declaringClass, String name, InvokeKind
public ResolvedJavaMethod findMethod(Class<?> declaringClass, String name, boolean isStatic) {
ResolvedJavaType type = getMetaAccess().lookupJavaType(declaringClass);
ResolvedJavaMethod method = null;
for (ResolvedJavaMethod m : type.getDeclaredMethods()) {
for (ResolvedJavaMethod m : type.getDeclaredMethods(false)) {
if (Modifier.isStatic(m.getModifiers()) == isStatic && m.getName().equals(name)) {
assert method == null : "found more than one method in " + declaringClass + " named " + name;
method = m;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,9 @@ protected AbstractTemplates(OptionValues options, Providers providers) {

public static ResolvedJavaMethod findMethod(MetaAccessProvider metaAccess, Class<?> declaringClass, String methodName) {
ResolvedJavaType type = metaAccess.lookupJavaType(declaringClass);
type.link();
ResolvedJavaMethod result = null;
for (ResolvedJavaMethod m : type.getDeclaredMethods()) {
for (ResolvedJavaMethod m : type.getDeclaredMethods(false)) {
if (m.getName().equals(methodName)) {
if (!Assertions.assertionsEnabled()) {
return m;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,14 @@ ResolvedJavaMethod lookup(ResolvedJavaType type, String name, String descriptor)
if (!name.equals("<init>")) {
if (methods == null) {
// Racy initialization is safe since `methods` is volatile
methods = createMethodMap(type.getDeclaredMethods());
methods = createMethodMap(type.getDeclaredMethods(false));
}

return methods.get(key);
} else {
if (constructors == null) {
// Racy initialization is safe since instanceFields is volatile
constructors = createMethodMap(type.getDeclaredConstructors());
constructors = createMethodMap(type.getDeclaredConstructors(false));
}
return constructors.get(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private TypeCache createTypeCache(ResolvedJavaType declaringClass) {
GraalError.guarantee(fields.size() == entries.length, "duplicate field name");

Map<String, List<ResolvedJavaMethod>> methods = new HashMap<>();
for (ResolvedJavaMethod method : declaringClass.getDeclaredMethods()) {
for (ResolvedJavaMethod method : declaringClass.getDeclaredMethods(false)) {
methods.computeIfAbsent(method.getName(), (v) -> new ArrayList<>(2)).add(method);
}
return new TypeCache(declaringClass, instanceFields, fields, methods);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ protected void appendParsingNodePlugins(Plugins plugins) {
if (JavaVersionUtil.JAVA_SPEC >= 16 && JavaVersionUtil.JAVA_SPEC < 19) {
ResolvedJavaType memorySegmentProxyType = TruffleCompilerEnvironment.get().runtime().resolveType(config.lastTier().providers().getMetaAccess(),
"jdk.internal.access.foreign.MemorySegmentProxy");
for (ResolvedJavaMethod m : memorySegmentProxyType.getDeclaredMethods()) {
for (ResolvedJavaMethod m : memorySegmentProxyType.getDeclaredMethods(false)) {
if (m.getName().equals("scope")) {
appendMemorySegmentScopePlugin(plugins, m);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ public boolean bypassedReservedOop(boolean waitForInit) {

private static void installCallBoundaryMethods(HotSpotTruffleCompiler compiler) {
ResolvedJavaType type = getMetaAccess().lookupJavaType(OptimizedCallTarget.class);
for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
for (ResolvedJavaMethod method : type.getDeclaredMethods(false)) {
if (method.getAnnotation(TruffleCallBoundary.class) != null) {
if (compiler != null) {
compiler.installTruffleCallBoundaryMethod(method);
Expand All @@ -539,7 +539,7 @@ private static void installCallBoundaryMethods(HotSpotTruffleCompiler compiler)

private static void installReservedOopMethods(HotSpotTruffleCompiler compiler) {
ResolvedJavaType local = getMetaAccess().lookupJavaType(HotSpotFastThreadLocal.class);
for (ResolvedJavaMethod method : local.getDeclaredMethods()) {
for (ResolvedJavaMethod method : local.getDeclaredMethods(false)) {
String name = method.getName();
switch (name) {
case "set":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1210,18 +1210,30 @@ public AnalysisType getEnclosingType() {
}

@Override
public AnalysisMethod[] getDeclaredConstructors() {
return universe.lookup(wrapped.getDeclaredConstructors());
public ResolvedJavaMethod[] getDeclaredMethods() {
return getDeclaredMethods(true);
}

@Override
public AnalysisMethod[] getDeclaredMethods() {
return universe.lookup(wrapped.getDeclaredMethods());
public AnalysisMethod[] getDeclaredMethods(boolean forceLink) {
GraalError.guarantee(forceLink == false, "only use getDeclaredMethods without forcing to link, because linking can throw LinkageError");
return universe.lookup(wrapped.getDeclaredMethods(forceLink));
}

@Override
public ResolvedJavaMethod[] getDeclaredConstructors() {
return getDeclaredConstructors(true);
}

@Override
public AnalysisMethod[] getDeclaredConstructors(boolean forceLink) {
GraalError.guarantee(forceLink == false, "only use getDeclaredConstructors without forcing to link, because linking can throw LinkageError");
return universe.lookup(wrapped.getDeclaredConstructors(forceLink));
}

@Override
public AnalysisMethod findMethod(String name, Signature signature) {
for (AnalysisMethod method : getDeclaredMethods()) {
for (AnalysisMethod method : getDeclaredMethods(false)) {
if (method.getName().equals(name) && method.getSignature().equals(signature)) {
return method;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public final class IsolateEnterStub {
public static ConstantPool getConstantPool(MetaAccessProvider metaAccess) {
// Generated call wrappers need a valid constant pool, so we provide that of our constructor
return metaAccess.lookupJavaType(IsolateEnterStub.class).getDeclaredConstructors()[0].getConstantPool();
return metaAccess.lookupJavaType(IsolateEnterStub.class).getDeclaredConstructors(false)[0].getConstantPool();
}

private IsolateEnterStub() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public final class JNIJavaCallVariantWrapperHolder {
* constructor.
*/
public static ConstantPool getConstantPool(MetaAccessProvider metaAccess) {
return metaAccess.lookupJavaType(JNIJavaCallVariantWrapperHolder.class).getDeclaredConstructors()[0].getConstantPool();
return metaAccess.lookupJavaType(JNIJavaCallVariantWrapperHolder.class).getDeclaredConstructors(false)[0].getConstantPool();
}

private JNIJavaCallVariantWrapperHolder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class JNIJavaCallWrapperHolder {
public static ConstantPool getConstantPool(MetaAccessProvider metaAccess) {
// Each generated call wrapper needs an actual constant pool, so we provide our
// private constructor's
return metaAccess.lookupJavaType(JNIJavaCallWrapperHolder.class).getDeclaredConstructors()[0].getConstantPool();
return metaAccess.lookupJavaType(JNIJavaCallWrapperHolder.class).getDeclaredConstructors(false)[0].getConstantPool();
}

private JNIJavaCallWrapperHolder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,21 @@ public ResolvedJavaType getEnclosingType() {

@Override
public ResolvedJavaMethod[] getDeclaredConstructors() {
return getDeclaredConstructors(true);
}

@Override
public ResolvedJavaMethod[] getDeclaredConstructors(boolean forceLink) {
throw VMError.intentionallyUnimplemented(); // ExcludeFromJacocoGeneratedReport
}

@Override
public ResolvedJavaMethod[] getDeclaredMethods() {
return getDeclaredMethods(true);
}

@Override
public ResolvedJavaMethod[] getDeclaredMethods(boolean forceLink) {
throw VMError.intentionallyUnimplemented(); // ExcludeFromJacocoGeneratedReport
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private static String toCIntegerType(ResolvedJavaType type, boolean isUnsigned)
private static boolean isFunctionPointer(MetaAccessProvider metaAccess, ResolvedJavaType type) {
boolean functionPointer = metaAccess.lookupJavaType(CFunctionPointer.class).isAssignableFrom(type);
return functionPointer &&
Arrays.stream(type.getDeclaredMethods()).anyMatch(v -> v.getDeclaredAnnotation(InvokeCFunctionPointer.class) != null);
Arrays.stream(type.getDeclaredMethods(false)).anyMatch(v -> v.getDeclaredAnnotation(InvokeCFunctionPointer.class) != null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private void createCPointerToInfo(ResolvedJavaType type) {
}
List<AccessorInfo> accessorInfos = new ArrayList<>();

for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
for (ResolvedJavaMethod method : type.getDeclaredMethods(false)) {
AccessorKind accessorKind = returnsDeclaringClass(method) ? AccessorKind.ADDRESS : getAccessorKind(method);
boolean isIndexed = getParameterCount(method) > (accessorKind == AccessorKind.SETTER ? 1 : 0);
AccessorInfo accessorInfo = new AccessorInfo(method, accessorKind, isIndexed, false, false);
Expand All @@ -180,7 +180,7 @@ private void createRawPointerToInfo(ResolvedJavaType type) {
}
List<AccessorInfo> accessorInfos = new ArrayList<>();

for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
for (ResolvedJavaMethod method : type.getDeclaredMethods(false)) {
AccessorKind accessorKind = returnsDeclaringClass(method) ? AccessorKind.ADDRESS : getAccessorKind(method);
boolean isIndexed = getParameterCount(method) > (accessorKind == AccessorKind.SETTER ? 1 : 0);
AccessorInfo accessorInfo = new AccessorInfo(method, accessorKind, isIndexed, false, false);
Expand Down Expand Up @@ -223,7 +223,7 @@ private void createStructInfo(ResolvedJavaType type) {
Map<String, List<AccessorInfo>> bitfieldAccessorInfos = new TreeMap<>();
List<AccessorInfo> structAccessorInfos = new ArrayList<>();

for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
for (ResolvedJavaMethod method : type.getDeclaredMethods(false)) {
final AccessorInfo accessorInfo;
final String fieldName;

Expand Down Expand Up @@ -298,7 +298,7 @@ private void createRawStructInfo(ResolvedJavaType type) {
Map<String, List<AccessorInfo>> fieldAccessorInfos = new TreeMap<>();
List<AccessorInfo> structAccessorInfos = new ArrayList<>();

for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
for (ResolvedJavaMethod method : type.getDeclaredMethods(false)) {
final AccessorInfo accessorInfo;
final String fieldName;

Expand Down Expand Up @@ -681,7 +681,7 @@ private void createEnumInfo(ResolvedJavaType type) {
createEnumConstantInfo(enumInfo, field);
}
}
for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
for (ResolvedJavaMethod method : type.getDeclaredMethods(false)) {
if (getMethodAnnotation(method, CEnumValue.class) != null) {
createEnumValueInfo(enumInfo, method);
}
Expand Down
Loading