Skip to content

Commit 187da56

Browse files
committed
hotspot: Fix verifier error
1 parent a9fbc15 commit 187da56

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

src/hotspot/share/classfile/verificationType.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ bool VerificationType::resolve_and_check_assignability(InstanceKlass* current_kl
8282
target_klass == vmClasses::Serializable_klass();
8383
} else if (from_is_object) {
8484
Klass* from_klass;
85+
#if HOTSPOT_TARGET_CLASSLIB == 8
86+
if (current_klass->name() == from_name) {
87+
#else
8588
if (current_klass->is_hidden() && current_klass->name() == from_name) {
89+
#endif
8690
from_klass = current_klass;
8791
} else {
8892
from_klass = SystemDictionary::resolve_or_fail(

src/hotspot/share/classfile/verifier.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,15 @@ bool Verifier::relax_access_for(oop loader) {
132132
// or pass true for redefinition of any class.
133133
static bool is_eligible_for_verification(InstanceKlass* klass, bool should_verify_class) {
134134
Symbol* name = klass->name();
135+
#if HOTSPOT_TARGET_CLASSLIB == 8
136+
Klass* refl_magic_klass = vmClasses::reflect_MagicAccessorImpl_klass();
135137

138+
bool is_reflect = refl_magic_klass != nullptr && klass->is_subtype_of(refl_magic_klass);
139+
140+
return (should_verify_class && (!is_reflect) &&
141+
#else
136142
return (should_verify_class &&
143+
#endif
137144
// Can not verify the bytecodes for shared classes because they have
138145
// already been rewritten to contain constant pool cache indices,
139146
// which the verifier can't understand.
@@ -2911,8 +2918,20 @@ void ClassVerifier::verify_invoke_instructions(
29112918
// and we loaded the class. For any other "true" returns (e.g. same class
29122919
// or Object) we either can't get here (same class already excluded above)
29132920
// or we know it is not an interface (i.e. Object).
2921+
#if HOTSPOT_TARGET_CLASSLIB == 8
2922+
bool subtype = false;
2923+
if (!current_class()->is_hidden()) {
2924+
subtype = ref_class_type.is_reference_assignable_from(current_type(), this, false,
2925+
&is_interface, CHECK_VERIFY(this));
2926+
} else {
2927+
VerificationType host_klass_type =
2928+
VerificationType::reference_type(current_class()->nest_host(THREAD)->name());
2929+
subtype = ref_class_type.is_assignable_from(host_klass_type, this, false, CHECK_VERIFY(this));
2930+
}
2931+
#else
29142932
bool subtype = ref_class_type.is_reference_assignable_from(current_type(), this, false,
29152933
&is_interface, CHECK_VERIFY(this));
2934+
#endif
29162935
if (!subtype) { // Totally unrelated class
29172936
verify_error(ErrorContext::bad_code(bci),
29182937
"Bad invokespecial instruction: "
@@ -2950,7 +2969,28 @@ void ClassVerifier::verify_invoke_instructions(
29502969
} else { // other methods
29512970
// Ensures that target class is assignable to method class.
29522971
if (opcode == Bytecodes::_invokespecial) {
2972+
#if HOTSPOT_TARGET_CLASSLIB == 8
2973+
if (!current_class()->is_hidden()) {
2974+
current_frame->pop_stack(current_type(), CHECK_VERIFY(this));
2975+
} else {
2976+
// anonymous class invokespecial calls: check if the
2977+
// objectref is a subtype of the host_klass of the current class
2978+
// to allow an anonymous class to reference methods in the host_klass
2979+
VerificationType top = current_frame->pop_stack(CHECK_VERIFY(this));
2980+
VerificationType hosttype =
2981+
VerificationType::reference_type(current_class()->nest_host(THREAD)->name());
2982+
bool subtype = hosttype.is_assignable_from(top, this, false, CHECK_VERIFY(this));
2983+
if (!subtype) {
2984+
verify_error( ErrorContext::bad_type(current_frame->offset(),
2985+
current_frame->stack_top_ctx(),
2986+
TypeOrigin::implicit(top)),
2987+
"Bad type on operand stack");
2988+
return;
2989+
}
2990+
}
2991+
#else
29532992
current_frame->pop_stack(current_type(), CHECK_VERIFY(this));
2993+
#endif
29542994
} else if (opcode == Bytecodes::_invokevirtual) {
29552995
VerificationType stack_object_type =
29562996
current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));

src/hotspot/share/classfile/vmClassMacros.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
do_klass(reflect_ConstantPool_klass, reflect_ConstantPool ) \
107107
do_klass(reflect_CallerSensitive_klass, reflect_CallerSensitive ) \
108108
do_klass(reflect_DirectConstructorHandleAccessor_NativeAccessor_klass, reflect_DirectConstructorHandleAccessor_NativeAccessor) \
109+
do_klass(reflect_MagicAccessorImpl_klass, reflect_MagicAccessorImpl ) \
109110
\
110111
/* support for dynamic typing */ \
111112
do_klass(DirectMethodHandle_klass, java_lang_invoke_DirectMethodHandle ) \

src/hotspot/share/classfile/vmSymbols.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class SerializeClosure;
6464
template(reflect_MethodAccessorImpl, "sun/reflect/MethodAccessorImpl") \
6565
template(reflect_CallerSensitive, "sun/reflect/CallerSensitive") \
6666
template(reflect_CallerSensitive_signature, "Lsun/reflect/CallerSensitive;") \
67+
template(reflect_MagicAccessorImpl, "sun/reflect/MagicAccessorImpl") \
6768
template(vmloader_name, "vmloader") \
6869
template(java_security_PrivilegedActionException, "java/security/PrivilegedActionException") \
6970
template(exception_void_signature, "(Ljava/lang/Exception;)V") \

src/hotspot/share/interpreter/linkResolver.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,18 @@ Method* LinkResolver::linktime_resolve_special_method(const LinkInfo& link_info,
12161216
Klass* current_klass = link_info.current_klass();
12171217
if (current_klass != nullptr && resolved_klass->is_interface()) {
12181218
InstanceKlass* klass_to_check = InstanceKlass::cast(current_klass);
1219+
#if HOTSPOT_TARGET_CLASSLIB == 8
1220+
if (klass_to_check->is_hidden()) {
1221+
klass_to_check = klass_to_check->nest_host(THREAD);
1222+
}
1223+
// Disable verification for the dynamically-generated reflection bytecodes.
1224+
bool is_reflect = klass_to_check->is_subclass_of(
1225+
vmClasses::reflect_MagicAccessorImpl_klass());
1226+
if (!is_reflect &&
1227+
!klass_to_check->is_same_or_direct_interface(resolved_klass)) {
1228+
#else
12191229
if (!klass_to_check->is_same_or_direct_interface(resolved_klass)) {
1230+
#endif
12201231
ResourceMark rm(THREAD);
12211232
stringStream ss;
12221233
ss.print("Interface method reference: '");

0 commit comments

Comments
 (0)