Skip to content

Commit a5c50a0

Browse files
committed
added support for annotation member default values
1 parent 2701301 commit a5c50a0

File tree

22 files changed

+429
-300
lines changed

22 files changed

+429
-300
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, "([BILjava/lang/Class;Ljdk/internal/reflect/ConstantPool;)[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: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3014,8 +3014,9 @@ C2V_VMENTRY_NULL(jobject, asReflectionField, (JNIEnv* env, jobject, ARGUMENT_PAI
30143014
return JNIHandles::make_local(THREAD, reflected);
30153015
C2V_END
30163016

3017-
static jbyteArray get_encoded_annotation_values(InstanceKlass* holder, AnnotationArray* annotations_array, jint category,
3018-
JavaThread* THREAD, JVMCI_TRAPS) {
3017+
static jbyteArray get_encoded_annotation_values(InstanceKlass* holder, AnnotationArray* annotations_array,
3018+
jint category, Klass* memberType,
3019+
JavaThread* THREAD, JVMCI_TRAPS) {
30193020
// Get a ConstantPool object for annotation parsing
30203021
Handle jcp = reflect_ConstantPool::create(CHECK_NULL);
30213022
reflect_ConstantPool::set_cp(jcp(), holder->constants());
@@ -3031,6 +3032,10 @@ static jbyteArray get_encoded_annotation_values(InstanceKlass* holder, Annotatio
30313032

30323033
typeArrayOop annotations_oop = Annotations::make_java_array(annotations_array, CHECK_NULL);
30333034
typeArrayHandle annotations = typeArrayHandle(THREAD, annotations_oop);
3035+
Handle memberTypeMirror;
3036+
if (memberType != nullptr) {
3037+
memberTypeMirror = Handle(THREAD, memberType->java_mirror());
3038+
}
30343039

30353040
// invoke VMSupport.encodeAnnotations
30363041
JavaValue result(T_OBJECT);
@@ -3039,6 +3044,7 @@ static jbyteArray get_encoded_annotation_values(InstanceKlass* holder, Annotatio
30393044
args.push_int(category);
30403045
args.push_oop(Handle(THREAD, holder->java_mirror()));
30413046
args.push_oop(jcp);
3047+
args.push_oop(memberTypeMirror);
30423048
Symbol* signature = vmSymbols::encodeAnnotations_signature();
30433049
JavaCalls::call_static(&result,
30443050
vm_support,
@@ -3078,23 +3084,27 @@ C2V_VMENTRY_NULL(jbyteArray, getEncodedClassAnnotationValues, (JNIEnv* env, jobj
30783084
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
30793085
err_msg("%d", category));
30803086
}
3081-
return get_encoded_annotation_values(holder, raw_annotations, category, THREAD, JVMCIENV);
3087+
return get_encoded_annotation_values(holder, raw_annotations, category, nullptr, THREAD, JVMCIENV);
30823088
C2V_END
30833089

3084-
C2V_VMENTRY_NULL(jbyteArray, getEncodedExecutableAnnotationValues, (JNIEnv* env, jobject, ARGUMENT_PAIR(method), jint category))
3090+
C2V_VMENTRY_NULL(jbyteArray, getEncodedExecutableAnnotationValues, (JNIEnv* env, jobject, ARGUMENT_PAIR(method), ARGUMENT_PAIR(memberTypeKlass), jint category))
30853091
CompilerThreadCanCallJava canCallJava(thread, true); // Requires Java support
30863092
methodHandle method(THREAD, UNPACK_PAIR(Method, method));
30873093
AnnotationArray* raw_annotations;
3094+
Klass* memberType = nullptr;
30883095
if (category == CompilerToVM::DECLARED_ANNOTATIONS) {
30893096
raw_annotations = method->annotations();
30903097
} else if (category == CompilerToVM::PARAMETER_ANNOTATIONS) {
30913098
raw_annotations = method->parameter_annotations();
30923099
} else if (category == CompilerToVM::TYPE_ANNOTATIONS) {
30933100
raw_annotations = method->type_annotations();
3101+
} else if (category == CompilerToVM::ANNOTATION_MEMBER_VALUE) {
3102+
raw_annotations = method->annotation_default();
3103+
memberType = UNPACK_PAIR(Klass, memberTypeKlass);
30943104
} else {
30953105
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), err_msg("%d", category));
30963106
}
3097-
return get_encoded_annotation_values(method->method_holder(), raw_annotations, category, THREAD, JVMCIENV);
3107+
return get_encoded_annotation_values(method->method_holder(), raw_annotations, category, memberType, THREAD, JVMCIENV);
30983108
C2V_END
30993109

31003110
C2V_VMENTRY_NULL(jbyteArray, getEncodedFieldAnnotationValues, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint index, jint category))
@@ -3110,7 +3120,7 @@ C2V_VMENTRY_NULL(jbyteArray, getEncodedFieldAnnotationValues, (JNIEnv* env, jobj
31103120
THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
31113121
err_msg("%d", category));
31123122
}
3113-
return get_encoded_annotation_values(holder, raw_annotations, category, THREAD, JVMCIENV);
3123+
return get_encoded_annotation_values(holder, raw_annotations, category, nullptr, THREAD, JVMCIENV);
31143124
C2V_END
31153125

31163126
C2V_VMENTRY_NULL(jobjectArray, getFailedSpeculations, (JNIEnv* env, jobject, jlong failed_speculations_address, jobjectArray current))
@@ -3455,7 +3465,7 @@ JNINativeMethod CompilerToVM::methods[] = {
34553465
{CC "asReflectionExecutable", CC "(" HS_METHOD2 ")" REFLECTION_EXECUTABLE, FN_PTR(asReflectionExecutable)},
34563466
{CC "asReflectionField", CC "(" HS_KLASS2 "I)" REFLECTION_FIELD, FN_PTR(asReflectionField)},
34573467
{CC "getEncodedClassAnnotationValues", CC "(" HS_KLASS2 "I)[B", FN_PTR(getEncodedClassAnnotationValues)},
3458-
{CC "getEncodedExecutableAnnotationValues", CC "(" HS_METHOD2 "I)[B", FN_PTR(getEncodedExecutableAnnotationValues)},
3468+
{CC "getEncodedExecutableAnnotationValues", CC "(" HS_METHOD2 HS_KLASS2 "I)[B", FN_PTR(getEncodedExecutableAnnotationValues)},
34593469
{CC "getEncodedFieldAnnotationValues", CC "(" HS_KLASS2 "II)[B", FN_PTR(getEncodedFieldAnnotationValues)},
34603470
{CC "getFailedSpeculations", CC "(J[[B)[[B", FN_PTR(getFailedSpeculations)},
34613471
{CC "getFailedSpeculationsAddress", CC "(" HS_METHOD2 ")J", FN_PTR(getFailedSpeculationsAddress)},

src/hotspot/share/jvmci/jvmciCompilerToVM.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class CompilerToVM {
3939
static const int DECLARED_ANNOTATIONS = 0;
4040
static const int PARAMETER_ANNOTATIONS = 1;
4141
static const int TYPE_ANNOTATIONS = 2;
42+
static const int ANNOTATION_MEMBER_VALUE = 3;
4243

4344
class Data {
4445
friend class JVMCIVMStructs;

src/hotspot/share/jvmci/jvmciJavaClasses.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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"(III)V", FN_PTR(JVM_RegisterJVMCINatives) }};
567+
JNINativeMethod CompilerToVM_nmethods[] = {{ CC"registerNatives", CC"()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/jvmciJavaClasses.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@
233233
start_class(VMSupport, jdk_internal_vm_VMSupport) \
234234
jvmci_method(CallStaticIntMethod, GetStaticMethodID, call_static, int, VMSupport, encodeThrowable, encodeThrowable_signature) \
235235
jvmci_method(CallStaticVoidMethod, GetStaticMethodID, call_static, void, VMSupport, decodeAndThrowThrowable, decodeAndThrowThrowable_signature) \
236+
static_int_field(VMSupport, DECLARED_ANNOTATIONS) \
237+
static_int_field(VMSupport, PARAMETER_ANNOTATIONS) \
238+
static_int_field(VMSupport, TYPE_ANNOTATIONS) \
239+
static_int_field(VMSupport, ANNOTATION_MEMBER_VALUE) \
236240
end_class \
237241
start_class(ArrayIndexOutOfBoundsException, java_lang_ArrayIndexOutOfBoundsException) \
238242
jvmci_constructor(ArrayIndexOutOfBoundsException, "(Ljava/lang/String;)V") \

src/hotspot/share/jvmci/jvmciRuntime.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,15 +1510,22 @@ JVMCIObject JVMCIRuntime::get_HotSpotJVMCIRuntime(JVMCI_TRAPS) {
15101510
return _HotSpotJVMCIRuntime_instance;
15111511
}
15121512

1513+
#ifdef ASSERT
1514+
static void assert_equals(const char* desc, int expect, int actual) {
1515+
assert(expect == actual, "%s: %d != %d", desc, expect, actual);
1516+
1517+
}
1518+
#endif
1519+
15131520
// Implementation of CompilerToVM.registerNatives()
15141521
// 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,
1516-
jint declaredAnnotations, jint parameterAnnotations, jint typeAnnotations))
1522+
JVM_ENTRY_NO_ENV(void, JVM_RegisterJVMCINatives(JNIEnv *libjvmciOrHotspotEnv, jclass c2vmClass))
15171523
JVMCIENV_FROM_JNI(thread, libjvmciOrHotspotEnv);
15181524

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);
1525+
DEBUG_ONLY(assert_equals("DECLARED_ANNOTATIONS", CompilerToVM::DECLARED_ANNOTATIONS, JVMCIENV->get_VMSupport_DECLARED_ANNOTATIONS()));
1526+
DEBUG_ONLY(assert_equals("PARAMETER_ANNOTATIONS", CompilerToVM::PARAMETER_ANNOTATIONS, JVMCIENV->get_VMSupport_PARAMETER_ANNOTATIONS()));
1527+
DEBUG_ONLY(assert_equals("TYPE_ANNOTATIONS", CompilerToVM::TYPE_ANNOTATIONS, JVMCIENV->get_VMSupport_TYPE_ANNOTATIONSS()));
1528+
DEBUG_ONLY(assert_equals("ANNOTATION_MEMBER_VALUE", CompilerToVM::ANNOTATION_MEMBER_VALUE, JVMCIENV->get_VMSupport_ANNOTATION_MEMBER_VALUE()));
15221529

15231530
if (!EnableJVMCI) {
15241531
JVMCI_THROW_MSG(InternalError, JVMCI_NOT_ENABLED_ERROR_MESSAGE);

src/hotspot/share/jvmci/vmStructs_jvmci.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@
710710
declare_constant(ConstMethodFlags::_misc_has_exception_table) \
711711
declare_constant(ConstMethodFlags::_misc_has_method_annotations) \
712712
declare_constant(ConstMethodFlags::_misc_has_parameter_annotations) \
713+
declare_constant(ConstMethodFlags::_misc_has_default_annotations) \
713714
declare_constant(ConstMethodFlags::_misc_caller_sensitive) \
714715
declare_constant(ConstMethodFlags::_misc_is_hidden) \
715716
declare_constant(ConstMethodFlags::_misc_intrinsic_candidate) \

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, jint declaredAnnotations, jint parameterAnnotations, jint typeAnnotations);
213+
void JNICALL JVM_RegisterJVMCINatives(JNIEnv *env, jclass compilerToVMClass);
214214
#endif
215215
}
216216

0 commit comments

Comments
 (0)