mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8139163: InstanceKlass::cast passes through NULL
Reduce raw (InstanceKlass*) casts and InstanceKlass::cast, which no long allows null Reviewed-by: twisti, kbarrett
This commit is contained in:
parent
25cc742a8f
commit
5179fc3488
43 changed files with 215 additions and 252 deletions
|
@ -114,17 +114,17 @@ static bool find_field(InstanceKlass* ik,
|
|||
// Helpful routine for computing field offsets at run time rather than hardcoding them
|
||||
static void
|
||||
compute_offset(int &dest_offset,
|
||||
Klass* klass_oop, Symbol* name_symbol, Symbol* signature_symbol,
|
||||
Klass* klass, Symbol* name_symbol, Symbol* signature_symbol,
|
||||
bool is_static = false, bool allow_super = false) {
|
||||
fieldDescriptor fd;
|
||||
InstanceKlass* ik = InstanceKlass::cast(klass_oop);
|
||||
InstanceKlass* ik = InstanceKlass::cast(klass);
|
||||
if (!find_field(ik, name_symbol, signature_symbol, &fd, is_static, allow_super)) {
|
||||
ResourceMark rm;
|
||||
tty->print_cr("Invalid layout of %s at %s", ik->external_name(), name_symbol->as_C_string());
|
||||
#ifndef PRODUCT
|
||||
klass_oop->print();
|
||||
ik->print();
|
||||
tty->print_cr("all fields:");
|
||||
for (AllFieldStream fs(InstanceKlass::cast(klass_oop)); !fs.done(); fs.next()) {
|
||||
for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
|
||||
tty->print_cr(" name: %s, sig: %s, flags: %08x", fs.name()->as_C_string(), fs.signature()->as_C_string(), fs.access_flags().as_int());
|
||||
}
|
||||
#endif //PRODUCT
|
||||
|
@ -136,10 +136,10 @@ compute_offset(int &dest_offset,
|
|||
// Same as above but for "optional" offsets that might not be present in certain JDK versions
|
||||
static void
|
||||
compute_optional_offset(int& dest_offset,
|
||||
Klass* klass_oop, Symbol* name_symbol, Symbol* signature_symbol,
|
||||
Klass* klass, Symbol* name_symbol, Symbol* signature_symbol,
|
||||
bool allow_super = false) {
|
||||
fieldDescriptor fd;
|
||||
InstanceKlass* ik = InstanceKlass::cast(klass_oop);
|
||||
InstanceKlass* ik = InstanceKlass::cast(klass);
|
||||
if (find_field(ik, name_symbol, signature_symbol, &fd, allow_super)) {
|
||||
dest_offset = fd.offset();
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ Handle java_lang_String::basic_create(int length, TRAPS) {
|
|||
// Create the String object first, so there's a chance that the String
|
||||
// and the char array it points to end up in the same cache line.
|
||||
oop obj;
|
||||
obj = InstanceKlass::cast(SystemDictionary::String_klass())->allocate_instance(CHECK_NH);
|
||||
obj = SystemDictionary::String_klass()->allocate_instance(CHECK_NH);
|
||||
|
||||
// Create the char array. The String object must be handlized here
|
||||
// because GC can happen as a result of the allocation attempt.
|
||||
|
@ -1236,7 +1236,7 @@ void java_lang_ThreadGroup::compute_offsets() {
|
|||
}
|
||||
|
||||
oop java_lang_Throwable::unassigned_stacktrace() {
|
||||
InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::Throwable_klass());
|
||||
InstanceKlass* ik = SystemDictionary::Throwable_klass();
|
||||
address addr = ik->static_field_addr(static_unassigned_stacktrace_offset);
|
||||
if (UseCompressedOops) {
|
||||
return oopDesc::load_decode_heap_oop((narrowOop *)addr);
|
||||
|
@ -1293,7 +1293,7 @@ void java_lang_Throwable::print(oop throwable, outputStream* st) {
|
|||
ResourceMark rm;
|
||||
Klass* k = throwable->klass();
|
||||
assert(k != NULL, "just checking");
|
||||
st->print("%s", InstanceKlass::cast(k)->external_name());
|
||||
st->print("%s", k->external_name());
|
||||
oop msg = message(throwable);
|
||||
if (msg != NULL) {
|
||||
st->print(": %s", java_lang_String::as_utf8_string(msg));
|
||||
|
@ -1305,7 +1305,7 @@ void java_lang_Throwable::print(Handle throwable, outputStream* st) {
|
|||
ResourceMark rm;
|
||||
Klass* k = throwable->klass();
|
||||
assert(k != NULL, "just checking");
|
||||
st->print("%s", InstanceKlass::cast(k)->external_name());
|
||||
st->print("%s", k->external_name());
|
||||
oop msg = message(throwable);
|
||||
if (msg != NULL) {
|
||||
st->print(": %s", java_lang_String::as_utf8_string(msg));
|
||||
|
@ -2663,13 +2663,13 @@ void java_lang_boxing_object::print(BasicType type, jvalue* value, outputStream*
|
|||
|
||||
// Support for java_lang_ref_Reference
|
||||
HeapWord *java_lang_ref_Reference::pending_list_lock_addr() {
|
||||
InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::Reference_klass());
|
||||
InstanceKlass* ik = SystemDictionary::Reference_klass();
|
||||
address addr = ik->static_field_addr(static_lock_offset);
|
||||
return (HeapWord*) addr;
|
||||
}
|
||||
|
||||
oop java_lang_ref_Reference::pending_list_lock() {
|
||||
InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::Reference_klass());
|
||||
InstanceKlass* ik = SystemDictionary::Reference_klass();
|
||||
address addr = ik->static_field_addr(static_lock_offset);
|
||||
if (UseCompressedOops) {
|
||||
return oopDesc::load_decode_heap_oop((narrowOop *)addr);
|
||||
|
@ -2679,7 +2679,7 @@ oop java_lang_ref_Reference::pending_list_lock() {
|
|||
}
|
||||
|
||||
HeapWord *java_lang_ref_Reference::pending_list_addr() {
|
||||
InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::Reference_klass());
|
||||
InstanceKlass* ik = SystemDictionary::Reference_klass();
|
||||
address addr = ik->static_field_addr(static_pending_offset);
|
||||
// XXX This might not be HeapWord aligned, almost rather be char *.
|
||||
return (HeapWord*)addr;
|
||||
|
@ -2702,13 +2702,13 @@ jlong java_lang_ref_SoftReference::timestamp(oop ref) {
|
|||
}
|
||||
|
||||
jlong java_lang_ref_SoftReference::clock() {
|
||||
InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::SoftReference_klass());
|
||||
InstanceKlass* ik = SystemDictionary::SoftReference_klass();
|
||||
jlong* offset = (jlong*)ik->static_field_addr(static_clock_offset);
|
||||
return *offset;
|
||||
}
|
||||
|
||||
void java_lang_ref_SoftReference::set_clock(jlong value) {
|
||||
InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::SoftReference_klass());
|
||||
InstanceKlass* ik = SystemDictionary::SoftReference_klass();
|
||||
jlong* offset = (jlong*)ik->static_field_addr(static_clock_offset);
|
||||
*offset = value;
|
||||
}
|
||||
|
@ -3033,7 +3033,7 @@ int java_security_AccessControlContext::_isAuthorized_offset = -1;
|
|||
void java_security_AccessControlContext::compute_offsets() {
|
||||
assert(_isPrivileged_offset == 0, "offsets should be initialized only once");
|
||||
fieldDescriptor fd;
|
||||
InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::AccessControlContext_klass());
|
||||
InstanceKlass* ik = SystemDictionary::AccessControlContext_klass();
|
||||
|
||||
if (!ik->find_local_field(vmSymbols::context_name(), vmSymbols::protectiondomain_signature(), &fd)) {
|
||||
fatal("Invalid layout of java.security.AccessControlContext");
|
||||
|
@ -3066,9 +3066,9 @@ bool java_security_AccessControlContext::is_authorized(Handle context) {
|
|||
oop java_security_AccessControlContext::create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS) {
|
||||
assert(_isPrivileged_offset != 0, "offsets should have been initialized");
|
||||
// Ensure klass is initialized
|
||||
InstanceKlass::cast(SystemDictionary::AccessControlContext_klass())->initialize(CHECK_0);
|
||||
SystemDictionary::AccessControlContext_klass()->initialize(CHECK_0);
|
||||
// Allocate result
|
||||
oop result = InstanceKlass::cast(SystemDictionary::AccessControlContext_klass())->allocate_instance(CHECK_0);
|
||||
oop result = SystemDictionary::AccessControlContext_klass()->allocate_instance(CHECK_0);
|
||||
// Fill in values
|
||||
result->obj_field_put(_context_offset, context());
|
||||
result->obj_field_put(_privilegedContext_offset, privileged_context());
|
||||
|
@ -3190,7 +3190,7 @@ int java_lang_System::err_offset_in_bytes() {
|
|||
|
||||
|
||||
bool java_lang_System::has_security_manager() {
|
||||
InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::System_klass());
|
||||
InstanceKlass* ik = SystemDictionary::System_klass();
|
||||
address addr = ik->static_field_addr(static_security_offset);
|
||||
if (UseCompressedOops) {
|
||||
return oopDesc::load_decode_heap_oop((narrowOop *)addr) != NULL;
|
||||
|
@ -3630,8 +3630,8 @@ void JavaClasses::check_offsets() {
|
|||
#endif // PRODUCT
|
||||
|
||||
int InjectedField::compute_offset() {
|
||||
Klass* klass_oop = klass();
|
||||
for (AllFieldStream fs(InstanceKlass::cast(klass_oop)); !fs.done(); fs.next()) {
|
||||
InstanceKlass* ik = InstanceKlass::cast(klass());
|
||||
for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
|
||||
if (!may_be_java && !fs.access_flags().is_internal()) {
|
||||
// Only look at injected fields
|
||||
continue;
|
||||
|
@ -3641,11 +3641,11 @@ int InjectedField::compute_offset() {
|
|||
}
|
||||
}
|
||||
ResourceMark rm;
|
||||
tty->print_cr("Invalid layout of %s at %s/%s%s", InstanceKlass::cast(klass_oop)->external_name(), name()->as_C_string(), signature()->as_C_string(), may_be_java ? " (may_be_java)" : "");
|
||||
tty->print_cr("Invalid layout of %s at %s/%s%s", ik->external_name(), name()->as_C_string(), signature()->as_C_string(), may_be_java ? " (may_be_java)" : "");
|
||||
#ifndef PRODUCT
|
||||
klass_oop->print();
|
||||
ik->print();
|
||||
tty->print_cr("all fields:");
|
||||
for (AllFieldStream fs(InstanceKlass::cast(klass_oop)); !fs.done(); fs.next()) {
|
||||
for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
|
||||
tty->print_cr(" name: %s, sig: %s, flags: %08x", fs.name()->as_C_string(), fs.signature()->as_C_string(), fs.access_flags().as_int());
|
||||
}
|
||||
#endif //PRODUCT
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue