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 @@ -32,12 +32,15 @@

import com.oracle.svm.core.hub.DynamicHub;
import com.oracle.svm.core.hub.registry.SymbolsSupport;
import com.oracle.svm.core.invoke.Target_java_lang_invoke_MemberName;
import com.oracle.svm.espresso.classfile.ParserKlass;
import com.oracle.svm.espresso.classfile.descriptors.ByteSequence;
import com.oracle.svm.espresso.classfile.descriptors.Signature;
import com.oracle.svm.espresso.classfile.descriptors.Symbol;
import com.oracle.svm.espresso.classfile.descriptors.Type;

import jdk.vm.ci.meta.JavaType;
import jdk.vm.ci.meta.ResolvedJavaField;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.ResolvedJavaType;

Expand All @@ -47,6 +50,20 @@ public interface CremaSupport {

int getAfterFieldsOffset(DynamicHub hub);

Target_java_lang_invoke_MemberName resolveMemberName(Target_java_lang_invoke_MemberName mn, Class<?> caller);

Object invokeBasic(Target_java_lang_invoke_MemberName memberName, Object methodHandle, Object[] args);

Object linkToVirtual(Object[] args);

Object linkToStatic(Object[] args);

Object linkToSpecial(Object[] args);

Object linkToInterface(Object[] args);

Object getStaticStorage(ResolvedJavaField resolved);

interface CremaDispatchTable {
int vtableLength();

Expand Down Expand Up @@ -97,6 +114,8 @@ default Class<?> findLoadedClass(JavaType unresolvedJavaType, ResolvedJavaType a

Object getStaticStorage(Class<?> cls, boolean primitives, int layerNum);

ResolvedJavaMethod findMethodHandleIntrinsic(ResolvedJavaMethod signaturePolymorphicMethod, Symbol<Signature> signature);

static CremaSupport singleton() {
return ImageSingletons.lookup(CremaSupport.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,17 @@ private static boolean isParallelClassLoader(ClassLoader loader) {
protected abstract boolean loaderIsBootOrPlatform();

public final Class<?> defineClass(Symbol<Type> typeOrNull, byte[] b, int off, int len, ClassDefinitionInfo info) {
if (isParallelClassLoader()) {
// GR-62338: for parallel class loaders this synchronization should be skipped.
Object syncObject = getClassLoader();
if (syncObject == null) {
syncObject = this;
}
synchronized (syncObject) {
return defineClassInner(typeOrNull, b, off, len, info);
} else {
synchronized (getClassLoader()) {
return defineClassInner(typeOrNull, b, off, len, info);
}
}
}

private Class<?> defineClassInner(Symbol<Type> typeOrNull, byte[] b, int off, int len, ClassDefinitionInfo info) {
if (isParallelClassLoader() || getClassLoader() == null) {
// GR-62338
throw VMError.unimplemented("Parallel class loading:" + getClassLoader());
}
byte[] data = b;
if (off != 0 || b.length != len) {
if (len < 0) {
Expand All @@ -201,7 +198,7 @@ private Class<?> defineClassInner(Symbol<Type> typeOrNull, byte[] b, int off, in
}
ParserKlass parsed = parseClass(typeOrNull, info, data);
Symbol<Type> type = typeOrNull == null ? parsed.getType() : typeOrNull;
assert typeOrNull == null || type == parsed.getType();
assert typeOrNull == null || type == parsed.getType() : typeOrNull + " vs. " + parsed.getType();
if (info.addedToRegistry() && findLoadedClass(type) != null) {
String kind;
if (Modifier.isInterface(parsed.getFlags())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,14 @@ public static InterpreterSupport singleton() {
return ImageSingletons.lookup(InterpreterSupport.class);
}

/*
* Check if a given argument matches the inner class Interpreter.Root (holder of the interpreter
* dispatch loop).
/**
* Check if a given frame should be processed by {@link #getInterpretedMethodFrameInfo}.
*/
public abstract boolean isInterpreterRoot(Class<?> clazz);
public abstract boolean isInterpreterRoot(FrameInfoQueryResult frameInfo);

/**
* Transforms an interpreter (root) frame into a frame of the interpreted method. The passed
* frame must be an interpreter root e.g. {@code isInterpreterRoot(frameInfo.getSourceClass())}
* otherwise a fatal exception is thrown.
* Transforms an interpreter (root) frame into a frame of the interpreted method. An error is
* thrown if the passed frame is not an {@link #isInterpreterRoot interpreter root}.
*
* @param frameInfo interpreter root frame
* @param sp stack pointer of the interpreter frame
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.lang.invoke.MethodHandle;

import com.oracle.svm.core.AlwaysInline;
import com.oracle.svm.core.hub.RuntimeClassLoading;

import sun.invoke.util.Wrapper;

Expand Down Expand Up @@ -127,4 +128,15 @@ public static short shortUnbox(Object retVal, Class<?> returnType) {
throw shouldNotReachHere("Unexpected type for unbox function");
}
}

/**
* Returns the resolved member if runtime class loading is enabled. Otherwise, always returns
* {@code null}.
*/
public static ResolvedMember getResolvedMember(Target_java_lang_invoke_MemberName memberName) {
if (RuntimeClassLoading.isSupported()) {
return memberName.resolved;
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2025, 2025, 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.svm.core.invoke;

/**
* This interface should be implemented by the possible resolution results of member names.
*
* @see Target_java_lang_invoke_MemberName#resolved
*/
public interface ResolvedMember {
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import com.oracle.svm.core.annotate.RecomputeFieldValue;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.annotate.TargetElement;
import com.oracle.svm.core.hub.RuntimeClassLoading.WithRuntimeClassLoading;
import com.oracle.svm.core.methodhandles.Target_java_lang_invoke_MethodHandleNatives;
import com.oracle.svm.core.util.BasedOnJDKFile;
import com.oracle.svm.core.util.VMError;
Expand All @@ -46,7 +48,16 @@ public final class Target_java_lang_invoke_MemberName {
@Inject @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)//
public MethodHandleIntrinsic intrinsic;

/**
* This is used by crema to store metadata for the resolved field or method.
*/
@Inject @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)//
@TargetElement(onlyWith = WithRuntimeClassLoading.class)//
public ResolvedMember resolved;

@Alias public Class<?> clazz;
@Alias public String name;
@Alias public Object type;
@Alias public int flags;
@Alias public Object resolution;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ private static Class<?> defineClass0(ClassLoader loader, Class<?> lookup, String
@SuppressWarnings("unused") boolean initialize, int flags, Object classData) {
// Note that if name is not null, it is a binary name in either / or .-form
String actualName = name;
if (LambdaUtils.isLambdaClassName(name)) {
assert !(PredefinedClassesSupport.hasBytecodeClasses() && RuntimeClassLoading.isSupported());
if (!RuntimeClassLoading.isSupported() && LambdaUtils.isLambdaClassName(name)) {
actualName += Digest.digest(b);
}
boolean isNestMate = (flags & ClassLoaderHelper.NESTMATE_CLASS) != 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2020, 2020, 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.svm.core.methodhandles;

import java.lang.invoke.MethodHandle;

import com.oracle.svm.core.SubstrateUtil;
import com.oracle.svm.core.invoke.Target_java_lang_invoke_MemberName;

public final class MethodHandleInterpreterUtils {
private MethodHandleInterpreterUtils() {
}

public static Target_java_lang_invoke_MemberName extractVMEntry(MethodHandle handle) {
Target_java_lang_invoke_LambdaForm lform = SubstrateUtil.cast(handle, Target_java_lang_invoke_MethodHandle.class).internalForm();
return lform.vmentry;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2025, 2025, 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.svm.core.methodhandles;

import static com.oracle.svm.core.util.VMError.unsupportedFeature;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;

import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.hub.RuntimeClassLoading.WithRuntimeClassLoading;
import com.oracle.svm.core.util.BasedOnJDKFile;

/**
* This is used in a special case of {@code BootstrapMethodInvoker.invoke} (See
* {@code @BasedOnJDKFile} annotation on this class) which is not currently used in SVM.
* <p>
* These substitutions cut paths that would lead to useless code being included and some deleted
* methods being reached.
*/
@TargetClass(className = "java.lang.invoke.BootstrapMethodInvoker", innerClass = "VM_BSCI", onlyWith = WithRuntimeClassLoading.class)
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-25+36/src/java.base/share/classes/java/lang/invoke/BootstrapMethodInvoker.java#L113-L126")
final class Target_java_lang_invoke_BootstrapMethodInvoker_VM_BSCI {
@Substitute
@SuppressWarnings("unused")
Target_java_lang_invoke_BootstrapMethodInvoker_VM_BSCI(MethodHandle bsm, String name, Object type, MethodHandles.Lookup lookup, int[] indexInfo) {
throw unsupportedFeature("BootstrapMethodInvoker$VM_BSCI");
}

@Substitute
@SuppressWarnings({"unused", "static-method"})
Object fillCache(int i) {
throw unsupportedFeature("BootstrapMethodInvoker$VM_BSCI.fillCache");
}

@Substitute
@SuppressWarnings({"unused", "static-method"})
public int copyConstants(int start, int end, Object[] buf, int pos) {
throw unsupportedFeature("BootstrapMethodInvoker$VM_BSCI.copyConstants");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.annotate.TargetElement;
import com.oracle.svm.core.fieldvaluetransformer.NewEmptyArrayFieldValueTransformer;
import com.oracle.svm.core.hub.RuntimeClassLoading.NoRuntimeClassLoading;

/**
* In the JDK implementation of method handles, each bound method handle is an instance of a
Expand Down Expand Up @@ -73,7 +74,7 @@ final class Target_java_lang_invoke_BoundMethodHandle {
* We hijack the species with no bound parameters for our implementation since it already inherits
* from BoundMethodHandle and doesn't contain any superfluous members.
*/
@TargetClass(className = "java.lang.invoke.SimpleMethodHandle")
@TargetClass(className = "java.lang.invoke.SimpleMethodHandle", onlyWith = NoRuntimeClassLoading.class)
final class Target_java_lang_invoke_SimpleMethodHandle {
/*
* Since we represent all the bound method handle species with the basic one, the species data
Expand Down Expand Up @@ -130,7 +131,7 @@ Target_java_lang_invoke_BoundMethodHandle copyWith(MethodType type, Target_java_
}

/* Hardcoded species, needs a special case to avoid initialization */
@TargetClass(className = "java.lang.invoke.BoundMethodHandle", innerClass = "Species_L")
@TargetClass(className = "java.lang.invoke.BoundMethodHandle", innerClass = "Species_L", onlyWith = NoRuntimeClassLoading.class)
final class Target_java_lang_invoke_BoundMethodHandle_Species_L {
@Substitute
static Target_java_lang_invoke_BoundMethodHandle make(MethodType mt, Target_java_lang_invoke_LambdaForm lf, Object argL0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import com.oracle.svm.core.annotate.RecomputeFieldValue;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.annotate.TargetElement;
import com.oracle.svm.core.hub.RuntimeClassLoading.NoRuntimeClassLoading;
import com.oracle.svm.core.invoke.Target_java_lang_invoke_MemberName;
import com.oracle.svm.util.ReflectionUtil;

Expand All @@ -42,10 +44,18 @@ public final class Target_java_lang_invoke_LambdaForm {
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = LambdaFormCacheTransformer.class)//
volatile Object transformCache;

// isCompiled needs to be reset if vmentry is reset
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)//
boolean isCompiled;

@Alias
native String lambdaName();

@Alias
native void prepare();

@Substitute
@TargetElement(onlyWith = NoRuntimeClassLoading.class)
void compileToBytecode() {
/*
* Those lambda form types are required to be precompiled to bytecode during method handles
Expand All @@ -62,6 +72,7 @@ void compileToBytecode() {
*/
@Substitute
@SuppressWarnings("static-method")
@TargetElement(onlyWith = NoRuntimeClassLoading.class)
private boolean forceInterpretation() {
return true;
}
Expand Down
Loading