mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-23 04:24:49 +02:00
8016839: JSR292: AME instead of IAE when calling a method
Catch missing-because-illegal case for itable entries and use an exception-throwing method instead of null. Reviewed-by: acorn, jrose, coleenp
This commit is contained in:
parent
3646381ba6
commit
78f1afbf45
14 changed files with 763 additions and 65 deletions
|
@ -165,6 +165,7 @@ class SymbolPropertyTable;
|
|||
\
|
||||
do_klass(StringBuffer_klass, java_lang_StringBuffer, Pre ) \
|
||||
do_klass(StringBuilder_klass, java_lang_StringBuilder, Pre ) \
|
||||
do_klass(misc_Unsafe_klass, sun_misc_Unsafe, Pre ) \
|
||||
\
|
||||
/* It's NULL in non-1.4 JDKs. */ \
|
||||
do_klass(StackTraceElement_klass, java_lang_StackTraceElement, Opt ) \
|
||||
|
|
|
@ -331,6 +331,7 @@
|
|||
template(findNative_name, "findNative") \
|
||||
template(deadChild_name, "deadChild") \
|
||||
template(addClass_name, "addClass") \
|
||||
template(throwIllegalAccessError_name, "throwIllegalAccessError") \
|
||||
template(getFromClass_name, "getFromClass") \
|
||||
template(dispatch_name, "dispatch") \
|
||||
template(getSystemClassLoader_name, "getSystemClassLoader") \
|
||||
|
|
|
@ -120,6 +120,7 @@ oop Universe::_null_ptr_exception_instance = NULL;
|
|||
oop Universe::_arithmetic_exception_instance = NULL;
|
||||
oop Universe::_virtual_machine_error_instance = NULL;
|
||||
oop Universe::_vm_exception = NULL;
|
||||
Method* Universe::_throw_illegal_access_error = NULL;
|
||||
Array<int>* Universe::_the_empty_int_array = NULL;
|
||||
Array<u2>* Universe::_the_empty_short_array = NULL;
|
||||
Array<Klass*>* Universe::_the_empty_klass_array = NULL;
|
||||
|
@ -1096,6 +1097,18 @@ bool universe_post_init() {
|
|||
Universe::_finalizer_register_cache->init(
|
||||
SystemDictionary::Finalizer_klass(), m);
|
||||
|
||||
InstanceKlass::cast(SystemDictionary::misc_Unsafe_klass())->link_class(CHECK_false);
|
||||
m = InstanceKlass::cast(SystemDictionary::misc_Unsafe_klass())->find_method(
|
||||
vmSymbols::throwIllegalAccessError_name(),
|
||||
vmSymbols::void_method_signature());
|
||||
if (m != NULL && !m->is_static()) {
|
||||
// Note null is okay; this method is used in itables, and if it is null,
|
||||
// then AbstractMethodError is thrown instead.
|
||||
tty->print_cr("Unable to link/verify Unsafe.throwIllegalAccessError method");
|
||||
return false; // initialization failed (cannot throw exception yet)
|
||||
}
|
||||
Universe::_throw_illegal_access_error = m;
|
||||
|
||||
// Setup method for registering loaded classes in class loader vector
|
||||
InstanceKlass::cast(SystemDictionary::ClassLoader_klass())->link_class(CHECK_false);
|
||||
m = InstanceKlass::cast(SystemDictionary::ClassLoader_klass())->find_method(vmSymbols::addClass_name(), vmSymbols::class_void_signature());
|
||||
|
|
|
@ -149,6 +149,8 @@ class Universe: AllStatic {
|
|||
static LatestMethodCache* _loader_addClass_cache; // method for registering loaded classes in class loader vector
|
||||
static LatestMethodCache* _pd_implies_cache; // method for checking protection domain attributes
|
||||
|
||||
static Method* _throw_illegal_access_error;
|
||||
|
||||
// preallocated error objects (no backtrace)
|
||||
static oop _out_of_memory_error_java_heap;
|
||||
static oop _out_of_memory_error_metaspace;
|
||||
|
@ -305,6 +307,7 @@ class Universe: AllStatic {
|
|||
static oop arithmetic_exception_instance() { return _arithmetic_exception_instance; }
|
||||
static oop virtual_machine_error_instance() { return _virtual_machine_error_instance; }
|
||||
static oop vm_exception() { return _vm_exception; }
|
||||
static Method* throw_illegal_access_error() { return _throw_illegal_access_error; }
|
||||
|
||||
static Array<int>* the_empty_int_array() { return _the_empty_int_array; }
|
||||
static Array<u2>* the_empty_short_array() { return _the_empty_short_array; }
|
||||
|
|
|
@ -1076,7 +1076,12 @@ void klassItable::initialize_itable_for_interface(int method_table_offset, Klass
|
|||
LinkResolver::lookup_instance_method_in_klasses(target, _klass, m->name(), m->signature(), CHECK);
|
||||
}
|
||||
if (target == NULL || !target->is_public() || target->is_abstract()) {
|
||||
// Entry do not resolve. Leave it empty
|
||||
// Entry does not resolve. Leave it empty for AbstractMethodError.
|
||||
if (!(target == NULL) && !target->is_public()) {
|
||||
// Stuff an IllegalAccessError throwing method in there instead.
|
||||
itableOffsetEntry::method_entry(_klass(), method_table_offset)[m->itable_index()].
|
||||
initialize(Universe::throw_illegal_access_error());
|
||||
}
|
||||
} else {
|
||||
// Entry did resolve, check loader constraints before initializing
|
||||
// if checkconstraints requested
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue