Skip to content
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
15 changes: 15 additions & 0 deletions substratevm/debug/gdbpy/gdb-debughelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,21 @@ def HLRep(original_class):
return original_class


@HLRep
class EspressoSymbol:
target_type = 'com.oracle.svm.espresso.classfile.descriptors.Symbol'

def __init__(self, svm_util: SVMUtil, obj: gdb.Value):
trace(f'<EspressoSymbol> - __init__({obj.type} @ {hex(svm_util.get_adr(obj))})')
value = svm_util.get_obj_field(obj, 'value')
self.__length = svm_util.get_int_field(value, 'len')
self.__array = svm_util.get_obj_field(value, 'data', None)

def to_string(self) -> str:
trace('<EspressoSymbol> - to_string')
byte_list = [self.__array[i] for i in range(self.__length)]
return f'EspressoSymbol({str(bytes(byte_list))})'

@HLRep
class ArrayList:
target_type = 'java.util.ArrayList'
Expand Down
41 changes: 41 additions & 0 deletions substratevm/mx.substratevm/mx_substratevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,47 @@ def prevent_build_path_in_libgraal():

mx_sdk_vm.register_graalvm_component(libsvmjdwp)

lib_jvm_preserved_packages = [
'java.util',
'java.util.stream',
'java.util.concurrent.locks',
'java.lang',
'java.lang.invoke',
'java.io'
]

mx_sdk_vm.register_graalvm_component(mx_sdk_vm.GraalVmJreComponent(
suite=suite,
name='SubstrateVM java',
short_name='svmjava',
dir_name='svm',
license_files=[],
third_party_license_files=[],
dependencies=[],
jar_distributions=[],
builder_jar_distributions=[],
support_distributions=[],
priority=0,
library_configs=[
mx_sdk_vm.LibraryConfig(
destination='<lib:jvm>',
jar_distributions=[],
build_args=[
'--features=com.oracle.svm.hosted.libjvm.LibJVMFeature'
] + svm_experimental_options([
'-H:+RuntimeClassLoading',
'-H:+InterpreterTraceSupport',
'-H:+AllowJRTFileSystem'
] + ['-H:Preserve=package=' + pkg for pkg in lib_jvm_preserved_packages]),
headers=False,
home_finder=False,
),
],
support_libraries_distributions=[],
stability="experimental",
jlink=False,
))

