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 @@ -28,6 +28,7 @@

import java.lang.reflect.AnnotatedElement;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;
Expand Down Expand Up @@ -238,4 +239,6 @@ public void clearInThread() {
public Object getConfiguration() {
return null;
}

public abstract Comparator<? super ResolvedJavaType> getTypeComparator();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;

import com.oracle.graal.pointsto.BigBang;
import com.oracle.graal.pointsto.api.PointstoOptions;
Expand All @@ -38,6 +39,7 @@
import jdk.vm.ci.meta.JavaMethodProfile;
import jdk.vm.ci.meta.JavaTypeProfile;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.ResolvedJavaType;
import jdk.vm.ci.meta.TriState;

public abstract class AbstractAnalysisResultsBuilder {
Expand Down Expand Up @@ -126,9 +128,12 @@ private JavaTypeProfile cachedTypeProfile(JavaTypeProfile[] cache, int cacheIdx,

private JavaTypeProfile createTypeProfile(TypeState typeState) {
double probability = 1d / typeState.typesCount();
JavaTypeProfile.ProfiledType[] pitems = typeState.typesStream(bb)
.map(analysisType -> converter == null ? analysisType : converter.lookup(analysisType))
.sorted()

Stream<? extends ResolvedJavaType> stream = typeState.typesStream(bb);
if (converter != null) {
stream = stream.map(converter::lookup).sorted(converter.hostVM().getTypeComparator());
}
JavaTypeProfile.ProfiledType[] pitems = stream
.map(type -> new JavaTypeProfile.ProfiledType(type, probability))
.toArray(JavaTypeProfile.ProfiledType[]::new);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BiFunction;

import com.oracle.svm.shadowed.org.bytedeco.llvm.global.LLVM;
import org.graalvm.compiler.code.CompilationResult;
import org.graalvm.compiler.core.common.CompressEncoding;
import org.graalvm.compiler.core.common.LIRKind;
Expand Down Expand Up @@ -83,7 +82,6 @@
import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
import org.graalvm.nativeimage.c.constant.CEnum;
import org.graalvm.nativeimage.c.function.CEntryPoint;
import com.oracle.svm.util.GuardedAnnotationAccess;

import com.oracle.svm.core.FrameAccess;
import com.oracle.svm.core.ReservedRegisters;
Expand Down Expand Up @@ -125,6 +123,8 @@
import com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef;
import com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef;
import com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef;
import com.oracle.svm.shadowed.org.bytedeco.llvm.global.LLVM;
import com.oracle.svm.util.GuardedAnnotationAccess;
import com.oracle.svm.util.ReflectionUtil;

import jdk.vm.ci.code.CallingConvention;
Expand Down Expand Up @@ -186,7 +186,7 @@ public class LLVMGenerator implements LIRGeneratorTool, SubstrateLIRGenerator {
this.lirKindTool = new LLVMUtils.LLVMKindTool(builder);
this.debugInfoPrinter = new DebugInfoPrinter(this, debugLevel);

this.functionName = SubstrateUtil.uniqueShortName(method);
this.functionName = ((HostedMethod) method).getUniqueShortName();
this.isEntryPoint = isEntryPoint(method);
this.modifiesSpecialRegisters = modifiesSpecialRegisters(graph);

Expand Down Expand Up @@ -291,7 +291,7 @@ byte[] getBitcode() {
}

private static String getFunctionName(ResolvedJavaMethod method) {
return SubstrateUtil.uniqueShortName(method);
return ((HostedMethod) method).getUniqueShortName();
}

private static boolean isEntryPoint(ResolvedJavaMethod method) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import com.oracle.objectfile.ObjectFile.Element;
import com.oracle.objectfile.SectionName;
import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.SubstrateUtil;
import com.oracle.svm.core.c.CGlobalDataImpl;
import com.oracle.svm.core.graal.code.CGlobalDataInfo;
import com.oracle.svm.core.graal.code.CGlobalDataReference;
Expand Down Expand Up @@ -224,7 +223,7 @@ private void linkCompiledBatches(BatchExecutor executor, DebugContext debug, int

executor.forEach(getOrderedCompilations(), pair -> (debugContext) -> {
HostedMethod method = pair.getLeft();
int offset = textSectionInfo.getOffset(SubstrateUtil.uniqueShortName(method));
int offset = textSectionInfo.getOffset(method.getUniqueShortName());
int nextFunctionStartOffset = textSectionInfo.getNextOffset(offset);
int functionSize = nextFunctionStartOffset - offset;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@

import com.oracle.objectfile.ObjectFile;
import com.oracle.objectfile.SectionName;
import com.oracle.svm.core.SubstrateUtil;
import com.oracle.svm.core.graal.llvm.LLVMGenerator;
import com.oracle.svm.core.graal.llvm.LLVMNativeImageCodeCache.StackMapDumper;
import com.oracle.svm.core.heap.SubstrateReferenceMap;
import com.oracle.svm.hosted.meta.HostedMethod;
import com.oracle.svm.shadowed.org.bytedeco.javacpp.BytePointer;
import com.oracle.svm.shadowed.org.bytedeco.javacpp.Pointer;
import com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMMemoryBufferRef;
Expand Down Expand Up @@ -161,7 +161,7 @@ private LLVMStackMapInfo readStackMapSection(LLVMSectionIteratorRef sectionItera
}

public void readStackMap(LLVMStackMapInfo info, CompilationResult compilation, ResolvedJavaMethod method, int id) {
String methodSymbolName = SYMBOL_PREFIX + SubstrateUtil.uniqueShortName(method);
String methodSymbolName = SYMBOL_PREFIX + ((HostedMethod) method).getUniqueShortName();

long startPatchpointID = compilation.getInfopoints().stream().filter(ip -> ip.reason == InfopointReason.METHOD_START).findFirst()
.orElseThrow(() -> new GraalError("no method start infopoint: " + methodSymbolName)).pcOffset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.ResolvedJavaType;
import jdk.vm.ci.meta.Signature;
import jdk.vm.ci.services.Services;

public class SubstrateUtil {
Expand Down Expand Up @@ -278,21 +279,38 @@ public static String digest(String value) {
* name includes a digest of the fully qualified method name, which ensures uniqueness.
*/
public static String uniqueShortName(ResolvedJavaMethod m) {
StringBuilder fullName = new StringBuilder();
fullName.append(m.getDeclaringClass().toClassName()).append(".").append(m.getName()).append("(");
for (int i = 0; i < m.getSignature().getParameterCount(false); i++) {
fullName.append(m.getSignature().getParameterType(i, null).toClassName()).append(",");
return uniqueShortName("", m.getDeclaringClass(), m.getName(), m.getSignature(), m.isConstructor());
}

public static String uniqueShortName(String loaderNameAndId, ResolvedJavaType declaringClass, String methodName, Signature methodSignature, boolean isConstructor) {
StringBuilder sb = new StringBuilder(loaderNameAndId);
sb.append(declaringClass.toClassName()).append(".").append(methodName).append("(");
for (int i = 0; i < methodSignature.getParameterCount(false); i++) {
sb.append(methodSignature.getParameterType(i, null).toClassName()).append(",");
}
fullName.append(')');
if (!m.isConstructor()) {
fullName.append(m.getSignature().getReturnType(null).toClassName());
sb.append(')');
if (!isConstructor) {
sb.append(methodSignature.getReturnType(null).toClassName());
}

return stripPackage(m.getDeclaringClass().toJavaName()) + "_" +
(m.isConstructor() ? "constructor" : m.getName()) + "_" +
SubstrateUtil.digest(fullName.toString());
return stripPackage(declaringClass.toJavaName()) + "_" +
(isConstructor ? "constructor" : methodName) + "_" +
SubstrateUtil.digest(sb.toString());
}

public static String classLoaderNameAndId(ClassLoader loader) {
if (loader == null) {
return "";
}
try {
return (String) classLoaderNameAndId.get(loader);
} catch (IllegalAccessException e) {
throw VMError.shouldNotReachHere("Cannot reflectively access ClassLoader.nameAndId");
}
}

private static final Field classLoaderNameAndId = ReflectionUtil.lookupField(ClassLoader.class, "nameAndId");

/**
* Returns a short, reasonably descriptive, but still unique name for the provided
* {@link Method}, {@link Constructor}, or {@link Field}. The name includes a digest of the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Modifier;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -65,7 +66,6 @@
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.c.function.RelocatedPointer;
import com.oracle.svm.util.GuardedAnnotationAccess;

import com.oracle.graal.pointsto.BigBang;
import com.oracle.graal.pointsto.api.HostVM;
Expand Down Expand Up @@ -109,10 +109,12 @@
import com.oracle.svm.hosted.code.UninterruptibleAnnotationChecker;
import com.oracle.svm.hosted.heap.PodSupport;
import com.oracle.svm.hosted.meta.HostedType;
import com.oracle.svm.hosted.meta.HostedUniverse;
import com.oracle.svm.hosted.phases.AnalysisGraphBuilderPhase;
import com.oracle.svm.hosted.phases.ImplicitAssertionsPhase;
import com.oracle.svm.hosted.phases.InlineBeforeAnalysisPolicyImpl;
import com.oracle.svm.hosted.substitute.UnsafeAutomaticSubstitutionProcessor;
import com.oracle.svm.util.GuardedAnnotationAccess;

import jdk.vm.ci.meta.DeoptimizationReason;
import jdk.vm.ci.meta.ResolvedJavaField;
Expand Down Expand Up @@ -743,4 +745,11 @@ public boolean neverInlineTrivial(AnalysisMethod caller, AnalysisMethod callee)
}
return false;
}

@Override
public Comparator<? super ResolvedJavaType> getTypeComparator() {
return (Comparator<ResolvedJavaType>) (o1, o2) -> {
return HostedUniverse.TYPE_COMPARATOR.compare((HostedType) o1, (HostedType) o2);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,6 @@ private void parseDeoptimizationTargetMethods() {
universe.getMethods().stream()
.filter(method -> method.getWrapped().isImplementationInvoked() && canDeoptForTesting(method))
.forEach(this::ensureParsedForDeoptTesting);

}

private void ensureParsedForDeoptTesting(HostedMethod method) {
Expand Down Expand Up @@ -1675,7 +1674,7 @@ private static void insertDeoptTests(HostedMethod method, StructuredGraph graph)
}

public Map<HostedMethod, CompilationResult> getCompilationResults() {
Map<HostedMethod, CompilationResult> result = new TreeMap<>();
Map<HostedMethod, CompilationResult> result = new TreeMap<>(HostedUniverse.METHOD_COMPARATOR);
for (Entry<HostedMethod, CompileTask> entry : compilations.entrySet()) {
result.put(entry.getKey(), entry.getValue().result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,4 @@ public boolean isLocal() {
public boolean isMember() {
return false;
}

@Override
int compareToEqualClass(HostedType other) {
assert getClass().equals(other.getClass());
return getComponentType().compareTo(other.getComponentType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
/**
* Store the compile-time information for a field in the Substrate VM, such as the field offset.
*/
public class HostedField implements OriginalFieldProvider, SharedField, Comparable<HostedField>, WrappedJavaField, AnnotationWrapper {
public class HostedField implements OriginalFieldProvider, SharedField, WrappedJavaField, AnnotationWrapper {

private final HostedUniverse universe;
private final HostedMetaAccess metaAccess;
Expand Down Expand Up @@ -198,20 +198,6 @@ public JavaKind getStorageKind() {
return getType().getStorageKind();
}

@Override
public int compareTo(HostedField other) {
/*
* Order by JavaKind. This is required, since we want instance fields of the same size and
* kind consecutive.
*/
int result = other.getJavaKind().ordinal() - this.getJavaKind().ordinal();
/*
* If the kind is the same, i.e., result == 0, we return 0 so that the sorting keeps the
* order unchanged and therefore keeps the field order we get from the hosting VM.
*/
return result;
}

@Override
public Field getJavaField() {
return OriginalFieldProvider.getJavaField(getDeclaringClass().universe.getSnippetReflection(), wrapped);
Expand Down
Loading