Skip to content

Commit ece77ee

Browse files
committed
added JVMCI support for parameter annotations
1 parent 16f4b8d commit ece77ee

File tree

17 files changed

+309
-97
lines changed

17 files changed

+309
-97
lines changed

src/hotspot/share/classfile/vmSymbols.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ class SerializeClosure;
706706
template(encodeThrowable_signature, "(Ljava/lang/Throwable;JI)I") \
707707
template(decodeAndThrowThrowable_name, "decodeAndThrowThrowable") \
708708
template(encodeAnnotations_name, "encodeAnnotations") \
709-
template(encodeAnnotations_signature, "([BZLjava/lang/Class;Ljdk/internal/reflect/ConstantPool;[Ljava/lang/Class;)[B")\
709+
template(encodeAnnotations_signature, "([BILjava/lang/Class;Ljdk/internal/reflect/ConstantPool;[Ljava/lang/Class;)[B")\
710710
template(decodeAndThrowThrowable_signature, "(IJZZ)V") \
711711
template(classRedefinedCount_name, "classRedefinedCount") \
712712
template(classLoader_name, "classLoader") \

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3015,7 +3015,7 @@ C2V_VMENTRY_NULL(jobject, asReflectionField, (JNIEnv* env, jobject, ARGUMENT_PAI
30153015
C2V_END
30163016

30173017
static jbyteArray get_encoded_annotation_values(InstanceKlass* holder, AnnotationArray* annotations_array,
3018-
jboolean is_type_annotations,
3018+
jint category,
30193019
jint filter_length, jlong filter_klass_pointers,
30203020
JavaThread* THREAD, JVMCI_TRAPS) {
30213021
// Get a ConstantPool object for annotation parsing
@@ -3050,7 +3050,7 @@ static jbyteArray get_encoded_annotation_values(InstanceKlass* holder, Annotatio
30503050
JavaValue result(T_OBJECT);
30513051
JavaCallArguments args;
30523052
args.push_oop(annotations);
3053-
args.push_int(is_type_annotations);
3053+
args.push_int(category);
30543054
args.push_oop(Handle(THREAD, holder->java_mirror()));
30553055
args.push_oop(jcp);
30563056
args.push_oop(filter_classes);
@@ -3081,29 +3081,54 @@ static jbyteArray get_encoded_annotation_values(InstanceKlass* holder, Annotatio
30813081
return JVMCIENV->get_jbyteArray(ba_dest);
30823082
}
30833083

3084-
C2V_VMENTRY_NULL(jbyteArray, getEncodedClassAnnotationValues, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jboolean is_type_annotations,
3084+
C2V_VMENTRY_NULL(jbyteArray, getEncodedClassAnnotationValues, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint category,
30853085
jobject filter, jint filter_length, jlong filter_klass_pointers))
30863086
CompilerThreadCanCallJava canCallJava(thread, true); // Requires Java support
30873087
InstanceKlass* holder = InstanceKlass::cast(UNPACK_PAIR(Klass, klass));
3088-
AnnotationArray* raw_annotations = is_type_annotations ? holder->class_type_annotations() : holder->class_annotations();
3089-
return get_encoded_annotation_values(holder, raw_annotations, is_type_annotations, filter_length, filter_klass_pointers, THREAD, JVMCIENV);
3088+
AnnotationArray* raw_annotations;
3089+
if (category == CompilerToVM::DECLARED_ANNOTATIONS) {
3090+
raw_annotations = holder->class_annotations();
3091+
} else if (category == CompilerToVM::TYPE_ANNOTATIONS) {
3092+
raw_annotations = holder->class_type_annotations();
3093+
} else {
3094+
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
3095+
err_msg("%d", category));
3096+
}
3097+
return get_encoded_annotation_values(holder, raw_annotations, category, filter_length, filter_klass_pointers, THREAD, JVMCIENV);
30903098
C2V_END
30913099

3092-
C2V_VMENTRY_NULL(jbyteArray, getEncodedExecutableAnnotationValues, (JNIEnv* env, jobject, ARGUMENT_PAIR(method), jboolean is_type_annotations,
3100+
C2V_VMENTRY_NULL(jbyteArray, getEncodedExecutableAnnotationValues, (JNIEnv* env, jobject, ARGUMENT_PAIR(method), jint category,
30933101
jobject filter, jint filter_length, jlong filter_klass_pointers))
30943102
CompilerThreadCanCallJava canCallJava(thread, true); // Requires Java support
30953103
methodHandle method(THREAD, UNPACK_PAIR(Method, method));
3096-
AnnotationArray* raw_annotations = is_type_annotations ? method->type_annotations() : method->annotations();
3097-
return get_encoded_annotation_values(method->method_holder(), raw_annotations, is_type_annotations, filter_length, filter_klass_pointers, THREAD, JVMCIENV);
3104+
AnnotationArray* raw_annotations;
3105+
if (category == CompilerToVM::DECLARED_ANNOTATIONS) {
3106+
raw_annotations = method->annotations();
3107+
} else if (category == CompilerToVM::PARAMETER_ANNOTATIONS) {
3108+
raw_annotations = method->parameter_annotations();
3109+
} else if (category == CompilerToVM::TYPE_ANNOTATIONS) {
3110+
raw_annotations = method->type_annotations();
3111+
} else {
3112+
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), err_msg("%d", category));
3113+
}
3114+
return get_encoded_annotation_values(method->method_holder(), raw_annotations, category, filter_length, filter_klass_pointers, THREAD, JVMCIENV);
30983115
C2V_END
30993116

3100-
C2V_VMENTRY_NULL(jbyteArray, getEncodedFieldAnnotationValues, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint index, jboolean is_type_annotations,
3117+
C2V_VMENTRY_NULL(jbyteArray, getEncodedFieldAnnotationValues, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint index, jint category,
31013118
jobject filter, jint filter_length, jlong filter_klass_pointers))
31023119
CompilerThreadCanCallJava canCallJava(thread, true); // Requires Java support
31033120
InstanceKlass* holder = check_field(InstanceKlass::cast(UNPACK_PAIR(Klass, klass)), index, JVMCI_CHECK_NULL);
31043121
fieldDescriptor fd(holder, index);
3105-
AnnotationArray* raw_annotations = is_type_annotations ? fd.type_annotations() : fd.annotations();
3106-
return get_encoded_annotation_values(holder, raw_annotations, is_type_annotations, filter_length, filter_klass_pointers, THREAD, JVMCIENV);
3122+
AnnotationArray* raw_annotations;
3123+
if (category == CompilerToVM::DECLARED_ANNOTATIONS) {
3124+
raw_annotations = fd.annotations();
3125+
} else if (category == CompilerToVM::TYPE_ANNOTATIONS) {
3126+
raw_annotations = fd.type_annotations();
3127+
} else {
3128+
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
3129+
err_msg("%d", category));
3130+
}
3131+
return get_encoded_annotation_values(holder, raw_annotations, category, filter_length, filter_klass_pointers, THREAD, JVMCIENV);
31073132
C2V_END
31083133

31093134
C2V_VMENTRY_NULL(jobjectArray, getFailedSpeculations, (JNIEnv* env, jobject, jlong failed_speculations_address, jobjectArray current))
@@ -3447,9 +3472,9 @@ JNINativeMethod CompilerToVM::methods[] = {
34473472
{CC "getCode", CC "(" HS_INSTALLED_CODE ")[B", FN_PTR(getCode)},
34483473
{CC "asReflectionExecutable", CC "(" HS_METHOD2 ")" REFLECTION_EXECUTABLE, FN_PTR(asReflectionExecutable)},
34493474
{CC "asReflectionField", CC "(" HS_KLASS2 "I)" REFLECTION_FIELD, FN_PTR(asReflectionField)},
3450-
{CC "getEncodedClassAnnotationValues", CC "(" HS_KLASS2 "Z" OBJECT "IJ)[B", FN_PTR(getEncodedClassAnnotationValues)},
3451-
{CC "getEncodedExecutableAnnotationValues", CC "(" HS_METHOD2 "Z" OBJECT "IJ)[B", FN_PTR(getEncodedExecutableAnnotationValues)},
3452-
{CC "getEncodedFieldAnnotationValues", CC "(" HS_KLASS2 "IZ" OBJECT "IJ)[B", FN_PTR(getEncodedFieldAnnotationValues)},
3475+
{CC "getEncodedClassAnnotationValues", CC "(" HS_KLASS2 "I" OBJECT "IJ)[B", FN_PTR(getEncodedClassAnnotationValues)},
3476+
{CC "getEncodedExecutableAnnotationValues", CC "(" HS_METHOD2 "I" OBJECT "IJ)[B", FN_PTR(getEncodedExecutableAnnotationValues)},
3477+
{CC "getEncodedFieldAnnotationValues", CC "(" HS_KLASS2 "II" OBJECT "IJ)[B", FN_PTR(getEncodedFieldAnnotationValues)},
34533478
{CC "getFailedSpeculations", CC "(J[[B)[[B", FN_PTR(getFailedSpeculations)},
34543479
{CC "getFailedSpeculationsAddress", CC "(" HS_METHOD2 ")J", FN_PTR(getFailedSpeculationsAddress)},
34553480
{CC "releaseFailedSpeculations", CC "(J)V", FN_PTR(releaseFailedSpeculations)},

src/hotspot/share/jvmci/jvmciCompilerToVM.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class JVMCIObjectArray;
3535

3636
class CompilerToVM {
3737
public:
38+
// Keep in sync with constants in VMSupport.java
39+
static const int DECLARED_ANNOTATIONS = 0;
40+
static const int PARAMETER_ANNOTATIONS = 1;
41+
static const int TYPE_ANNOTATIONS = 2;
42+
3843
class Data {
3944
friend class JVMCIVMStructs;
4045

src/hotspot/share/jvmci/jvmciJavaClasses.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ void JNIJVMCI::initialize_field_id(JNIEnv* env, jfieldID &fieldid, jclass clazz,
403403
GET_JNI_CONSTRUCTOR(className, signature)
404404

405405
extern "C" {
406-
void JNICALL JVM_RegisterJVMCINatives(JNIEnv *env, jclass compilerToVMClass);
406+
void JNICALL JVM_RegisterJVMCINatives(JNIEnv *env, jclass compilerToVMClass, jint declaredAnnotations, jint parameterAnnotations, jint typeAnnotations);
407407
jobject JNICALL JVM_GetJVMCIRuntime(JNIEnv *env, jclass c);
408408
jlong JNICALL JVM_ReadSystemPropertiesInfo(JNIEnv *env, jclass c, jintArray offsets_handle);
409409
}
@@ -564,7 +564,7 @@ static void register_natives_for_class(JNIEnv* env, jclass clazz, const char* na
564564

565565
void JNIJVMCI::register_natives(JNIEnv* env) {
566566
if (env != JavaThread::current()->jni_environment()) {
567-
JNINativeMethod CompilerToVM_nmethods[] = {{ CC"registerNatives", CC"()V", FN_PTR(JVM_RegisterJVMCINatives) }};
567+
JNINativeMethod CompilerToVM_nmethods[] = {{ CC"registerNatives", CC"(III)V", FN_PTR(JVM_RegisterJVMCINatives) }};
568568
JNINativeMethod JVMCI_nmethods[] = {{ CC"initializeRuntime", CC"()Ljdk/vm/ci/runtime/JVMCIRuntime;", FN_PTR(JVM_GetJVMCIRuntime) }};
569569
JNINativeMethod Services_nmethods[] = {{ CC"readSystemPropertiesInfo", CC"([I)J", FN_PTR(JVM_ReadSystemPropertiesInfo) }};
570570

src/hotspot/share/jvmci/jvmciRuntime.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,9 +1512,14 @@ JVMCIObject JVMCIRuntime::get_HotSpotJVMCIRuntime(JVMCI_TRAPS) {
15121512

15131513
// Implementation of CompilerToVM.registerNatives()
15141514
// When called from libjvmci, `libjvmciOrHotspotEnv` is a libjvmci env so use JVM_ENTRY_NO_ENV.
1515-
JVM_ENTRY_NO_ENV(void, JVM_RegisterJVMCINatives(JNIEnv *libjvmciOrHotspotEnv, jclass c2vmClass))
1515+
JVM_ENTRY_NO_ENV(void, JVM_RegisterJVMCINatives(JNIEnv *libjvmciOrHotspotEnv, jclass c2vmClass,
1516+
jint declaredAnnotations, jint parameterAnnotations, jint typeAnnotations))
15161517
JVMCIENV_FROM_JNI(thread, libjvmciOrHotspotEnv);
15171518

1519+
assert(CompilerToVM::DECLARED_ANNOTATIONS == declaredAnnotations, "%d != %d", CompilerToVM::DECLARED_ANNOTATIONS, declaredAnnotations);
1520+
assert(CompilerToVM::PARAMETER_ANNOTATIONS == parameterAnnotations, "%d != %d", CompilerToVM::PARAMETER_ANNOTATIONS, parameterAnnotations);
1521+
assert(CompilerToVM::TYPE_ANNOTATIONS == typeAnnotations, "%d != %d", CompilerToVM::TYPE_ANNOTATIONS, typeAnnotations);
1522+
15181523
if (!EnableJVMCI) {
15191524
JVMCI_THROW_MSG(InternalError, JVMCI_NOT_ENABLED_ERROR_MESSAGE);
15201525
}

src/hotspot/share/prims/nativeLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ extern "C" {
210210
#if INCLUDE_JVMCI
211211
jobject JNICALL JVM_GetJVMCIRuntime(JNIEnv *env, jclass c);
212212
jlong JNICALL JVM_ReadSystemPropertiesInfo(JNIEnv *env, jclass c, jintArray offsets);
213-
void JNICALL JVM_RegisterJVMCINatives(JNIEnv *env, jclass compilerToVMClass);
213+
void JNICALL JVM_RegisterJVMCINatives(JNIEnv *env, jclass compilerToVMClass, jint declaredAnnotations, jint parameterAnnotations, jint typeAnnotations);
214214
#endif
215215
}
216216

0 commit comments

Comments
 (0)