def _native_image_utils_extra_jvm_args():
packages = ['jdk.graal.compiler/jdk.graal.compiler.phases.common', 'jdk.internal.vm.ci/jdk.vm.ci.meta', 'jdk.internal.vm.ci/jdk.vm.ci.services', 'jdk.graal.compiler/jdk.graal.compiler.core.common.util']
args = ['--add-exports=' + packageName + '=ALL-UNNAMED' for packageName in packages]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,9 @@ public Optional<AnalysisMethod> handleForeignCall(ForeignCallDescriptor foreignC
public boolean isClosedTypeWorld() {
return isClosedTypeWorld;
}

@Override
public String loaderName(AnalysisType type) {
return loaderName(typeToClass.get(type).getClassLoader());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,20 @@ public Set<Module> getSharedLayerForbiddenModules() {
return Set.of();
}

public abstract String loaderName(AnalysisType type);

public static String loaderName(ClassLoader loader) {
if (loader == null) {
return "null";
}
var loaderName = loader.getName();
if (loaderName == null || loaderName.isBlank()) {
return loader.getClass().getName();
} else {
return loaderName;
}
}

/**
* Helpers to determine what analysis actions should be taken for a given Multi-Method version.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ static class MethodNodeReference implements Node {

@Override
public String format() {
return ReportUtils.loaderName(methodNode.method.getDeclaringClass()) + ':' + methodNode.method.format(METHOD_FORMAT) + " id-ref=" + methodNode.id;
var hostVM = methodNode.method.getUniverse().hostVM();
return hostVM.loaderName(methodNode.method.getDeclaringClass()) + ':' + methodNode.method.format(METHOD_FORMAT) + " id-ref=" + methodNode.id;
}

}
Expand Down Expand Up @@ -140,7 +141,7 @@ void addInvoke(InvokeNode invoke) {

@Override
public String format() {
return ReportUtils.loaderName(method.getDeclaringClass()) + ':' + method.format(METHOD_FORMAT) + " id=" + id;
return method.getUniverse().hostVM().loaderName(method.getDeclaringClass()) + ':' + method.format(METHOD_FORMAT) + " id=" + id;
}
}

Expand Down Expand Up @@ -307,7 +308,7 @@ private static void printCallTreeNode(PrintWriter out, String prefix, MethodNode
private void printUsedMethods(PrintWriter out) {
List<String> methodsList = new ArrayList<>();
for (AnalysisMethod method : methodToNode.keySet()) {
methodsList.add(ReportUtils.loaderName(method.getDeclaringClass()) + ':' + method.format(METHOD_FORMAT));
methodsList.add(method.getUniverse().hostVM().loaderName(method.getDeclaringClass()) + ':' + method.format(METHOD_FORMAT));
}
methodsList.sort(null);
for (String name : methodsList) {
Expand All @@ -334,7 +335,8 @@ public Set<String> classesSet(boolean packageNameOnly) {
name = packagePrefix(name);
}
}
classSet.add(ReportUtils.loaderName(type) + ':' + name);

classSet.add(type.getUniverse().hostVM().loaderName(type) + ':' + name);
}
return classSet;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.oracle.graal.pointsto.BigBang;
import com.oracle.graal.pointsto.ObjectScanner;
import com.oracle.graal.pointsto.ObjectScanningObserver;
import com.oracle.graal.pointsto.api.HostVM;
import com.oracle.graal.pointsto.meta.AnalysisField;
import com.oracle.graal.pointsto.meta.AnalysisMethod;
import com.oracle.graal.pointsto.meta.AnalysisType;
Expand Down Expand Up @@ -84,12 +85,16 @@ String format() {

private static String format(Object srcObj) {
return switch (srcObj) {
case AnalysisField field -> ReportUtils.loaderName(field.getDeclaringClass()) + ':' + field.format("%H.%n:%T");
case AnalysisMethod method -> ReportUtils.loaderName(method.getDeclaringClass()) + ':' + method.format("%H.%n(%p)");
case AnalysisField field -> loaderName(field.getDeclaringClass()) + ':' + field.format("%H.%n:%T");
case AnalysisMethod method -> loaderName(method.getDeclaringClass()) + ':' + method.format("%H.%n(%p)");
case BytecodePosition bcp -> "%s [bci: %d]".formatted(format(bcp.getMethod()), bcp.getBCI());
default -> throw JVMCIError.shouldNotReachHere("unknown srcObj");
};
}

private static String loaderName(AnalysisType type) {
return type.getUniverse().hostVM().loaderName(type);
}
}

static class ObjectNodeBase {
Expand Down Expand Up @@ -400,7 +405,7 @@ static String constantAsString(BigBang bb, JavaConstant constant) {
Object object = constantAsObject(bb, constant);
String loaderPrefix = "";
if (object != null) {
loaderPrefix = ReportUtils.loaderName(object.getClass().getClassLoader()) + ':';
loaderPrefix = HostVM.loaderName(object.getClass().getClassLoader()) + ':';
}
if (object instanceof String) {
String str = (String) object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,24 +319,4 @@ private static void followInput(PointsToAnalysis bb, TypeFlow<?> flow, AnalysisT
}
}
}

public static String loaderName(AnalysisType type) {
var declaringJavaClass = type.getJavaClass();
if (declaringJavaClass == null) {
return "err";
}
return loaderName(declaringJavaClass.getClassLoader());
}

public static String loaderName(ClassLoader loader) {
if (loader == null) {
return "null";
}
var loaderName = loader.getName();
if (loaderName == null || loaderName.isBlank()) {
return loader.getClass().getName();
} else {
return loaderName;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
package com.oracle.svm.core.posix;

import jdk.graal.compiler.word.Word;
import org.graalvm.nativeimage.c.type.CCharPointer;
import org.graalvm.nativeimage.c.type.CTypeConversion;

Expand All @@ -33,8 +32,17 @@
import com.oracle.svm.core.posix.headers.Limits;
import com.oracle.svm.core.posix.headers.Unistd;

import jdk.graal.compiler.word.Word;

public abstract class PosixSystemPropertiesSupport extends SystemPropertiesSupport {

@Override
protected String jvmLibName() {
return "libjvm" + jvmLibSuffix();
}

protected abstract String jvmLibSuffix();

/*
* Initialization code is adapted from the JDK native code that initializes the system
* properties, as found in src/solaris/native/java/lang/java_props_md.c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ protected String osVersionValue() {
}
return osVersionValue = "Unknown";
}

@Override
protected String jvmLibSuffix() {
return ".dylib";
}
}

@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = NoLayeredCallbacks.class, layeredInstallationKind = Disallowed.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ protected String osVersionValue() {
}
return "Unknown";
}

@Override
protected String jvmLibSuffix() {
return ".so";
}
}

@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = SingleLayer.class, layeredInstallationKind = Independent.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ protected String osVersionValue() {
return cachedOsVersion;
}

@Override
protected String jvmLibName() {
return "jvm.dll";
}

private void computeOsNameAndVersion() {
/*
* Reimplementation of code from java_props_md.c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.espresso.classfile.descriptors.Symbol;
import com.oracle.svm.espresso.classfile.descriptors.Type;
import com.oracle.svm.espresso.classfile.descriptors.TypeSymbols;

/**
* This class registry corresponds to the {@code null} class loader when runtime class loading is
Expand Down Expand Up @@ -77,7 +78,8 @@ public synchronized Class<?> doLoadClass(Symbol<Type> type) {
if (moduleName == null) {
return null;
}
Path classPath = getFileSystem().getPath("/modules/" + moduleName + "/" + type + ".class");
var jrtTypePath = TypeSymbols.typeToName(type);
Path classPath = getFileSystem().getPath("/modules/" + moduleName + "/" + jrtTypePath + ".class");
if (!Files.exists(classPath)) {
return null;
}
Expand All @@ -93,7 +95,7 @@ private static String packageFromType(Symbol<Type> type) {
if (lastSlash == -1) {
return null;
}
return type.subSequence(0, lastSlash).toString();
return type.subSequence(1, lastSlash).toString().replace('/', '.');
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import static jdk.graal.compiler.core.common.LibGraalSupport.LIBGRAAL_SETTING_PROPERTY_PREFIX;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -40,13 +41,17 @@
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.hosted.RuntimeSystemProperties;
import org.graalvm.nativeimage.impl.ProcessPropertiesSupport;
import org.graalvm.nativeimage.impl.RuntimeSystemPropertiesSupport;

import com.oracle.svm.core.FutureDefaultsOptions;
import com.oracle.svm.core.NeverInline;
import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.VM;
import com.oracle.svm.core.c.locale.LocaleSupport;
import com.oracle.svm.core.config.ConfigurationValues;
import com.oracle.svm.core.libjvm.LibJVMMainMethodWrappers;
import com.oracle.svm.core.snippets.KnownIntrinsics;
import com.oracle.svm.core.util.VMError;

import jdk.graal.compiler.api.replacements.Fold;
Expand Down Expand Up @@ -152,6 +157,7 @@ protected SystemPropertiesSupport() {
lazyProperties.add(new LazySystemProperty(UserSystemProperty.NAME, this::userNameValue));
lazyProperties.add(new LazySystemProperty(UserSystemProperty.HOME, this::userHomeValue));
lazyProperties.add(new LazySystemProperty(UserSystemProperty.DIR, this::userDirValue));
lazyProperties.add(new LazySystemProperty("java.home", this::javaHomeValue));
lazyProperties.add(new LazySystemProperty("java.io.tmpdir", this::javaIoTmpdirValue));
lazyProperties.add(new LazySystemProperty("java.library.path", this::javaLibraryPathValue));
lazyProperties.add(new LazySystemProperty("os.version", this::osVersionValue));
Expand Down Expand Up @@ -351,6 +357,39 @@ private synchronized void initializeProperty(LazySystemProperty property) {

protected abstract String osVersionValue();

@NeverInline("Reads the return address.")
private String javaHomeValue() {

if (!ImageSingletons.contains(LibJVMMainMethodWrappers.class)) {
return null;
}

if (!SubstrateOptions.SharedLibrary.getValue()) {
throw VMError.shouldNotReachHere("Invalid " + jvmLibName() + " image. Not a shared library image.");
}
var objectFileStr = ImageSingletons.lookup(ProcessPropertiesSupport.class).getObjectFile(KnownIntrinsics.readReturnAddress());
if (objectFileStr == null) {
throw VMError.shouldNotReachHere("Unable to get path to " + jvmLibName() + " image.");
}
var pathToSharedLib = Path.of(objectFileStr);
if (!pathToSharedLib.endsWith(jvmLibName())) {
throw VMError.shouldNotReachHere("Invalid name for a " + jvmLibName() + " image: " + objectFileStr);
}
// At this point we know that this is a libjvm shared library image
try {
return pathToSharedLib // <java.home>/{lib|bin}/svm/<jvmLibName()>
.getParent() // <java.home>/{lib|bin}/svm
.getParent() // <java.home>/{lib|bin}
.getParent().toString();
} catch (NullPointerException e) {
throw VMError.shouldNotReachHere("Unable to determine java.home for " + objectFileStr);
}
}

protected String jvmLibName() {
throw VMError.shouldNotReachHere("System property java.home is not supported in this configuration");
}

protected abstract String javaIoTmpdirValue();

protected abstract String javaLibraryPathValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,22 @@ public final class Target_java_lang_ClassLoader {
@Alias @RecomputeFieldValue(kind = Kind.Custom, declClass = AssertionLockComputer.class, isFinal = true) // GR-62338
private Object assertionLock;

@Alias //
private static ClassLoader scl;
@Delete private static ClassLoader scl;

@Inject @RecomputeFieldValue(kind = Kind.Custom, declClass = ClassRegistries.ClassRegistryComputer.class)//
@TargetElement(onlyWith = ClassForNameSupport.RespectsClassLoader.class)//
public volatile AbstractClassRegistry classRegistry;

@Alias
static native ClassLoader getBuiltinAppClassLoader();

@Substitute
public static ClassLoader getSystemClassLoader() {
VMError.guarantee(scl != null);
return scl;
/*
* Setting custom SystemClassLoader via java.system.class.loader system property currently
* not supported for native-images.
*/
return getBuiltinAppClassLoader();
}

@Delete
Expand Down
Loading