提交 d213e7bb 编写于 作者: A acorn

8026022: Verifier: allow anon classes to invokespecial host class/intf methods.

Reviewed-by: coleenp, bharadwaj
上级 5b188c9d
......@@ -2441,6 +2441,11 @@ void ClassVerifier::verify_invoke_instructions(
current_class()->super()->name()))) {
bool subtype = ref_class_type.is_assignable_from(
current_type(), this, CHECK_VERIFY(this));
if (!subtype) {
if (current_class()->is_anonymous()) {
subtype = ref_class_type.is_assignable_from(VerificationType::reference_type(
current_class()->host_klass()->name()), this, CHECK_VERIFY(this));
}
if (!subtype) {
verify_error(ErrorContext::bad_code(bci),
"Bad invokespecial instruction: "
......@@ -2448,6 +2453,7 @@ void ClassVerifier::verify_invoke_instructions(
return;
}
}
}
// Match method descriptor with operand stack
for (int i = nargs - 1; i >= 0; i--) { // Run backwards
current_frame->pop_stack(sig_types[i], CHECK_VERIFY(this));
......@@ -2461,7 +2467,28 @@ void ClassVerifier::verify_invoke_instructions(
} else { // other methods
// Ensures that target class is assignable to method class.
if (opcode == Bytecodes::_invokespecial) {
if (!current_class()->is_anonymous()) {
current_frame->pop_stack(current_type(), CHECK_VERIFY(this));
} else {
// anonymous class invokespecial calls: either the
// operand stack/objectref is a subtype of the current class OR
// the objectref is a subtype of the host_klass of the current class
// to allow an anonymous class to reference methods in the host_klass
VerificationType top = current_frame->pop_stack(CHECK_VERIFY(this));
bool subtype = current_type().is_assignable_from(top, this, CHECK_VERIFY(this));
if (!subtype) {
VerificationType hosttype =
VerificationType::reference_type(current_class()->host_klass()->name());
subtype = hosttype.is_assignable_from(top, this, CHECK_VERIFY(this));
}
if (!subtype) {
verify_error( ErrorContext::bad_type(current_frame->offset(),
current_frame->stack_top_ctx(),
TypeOrigin::implicit(top)),
"Bad type on operand stack");
return;
}
}
} else if (opcode == Bytecodes::_invokevirtual) {
VerificationType stack_object_type =
current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册