Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8265480: add basic JVMCI support for JEP 309: Dynamic Class-File Constants #3578

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
@@ -501,10 +501,11 @@ C2V_END

C2V_VMENTRY_0(jboolean, isCompilable,(JNIEnv* env, jobject, jobject jvmci_method))
Method* method = JVMCIENV->asMethod(jvmci_method);
ConstantPool* cp = method->constMethod()->constants();
assert(cp != NULL, "npe");
// don't inline method when constant pool contains a CONSTANT_Dynamic
return !method->is_not_compilable(CompLevel_full_optimization) && !cp->has_dynamic_constant();
// Skip redefined methods
if (method->is_old()) {
return false;
}
return !method->is_not_compilable(CompLevel_full_optimization);
C2V_END

C2V_VMENTRY_0(jboolean, hasNeverInlineDirective,(JNIEnv* env, jobject, jobject jvmci_method))
@@ -620,8 +621,48 @@ C2V_VMENTRY_NULL(jobject, lookupClass, (JNIEnv* env, jobject, jclass mirror))

C2V_VMENTRY_NULL(jobject, resolvePossiblyCachedConstantInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
constantPoolHandle cp(THREAD, JVMCIENV->asConstantPool(jvmci_constant_pool));
oop result = cp->resolve_possibly_cached_constant_at(index, CHECK_NULL);
return JVMCIENV->get_jobject(JVMCIENV->get_object_constant(result));
oop obj = cp->resolve_possibly_cached_constant_at(index, CHECK_NULL);
constantTag tag = cp->tag_at(index);
if (tag.is_dynamic_constant() || tag.is_dynamic_constant_in_error()) {
if (obj == Universe::the_null_sentinel()) {
return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_NULL_POINTER());
}
BasicType bt = Signature::basic_type(cp->uncached_signature_ref_at(index));
if (!is_reference_type(bt)) {
if (!is_java_primitive(bt)) {
return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_ILLEGAL());
}

// Convert standard box (e.g. java.lang.Integer) to JVMCI box (e.g. jdk.vm.ci.meta.PrimitiveConstant)
jvalue value;
jlong raw_value;
BasicType bt2 = java_lang_boxing_object::get_value(obj, &value);
assert(bt2 == bt, "");
switch (bt2) {
case T_BOOLEAN: raw_value = value.z; break;
case T_BYTE: raw_value = value.b; break;
case T_SHORT: raw_value = value.s; break;
case T_CHAR: raw_value = value.c; break;
case T_INT: raw_value = value.i; break;
case T_LONG: raw_value = value.j; break;
case T_FLOAT: {
JVMCIObject result = JVMCIENV->call_JavaConstant_forFloat(value.f, JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(result);
}
case T_DOUBLE: {
JVMCIObject result = JVMCIENV->call_JavaConstant_forDouble(value.d, JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(result);
}
default: {
return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_ILLEGAL());
}
}

JVMCIObject result = JVMCIENV->call_PrimitiveConstant_forTypeChar(type2char(bt2), raw_value, JVMCI_CHECK_NULL);

This comment has been minimized.

Loading
@PaulSandoz

PaulSandoz Apr 21, 2021
Member

Given the above switch is total this part is unreachable? Did you mean for it to occur after the if (!is_reference_type(bt)) block?

This comment has been minimized.

Loading
@dougxc

dougxc Apr 21, 2021
Author Member

No - it should not be there at all: b70c7b1
Thanks for spotting.

This comment has been minimized.

Loading
@PaulSandoz

PaulSandoz Apr 21, 2021
Member

Oops, i think i need glasses, the switch has break statements that results in processing of the raw_value:

      switch (bt2) {
        case T_BOOLEAN: raw_value = value.z; break;
...

This comment has been minimized.

Loading
@dougxc

dougxc Apr 22, 2021
Author Member

I need more than glasses since I wrote this code! Thankfully the test I added also showed the problem with removing this "unreachable" code.

return JVMCIENV->get_jobject(result);
}
}
return JVMCIENV->get_jobject(JVMCIENV->get_object_constant(obj));
C2V_END

C2V_VMENTRY_0(jint, lookupNameAndTypeRefIndexInPool, (JNIEnv* env, jobject, jobject jvmci_constant_pool, jint index))
@@ -2696,7 +2737,7 @@ JNINativeMethod CompilerToVM::methods[] = {
{CC "lookupAppendixInPool", CC "(" HS_CONSTANT_POOL "I)" OBJECTCONSTANT, FN_PTR(lookupAppendixInPool)},
{CC "lookupMethodInPool", CC "(" HS_CONSTANT_POOL "IB)" HS_RESOLVED_METHOD, FN_PTR(lookupMethodInPool)},
{CC "constantPoolRemapInstructionOperandFromCache", CC "(" HS_CONSTANT_POOL "I)I", FN_PTR(constantPoolRemapInstructionOperandFromCache)},
{CC "resolvePossiblyCachedConstantInPool", CC "(" HS_CONSTANT_POOL "I)" OBJECTCONSTANT, FN_PTR(resolvePossiblyCachedConstantInPool)},
{CC "resolvePossiblyCachedConstantInPool", CC "(" HS_CONSTANT_POOL "I)" JAVACONSTANT, FN_PTR(resolvePossiblyCachedConstantInPool)},
{CC "resolveTypeInPool", CC "(" HS_CONSTANT_POOL "I)" HS_RESOLVED_KLASS, FN_PTR(resolveTypeInPool)},
{CC "resolveFieldInPool", CC "(" HS_CONSTANT_POOL "I" HS_RESOLVED_METHOD "B[I)" HS_RESOLVED_KLASS, FN_PTR(resolveFieldInPool)},
{CC "resolveInvokeDynamicInPool", CC "(" HS_CONSTANT_POOL "I)V", FN_PTR(resolveInvokeDynamicInPool)},
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, 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
@@ -245,6 +245,7 @@
int_field(BytecodePosition, bci) \
end_class \
start_class(JavaConstant, jdk_vm_ci_meta_JavaConstant) \
static_object_field(JavaConstant, ILLEGAL, "Ljdk/vm/ci/meta/PrimitiveConstant;") \
static_object_field(JavaConstant, NULL_POINTER, "Ljdk/vm/ci/meta/JavaConstant;") \
jvmci_method(CallStaticObjectMethod, GetStaticMethodID, call_static, JVMCIObject, JavaConstant, forFloat, forFloat_signature, (JVMCIObject kind, jlong value, JVMCI_TRAPS)) \
jvmci_method(CallStaticObjectMethod, GetStaticMethodID, call_static, JVMCIObject, JavaConstant, forDouble, forDouble_signature, (JVMCIObject kind, jlong value, JVMCI_TRAPS)) \
@@ -286,7 +287,9 @@
static_object_field(JavaKind, Char, "Ljdk/vm/ci/meta/JavaKind;") \
static_object_field(JavaKind, Short, "Ljdk/vm/ci/meta/JavaKind;") \
static_object_field(JavaKind, Int, "Ljdk/vm/ci/meta/JavaKind;") \
static_object_field(JavaKind, Float, "Ljdk/vm/ci/meta/JavaKind;") \
static_object_field(JavaKind, Long, "Ljdk/vm/ci/meta/JavaKind;") \
static_object_field(JavaKind, Double, "Ljdk/vm/ci/meta/JavaKind;") \
end_class \
start_class(ValueKind, jdk_vm_ci_meta_ValueKind) \
object_field(ValueKind, platformKind, "Ljdk/vm/ci/meta/PlatformKind;") \
@@ -430,6 +430,7 @@
declare_constant(JVM_CONSTANT_MethodHandle) \
declare_constant(JVM_CONSTANT_MethodType) \
declare_constant(JVM_CONSTANT_InvokeDynamic) \
declare_constant(JVM_CONSTANT_Dynamic) \
declare_constant(JVM_CONSTANT_Module) \
declare_constant(JVM_CONSTANT_Package) \
declare_constant(JVM_CONSTANT_ExternalMax) \
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, 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
@@ -215,11 +215,11 @@ public static CompilerToVM compilerToVM() {
* constant pool cache first.
*
* The behavior of this method is undefined if {@code cpi} does not denote one of the following
* entry types: {@code JVM_CONSTANT_String}, {@code JVM_CONSTANT_MethodHandle},
* {@code JVM_CONSTANT_MethodHandleInError}, {@code JVM_CONSTANT_MethodType} and
* {@code JVM_CONSTANT_MethodTypeInError}.
* entry types: {@code JVM_CONSTANT_Dynamic}, {@code JVM_CONSTANT_String},
* {@code JVM_CONSTANT_MethodHandle}, {@code JVM_CONSTANT_MethodHandleInError},
* {@code JVM_CONSTANT_MethodType} and {@code JVM_CONSTANT_MethodTypeInError}.
*/
native HotSpotObjectConstantImpl resolvePossiblyCachedConstantInPool(HotSpotConstantPool constantPool, int cpi);
native JavaConstant resolvePossiblyCachedConstantInPool(HotSpotConstantPool constantPool, int cpi);

/**
* Gets the {@code JVM_CONSTANT_NameAndType} index from the entry at index {@code cpi} in
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, 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
@@ -140,6 +140,8 @@ public String toString() {
final JvmConstant jvmMethodType = add(new JvmConstant(c.jvmConstantMethodType, "MethodType"));
final JvmConstant jvmMethodTypeInError = add(new JvmConstant(c.jvmConstantMethodTypeInError, "MethodTypeInError"));
final JvmConstant jvmInvokeDynamic = add(new JvmConstant(c.jvmConstantInvokeDynamic, "InvokeDynamic"));
final JvmConstant jvmDynamic = add(new JvmConstant(c.jvmConstantDynamic, "Dynamic"));
final JvmConstant jvmDynamicInError = add(new JvmConstant(c.jvmConstantDynamicInError, "DynamicInError"));

private JvmConstant add(JvmConstant constant) {
table[indexOf(constant.tag)] = constant;
@@ -545,6 +547,8 @@ public Object lookupConstant(int cpi) {
case "MethodHandleInError":
case "MethodType":
case "MethodTypeInError":
case "Dynamic":
case "DynamicInError":
return compilerToVM().resolvePossiblyCachedConstantInPool(this, cpi);
default:
throw new JVMCIError("Unknown constant pool tag %s", tag);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, 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
@@ -255,6 +255,8 @@ long arrayPrototypeMarkWord() {
final int jvmConstantMethodHandleInError = getConstant("JVM_CONSTANT_MethodHandleInError", Integer.class);
final int jvmConstantMethodType = getConstant("JVM_CONSTANT_MethodType", Integer.class);
final int jvmConstantMethodTypeInError = getConstant("JVM_CONSTANT_MethodTypeInError", Integer.class);
final int jvmConstantDynamic = getConstant("JVM_CONSTANT_Dynamic", Integer.class);
final int jvmConstantDynamicInError = getConstant("JVM_CONSTANT_DynamicInError", Integer.class);
final int jvmConstantInvokeDynamic = getConstant("JVM_CONSTANT_InvokeDynamic", Integer.class);

final int jvmConstantExternalMax = getConstant("JVM_CONSTANT_ExternalMax", Integer.class);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2021, 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
@@ -46,6 +46,7 @@
PrimitiveConstant DOUBLE_1 = new PrimitiveConstant(JavaKind.Double, Double.doubleToRawLongBits(1.0D));
PrimitiveConstant TRUE = new PrimitiveConstant(JavaKind.Boolean, 1L);
PrimitiveConstant FALSE = new PrimitiveConstant(JavaKind.Boolean, 0L);
PrimitiveConstant ILLEGAL = new PrimitiveConstant(JavaKind.Illegal, 0);

/**
* Returns the Java kind of this constant.
@@ -329,7 +330,7 @@ static PrimitiveConstant forBoxedPrimitive(Object value) {
}

static PrimitiveConstant forIllegal() {
return new PrimitiveConstant(JavaKind.Illegal, 0);
return JavaConstant.ILLEGAL;
}

/**
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2021, 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
@@ -473,7 +473,7 @@ public int getBitCount() {
case Long:
return 64;
default:
throw new IllegalArgumentException("illegal call to bits on " + this);
throw new IllegalArgumentException("illegal call to getBitCount() on " + this);
}
}
}
Loading