112 } |
112 } |
113 |
113 |
114 // Helpful routine for computing field offsets at run time rather than hardcoding them |
114 // Helpful routine for computing field offsets at run time rather than hardcoding them |
115 static void |
115 static void |
116 compute_offset(int &dest_offset, |
116 compute_offset(int &dest_offset, |
117 Klass* klass_oop, Symbol* name_symbol, Symbol* signature_symbol, |
117 Klass* klass, Symbol* name_symbol, Symbol* signature_symbol, |
118 bool is_static = false, bool allow_super = false) { |
118 bool is_static = false, bool allow_super = false) { |
119 fieldDescriptor fd; |
119 fieldDescriptor fd; |
120 InstanceKlass* ik = InstanceKlass::cast(klass_oop); |
120 InstanceKlass* ik = InstanceKlass::cast(klass); |
121 if (!find_field(ik, name_symbol, signature_symbol, &fd, is_static, allow_super)) { |
121 if (!find_field(ik, name_symbol, signature_symbol, &fd, is_static, allow_super)) { |
122 ResourceMark rm; |
122 ResourceMark rm; |
123 tty->print_cr("Invalid layout of %s at %s", ik->external_name(), name_symbol->as_C_string()); |
123 tty->print_cr("Invalid layout of %s at %s", ik->external_name(), name_symbol->as_C_string()); |
124 #ifndef PRODUCT |
124 #ifndef PRODUCT |
125 klass_oop->print(); |
125 ik->print(); |
126 tty->print_cr("all fields:"); |
126 tty->print_cr("all fields:"); |
127 for (AllFieldStream fs(InstanceKlass::cast(klass_oop)); !fs.done(); fs.next()) { |
127 for (AllFieldStream fs(ik); !fs.done(); fs.next()) { |
128 tty->print_cr(" name: %s, sig: %s, flags: %08x", fs.name()->as_C_string(), fs.signature()->as_C_string(), fs.access_flags().as_int()); |
128 tty->print_cr(" name: %s, sig: %s, flags: %08x", fs.name()->as_C_string(), fs.signature()->as_C_string(), fs.access_flags().as_int()); |
129 } |
129 } |
130 #endif //PRODUCT |
130 #endif //PRODUCT |
131 vm_exit_during_initialization("Invalid layout of preloaded class: use -XX:+TraceClassLoading to see the origin of the problem class"); |
131 vm_exit_during_initialization("Invalid layout of preloaded class: use -XX:+TraceClassLoading to see the origin of the problem class"); |
132 } |
132 } |
134 } |
134 } |
135 |
135 |
136 // Same as above but for "optional" offsets that might not be present in certain JDK versions |
136 // Same as above but for "optional" offsets that might not be present in certain JDK versions |
137 static void |
137 static void |
138 compute_optional_offset(int& dest_offset, |
138 compute_optional_offset(int& dest_offset, |
139 Klass* klass_oop, Symbol* name_symbol, Symbol* signature_symbol, |
139 Klass* klass, Symbol* name_symbol, Symbol* signature_symbol, |
140 bool allow_super = false) { |
140 bool allow_super = false) { |
141 fieldDescriptor fd; |
141 fieldDescriptor fd; |
142 InstanceKlass* ik = InstanceKlass::cast(klass_oop); |
142 InstanceKlass* ik = InstanceKlass::cast(klass); |
143 if (find_field(ik, name_symbol, signature_symbol, &fd, allow_super)) { |
143 if (find_field(ik, name_symbol, signature_symbol, &fd, allow_super)) { |
144 dest_offset = fd.offset(); |
144 dest_offset = fd.offset(); |
145 } |
145 } |
146 } |
146 } |
147 |
147 |
172 Handle java_lang_String::basic_create(int length, TRAPS) { |
172 Handle java_lang_String::basic_create(int length, TRAPS) { |
173 assert(initialized, "Must be initialized"); |
173 assert(initialized, "Must be initialized"); |
174 // Create the String object first, so there's a chance that the String |
174 // Create the String object first, so there's a chance that the String |
175 // and the char array it points to end up in the same cache line. |
175 // and the char array it points to end up in the same cache line. |
176 oop obj; |
176 oop obj; |
177 obj = InstanceKlass::cast(SystemDictionary::String_klass())->allocate_instance(CHECK_NH); |
177 obj = SystemDictionary::String_klass()->allocate_instance(CHECK_NH); |
178 |
178 |
179 // Create the char array. The String object must be handlized here |
179 // Create the char array. The String object must be handlized here |
180 // because GC can happen as a result of the allocation attempt. |
180 // because GC can happen as a result of the allocation attempt. |
181 Handle h_obj(THREAD, obj); |
181 Handle h_obj(THREAD, obj); |
182 typeArrayOop buffer; |
182 typeArrayOop buffer; |
1234 compute_offset(_nthreads_offset, k, vmSymbols::nthreads_name(), vmSymbols::int_signature()); |
1234 compute_offset(_nthreads_offset, k, vmSymbols::nthreads_name(), vmSymbols::int_signature()); |
1235 compute_offset(_ngroups_offset, k, vmSymbols::ngroups_name(), vmSymbols::int_signature()); |
1235 compute_offset(_ngroups_offset, k, vmSymbols::ngroups_name(), vmSymbols::int_signature()); |
1236 } |
1236 } |
1237 |
1237 |
1238 oop java_lang_Throwable::unassigned_stacktrace() { |
1238 oop java_lang_Throwable::unassigned_stacktrace() { |
1239 InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::Throwable_klass()); |
1239 InstanceKlass* ik = SystemDictionary::Throwable_klass(); |
1240 address addr = ik->static_field_addr(static_unassigned_stacktrace_offset); |
1240 address addr = ik->static_field_addr(static_unassigned_stacktrace_offset); |
1241 if (UseCompressedOops) { |
1241 if (UseCompressedOops) { |
1242 return oopDesc::load_decode_heap_oop((narrowOop *)addr); |
1242 return oopDesc::load_decode_heap_oop((narrowOop *)addr); |
1243 } else { |
1243 } else { |
1244 return oopDesc::load_decode_heap_oop((oop*)addr); |
1244 return oopDesc::load_decode_heap_oop((oop*)addr); |
1291 |
1291 |
1292 void java_lang_Throwable::print(oop throwable, outputStream* st) { |
1292 void java_lang_Throwable::print(oop throwable, outputStream* st) { |
1293 ResourceMark rm; |
1293 ResourceMark rm; |
1294 Klass* k = throwable->klass(); |
1294 Klass* k = throwable->klass(); |
1295 assert(k != NULL, "just checking"); |
1295 assert(k != NULL, "just checking"); |
1296 st->print("%s", InstanceKlass::cast(k)->external_name()); |
1296 st->print("%s", k->external_name()); |
1297 oop msg = message(throwable); |
1297 oop msg = message(throwable); |
1298 if (msg != NULL) { |
1298 if (msg != NULL) { |
1299 st->print(": %s", java_lang_String::as_utf8_string(msg)); |
1299 st->print(": %s", java_lang_String::as_utf8_string(msg)); |
1300 } |
1300 } |
1301 } |
1301 } |
1303 |
1303 |
1304 void java_lang_Throwable::print(Handle throwable, outputStream* st) { |
1304 void java_lang_Throwable::print(Handle throwable, outputStream* st) { |
1305 ResourceMark rm; |
1305 ResourceMark rm; |
1306 Klass* k = throwable->klass(); |
1306 Klass* k = throwable->klass(); |
1307 assert(k != NULL, "just checking"); |
1307 assert(k != NULL, "just checking"); |
1308 st->print("%s", InstanceKlass::cast(k)->external_name()); |
1308 st->print("%s", k->external_name()); |
1309 oop msg = message(throwable); |
1309 oop msg = message(throwable); |
1310 if (msg != NULL) { |
1310 if (msg != NULL) { |
1311 st->print(": %s", java_lang_String::as_utf8_string(msg)); |
1311 st->print(": %s", java_lang_String::as_utf8_string(msg)); |
1312 } |
1312 } |
1313 } |
1313 } |
2661 } |
2661 } |
2662 |
2662 |
2663 |
2663 |
2664 // Support for java_lang_ref_Reference |
2664 // Support for java_lang_ref_Reference |
2665 HeapWord *java_lang_ref_Reference::pending_list_lock_addr() { |
2665 HeapWord *java_lang_ref_Reference::pending_list_lock_addr() { |
2666 InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::Reference_klass()); |
2666 InstanceKlass* ik = SystemDictionary::Reference_klass(); |
2667 address addr = ik->static_field_addr(static_lock_offset); |
2667 address addr = ik->static_field_addr(static_lock_offset); |
2668 return (HeapWord*) addr; |
2668 return (HeapWord*) addr; |
2669 } |
2669 } |
2670 |
2670 |
2671 oop java_lang_ref_Reference::pending_list_lock() { |
2671 oop java_lang_ref_Reference::pending_list_lock() { |
2672 InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::Reference_klass()); |
2672 InstanceKlass* ik = SystemDictionary::Reference_klass(); |
2673 address addr = ik->static_field_addr(static_lock_offset); |
2673 address addr = ik->static_field_addr(static_lock_offset); |
2674 if (UseCompressedOops) { |
2674 if (UseCompressedOops) { |
2675 return oopDesc::load_decode_heap_oop((narrowOop *)addr); |
2675 return oopDesc::load_decode_heap_oop((narrowOop *)addr); |
2676 } else { |
2676 } else { |
2677 return oopDesc::load_decode_heap_oop((oop*)addr); |
2677 return oopDesc::load_decode_heap_oop((oop*)addr); |
2678 } |
2678 } |
2679 } |
2679 } |
2680 |
2680 |
2681 HeapWord *java_lang_ref_Reference::pending_list_addr() { |
2681 HeapWord *java_lang_ref_Reference::pending_list_addr() { |
2682 InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::Reference_klass()); |
2682 InstanceKlass* ik = SystemDictionary::Reference_klass(); |
2683 address addr = ik->static_field_addr(static_pending_offset); |
2683 address addr = ik->static_field_addr(static_pending_offset); |
2684 // XXX This might not be HeapWord aligned, almost rather be char *. |
2684 // XXX This might not be HeapWord aligned, almost rather be char *. |
2685 return (HeapWord*)addr; |
2685 return (HeapWord*)addr; |
2686 } |
2686 } |
2687 |
2687 |
2700 jlong java_lang_ref_SoftReference::timestamp(oop ref) { |
2700 jlong java_lang_ref_SoftReference::timestamp(oop ref) { |
2701 return ref->long_field(timestamp_offset); |
2701 return ref->long_field(timestamp_offset); |
2702 } |
2702 } |
2703 |
2703 |
2704 jlong java_lang_ref_SoftReference::clock() { |
2704 jlong java_lang_ref_SoftReference::clock() { |
2705 InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::SoftReference_klass()); |
2705 InstanceKlass* ik = SystemDictionary::SoftReference_klass(); |
2706 jlong* offset = (jlong*)ik->static_field_addr(static_clock_offset); |
2706 jlong* offset = (jlong*)ik->static_field_addr(static_clock_offset); |
2707 return *offset; |
2707 return *offset; |
2708 } |
2708 } |
2709 |
2709 |
2710 void java_lang_ref_SoftReference::set_clock(jlong value) { |
2710 void java_lang_ref_SoftReference::set_clock(jlong value) { |
2711 InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::SoftReference_klass()); |
2711 InstanceKlass* ik = SystemDictionary::SoftReference_klass(); |
2712 jlong* offset = (jlong*)ik->static_field_addr(static_clock_offset); |
2712 jlong* offset = (jlong*)ik->static_field_addr(static_clock_offset); |
2713 *offset = value; |
2713 *offset = value; |
2714 } |
2714 } |
2715 |
2715 |
2716 // Support for java_lang_invoke_DirectMethodHandle |
2716 // Support for java_lang_invoke_DirectMethodHandle |
3031 int java_security_AccessControlContext::_isAuthorized_offset = -1; |
3031 int java_security_AccessControlContext::_isAuthorized_offset = -1; |
3032 |
3032 |
3033 void java_security_AccessControlContext::compute_offsets() { |
3033 void java_security_AccessControlContext::compute_offsets() { |
3034 assert(_isPrivileged_offset == 0, "offsets should be initialized only once"); |
3034 assert(_isPrivileged_offset == 0, "offsets should be initialized only once"); |
3035 fieldDescriptor fd; |
3035 fieldDescriptor fd; |
3036 InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::AccessControlContext_klass()); |
3036 InstanceKlass* ik = SystemDictionary::AccessControlContext_klass(); |
3037 |
3037 |
3038 if (!ik->find_local_field(vmSymbols::context_name(), vmSymbols::protectiondomain_signature(), &fd)) { |
3038 if (!ik->find_local_field(vmSymbols::context_name(), vmSymbols::protectiondomain_signature(), &fd)) { |
3039 fatal("Invalid layout of java.security.AccessControlContext"); |
3039 fatal("Invalid layout of java.security.AccessControlContext"); |
3040 } |
3040 } |
3041 _context_offset = fd.offset(); |
3041 _context_offset = fd.offset(); |
3064 } |
3064 } |
3065 |
3065 |
3066 oop java_security_AccessControlContext::create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS) { |
3066 oop java_security_AccessControlContext::create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS) { |
3067 assert(_isPrivileged_offset != 0, "offsets should have been initialized"); |
3067 assert(_isPrivileged_offset != 0, "offsets should have been initialized"); |
3068 // Ensure klass is initialized |
3068 // Ensure klass is initialized |
3069 InstanceKlass::cast(SystemDictionary::AccessControlContext_klass())->initialize(CHECK_0); |
3069 SystemDictionary::AccessControlContext_klass()->initialize(CHECK_0); |
3070 // Allocate result |
3070 // Allocate result |
3071 oop result = InstanceKlass::cast(SystemDictionary::AccessControlContext_klass())->allocate_instance(CHECK_0); |
3071 oop result = SystemDictionary::AccessControlContext_klass()->allocate_instance(CHECK_0); |
3072 // Fill in values |
3072 // Fill in values |
3073 result->obj_field_put(_context_offset, context()); |
3073 result->obj_field_put(_context_offset, context()); |
3074 result->obj_field_put(_privilegedContext_offset, privileged_context()); |
3074 result->obj_field_put(_privilegedContext_offset, privileged_context()); |
3075 result->bool_field_put(_isPrivileged_offset, isPrivileged); |
3075 result->bool_field_put(_isPrivileged_offset, isPrivileged); |
3076 // whitelist AccessControlContexts created by the JVM if present |
3076 // whitelist AccessControlContexts created by the JVM if present |
3188 return (InstanceMirrorKlass::offset_of_static_fields() + static_err_offset); |
3188 return (InstanceMirrorKlass::offset_of_static_fields() + static_err_offset); |
3189 } |
3189 } |
3190 |
3190 |
3191 |
3191 |
3192 bool java_lang_System::has_security_manager() { |
3192 bool java_lang_System::has_security_manager() { |
3193 InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::System_klass()); |
3193 InstanceKlass* ik = SystemDictionary::System_klass(); |
3194 address addr = ik->static_field_addr(static_security_offset); |
3194 address addr = ik->static_field_addr(static_security_offset); |
3195 if (UseCompressedOops) { |
3195 if (UseCompressedOops) { |
3196 return oopDesc::load_decode_heap_oop((narrowOop *)addr) != NULL; |
3196 return oopDesc::load_decode_heap_oop((narrowOop *)addr) != NULL; |
3197 } else { |
3197 } else { |
3198 return oopDesc::load_decode_heap_oop((oop*)addr) != NULL; |
3198 return oopDesc::load_decode_heap_oop((oop*)addr) != NULL; |
3628 } |
3628 } |
3629 |
3629 |
3630 #endif // PRODUCT |
3630 #endif // PRODUCT |
3631 |
3631 |
3632 int InjectedField::compute_offset() { |
3632 int InjectedField::compute_offset() { |
3633 Klass* klass_oop = klass(); |
3633 InstanceKlass* ik = InstanceKlass::cast(klass()); |
3634 for (AllFieldStream fs(InstanceKlass::cast(klass_oop)); !fs.done(); fs.next()) { |
3634 for (AllFieldStream fs(ik); !fs.done(); fs.next()) { |
3635 if (!may_be_java && !fs.access_flags().is_internal()) { |
3635 if (!may_be_java && !fs.access_flags().is_internal()) { |
3636 // Only look at injected fields |
3636 // Only look at injected fields |
3637 continue; |
3637 continue; |
3638 } |
3638 } |
3639 if (fs.name() == name() && fs.signature() == signature()) { |
3639 if (fs.name() == name() && fs.signature() == signature()) { |
3640 return fs.offset(); |
3640 return fs.offset(); |
3641 } |
3641 } |
3642 } |
3642 } |
3643 ResourceMark rm; |
3643 ResourceMark rm; |
3644 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)" : ""); |
3644 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)" : ""); |
3645 #ifndef PRODUCT |
3645 #ifndef PRODUCT |
3646 klass_oop->print(); |
3646 ik->print(); |
3647 tty->print_cr("all fields:"); |
3647 tty->print_cr("all fields:"); |
3648 for (AllFieldStream fs(InstanceKlass::cast(klass_oop)); !fs.done(); fs.next()) { |
3648 for (AllFieldStream fs(ik); !fs.done(); fs.next()) { |
3649 tty->print_cr(" name: %s, sig: %s, flags: %08x", fs.name()->as_C_string(), fs.signature()->as_C_string(), fs.access_flags().as_int()); |
3649 tty->print_cr(" name: %s, sig: %s, flags: %08x", fs.name()->as_C_string(), fs.signature()->as_C_string(), fs.access_flags().as_int()); |
3650 } |
3650 } |
3651 #endif //PRODUCT |
3651 #endif //PRODUCT |
3652 vm_exit_during_initialization("Invalid layout of preloaded class: use -XX:+TraceClassLoading to see the origin of the problem class"); |
3652 vm_exit_during_initialization("Invalid layout of preloaded class: use -XX:+TraceClassLoading to see the origin of the problem class"); |
3653 return -1; |
3653 return -1; |