mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8182310: [AOT][JVMCI] Get host class of VM anonymous class
Add missing JVMCI functionality Reviewed-by: dlong, kvn
This commit is contained in:
parent
b7d9fe6bbb
commit
a7a368b2f9
6 changed files with 55 additions and 0 deletions
|
@ -644,4 +644,9 @@ final class CompilerToVM {
|
|||
* {@link Long}
|
||||
*/
|
||||
native Object getFlagValue(String name);
|
||||
|
||||
/**
|
||||
* Gets the host class for {@code type}.
|
||||
*/
|
||||
native HotSpotResolvedObjectTypeImpl getHostClass(HotSpotResolvedObjectTypeImpl type);
|
||||
}
|
||||
|
|
|
@ -411,6 +411,14 @@ final class HotSpotResolvedObjectTypeImpl extends HotSpotResolvedJavaType implem
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResolvedJavaType getHostClass() {
|
||||
if (isArray()) {
|
||||
return null;
|
||||
}
|
||||
return compilerToVM().getHostClass(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJavaLangObject() {
|
||||
return javaClass.equals(Object.class);
|
||||
|
|
|
@ -153,6 +153,11 @@ public final class HotSpotResolvedPrimitiveType extends HotSpotResolvedJavaType
|
|||
return other.equals(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResolvedJavaType getHostClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaKind getJavaKind() {
|
||||
return kind;
|
||||
|
|
|
@ -104,6 +104,13 @@ public interface ResolvedJavaType extends JavaType, ModifiersProvider, Annotated
|
|||
*/
|
||||
boolean isAssignableFrom(ResolvedJavaType other);
|
||||
|
||||
/**
|
||||
* Returns the {@link ResolvedJavaType} object representing the host class of this VM anonymous
|
||||
* class (as opposed to the unrelated concept specified by {@link Class#isAnonymousClass()}) or
|
||||
* {@code null} if this object does not represent a VM anonymous class.
|
||||
*/
|
||||
ResolvedJavaType getHostClass();
|
||||
|
||||
/**
|
||||
* Returns true if this type is exactly the type {@link java.lang.Object}.
|
||||
*/
|
||||
|
|
|
@ -1687,6 +1687,13 @@ C2V_VMENTRY(jlong, getFingerprint, (JNIEnv*, jobject, jlong metaspace_klass))
|
|||
}
|
||||
C2V_END
|
||||
|
||||
C2V_VMENTRY(jobject, getHostClass, (JNIEnv*, jobject, jobject jvmci_type))
|
||||
InstanceKlass* k = InstanceKlass::cast(CompilerToVM::asKlass(jvmci_type));
|
||||
InstanceKlass* host = k->host_klass();
|
||||
oop result = CompilerToVM::get_jvmci_type(host, CHECK_NULL);
|
||||
return JNIHandles::make_local(THREAD, result);
|
||||
C2V_END
|
||||
|
||||
C2V_VMENTRY(int, interpreterFrameSize, (JNIEnv*, jobject, jobject bytecode_frame_handle))
|
||||
if (bytecode_frame_handle == NULL) {
|
||||
THROW_0(vmSymbols::java_lang_NullPointerException());
|
||||
|
@ -1817,6 +1824,7 @@ JNINativeMethod CompilerToVM::methods[] = {
|
|||
{CC "flushDebugOutput", CC "()V", FN_PTR(flushDebugOutput)},
|
||||
{CC "methodDataProfileDataSize", CC "(JI)I", FN_PTR(methodDataProfileDataSize)},
|
||||
{CC "getFingerprint", CC "(J)J", FN_PTR(getFingerprint)},
|
||||
{CC "getHostClass", CC "(" HS_RESOLVED_KLASS ")" HS_RESOLVED_KLASS, FN_PTR(getHostClass)},
|
||||
{CC "interpreterFrameSize", CC "(" BYTECODE_FRAME ")I", FN_PTR(interpreterFrameSize)},
|
||||
{CC "compileToBytecode", CC "(" OBJECT ")V", FN_PTR(compileToBytecode)},
|
||||
{CC "getFlagValue", CC "(" STRING ")" OBJECT, FN_PTR(getFlagValue)},
|
||||
|
|
|
@ -54,6 +54,7 @@ import java.lang.reflect.Method;
|
|||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
@ -142,6 +143,27 @@ public class TestResolvedJavaType extends TypeUniverse {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHostClassTest() {
|
||||
for (Class<?> c : classes) {
|
||||
ResolvedJavaType type = metaAccess.lookupJavaType(c);
|
||||
ResolvedJavaType host = type.getHostClass();
|
||||
assertNull(host);
|
||||
}
|
||||
|
||||
class LocalClass {}
|
||||
Cloneable clone = new Cloneable() {};
|
||||
assertNull(metaAccess.lookupJavaType(LocalClass.class).getHostClass());
|
||||
assertNull(metaAccess.lookupJavaType(clone.getClass()).getHostClass());
|
||||
|
||||
Supplier<Runnable> lambda = () -> () -> System.out.println("run");
|
||||
ResolvedJavaType lambdaType = metaAccess.lookupJavaType(lambda.getClass());
|
||||
ResolvedJavaType nestedLambdaType = metaAccess.lookupJavaType(lambda.get().getClass());
|
||||
assertNotNull(lambdaType.getHostClass());
|
||||
assertNotNull(nestedLambdaType.getHostClass());
|
||||
assertEquals(lambdaType.getHostClass(), nestedLambdaType.getHostClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getModifiersTest() {
|
||||
for (Class<?> c : classes) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue