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 @@ -56,7 +56,6 @@
import com.oracle.graal.pointsto.flow.OffsetLoadTypeFlow.AbstractUnsafeLoadTypeFlow;
import com.oracle.graal.pointsto.flow.OffsetStoreTypeFlow.AbstractUnsafeStoreTypeFlow;
import com.oracle.graal.pointsto.flow.TypeFlow;
import com.oracle.graal.pointsto.infrastructure.WrappedSignature;
import com.oracle.graal.pointsto.meta.AnalysisField;
import com.oracle.graal.pointsto.meta.AnalysisMetaAccess;
import com.oracle.graal.pointsto.meta.AnalysisMethod;
Expand Down Expand Up @@ -88,6 +87,7 @@
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.JavaType;
import jdk.vm.ci.meta.ResolvedJavaField;
import jdk.vm.ci.meta.Signature;

public abstract class PointsToAnalysis extends AbstractAnalysisEngine {
/** The type of {@link java.lang.Object}. */
Expand Down Expand Up @@ -323,7 +323,7 @@ public AnalysisMethod addRootMethod(AnalysisMethod aMethod, boolean invokeSpecia
AnalysisError.guarantee(aMethod.isOriginalMethod());
AnalysisType declaringClass = aMethod.getDeclaringClass();
boolean isStatic = aMethod.isStatic();
WrappedSignature signature = aMethod.getSignature();
Signature signature = aMethod.getSignature();
int paramCount = signature.getParameterCount(!isStatic);
PointsToAnalysisMethod originalPTAMethod = assertPointsToAnalysisMethod(aMethod);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.graal.pointsto.infrastructure;

import java.lang.invoke.MethodType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.MetaAccessProvider;
import jdk.vm.ci.meta.ResolvedJavaType;
import jdk.vm.ci.meta.Signature;

/**
* A straightforward implementation of {@link Signature} where all parameter types and the return
* type are {@link ResolvedJavaType}. The generic type allows to further improve type safety of
* usages.
*
* In a regular {@link Signature}, looking up a
* {@link Signature#getParameterType(int, ResolvedJavaType) parameter type} or the
* {@link Signature#getReturnType(ResolvedJavaType) return type} requires to provide the "accessing
* class" for type resolution. Since in this implementation all types are always pre-resolved, these
* parameters are ignored. In addition, methods are offered that allow parameter type and return
* type lookup without providing the accessing class.
*/
public final class ResolvedSignature<T extends ResolvedJavaType> implements Signature {

public static <T extends ResolvedJavaType> ResolvedSignature<T> fromArray(T[] parameterTypes, T returnType) {
return new ResolvedSignature<>(List.of(parameterTypes), returnType);
}

public static <T extends ResolvedJavaType> ResolvedSignature<T> fromList(List<T> parameterTypes, T returnType) {
return new ResolvedSignature<>(List.copyOf(parameterTypes), returnType);
}

public static ResolvedSignature<ResolvedJavaType> fromKinds(JavaKind[] parameterKinds, JavaKind returnKind, MetaAccessProvider metaAccess) {
return new ResolvedSignature<>(
Arrays.stream(parameterKinds).map(kind -> resolveType(kind, metaAccess)).collect(Collectors.toUnmodifiableList()),
resolveType(returnKind, metaAccess));
}

private static ResolvedJavaType resolveType(JavaKind kind, MetaAccessProvider metaAccess) {
return metaAccess.lookupJavaType(kind.isObject() ? Object.class : kind.toJavaClass());
}

public static ResolvedSignature<ResolvedJavaType> fromMethodType(MethodType mt, MetaAccessProvider metaAccess) {
return new ResolvedSignature<>(
Arrays.stream(mt.parameterArray()).map(metaAccess::lookupJavaType).collect(Collectors.toUnmodifiableList()),
metaAccess.lookupJavaType(mt.returnType()));
}

private final List<T> parameterTypes;
private final T returnType;

private ResolvedSignature(List<T> parameterTypes, T returnType) {
/*
* All factory methods must pass in an immutable list for the parameter types, so that the
* list can be safely passes out again as the parameter list. Unfortunately, there is no way
* to assert that here.
*/
this.parameterTypes = parameterTypes;
this.returnType = returnType;
}

@Override
public int getParameterCount(boolean withReceiver) {
return parameterTypes.size() + (withReceiver ? 1 : 0);
}

@Override
public T getParameterType(int index, ResolvedJavaType accessingClass) {
return getParameterType(index);
}

public T getParameterType(int index) {
return parameterTypes.get(index);
}

@Override
public T getReturnType(ResolvedJavaType accessingClass) {
return getReturnType();
}

public T getReturnType() {
return returnType;
}

/**
* A type-safe version of {@link Signature#toParameterTypes}.
*
* @return An unmodifiable list with all parameter types, including the receiverType if it is
* non-null.
*/
public List<T> toParameterList(T receiverType) {
if (receiverType == null) {
/* parameterTypes is always an unmodifiable list, so we can return it directly. */
return parameterTypes;
}
List<T> withReceiver = new ArrayList<>(parameterTypes.size() + 1);
withReceiver.add(receiverType);
withReceiver.addAll(parameterTypes);
return Collections.unmodifiableList(withReceiver);
}

@Override
public boolean equals(Object obj) {
return this == obj || (obj instanceof ResolvedSignature<?> other && Objects.equals(parameterTypes, other.parameterTypes) && Objects.equals(returnType, other.returnType));
}

@Override
public int hashCode() {
return Objects.hash(parameterTypes, returnType);
}

@Override
public String toString() {
return toMethodDescriptor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
*/
package com.oracle.graal.pointsto.infrastructure;

import jdk.graal.compiler.api.replacements.SnippetReflectionProvider;

import com.oracle.graal.pointsto.api.HostVM;
import com.oracle.graal.pointsto.heap.ImageHeap;
import com.oracle.graal.pointsto.heap.ImageHeapConstant;

import jdk.graal.compiler.api.replacements.SnippetReflectionProvider;
import jdk.vm.ci.meta.ConstantPool;
import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.JavaField;
Expand Down Expand Up @@ -58,7 +57,7 @@ public interface Universe {

JavaMethod lookupAllowUnresolved(JavaMethod method);

WrappedSignature lookup(Signature signature, ResolvedJavaType defaultAccessingClass);
ResolvedSignature<?> lookup(Signature signature, ResolvedJavaType defaultAccessingClass);

WrappedConstantPool lookup(ConstantPool constantPool, ResolvedJavaType defaultAccessingClass);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@
import java.util.List;
import java.util.stream.Collectors;

import jdk.graal.compiler.core.common.BootstrapMethodIntrospection;
import jdk.graal.compiler.debug.GraalError;
import jdk.graal.compiler.serviceprovider.GraalServices;

import com.oracle.graal.pointsto.constraints.UnresolvedElementException;
import com.oracle.svm.util.ReflectionUtil;

import jdk.graal.compiler.core.common.BootstrapMethodIntrospection;
import jdk.graal.compiler.debug.GraalError;
import jdk.graal.compiler.serviceprovider.GraalServices;
import jdk.vm.ci.meta.ConstantPool;
import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.JavaField;
Expand Down Expand Up @@ -153,7 +152,7 @@ public JavaType lookupType(int cpi, int opcode) {
}

@Override
public WrappedSignature lookupSignature(int cpi) {
public ResolvedSignature<?> lookupSignature(int cpi) {
return universe.lookup(wrapped.lookupSignature(cpi), defaultAccessingClass);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
import com.oracle.graal.pointsto.flow.AnalysisParsedGraph;
import com.oracle.graal.pointsto.infrastructure.GraphProvider;
import com.oracle.graal.pointsto.infrastructure.OriginalMethodProvider;
import com.oracle.graal.pointsto.infrastructure.ResolvedSignature;
import com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod;
import com.oracle.graal.pointsto.infrastructure.WrappedSignature;
import com.oracle.graal.pointsto.reports.ReportUtils;
import com.oracle.graal.pointsto.util.AnalysisError;
import com.oracle.graal.pointsto.util.AtomicUtils;
Expand Down Expand Up @@ -119,6 +119,7 @@ public record Signature(String name, AnalysisType[] parameterTypes) {
private final String qualifiedName;

protected final AnalysisType declaringClass;
protected final ResolvedSignature<AnalysisType> signature;
private final int parsingContextMaxDepth;

private final MultiMethodKey multiMethodKey;
Expand Down Expand Up @@ -181,6 +182,7 @@ protected AnalysisMethod(AnalysisUniverse universe, ResolvedJavaMethod wrapped,
id = universe.nextMethodId.getAndIncrement();

declaringClass = universe.lookup(wrapped.getDeclaringClass());
signature = getUniverse().lookup(wrapped.getSignature(), wrapped.getDeclaringClass());
hasNeverInlineDirective = universe.hostVM().hasNeverInlineDirective(wrapped);

name = createName(wrapped, multiMethodKey);
Expand Down Expand Up @@ -228,6 +230,7 @@ protected AnalysisMethod(AnalysisMethod original, MultiMethodKey multiMethodKey)
wrapped = original.wrapped;
id = original.id;
declaringClass = original.declaringClass;
signature = original.signature;
hasNeverInlineDirective = original.hasNeverInlineDirective;
exceptionHandlers = original.exceptionHandlers;
localVariableTable = original.localVariableTable;
Expand Down Expand Up @@ -627,8 +630,8 @@ public String getName() {
}

@Override
public WrappedSignature getSignature() {
return getUniverse().lookup(wrapped.getSignature(), wrapped.getDeclaringClass());
public jdk.vm.ci.meta.Signature getSignature() {
return signature;
}

@Override
Expand Down
Loading