Wed, 03 Jul 2019 20:42:37 +0800
Merge
aoqi@0 | 1 | /* |
kbarrett@9099 | 2 | * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #include "precompiled.hpp" |
aoqi@0 | 26 | #include "classfile/altHashing.hpp" |
aoqi@0 | 27 | #include "classfile/javaClasses.hpp" |
aoqi@0 | 28 | #include "classfile/symbolTable.hpp" |
aoqi@0 | 29 | #include "classfile/vmSymbols.hpp" |
aoqi@0 | 30 | #include "code/debugInfo.hpp" |
aoqi@0 | 31 | #include "code/pcDesc.hpp" |
aoqi@0 | 32 | #include "compiler/compilerOracle.hpp" |
aoqi@0 | 33 | #include "interpreter/interpreter.hpp" |
aoqi@0 | 34 | #include "memory/oopFactory.hpp" |
aoqi@0 | 35 | #include "memory/resourceArea.hpp" |
aoqi@0 | 36 | #include "memory/universe.inline.hpp" |
aoqi@0 | 37 | #include "oops/fieldStreams.hpp" |
aoqi@0 | 38 | #include "oops/instanceKlass.hpp" |
aoqi@0 | 39 | #include "oops/instanceMirrorKlass.hpp" |
aoqi@0 | 40 | #include "oops/klass.hpp" |
aoqi@0 | 41 | #include "oops/method.hpp" |
aoqi@0 | 42 | #include "oops/symbol.hpp" |
aoqi@0 | 43 | #include "oops/typeArrayOop.hpp" |
coleenp@7391 | 44 | #include "prims/jvmtiRedefineClassesTrace.hpp" |
aoqi@0 | 45 | #include "runtime/fieldDescriptor.hpp" |
aoqi@0 | 46 | #include "runtime/handles.inline.hpp" |
aoqi@0 | 47 | #include "runtime/interfaceSupport.hpp" |
aoqi@0 | 48 | #include "runtime/java.hpp" |
aoqi@0 | 49 | #include "runtime/javaCalls.hpp" |
aoqi@0 | 50 | #include "runtime/safepoint.hpp" |
aoqi@0 | 51 | #include "runtime/thread.inline.hpp" |
aoqi@0 | 52 | #include "runtime/vframe.hpp" |
aoqi@0 | 53 | #include "utilities/preserveException.hpp" |
aoqi@0 | 54 | |
aoqi@0 | 55 | PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
aoqi@0 | 56 | |
aoqi@0 | 57 | #define INJECTED_FIELD_COMPUTE_OFFSET(klass, name, signature, may_be_java) \ |
aoqi@0 | 58 | klass::_##name##_offset = JavaClasses::compute_injected_offset(JavaClasses::klass##_##name##_enum); |
aoqi@0 | 59 | |
aoqi@0 | 60 | #define DECLARE_INJECTED_FIELD(klass, name, signature, may_be_java) \ |
aoqi@0 | 61 | { SystemDictionary::WK_KLASS_ENUM_NAME(klass), vmSymbols::VM_SYMBOL_ENUM_NAME(name##_name), vmSymbols::VM_SYMBOL_ENUM_NAME(signature), may_be_java }, |
aoqi@0 | 62 | |
aoqi@0 | 63 | InjectedField JavaClasses::_injected_fields[] = { |
aoqi@0 | 64 | ALL_INJECTED_FIELDS(DECLARE_INJECTED_FIELD) |
aoqi@0 | 65 | }; |
aoqi@0 | 66 | |
aoqi@0 | 67 | int JavaClasses::compute_injected_offset(InjectedFieldID id) { |
aoqi@0 | 68 | return _injected_fields[id].compute_offset(); |
aoqi@0 | 69 | } |
aoqi@0 | 70 | |
aoqi@0 | 71 | |
aoqi@0 | 72 | InjectedField* JavaClasses::get_injected(Symbol* class_name, int* field_count) { |
aoqi@0 | 73 | *field_count = 0; |
aoqi@0 | 74 | |
aoqi@0 | 75 | vmSymbols::SID sid = vmSymbols::find_sid(class_name); |
aoqi@0 | 76 | if (sid == vmSymbols::NO_SID) { |
aoqi@0 | 77 | // Only well known classes can inject fields |
aoqi@0 | 78 | return NULL; |
aoqi@0 | 79 | } |
aoqi@0 | 80 | |
aoqi@0 | 81 | int count = 0; |
aoqi@0 | 82 | int start = -1; |
aoqi@0 | 83 | |
aoqi@0 | 84 | #define LOOKUP_INJECTED_FIELD(klass, name, signature, may_be_java) \ |
aoqi@0 | 85 | if (sid == vmSymbols::VM_SYMBOL_ENUM_NAME(klass)) { \ |
aoqi@0 | 86 | count++; \ |
aoqi@0 | 87 | if (start == -1) start = klass##_##name##_enum; \ |
aoqi@0 | 88 | } |
aoqi@0 | 89 | ALL_INJECTED_FIELDS(LOOKUP_INJECTED_FIELD); |
aoqi@0 | 90 | #undef LOOKUP_INJECTED_FIELD |
aoqi@0 | 91 | |
aoqi@0 | 92 | if (start != -1) { |
aoqi@0 | 93 | *field_count = count; |
aoqi@0 | 94 | return _injected_fields + start; |
aoqi@0 | 95 | } |
aoqi@0 | 96 | return NULL; |
aoqi@0 | 97 | } |
aoqi@0 | 98 | |
aoqi@0 | 99 | |
aoqi@0 | 100 | static bool find_field(InstanceKlass* ik, |
aoqi@0 | 101 | Symbol* name_symbol, Symbol* signature_symbol, |
aoqi@0 | 102 | fieldDescriptor* fd, |
aoqi@0 | 103 | bool allow_super = false) { |
aoqi@0 | 104 | if (allow_super) |
aoqi@0 | 105 | return ik->find_field(name_symbol, signature_symbol, fd) != NULL; |
aoqi@0 | 106 | else |
aoqi@0 | 107 | return ik->find_local_field(name_symbol, signature_symbol, fd); |
aoqi@0 | 108 | } |
aoqi@0 | 109 | |
aoqi@0 | 110 | // Helpful routine for computing field offsets at run time rather than hardcoding them |
aoqi@0 | 111 | static void |
aoqi@0 | 112 | compute_offset(int &dest_offset, |
aoqi@0 | 113 | Klass* klass_oop, Symbol* name_symbol, Symbol* signature_symbol, |
aoqi@0 | 114 | bool allow_super = false) { |
aoqi@0 | 115 | fieldDescriptor fd; |
aoqi@0 | 116 | InstanceKlass* ik = InstanceKlass::cast(klass_oop); |
aoqi@0 | 117 | if (!find_field(ik, name_symbol, signature_symbol, &fd, allow_super)) { |
aoqi@0 | 118 | ResourceMark rm; |
aoqi@0 | 119 | tty->print_cr("Invalid layout of %s at %s", ik->external_name(), name_symbol->as_C_string()); |
aoqi@0 | 120 | #ifndef PRODUCT |
aoqi@0 | 121 | klass_oop->print(); |
aoqi@0 | 122 | tty->print_cr("all fields:"); |
aoqi@0 | 123 | for (AllFieldStream fs(InstanceKlass::cast(klass_oop)); !fs.done(); fs.next()) { |
aoqi@0 | 124 | tty->print_cr(" name: %s, sig: %s, flags: %08x", fs.name()->as_C_string(), fs.signature()->as_C_string(), fs.access_flags().as_int()); |
aoqi@0 | 125 | } |
aoqi@0 | 126 | #endif //PRODUCT |
dbuck@7788 | 127 | vm_exit_during_initialization("Invalid layout of preloaded class: use -XX:+TraceClassLoading to see the origin of the problem class"); |
aoqi@0 | 128 | } |
aoqi@0 | 129 | dest_offset = fd.offset(); |
aoqi@0 | 130 | } |
aoqi@0 | 131 | |
aoqi@0 | 132 | // Same as above but for "optional" offsets that might not be present in certain JDK versions |
aoqi@0 | 133 | static void |
aoqi@0 | 134 | compute_optional_offset(int& dest_offset, |
aoqi@0 | 135 | Klass* klass_oop, Symbol* name_symbol, Symbol* signature_symbol, |
aoqi@0 | 136 | bool allow_super = false) { |
aoqi@0 | 137 | fieldDescriptor fd; |
aoqi@0 | 138 | InstanceKlass* ik = InstanceKlass::cast(klass_oop); |
aoqi@0 | 139 | if (find_field(ik, name_symbol, signature_symbol, &fd, allow_super)) { |
aoqi@0 | 140 | dest_offset = fd.offset(); |
aoqi@0 | 141 | } |
aoqi@0 | 142 | } |
aoqi@0 | 143 | |
aoqi@0 | 144 | |
aoqi@0 | 145 | int java_lang_String::value_offset = 0; |
aoqi@0 | 146 | int java_lang_String::offset_offset = 0; |
aoqi@0 | 147 | int java_lang_String::count_offset = 0; |
aoqi@0 | 148 | int java_lang_String::hash_offset = 0; |
aoqi@0 | 149 | |
aoqi@0 | 150 | bool java_lang_String::initialized = false; |
aoqi@0 | 151 | |
aoqi@0 | 152 | void java_lang_String::compute_offsets() { |
aoqi@0 | 153 | assert(!initialized, "offsets should be initialized only once"); |
aoqi@0 | 154 | |
aoqi@0 | 155 | Klass* k = SystemDictionary::String_klass(); |
aoqi@0 | 156 | compute_offset(value_offset, k, vmSymbols::value_name(), vmSymbols::char_array_signature()); |
aoqi@0 | 157 | compute_optional_offset(offset_offset, k, vmSymbols::offset_name(), vmSymbols::int_signature()); |
aoqi@0 | 158 | compute_optional_offset(count_offset, k, vmSymbols::count_name(), vmSymbols::int_signature()); |
aoqi@0 | 159 | compute_optional_offset(hash_offset, k, vmSymbols::hash_name(), vmSymbols::int_signature()); |
aoqi@0 | 160 | |
aoqi@0 | 161 | initialized = true; |
aoqi@0 | 162 | } |
aoqi@0 | 163 | |
aoqi@0 | 164 | Handle java_lang_String::basic_create(int length, TRAPS) { |
aoqi@0 | 165 | assert(initialized, "Must be initialized"); |
aoqi@0 | 166 | // Create the String object first, so there's a chance that the String |
aoqi@0 | 167 | // and the char array it points to end up in the same cache line. |
aoqi@0 | 168 | oop obj; |
aoqi@0 | 169 | obj = InstanceKlass::cast(SystemDictionary::String_klass())->allocate_instance(CHECK_NH); |
aoqi@0 | 170 | |
aoqi@0 | 171 | // Create the char array. The String object must be handlized here |
aoqi@0 | 172 | // because GC can happen as a result of the allocation attempt. |
aoqi@0 | 173 | Handle h_obj(THREAD, obj); |
aoqi@0 | 174 | typeArrayOop buffer; |
aoqi@0 | 175 | buffer = oopFactory::new_charArray(length, CHECK_NH); |
aoqi@0 | 176 | |
aoqi@0 | 177 | // Point the String at the char array |
aoqi@0 | 178 | obj = h_obj(); |
aoqi@0 | 179 | set_value(obj, buffer); |
aoqi@0 | 180 | // No need to zero the offset, allocation zero'ed the entire String object |
aoqi@0 | 181 | assert(offset(obj) == 0, "initial String offset should be zero"); |
aoqi@0 | 182 | //set_offset(obj, 0); |
aoqi@0 | 183 | set_count(obj, length); |
aoqi@0 | 184 | |
aoqi@0 | 185 | return h_obj; |
aoqi@0 | 186 | } |
aoqi@0 | 187 | |
aoqi@0 | 188 | Handle java_lang_String::create_from_unicode(jchar* unicode, int length, TRAPS) { |
aoqi@0 | 189 | Handle h_obj = basic_create(length, CHECK_NH); |
aoqi@0 | 190 | typeArrayOop buffer = value(h_obj()); |
aoqi@0 | 191 | for (int index = 0; index < length; index++) { |
aoqi@0 | 192 | buffer->char_at_put(index, unicode[index]); |
aoqi@0 | 193 | } |
aoqi@0 | 194 | return h_obj; |
aoqi@0 | 195 | } |
aoqi@0 | 196 | |
aoqi@0 | 197 | oop java_lang_String::create_oop_from_unicode(jchar* unicode, int length, TRAPS) { |
aoqi@0 | 198 | Handle h_obj = create_from_unicode(unicode, length, CHECK_0); |
aoqi@0 | 199 | return h_obj(); |
aoqi@0 | 200 | } |
aoqi@0 | 201 | |
aoqi@0 | 202 | Handle java_lang_String::create_from_str(const char* utf8_str, TRAPS) { |
aoqi@0 | 203 | if (utf8_str == NULL) { |
aoqi@0 | 204 | return Handle(); |
aoqi@0 | 205 | } |
aoqi@0 | 206 | int length = UTF8::unicode_length(utf8_str); |
aoqi@0 | 207 | Handle h_obj = basic_create(length, CHECK_NH); |
aoqi@0 | 208 | if (length > 0) { |
aoqi@0 | 209 | UTF8::convert_to_unicode(utf8_str, value(h_obj())->char_at_addr(0), length); |
aoqi@0 | 210 | } |
aoqi@0 | 211 | return h_obj; |
aoqi@0 | 212 | } |
aoqi@0 | 213 | |
aoqi@0 | 214 | oop java_lang_String::create_oop_from_str(const char* utf8_str, TRAPS) { |
aoqi@0 | 215 | Handle h_obj = create_from_str(utf8_str, CHECK_0); |
aoqi@0 | 216 | return h_obj(); |
aoqi@0 | 217 | } |
aoqi@0 | 218 | |
aoqi@0 | 219 | Handle java_lang_String::create_from_symbol(Symbol* symbol, TRAPS) { |
aoqi@0 | 220 | int length = UTF8::unicode_length((char*)symbol->bytes(), symbol->utf8_length()); |
aoqi@0 | 221 | Handle h_obj = basic_create(length, CHECK_NH); |
aoqi@0 | 222 | if (length > 0) { |
aoqi@0 | 223 | UTF8::convert_to_unicode((char*)symbol->bytes(), value(h_obj())->char_at_addr(0), length); |
aoqi@0 | 224 | } |
aoqi@0 | 225 | return h_obj; |
aoqi@0 | 226 | } |
aoqi@0 | 227 | |
aoqi@0 | 228 | // Converts a C string to a Java String based on current encoding |
aoqi@0 | 229 | Handle java_lang_String::create_from_platform_dependent_str(const char* str, TRAPS) { |
aoqi@0 | 230 | assert(str != NULL, "bad arguments"); |
aoqi@0 | 231 | |
aoqi@0 | 232 | typedef jstring (*to_java_string_fn_t)(JNIEnv*, const char *); |
aoqi@0 | 233 | static to_java_string_fn_t _to_java_string_fn = NULL; |
aoqi@0 | 234 | |
aoqi@0 | 235 | if (_to_java_string_fn == NULL) { |
aoqi@0 | 236 | void *lib_handle = os::native_java_library(); |
aoqi@0 | 237 | _to_java_string_fn = CAST_TO_FN_PTR(to_java_string_fn_t, os::dll_lookup(lib_handle, "NewStringPlatform")); |
aoqi@0 | 238 | if (_to_java_string_fn == NULL) { |
aoqi@0 | 239 | fatal("NewStringPlatform missing"); |
aoqi@0 | 240 | } |
aoqi@0 | 241 | } |
aoqi@0 | 242 | |
aoqi@0 | 243 | jstring js = NULL; |
aoqi@0 | 244 | { JavaThread* thread = (JavaThread*)THREAD; |
aoqi@0 | 245 | assert(thread->is_Java_thread(), "must be java thread"); |
aoqi@0 | 246 | HandleMark hm(thread); |
aoqi@0 | 247 | ThreadToNativeFromVM ttn(thread); |
aoqi@0 | 248 | js = (_to_java_string_fn)(thread->jni_environment(), str); |
aoqi@0 | 249 | } |
aoqi@0 | 250 | return Handle(THREAD, JNIHandles::resolve(js)); |
aoqi@0 | 251 | } |
aoqi@0 | 252 | |
aoqi@0 | 253 | // Converts a Java String to a native C string that can be used for |
aoqi@0 | 254 | // native OS calls. |
aoqi@0 | 255 | char* java_lang_String::as_platform_dependent_str(Handle java_string, TRAPS) { |
aoqi@0 | 256 | |
aoqi@0 | 257 | typedef char* (*to_platform_string_fn_t)(JNIEnv*, jstring, bool*); |
aoqi@0 | 258 | static to_platform_string_fn_t _to_platform_string_fn = NULL; |
aoqi@0 | 259 | |
aoqi@0 | 260 | if (_to_platform_string_fn == NULL) { |
aoqi@0 | 261 | void *lib_handle = os::native_java_library(); |
aoqi@0 | 262 | _to_platform_string_fn = CAST_TO_FN_PTR(to_platform_string_fn_t, os::dll_lookup(lib_handle, "GetStringPlatformChars")); |
aoqi@0 | 263 | if (_to_platform_string_fn == NULL) { |
aoqi@0 | 264 | fatal("GetStringPlatformChars missing"); |
aoqi@0 | 265 | } |
aoqi@0 | 266 | } |
aoqi@0 | 267 | |
aoqi@0 | 268 | char *native_platform_string; |
aoqi@0 | 269 | { JavaThread* thread = (JavaThread*)THREAD; |
aoqi@0 | 270 | assert(thread->is_Java_thread(), "must be java thread"); |
aoqi@0 | 271 | JNIEnv *env = thread->jni_environment(); |
aoqi@0 | 272 | jstring js = (jstring) JNIHandles::make_local(env, java_string()); |
aoqi@0 | 273 | bool is_copy; |
aoqi@0 | 274 | HandleMark hm(thread); |
aoqi@0 | 275 | ThreadToNativeFromVM ttn(thread); |
aoqi@0 | 276 | native_platform_string = (_to_platform_string_fn)(env, js, &is_copy); |
aoqi@0 | 277 | assert(is_copy == JNI_TRUE, "is_copy value changed"); |
aoqi@0 | 278 | JNIHandles::destroy_local(js); |
aoqi@0 | 279 | } |
aoqi@0 | 280 | return native_platform_string; |
aoqi@0 | 281 | } |
aoqi@0 | 282 | |
aoqi@0 | 283 | Handle java_lang_String::char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS) { |
aoqi@0 | 284 | oop obj = java_string(); |
aoqi@0 | 285 | // Typical usage is to convert all '/' to '.' in string. |
aoqi@0 | 286 | typeArrayOop value = java_lang_String::value(obj); |
aoqi@0 | 287 | int offset = java_lang_String::offset(obj); |
aoqi@0 | 288 | int length = java_lang_String::length(obj); |
aoqi@0 | 289 | |
aoqi@0 | 290 | // First check if any from_char exist |
aoqi@0 | 291 | int index; // Declared outside, used later |
aoqi@0 | 292 | for (index = 0; index < length; index++) { |
aoqi@0 | 293 | if (value->char_at(index + offset) == from_char) { |
aoqi@0 | 294 | break; |
aoqi@0 | 295 | } |
aoqi@0 | 296 | } |
aoqi@0 | 297 | if (index == length) { |
aoqi@0 | 298 | // No from_char, so do not copy. |
aoqi@0 | 299 | return java_string; |
aoqi@0 | 300 | } |
aoqi@0 | 301 | |
aoqi@0 | 302 | // Create new UNICODE buffer. Must handlize value because GC |
aoqi@0 | 303 | // may happen during String and char array creation. |
aoqi@0 | 304 | typeArrayHandle h_value(THREAD, value); |
aoqi@0 | 305 | Handle string = basic_create(length, CHECK_NH); |
aoqi@0 | 306 | |
aoqi@0 | 307 | typeArrayOop from_buffer = h_value(); |
aoqi@0 | 308 | typeArrayOop to_buffer = java_lang_String::value(string()); |
aoqi@0 | 309 | |
aoqi@0 | 310 | // Copy contents |
aoqi@0 | 311 | for (index = 0; index < length; index++) { |
aoqi@0 | 312 | jchar c = from_buffer->char_at(index + offset); |
aoqi@0 | 313 | if (c == from_char) { |
aoqi@0 | 314 | c = to_char; |
aoqi@0 | 315 | } |
aoqi@0 | 316 | to_buffer->char_at_put(index, c); |
aoqi@0 | 317 | } |
aoqi@0 | 318 | return string; |
aoqi@0 | 319 | } |
aoqi@0 | 320 | |
aoqi@0 | 321 | jchar* java_lang_String::as_unicode_string(oop java_string, int& length, TRAPS) { |
aoqi@0 | 322 | typeArrayOop value = java_lang_String::value(java_string); |
aoqi@0 | 323 | int offset = java_lang_String::offset(java_string); |
aoqi@0 | 324 | length = java_lang_String::length(java_string); |
aoqi@0 | 325 | |
aoqi@0 | 326 | jchar* result = NEW_RESOURCE_ARRAY_RETURN_NULL(jchar, length); |
aoqi@0 | 327 | if (result != NULL) { |
aoqi@0 | 328 | for (int index = 0; index < length; index++) { |
aoqi@0 | 329 | result[index] = value->char_at(index + offset); |
aoqi@0 | 330 | } |
aoqi@0 | 331 | } else { |
aoqi@0 | 332 | THROW_MSG_0(vmSymbols::java_lang_OutOfMemoryError(), "could not allocate Unicode string"); |
aoqi@0 | 333 | } |
aoqi@0 | 334 | return result; |
aoqi@0 | 335 | } |
aoqi@0 | 336 | |
aoqi@0 | 337 | unsigned int java_lang_String::hash_code(oop java_string) { |
aoqi@0 | 338 | int length = java_lang_String::length(java_string); |
aoqi@0 | 339 | // Zero length string will hash to zero with String.hashCode() function. |
aoqi@0 | 340 | if (length == 0) return 0; |
aoqi@0 | 341 | |
aoqi@0 | 342 | typeArrayOop value = java_lang_String::value(java_string); |
aoqi@0 | 343 | int offset = java_lang_String::offset(java_string); |
aoqi@0 | 344 | return java_lang_String::hash_code(value->char_at_addr(offset), length); |
aoqi@0 | 345 | } |
aoqi@0 | 346 | |
aoqi@0 | 347 | char* java_lang_String::as_quoted_ascii(oop java_string) { |
aoqi@0 | 348 | typeArrayOop value = java_lang_String::value(java_string); |
aoqi@0 | 349 | int offset = java_lang_String::offset(java_string); |
aoqi@0 | 350 | int length = java_lang_String::length(java_string); |
aoqi@0 | 351 | |
aoqi@0 | 352 | jchar* base = (length == 0) ? NULL : value->char_at_addr(offset); |
aoqi@0 | 353 | if (base == NULL) return NULL; |
aoqi@0 | 354 | |
aoqi@0 | 355 | int result_length = UNICODE::quoted_ascii_length(base, length) + 1; |
aoqi@0 | 356 | char* result = NEW_RESOURCE_ARRAY(char, result_length); |
aoqi@0 | 357 | UNICODE::as_quoted_ascii(base, length, result, result_length); |
aoqi@0 | 358 | assert(result_length >= length + 1, "must not be shorter"); |
aoqi@0 | 359 | assert(result_length == (int)strlen(result) + 1, "must match"); |
aoqi@0 | 360 | return result; |
aoqi@0 | 361 | } |
aoqi@0 | 362 | |
aoqi@0 | 363 | unsigned int java_lang_String::hash_string(oop java_string) { |
aoqi@0 | 364 | int length = java_lang_String::length(java_string); |
aoqi@0 | 365 | // Zero length string doesn't hash necessarily hash to zero. |
aoqi@0 | 366 | if (length == 0) { |
aoqi@0 | 367 | return StringTable::hash_string(NULL, 0); |
aoqi@0 | 368 | } |
aoqi@0 | 369 | |
aoqi@0 | 370 | typeArrayOop value = java_lang_String::value(java_string); |
aoqi@0 | 371 | int offset = java_lang_String::offset(java_string); |
aoqi@0 | 372 | return StringTable::hash_string(value->char_at_addr(offset), length); |
aoqi@0 | 373 | } |
aoqi@0 | 374 | |
aoqi@0 | 375 | Symbol* java_lang_String::as_symbol(Handle java_string, TRAPS) { |
aoqi@0 | 376 | oop obj = java_string(); |
aoqi@0 | 377 | typeArrayOop value = java_lang_String::value(obj); |
aoqi@0 | 378 | int offset = java_lang_String::offset(obj); |
aoqi@0 | 379 | int length = java_lang_String::length(obj); |
aoqi@0 | 380 | jchar* base = (length == 0) ? NULL : value->char_at_addr(offset); |
aoqi@0 | 381 | Symbol* sym = SymbolTable::lookup_unicode(base, length, THREAD); |
aoqi@0 | 382 | return sym; |
aoqi@0 | 383 | } |
aoqi@0 | 384 | |
aoqi@0 | 385 | Symbol* java_lang_String::as_symbol_or_null(oop java_string) { |
aoqi@0 | 386 | typeArrayOop value = java_lang_String::value(java_string); |
aoqi@0 | 387 | int offset = java_lang_String::offset(java_string); |
aoqi@0 | 388 | int length = java_lang_String::length(java_string); |
aoqi@0 | 389 | jchar* base = (length == 0) ? NULL : value->char_at_addr(offset); |
aoqi@0 | 390 | return SymbolTable::probe_unicode(base, length); |
aoqi@0 | 391 | } |
aoqi@0 | 392 | |
aoqi@0 | 393 | |
aoqi@0 | 394 | int java_lang_String::utf8_length(oop java_string) { |
aoqi@0 | 395 | typeArrayOop value = java_lang_String::value(java_string); |
aoqi@0 | 396 | int offset = java_lang_String::offset(java_string); |
aoqi@0 | 397 | int length = java_lang_String::length(java_string); |
aoqi@0 | 398 | jchar* position = (length == 0) ? NULL : value->char_at_addr(offset); |
aoqi@0 | 399 | return UNICODE::utf8_length(position, length); |
aoqi@0 | 400 | } |
aoqi@0 | 401 | |
aoqi@0 | 402 | char* java_lang_String::as_utf8_string(oop java_string) { |
aoqi@0 | 403 | typeArrayOop value = java_lang_String::value(java_string); |
aoqi@0 | 404 | int offset = java_lang_String::offset(java_string); |
aoqi@0 | 405 | int length = java_lang_String::length(java_string); |
aoqi@0 | 406 | jchar* position = (length == 0) ? NULL : value->char_at_addr(offset); |
aoqi@0 | 407 | return UNICODE::as_utf8(position, length); |
aoqi@0 | 408 | } |
aoqi@0 | 409 | |
aoqi@0 | 410 | char* java_lang_String::as_utf8_string(oop java_string, char* buf, int buflen) { |
aoqi@0 | 411 | typeArrayOop value = java_lang_String::value(java_string); |
aoqi@0 | 412 | int offset = java_lang_String::offset(java_string); |
aoqi@0 | 413 | int length = java_lang_String::length(java_string); |
aoqi@0 | 414 | jchar* position = (length == 0) ? NULL : value->char_at_addr(offset); |
aoqi@0 | 415 | return UNICODE::as_utf8(position, length, buf, buflen); |
aoqi@0 | 416 | } |
aoqi@0 | 417 | |
aoqi@0 | 418 | char* java_lang_String::as_utf8_string(oop java_string, int start, int len) { |
aoqi@0 | 419 | typeArrayOop value = java_lang_String::value(java_string); |
aoqi@0 | 420 | int offset = java_lang_String::offset(java_string); |
aoqi@0 | 421 | int length = java_lang_String::length(java_string); |
aoqi@0 | 422 | assert(start + len <= length, "just checking"); |
aoqi@0 | 423 | jchar* position = value->char_at_addr(offset + start); |
aoqi@0 | 424 | return UNICODE::as_utf8(position, len); |
aoqi@0 | 425 | } |
aoqi@0 | 426 | |
aoqi@0 | 427 | bool java_lang_String::equals(oop java_string, jchar* chars, int len) { |
aoqi@0 | 428 | assert(java_string->klass() == SystemDictionary::String_klass(), |
aoqi@0 | 429 | "must be java_string"); |
aoqi@0 | 430 | typeArrayOop value = java_lang_String::value(java_string); |
aoqi@0 | 431 | int offset = java_lang_String::offset(java_string); |
aoqi@0 | 432 | int length = java_lang_String::length(java_string); |
aoqi@0 | 433 | if (length != len) { |
aoqi@0 | 434 | return false; |
aoqi@0 | 435 | } |
aoqi@0 | 436 | for (int i = 0; i < len; i++) { |
aoqi@0 | 437 | if (value->char_at(i + offset) != chars[i]) { |
aoqi@0 | 438 | return false; |
aoqi@0 | 439 | } |
aoqi@0 | 440 | } |
aoqi@0 | 441 | return true; |
aoqi@0 | 442 | } |
aoqi@0 | 443 | |
aoqi@0 | 444 | bool java_lang_String::equals(oop str1, oop str2) { |
aoqi@0 | 445 | assert(str1->klass() == SystemDictionary::String_klass(), |
aoqi@0 | 446 | "must be java String"); |
aoqi@0 | 447 | assert(str2->klass() == SystemDictionary::String_klass(), |
aoqi@0 | 448 | "must be java String"); |
aoqi@0 | 449 | typeArrayOop value1 = java_lang_String::value(str1); |
aoqi@0 | 450 | int offset1 = java_lang_String::offset(str1); |
aoqi@0 | 451 | int length1 = java_lang_String::length(str1); |
aoqi@0 | 452 | typeArrayOop value2 = java_lang_String::value(str2); |
aoqi@0 | 453 | int offset2 = java_lang_String::offset(str2); |
aoqi@0 | 454 | int length2 = java_lang_String::length(str2); |
aoqi@0 | 455 | |
aoqi@0 | 456 | if (length1 != length2) { |
aoqi@0 | 457 | return false; |
aoqi@0 | 458 | } |
aoqi@0 | 459 | for (int i = 0; i < length1; i++) { |
aoqi@0 | 460 | if (value1->char_at(i + offset1) != value2->char_at(i + offset2)) { |
aoqi@0 | 461 | return false; |
aoqi@0 | 462 | } |
aoqi@0 | 463 | } |
aoqi@0 | 464 | return true; |
aoqi@0 | 465 | } |
aoqi@0 | 466 | |
stefank@6975 | 467 | void java_lang_String::print(oop java_string, outputStream* st) { |
stefank@6975 | 468 | assert(java_string->klass() == SystemDictionary::String_klass(), "must be java_string"); |
stefank@6975 | 469 | typeArrayOop value = java_lang_String::value(java_string); |
stefank@6975 | 470 | int offset = java_lang_String::offset(java_string); |
stefank@6975 | 471 | int length = java_lang_String::length(java_string); |
aoqi@0 | 472 | |
aoqi@0 | 473 | int end = MIN2(length, 100); |
aoqi@0 | 474 | if (value == NULL) { |
aoqi@0 | 475 | // This can happen if, e.g., printing a String |
aoqi@0 | 476 | // object before its initializer has been called |
aoqi@0 | 477 | st->print_cr("NULL"); |
aoqi@0 | 478 | } else { |
aoqi@0 | 479 | st->print("\""); |
aoqi@0 | 480 | for (int index = 0; index < length; index++) { |
aoqi@0 | 481 | st->print("%c", value->char_at(index + offset)); |
aoqi@0 | 482 | } |
aoqi@0 | 483 | st->print("\""); |
aoqi@0 | 484 | } |
aoqi@0 | 485 | } |
aoqi@0 | 486 | |
aoqi@0 | 487 | |
aoqi@0 | 488 | static void initialize_static_field(fieldDescriptor* fd, Handle mirror, TRAPS) { |
aoqi@0 | 489 | assert(mirror.not_null() && fd->is_static(), "just checking"); |
aoqi@0 | 490 | if (fd->has_initial_value()) { |
aoqi@0 | 491 | BasicType t = fd->field_type(); |
aoqi@0 | 492 | switch (t) { |
aoqi@0 | 493 | case T_BYTE: |
aoqi@0 | 494 | mirror()->byte_field_put(fd->offset(), fd->int_initial_value()); |
aoqi@0 | 495 | break; |
aoqi@0 | 496 | case T_BOOLEAN: |
aoqi@0 | 497 | mirror()->bool_field_put(fd->offset(), fd->int_initial_value()); |
aoqi@0 | 498 | break; |
aoqi@0 | 499 | case T_CHAR: |
aoqi@0 | 500 | mirror()->char_field_put(fd->offset(), fd->int_initial_value()); |
aoqi@0 | 501 | break; |
aoqi@0 | 502 | case T_SHORT: |
aoqi@0 | 503 | mirror()->short_field_put(fd->offset(), fd->int_initial_value()); |
aoqi@0 | 504 | break; |
aoqi@0 | 505 | case T_INT: |
aoqi@0 | 506 | mirror()->int_field_put(fd->offset(), fd->int_initial_value()); |
aoqi@0 | 507 | break; |
aoqi@0 | 508 | case T_FLOAT: |
aoqi@0 | 509 | mirror()->float_field_put(fd->offset(), fd->float_initial_value()); |
aoqi@0 | 510 | break; |
aoqi@0 | 511 | case T_DOUBLE: |
aoqi@0 | 512 | mirror()->double_field_put(fd->offset(), fd->double_initial_value()); |
aoqi@0 | 513 | break; |
aoqi@0 | 514 | case T_LONG: |
aoqi@0 | 515 | mirror()->long_field_put(fd->offset(), fd->long_initial_value()); |
aoqi@0 | 516 | break; |
aoqi@0 | 517 | case T_OBJECT: |
aoqi@0 | 518 | { |
aoqi@0 | 519 | #ifdef ASSERT |
aoqi@0 | 520 | TempNewSymbol sym = SymbolTable::new_symbol("Ljava/lang/String;", CHECK); |
aoqi@0 | 521 | assert(fd->signature() == sym, "just checking"); |
aoqi@0 | 522 | #endif |
aoqi@0 | 523 | oop string = fd->string_initial_value(CHECK); |
aoqi@0 | 524 | mirror()->obj_field_put(fd->offset(), string); |
aoqi@0 | 525 | } |
aoqi@0 | 526 | break; |
aoqi@0 | 527 | default: |
aoqi@0 | 528 | THROW_MSG(vmSymbols::java_lang_ClassFormatError(), |
aoqi@0 | 529 | "Illegal ConstantValue attribute in class file"); |
aoqi@0 | 530 | } |
aoqi@0 | 531 | } |
aoqi@0 | 532 | } |
aoqi@0 | 533 | |
aoqi@0 | 534 | |
aoqi@0 | 535 | void java_lang_Class::fixup_mirror(KlassHandle k, TRAPS) { |
aoqi@0 | 536 | assert(InstanceMirrorKlass::offset_of_static_fields() != 0, "must have been computed already"); |
aoqi@0 | 537 | |
aoqi@0 | 538 | // If the offset was read from the shared archive, it was fixed up already |
aoqi@0 | 539 | if (!k->is_shared()) { |
aoqi@0 | 540 | if (k->oop_is_instance()) { |
aoqi@0 | 541 | // During bootstrap, java.lang.Class wasn't loaded so static field |
aoqi@0 | 542 | // offsets were computed without the size added it. Go back and |
aoqi@0 | 543 | // update all the static field offsets to included the size. |
aoqi@0 | 544 | for (JavaFieldStream fs(InstanceKlass::cast(k())); !fs.done(); fs.next()) { |
aoqi@0 | 545 | if (fs.access_flags().is_static()) { |
aoqi@0 | 546 | int real_offset = fs.offset() + InstanceMirrorKlass::offset_of_static_fields(); |
aoqi@0 | 547 | fs.set_offset(real_offset); |
aoqi@0 | 548 | } |
aoqi@0 | 549 | } |
aoqi@0 | 550 | } |
aoqi@0 | 551 | } |
coleenp@7129 | 552 | create_mirror(k, Handle(NULL), Handle(NULL), CHECK); |
aoqi@0 | 553 | } |
aoqi@0 | 554 | |
aoqi@0 | 555 | void java_lang_Class::initialize_mirror_fields(KlassHandle k, |
aoqi@0 | 556 | Handle mirror, |
aoqi@0 | 557 | Handle protection_domain, |
aoqi@0 | 558 | TRAPS) { |
aoqi@0 | 559 | // Allocate a simple java object for a lock. |
aoqi@0 | 560 | // This needs to be a java object because during class initialization |
aoqi@0 | 561 | // it can be held across a java call. |
aoqi@0 | 562 | typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK); |
aoqi@0 | 563 | set_init_lock(mirror(), r); |
aoqi@0 | 564 | |
aoqi@0 | 565 | // Set protection domain also |
aoqi@0 | 566 | set_protection_domain(mirror(), protection_domain()); |
aoqi@0 | 567 | |
aoqi@0 | 568 | // Initialize static fields |
aoqi@0 | 569 | InstanceKlass::cast(k())->do_local_static_fields(&initialize_static_field, mirror, CHECK); |
aoqi@0 | 570 | } |
aoqi@0 | 571 | |
coleenp@7129 | 572 | void java_lang_Class::create_mirror(KlassHandle k, Handle class_loader, |
coleenp@7129 | 573 | Handle protection_domain, TRAPS) { |
aoqi@0 | 574 | assert(k->java_mirror() == NULL, "should only assign mirror once"); |
aoqi@0 | 575 | // Use this moment of initialization to cache modifier_flags also, |
aoqi@0 | 576 | // to support Class.getModifiers(). Instance classes recalculate |
aoqi@0 | 577 | // the cached flags after the class file is parsed, but before the |
aoqi@0 | 578 | // class is put into the system dictionary. |
aoqi@0 | 579 | int computed_modifiers = k->compute_modifier_flags(CHECK); |
aoqi@0 | 580 | k->set_modifier_flags(computed_modifiers); |
aoqi@0 | 581 | // Class_klass has to be loaded because it is used to allocate |
aoqi@0 | 582 | // the mirror. |
aoqi@0 | 583 | if (SystemDictionary::Class_klass_loaded()) { |
aoqi@0 | 584 | // Allocate mirror (java.lang.Class instance) |
aoqi@0 | 585 | Handle mirror = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK); |
aoqi@0 | 586 | |
aoqi@0 | 587 | // Setup indirection from mirror->klass |
aoqi@0 | 588 | if (!k.is_null()) { |
aoqi@0 | 589 | java_lang_Class::set_klass(mirror(), k()); |
aoqi@0 | 590 | } |
aoqi@0 | 591 | |
aoqi@0 | 592 | InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass()); |
aoqi@0 | 593 | assert(oop_size(mirror()) == mk->instance_size(k), "should have been set"); |
aoqi@0 | 594 | |
aoqi@0 | 595 | java_lang_Class::set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror())); |
aoqi@0 | 596 | |
aoqi@0 | 597 | // It might also have a component mirror. This mirror must already exist. |
aoqi@0 | 598 | if (k->oop_is_array()) { |
aoqi@0 | 599 | Handle comp_mirror; |
aoqi@0 | 600 | if (k->oop_is_typeArray()) { |
aoqi@0 | 601 | BasicType type = TypeArrayKlass::cast(k())->element_type(); |
aoqi@0 | 602 | comp_mirror = Universe::java_mirror(type); |
aoqi@0 | 603 | } else { |
aoqi@0 | 604 | assert(k->oop_is_objArray(), "Must be"); |
aoqi@0 | 605 | Klass* element_klass = ObjArrayKlass::cast(k())->element_klass(); |
aoqi@0 | 606 | assert(element_klass != NULL, "Must have an element klass"); |
aoqi@0 | 607 | comp_mirror = element_klass->java_mirror(); |
aoqi@0 | 608 | } |
aoqi@0 | 609 | assert(comp_mirror.not_null(), "must have a mirror"); |
aoqi@0 | 610 | |
aoqi@0 | 611 | // Two-way link between the array klass and its component mirror: |
aoqi@0 | 612 | ArrayKlass::cast(k())->set_component_mirror(comp_mirror()); |
aoqi@0 | 613 | set_array_klass(comp_mirror(), k()); |
aoqi@0 | 614 | } else { |
aoqi@0 | 615 | assert(k->oop_is_instance(), "Must be"); |
aoqi@0 | 616 | |
aoqi@0 | 617 | initialize_mirror_fields(k, mirror, protection_domain, THREAD); |
aoqi@0 | 618 | if (HAS_PENDING_EXCEPTION) { |
aoqi@0 | 619 | // If any of the fields throws an exception like OOM remove the klass field |
aoqi@0 | 620 | // from the mirror so GC doesn't follow it after the klass has been deallocated. |
aoqi@0 | 621 | // This mirror looks like a primitive type, which logically it is because it |
aoqi@0 | 622 | // it represents no class. |
aoqi@0 | 623 | java_lang_Class::set_klass(mirror(), NULL); |
aoqi@0 | 624 | return; |
aoqi@0 | 625 | } |
aoqi@0 | 626 | } |
aoqi@0 | 627 | |
coleenp@7129 | 628 | // set the classLoader field in the java_lang_Class instance |
coleenp@7226 | 629 | assert(class_loader() == k->class_loader(), "should be same"); |
coleenp@7129 | 630 | set_class_loader(mirror(), class_loader()); |
coleenp@7129 | 631 | |
aoqi@0 | 632 | // Setup indirection from klass->mirror last |
aoqi@0 | 633 | // after any exceptions can happen during allocations. |
aoqi@0 | 634 | if (!k.is_null()) { |
aoqi@0 | 635 | k->set_java_mirror(mirror()); |
aoqi@0 | 636 | } |
aoqi@0 | 637 | } else { |
aoqi@0 | 638 | if (fixup_mirror_list() == NULL) { |
aoqi@0 | 639 | GrowableArray<Klass*>* list = |
aoqi@0 | 640 | new (ResourceObj::C_HEAP, mtClass) GrowableArray<Klass*>(40, true); |
aoqi@0 | 641 | set_fixup_mirror_list(list); |
aoqi@0 | 642 | } |
aoqi@0 | 643 | fixup_mirror_list()->push(k()); |
aoqi@0 | 644 | } |
aoqi@0 | 645 | } |
aoqi@0 | 646 | |
aoqi@0 | 647 | |
aoqi@0 | 648 | int java_lang_Class::oop_size(oop java_class) { |
aoqi@0 | 649 | assert(_oop_size_offset != 0, "must be set"); |
aoqi@0 | 650 | return java_class->int_field(_oop_size_offset); |
aoqi@0 | 651 | } |
aoqi@0 | 652 | void java_lang_Class::set_oop_size(oop java_class, int size) { |
aoqi@0 | 653 | assert(_oop_size_offset != 0, "must be set"); |
aoqi@0 | 654 | java_class->int_field_put(_oop_size_offset, size); |
aoqi@0 | 655 | } |
aoqi@0 | 656 | int java_lang_Class::static_oop_field_count(oop java_class) { |
aoqi@0 | 657 | assert(_static_oop_field_count_offset != 0, "must be set"); |
aoqi@0 | 658 | return java_class->int_field(_static_oop_field_count_offset); |
aoqi@0 | 659 | } |
aoqi@0 | 660 | void java_lang_Class::set_static_oop_field_count(oop java_class, int size) { |
aoqi@0 | 661 | assert(_static_oop_field_count_offset != 0, "must be set"); |
aoqi@0 | 662 | java_class->int_field_put(_static_oop_field_count_offset, size); |
aoqi@0 | 663 | } |
aoqi@0 | 664 | |
aoqi@0 | 665 | oop java_lang_Class::protection_domain(oop java_class) { |
aoqi@0 | 666 | assert(_protection_domain_offset != 0, "must be set"); |
aoqi@0 | 667 | return java_class->obj_field(_protection_domain_offset); |
aoqi@0 | 668 | } |
aoqi@0 | 669 | void java_lang_Class::set_protection_domain(oop java_class, oop pd) { |
aoqi@0 | 670 | assert(_protection_domain_offset != 0, "must be set"); |
aoqi@0 | 671 | java_class->obj_field_put(_protection_domain_offset, pd); |
aoqi@0 | 672 | } |
aoqi@0 | 673 | |
aoqi@0 | 674 | oop java_lang_Class::init_lock(oop java_class) { |
aoqi@0 | 675 | assert(_init_lock_offset != 0, "must be set"); |
aoqi@0 | 676 | return java_class->obj_field(_init_lock_offset); |
aoqi@0 | 677 | } |
aoqi@0 | 678 | void java_lang_Class::set_init_lock(oop java_class, oop init_lock) { |
aoqi@0 | 679 | assert(_init_lock_offset != 0, "must be set"); |
aoqi@0 | 680 | java_class->obj_field_put(_init_lock_offset, init_lock); |
aoqi@0 | 681 | } |
aoqi@0 | 682 | |
aoqi@0 | 683 | objArrayOop java_lang_Class::signers(oop java_class) { |
aoqi@0 | 684 | assert(_signers_offset != 0, "must be set"); |
aoqi@0 | 685 | return (objArrayOop)java_class->obj_field(_signers_offset); |
aoqi@0 | 686 | } |
aoqi@0 | 687 | void java_lang_Class::set_signers(oop java_class, objArrayOop signers) { |
aoqi@0 | 688 | assert(_signers_offset != 0, "must be set"); |
aoqi@0 | 689 | java_class->obj_field_put(_signers_offset, (oop)signers); |
aoqi@0 | 690 | } |
aoqi@0 | 691 | |
aoqi@0 | 692 | |
coleenp@7129 | 693 | void java_lang_Class::set_class_loader(oop java_class, oop loader) { |
coleenp@7129 | 694 | // jdk7 runs Queens in bootstrapping and jdk8-9 has no coordinated pushes yet. |
coleenp@7129 | 695 | if (_class_loader_offset != 0) { |
coleenp@7129 | 696 | java_class->obj_field_put(_class_loader_offset, loader); |
coleenp@7129 | 697 | } |
coleenp@7129 | 698 | } |
coleenp@7129 | 699 | |
coleenp@7129 | 700 | oop java_lang_Class::class_loader(oop java_class) { |
coleenp@7129 | 701 | assert(_class_loader_offset != 0, "must be set"); |
coleenp@7129 | 702 | return java_class->obj_field(_class_loader_offset); |
coleenp@7129 | 703 | } |
coleenp@7129 | 704 | |
aoqi@0 | 705 | oop java_lang_Class::create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS) { |
aoqi@0 | 706 | // This should be improved by adding a field at the Java level or by |
aoqi@0 | 707 | // introducing a new VM klass (see comment in ClassFileParser) |
aoqi@0 | 708 | oop java_class = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(NULL, CHECK_0); |
aoqi@0 | 709 | if (type != T_VOID) { |
aoqi@0 | 710 | Klass* aklass = Universe::typeArrayKlassObj(type); |
aoqi@0 | 711 | assert(aklass != NULL, "correct bootstrap"); |
aoqi@0 | 712 | set_array_klass(java_class, aklass); |
aoqi@0 | 713 | } |
aoqi@0 | 714 | #ifdef ASSERT |
aoqi@0 | 715 | InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(SystemDictionary::Class_klass()); |
aoqi@0 | 716 | assert(java_lang_Class::static_oop_field_count(java_class) == 0, "should have been zeroed by allocation"); |
aoqi@0 | 717 | #endif |
aoqi@0 | 718 | return java_class; |
aoqi@0 | 719 | } |
aoqi@0 | 720 | |
aoqi@0 | 721 | |
aoqi@0 | 722 | Klass* java_lang_Class::as_Klass(oop java_class) { |
aoqi@0 | 723 | //%note memory_2 |
aoqi@0 | 724 | assert(java_lang_Class::is_instance(java_class), "must be a Class object"); |
aoqi@0 | 725 | Klass* k = ((Klass*)java_class->metadata_field(_klass_offset)); |
aoqi@0 | 726 | assert(k == NULL || k->is_klass(), "type check"); |
aoqi@0 | 727 | return k; |
aoqi@0 | 728 | } |
aoqi@0 | 729 | |
aoqi@0 | 730 | |
aoqi@0 | 731 | void java_lang_Class::set_klass(oop java_class, Klass* klass) { |
aoqi@0 | 732 | assert(java_lang_Class::is_instance(java_class), "must be a Class object"); |
aoqi@0 | 733 | java_class->metadata_field_put(_klass_offset, klass); |
aoqi@0 | 734 | } |
aoqi@0 | 735 | |
aoqi@0 | 736 | |
aoqi@0 | 737 | void java_lang_Class::print_signature(oop java_class, outputStream* st) { |
aoqi@0 | 738 | assert(java_lang_Class::is_instance(java_class), "must be a Class object"); |
aoqi@0 | 739 | Symbol* name = NULL; |
aoqi@0 | 740 | bool is_instance = false; |
aoqi@0 | 741 | if (is_primitive(java_class)) { |
aoqi@0 | 742 | name = vmSymbols::type_signature(primitive_type(java_class)); |
aoqi@0 | 743 | } else { |
aoqi@0 | 744 | Klass* k = as_Klass(java_class); |
aoqi@0 | 745 | is_instance = k->oop_is_instance(); |
aoqi@0 | 746 | name = k->name(); |
aoqi@0 | 747 | } |
aoqi@0 | 748 | if (name == NULL) { |
aoqi@0 | 749 | st->print("<null>"); |
aoqi@0 | 750 | return; |
aoqi@0 | 751 | } |
aoqi@0 | 752 | if (is_instance) st->print("L"); |
aoqi@0 | 753 | st->write((char*) name->base(), (int) name->utf8_length()); |
aoqi@0 | 754 | if (is_instance) st->print(";"); |
aoqi@0 | 755 | } |
aoqi@0 | 756 | |
aoqi@0 | 757 | Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found, TRAPS) { |
aoqi@0 | 758 | assert(java_lang_Class::is_instance(java_class), "must be a Class object"); |
aoqi@0 | 759 | Symbol* name; |
aoqi@0 | 760 | if (is_primitive(java_class)) { |
aoqi@0 | 761 | name = vmSymbols::type_signature(primitive_type(java_class)); |
aoqi@0 | 762 | // Because this can create a new symbol, the caller has to decrement |
aoqi@0 | 763 | // the refcount, so make adjustment here and below for symbols returned |
aoqi@0 | 764 | // that are not created or incremented due to a successful lookup. |
aoqi@0 | 765 | name->increment_refcount(); |
aoqi@0 | 766 | } else { |
aoqi@0 | 767 | Klass* k = as_Klass(java_class); |
aoqi@0 | 768 | if (!k->oop_is_instance()) { |
aoqi@0 | 769 | name = k->name(); |
aoqi@0 | 770 | name->increment_refcount(); |
aoqi@0 | 771 | } else { |
aoqi@0 | 772 | ResourceMark rm; |
aoqi@0 | 773 | const char* sigstr = k->signature_name(); |
aoqi@0 | 774 | int siglen = (int) strlen(sigstr); |
aoqi@0 | 775 | if (!intern_if_not_found) { |
aoqi@0 | 776 | name = SymbolTable::probe(sigstr, siglen); |
aoqi@0 | 777 | } else { |
aoqi@0 | 778 | name = SymbolTable::new_symbol(sigstr, siglen, THREAD); |
aoqi@0 | 779 | } |
aoqi@0 | 780 | } |
aoqi@0 | 781 | } |
aoqi@0 | 782 | return name; |
aoqi@0 | 783 | } |
aoqi@0 | 784 | |
vkempik@8060 | 785 | // Returns the Java name for this Java mirror (Resource allocated) |
vkempik@8060 | 786 | // See Klass::external_name(). |
vkempik@8060 | 787 | // For primitive type Java mirrors, its type name is returned. |
vkempik@8060 | 788 | const char* java_lang_Class::as_external_name(oop java_class) { |
vkempik@8060 | 789 | assert(java_lang_Class::is_instance(java_class), "must be a Class object"); |
vkempik@8060 | 790 | const char* name = NULL; |
vkempik@8060 | 791 | if (is_primitive(java_class)) { |
vkempik@8060 | 792 | name = type2name(primitive_type(java_class)); |
vkempik@8060 | 793 | } else { |
vkempik@8060 | 794 | name = as_Klass(java_class)->external_name(); |
vkempik@8060 | 795 | } |
vkempik@8060 | 796 | if (name == NULL) { |
vkempik@8060 | 797 | name = "<null>"; |
vkempik@8060 | 798 | } |
vkempik@8060 | 799 | return name; |
vkempik@8060 | 800 | } |
aoqi@0 | 801 | |
aoqi@0 | 802 | Klass* java_lang_Class::array_klass(oop java_class) { |
aoqi@0 | 803 | Klass* k = ((Klass*)java_class->metadata_field(_array_klass_offset)); |
aoqi@0 | 804 | assert(k == NULL || k->is_klass() && k->oop_is_array(), "should be array klass"); |
aoqi@0 | 805 | return k; |
aoqi@0 | 806 | } |
aoqi@0 | 807 | |
aoqi@0 | 808 | |
aoqi@0 | 809 | void java_lang_Class::set_array_klass(oop java_class, Klass* klass) { |
aoqi@0 | 810 | assert(klass->is_klass() && klass->oop_is_array(), "should be array klass"); |
aoqi@0 | 811 | java_class->metadata_field_put(_array_klass_offset, klass); |
aoqi@0 | 812 | } |
aoqi@0 | 813 | |
aoqi@0 | 814 | |
aoqi@0 | 815 | bool java_lang_Class::is_primitive(oop java_class) { |
aoqi@0 | 816 | // should assert: |
aoqi@0 | 817 | //assert(java_lang_Class::is_instance(java_class), "must be a Class object"); |
aoqi@0 | 818 | bool is_primitive = (java_class->metadata_field(_klass_offset) == NULL); |
aoqi@0 | 819 | |
aoqi@0 | 820 | #ifdef ASSERT |
aoqi@0 | 821 | if (is_primitive) { |
aoqi@0 | 822 | Klass* k = ((Klass*)java_class->metadata_field(_array_klass_offset)); |
aoqi@0 | 823 | assert(k == NULL || is_java_primitive(ArrayKlass::cast(k)->element_type()), |
aoqi@0 | 824 | "Should be either the T_VOID primitive or a java primitive"); |
aoqi@0 | 825 | } |
aoqi@0 | 826 | #endif |
aoqi@0 | 827 | |
aoqi@0 | 828 | return is_primitive; |
aoqi@0 | 829 | } |
aoqi@0 | 830 | |
aoqi@0 | 831 | |
aoqi@0 | 832 | BasicType java_lang_Class::primitive_type(oop java_class) { |
aoqi@0 | 833 | assert(java_lang_Class::is_primitive(java_class), "just checking"); |
aoqi@0 | 834 | Klass* ak = ((Klass*)java_class->metadata_field(_array_klass_offset)); |
aoqi@0 | 835 | BasicType type = T_VOID; |
aoqi@0 | 836 | if (ak != NULL) { |
aoqi@0 | 837 | // Note: create_basic_type_mirror above initializes ak to a non-null value. |
aoqi@0 | 838 | type = ArrayKlass::cast(ak)->element_type(); |
aoqi@0 | 839 | } else { |
aoqi@0 | 840 | assert(java_class == Universe::void_mirror(), "only valid non-array primitive"); |
aoqi@0 | 841 | } |
aoqi@0 | 842 | assert(Universe::java_mirror(type) == java_class, "must be consistent"); |
aoqi@0 | 843 | return type; |
aoqi@0 | 844 | } |
aoqi@0 | 845 | |
aoqi@0 | 846 | BasicType java_lang_Class::as_BasicType(oop java_class, Klass** reference_klass) { |
aoqi@0 | 847 | assert(java_lang_Class::is_instance(java_class), "must be a Class object"); |
aoqi@0 | 848 | if (is_primitive(java_class)) { |
aoqi@0 | 849 | if (reference_klass != NULL) |
aoqi@0 | 850 | (*reference_klass) = NULL; |
aoqi@0 | 851 | return primitive_type(java_class); |
aoqi@0 | 852 | } else { |
aoqi@0 | 853 | if (reference_klass != NULL) |
aoqi@0 | 854 | (*reference_klass) = as_Klass(java_class); |
aoqi@0 | 855 | return T_OBJECT; |
aoqi@0 | 856 | } |
aoqi@0 | 857 | } |
aoqi@0 | 858 | |
aoqi@0 | 859 | |
aoqi@0 | 860 | oop java_lang_Class::primitive_mirror(BasicType t) { |
aoqi@0 | 861 | oop mirror = Universe::java_mirror(t); |
aoqi@0 | 862 | assert(mirror != NULL && mirror->is_a(SystemDictionary::Class_klass()), "must be a Class"); |
aoqi@0 | 863 | assert(java_lang_Class::is_primitive(mirror), "must be primitive"); |
aoqi@0 | 864 | return mirror; |
aoqi@0 | 865 | } |
aoqi@0 | 866 | |
aoqi@0 | 867 | bool java_lang_Class::offsets_computed = false; |
aoqi@0 | 868 | int java_lang_Class::classRedefinedCount_offset = -1; |
aoqi@0 | 869 | |
aoqi@0 | 870 | void java_lang_Class::compute_offsets() { |
aoqi@0 | 871 | assert(!offsets_computed, "offsets should be initialized only once"); |
aoqi@0 | 872 | offsets_computed = true; |
aoqi@0 | 873 | |
aoqi@0 | 874 | Klass* klass_oop = SystemDictionary::Class_klass(); |
aoqi@0 | 875 | // The classRedefinedCount field is only present starting in 1.5, |
aoqi@0 | 876 | // so don't go fatal. |
aoqi@0 | 877 | compute_optional_offset(classRedefinedCount_offset, |
aoqi@0 | 878 | klass_oop, vmSymbols::classRedefinedCount_name(), vmSymbols::int_signature()); |
aoqi@0 | 879 | |
coleenp@7129 | 880 | // Needs to be optional because the old build runs Queens during bootstrapping |
coleenp@7129 | 881 | // and jdk8-9 doesn't have coordinated pushes yet. |
coleenp@7129 | 882 | compute_optional_offset(_class_loader_offset, |
coleenp@7129 | 883 | klass_oop, vmSymbols::classLoader_name(), |
coleenp@7129 | 884 | vmSymbols::classloader_signature()); |
coleenp@7129 | 885 | |
aoqi@0 | 886 | CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET); |
aoqi@0 | 887 | } |
aoqi@0 | 888 | |
aoqi@0 | 889 | int java_lang_Class::classRedefinedCount(oop the_class_mirror) { |
aoqi@0 | 890 | if (!JDK_Version::is_gte_jdk15x_version() |
aoqi@0 | 891 | || classRedefinedCount_offset == -1) { |
aoqi@0 | 892 | // The classRedefinedCount field is only present starting in 1.5. |
aoqi@0 | 893 | // If we don't have an offset for it then just return -1 as a marker. |
aoqi@0 | 894 | return -1; |
aoqi@0 | 895 | } |
aoqi@0 | 896 | |
aoqi@0 | 897 | return the_class_mirror->int_field(classRedefinedCount_offset); |
aoqi@0 | 898 | } |
aoqi@0 | 899 | |
aoqi@0 | 900 | void java_lang_Class::set_classRedefinedCount(oop the_class_mirror, int value) { |
aoqi@0 | 901 | if (!JDK_Version::is_gte_jdk15x_version() |
aoqi@0 | 902 | || classRedefinedCount_offset == -1) { |
aoqi@0 | 903 | // The classRedefinedCount field is only present starting in 1.5. |
aoqi@0 | 904 | // If we don't have an offset for it then nothing to set. |
aoqi@0 | 905 | return; |
aoqi@0 | 906 | } |
aoqi@0 | 907 | |
aoqi@0 | 908 | the_class_mirror->int_field_put(classRedefinedCount_offset, value); |
aoqi@0 | 909 | } |
aoqi@0 | 910 | |
aoqi@0 | 911 | |
aoqi@0 | 912 | // Note: JDK1.1 and before had a privateInfo_offset field which was used for the |
aoqi@0 | 913 | // platform thread structure, and a eetop offset which was used for thread |
aoqi@0 | 914 | // local storage (and unused by the HotSpot VM). In JDK1.2 the two structures |
aoqi@0 | 915 | // merged, so in the HotSpot VM we just use the eetop field for the thread |
aoqi@0 | 916 | // instead of the privateInfo_offset. |
aoqi@0 | 917 | // |
aoqi@0 | 918 | // Note: The stackSize field is only present starting in 1.4. |
aoqi@0 | 919 | |
aoqi@0 | 920 | int java_lang_Thread::_name_offset = 0; |
aoqi@0 | 921 | int java_lang_Thread::_group_offset = 0; |
aoqi@0 | 922 | int java_lang_Thread::_contextClassLoader_offset = 0; |
aoqi@0 | 923 | int java_lang_Thread::_inheritedAccessControlContext_offset = 0; |
aoqi@0 | 924 | int java_lang_Thread::_priority_offset = 0; |
aoqi@0 | 925 | int java_lang_Thread::_eetop_offset = 0; |
aoqi@0 | 926 | int java_lang_Thread::_daemon_offset = 0; |
aoqi@0 | 927 | int java_lang_Thread::_stillborn_offset = 0; |
aoqi@0 | 928 | int java_lang_Thread::_stackSize_offset = 0; |
aoqi@0 | 929 | int java_lang_Thread::_tid_offset = 0; |
aoqi@0 | 930 | int java_lang_Thread::_thread_status_offset = 0; |
aoqi@0 | 931 | int java_lang_Thread::_park_blocker_offset = 0; |
aoqi@0 | 932 | int java_lang_Thread::_park_event_offset = 0 ; |
aoqi@0 | 933 | |
aoqi@0 | 934 | |
aoqi@0 | 935 | void java_lang_Thread::compute_offsets() { |
aoqi@0 | 936 | assert(_group_offset == 0, "offsets should be initialized only once"); |
aoqi@0 | 937 | |
aoqi@0 | 938 | Klass* k = SystemDictionary::Thread_klass(); |
shade@8288 | 939 | compute_offset(_name_offset, k, vmSymbols::name_name(), vmSymbols::string_signature()); |
aoqi@0 | 940 | compute_offset(_group_offset, k, vmSymbols::group_name(), vmSymbols::threadgroup_signature()); |
aoqi@0 | 941 | compute_offset(_contextClassLoader_offset, k, vmSymbols::contextClassLoader_name(), vmSymbols::classloader_signature()); |
aoqi@0 | 942 | compute_offset(_inheritedAccessControlContext_offset, k, vmSymbols::inheritedAccessControlContext_name(), vmSymbols::accesscontrolcontext_signature()); |
aoqi@0 | 943 | compute_offset(_priority_offset, k, vmSymbols::priority_name(), vmSymbols::int_signature()); |
aoqi@0 | 944 | compute_offset(_daemon_offset, k, vmSymbols::daemon_name(), vmSymbols::bool_signature()); |
aoqi@0 | 945 | compute_offset(_eetop_offset, k, vmSymbols::eetop_name(), vmSymbols::long_signature()); |
aoqi@0 | 946 | compute_offset(_stillborn_offset, k, vmSymbols::stillborn_name(), vmSymbols::bool_signature()); |
aoqi@0 | 947 | // The stackSize field is only present starting in 1.4, so don't go fatal. |
aoqi@0 | 948 | compute_optional_offset(_stackSize_offset, k, vmSymbols::stackSize_name(), vmSymbols::long_signature()); |
aoqi@0 | 949 | // The tid and thread_status fields are only present starting in 1.5, so don't go fatal. |
aoqi@0 | 950 | compute_optional_offset(_tid_offset, k, vmSymbols::thread_id_name(), vmSymbols::long_signature()); |
aoqi@0 | 951 | compute_optional_offset(_thread_status_offset, k, vmSymbols::thread_status_name(), vmSymbols::int_signature()); |
aoqi@0 | 952 | // The parkBlocker field is only present starting in 1.6, so don't go fatal. |
aoqi@0 | 953 | compute_optional_offset(_park_blocker_offset, k, vmSymbols::park_blocker_name(), vmSymbols::object_signature()); |
aoqi@0 | 954 | compute_optional_offset(_park_event_offset, k, vmSymbols::park_event_name(), |
aoqi@0 | 955 | vmSymbols::long_signature()); |
aoqi@0 | 956 | } |
aoqi@0 | 957 | |
aoqi@0 | 958 | |
aoqi@0 | 959 | JavaThread* java_lang_Thread::thread(oop java_thread) { |
aoqi@0 | 960 | return (JavaThread*)java_thread->address_field(_eetop_offset); |
aoqi@0 | 961 | } |
aoqi@0 | 962 | |
aoqi@0 | 963 | |
aoqi@0 | 964 | void java_lang_Thread::set_thread(oop java_thread, JavaThread* thread) { |
aoqi@0 | 965 | java_thread->address_field_put(_eetop_offset, (address)thread); |
aoqi@0 | 966 | } |
aoqi@0 | 967 | |
aoqi@0 | 968 | |
shade@8288 | 969 | oop java_lang_Thread::name(oop java_thread) { |
shade@8288 | 970 | return java_thread->obj_field(_name_offset); |
shade@8288 | 971 | } |
shade@8288 | 972 | |
shade@8288 | 973 | |
shade@8288 | 974 | void java_lang_Thread::set_name(oop java_thread, oop name) { |
aoqi@0 | 975 | java_thread->obj_field_put(_name_offset, name); |
aoqi@0 | 976 | } |
aoqi@0 | 977 | |
aoqi@0 | 978 | |
aoqi@0 | 979 | ThreadPriority java_lang_Thread::priority(oop java_thread) { |
aoqi@0 | 980 | return (ThreadPriority)java_thread->int_field(_priority_offset); |
aoqi@0 | 981 | } |
aoqi@0 | 982 | |
aoqi@0 | 983 | |
aoqi@0 | 984 | void java_lang_Thread::set_priority(oop java_thread, ThreadPriority priority) { |
aoqi@0 | 985 | java_thread->int_field_put(_priority_offset, priority); |
aoqi@0 | 986 | } |
aoqi@0 | 987 | |
aoqi@0 | 988 | |
aoqi@0 | 989 | oop java_lang_Thread::threadGroup(oop java_thread) { |
aoqi@0 | 990 | return java_thread->obj_field(_group_offset); |
aoqi@0 | 991 | } |
aoqi@0 | 992 | |
aoqi@0 | 993 | |
aoqi@0 | 994 | bool java_lang_Thread::is_stillborn(oop java_thread) { |
aoqi@0 | 995 | return java_thread->bool_field(_stillborn_offset) != 0; |
aoqi@0 | 996 | } |
aoqi@0 | 997 | |
aoqi@0 | 998 | |
aoqi@0 | 999 | // We never have reason to turn the stillborn bit off |
aoqi@0 | 1000 | void java_lang_Thread::set_stillborn(oop java_thread) { |
aoqi@0 | 1001 | java_thread->bool_field_put(_stillborn_offset, true); |
aoqi@0 | 1002 | } |
aoqi@0 | 1003 | |
aoqi@0 | 1004 | |
aoqi@0 | 1005 | bool java_lang_Thread::is_alive(oop java_thread) { |
aoqi@0 | 1006 | JavaThread* thr = java_lang_Thread::thread(java_thread); |
aoqi@0 | 1007 | return (thr != NULL); |
aoqi@0 | 1008 | } |
aoqi@0 | 1009 | |
aoqi@0 | 1010 | |
aoqi@0 | 1011 | bool java_lang_Thread::is_daemon(oop java_thread) { |
aoqi@0 | 1012 | return java_thread->bool_field(_daemon_offset) != 0; |
aoqi@0 | 1013 | } |
aoqi@0 | 1014 | |
aoqi@0 | 1015 | |
aoqi@0 | 1016 | void java_lang_Thread::set_daemon(oop java_thread) { |
aoqi@0 | 1017 | java_thread->bool_field_put(_daemon_offset, true); |
aoqi@0 | 1018 | } |
aoqi@0 | 1019 | |
aoqi@0 | 1020 | oop java_lang_Thread::context_class_loader(oop java_thread) { |
aoqi@0 | 1021 | return java_thread->obj_field(_contextClassLoader_offset); |
aoqi@0 | 1022 | } |
aoqi@0 | 1023 | |
aoqi@0 | 1024 | oop java_lang_Thread::inherited_access_control_context(oop java_thread) { |
aoqi@0 | 1025 | return java_thread->obj_field(_inheritedAccessControlContext_offset); |
aoqi@0 | 1026 | } |
aoqi@0 | 1027 | |
aoqi@0 | 1028 | |
aoqi@0 | 1029 | jlong java_lang_Thread::stackSize(oop java_thread) { |
aoqi@0 | 1030 | // The stackSize field is only present starting in 1.4 |
aoqi@0 | 1031 | if (_stackSize_offset > 0) { |
aoqi@0 | 1032 | assert(JDK_Version::is_gte_jdk14x_version(), "sanity check"); |
aoqi@0 | 1033 | return java_thread->long_field(_stackSize_offset); |
aoqi@0 | 1034 | } else { |
aoqi@0 | 1035 | return 0; |
aoqi@0 | 1036 | } |
aoqi@0 | 1037 | } |
aoqi@0 | 1038 | |
aoqi@0 | 1039 | // Write the thread status value to threadStatus field in java.lang.Thread java class. |
aoqi@0 | 1040 | void java_lang_Thread::set_thread_status(oop java_thread, |
aoqi@0 | 1041 | java_lang_Thread::ThreadStatus status) { |
aoqi@0 | 1042 | // The threadStatus is only present starting in 1.5 |
aoqi@0 | 1043 | if (_thread_status_offset > 0) { |
aoqi@0 | 1044 | java_thread->int_field_put(_thread_status_offset, status); |
aoqi@0 | 1045 | } |
aoqi@0 | 1046 | } |
aoqi@0 | 1047 | |
aoqi@0 | 1048 | // Read thread status value from threadStatus field in java.lang.Thread java class. |
aoqi@0 | 1049 | java_lang_Thread::ThreadStatus java_lang_Thread::get_thread_status(oop java_thread) { |
aoqi@0 | 1050 | assert(Thread::current()->is_Watcher_thread() || Thread::current()->is_VM_thread() || |
aoqi@0 | 1051 | JavaThread::current()->thread_state() == _thread_in_vm, |
aoqi@0 | 1052 | "Java Thread is not running in vm"); |
aoqi@0 | 1053 | // The threadStatus is only present starting in 1.5 |
aoqi@0 | 1054 | if (_thread_status_offset > 0) { |
aoqi@0 | 1055 | return (java_lang_Thread::ThreadStatus)java_thread->int_field(_thread_status_offset); |
aoqi@0 | 1056 | } else { |
aoqi@0 | 1057 | // All we can easily figure out is if it is alive, but that is |
aoqi@0 | 1058 | // enough info for a valid unknown status. |
aoqi@0 | 1059 | // These aren't restricted to valid set ThreadStatus values, so |
aoqi@0 | 1060 | // use JVMTI values and cast. |
aoqi@0 | 1061 | JavaThread* thr = java_lang_Thread::thread(java_thread); |
aoqi@0 | 1062 | if (thr == NULL) { |
aoqi@0 | 1063 | // the thread hasn't run yet or is in the process of exiting |
aoqi@0 | 1064 | return NEW; |
aoqi@0 | 1065 | } |
aoqi@0 | 1066 | return (java_lang_Thread::ThreadStatus)JVMTI_THREAD_STATE_ALIVE; |
aoqi@0 | 1067 | } |
aoqi@0 | 1068 | } |
aoqi@0 | 1069 | |
aoqi@0 | 1070 | |
aoqi@0 | 1071 | jlong java_lang_Thread::thread_id(oop java_thread) { |
aoqi@0 | 1072 | // The thread ID field is only present starting in 1.5 |
aoqi@0 | 1073 | if (_tid_offset > 0) { |
aoqi@0 | 1074 | return java_thread->long_field(_tid_offset); |
aoqi@0 | 1075 | } else { |
aoqi@0 | 1076 | return 0; |
aoqi@0 | 1077 | } |
aoqi@0 | 1078 | } |
aoqi@0 | 1079 | |
aoqi@0 | 1080 | oop java_lang_Thread::park_blocker(oop java_thread) { |
aoqi@0 | 1081 | assert(JDK_Version::current().supports_thread_park_blocker() && |
aoqi@0 | 1082 | _park_blocker_offset != 0, "Must support parkBlocker field"); |
aoqi@0 | 1083 | |
aoqi@0 | 1084 | if (_park_blocker_offset > 0) { |
aoqi@0 | 1085 | return java_thread->obj_field(_park_blocker_offset); |
aoqi@0 | 1086 | } |
aoqi@0 | 1087 | |
aoqi@0 | 1088 | return NULL; |
aoqi@0 | 1089 | } |
aoqi@0 | 1090 | |
aoqi@0 | 1091 | jlong java_lang_Thread::park_event(oop java_thread) { |
aoqi@0 | 1092 | if (_park_event_offset > 0) { |
aoqi@0 | 1093 | return java_thread->long_field(_park_event_offset); |
aoqi@0 | 1094 | } |
aoqi@0 | 1095 | return 0; |
aoqi@0 | 1096 | } |
aoqi@0 | 1097 | |
aoqi@0 | 1098 | bool java_lang_Thread::set_park_event(oop java_thread, jlong ptr) { |
aoqi@0 | 1099 | if (_park_event_offset > 0) { |
aoqi@0 | 1100 | java_thread->long_field_put(_park_event_offset, ptr); |
aoqi@0 | 1101 | return true; |
aoqi@0 | 1102 | } |
aoqi@0 | 1103 | return false; |
aoqi@0 | 1104 | } |
aoqi@0 | 1105 | |
aoqi@0 | 1106 | |
aoqi@0 | 1107 | const char* java_lang_Thread::thread_status_name(oop java_thread) { |
aoqi@0 | 1108 | assert(JDK_Version::is_gte_jdk15x_version() && _thread_status_offset != 0, "Must have thread status"); |
aoqi@0 | 1109 | ThreadStatus status = (java_lang_Thread::ThreadStatus)java_thread->int_field(_thread_status_offset); |
aoqi@0 | 1110 | switch (status) { |
aoqi@0 | 1111 | case NEW : return "NEW"; |
aoqi@0 | 1112 | case RUNNABLE : return "RUNNABLE"; |
aoqi@0 | 1113 | case SLEEPING : return "TIMED_WAITING (sleeping)"; |
aoqi@0 | 1114 | case IN_OBJECT_WAIT : return "WAITING (on object monitor)"; |
aoqi@0 | 1115 | case IN_OBJECT_WAIT_TIMED : return "TIMED_WAITING (on object monitor)"; |
aoqi@0 | 1116 | case PARKED : return "WAITING (parking)"; |
aoqi@0 | 1117 | case PARKED_TIMED : return "TIMED_WAITING (parking)"; |
aoqi@0 | 1118 | case BLOCKED_ON_MONITOR_ENTER : return "BLOCKED (on object monitor)"; |
aoqi@0 | 1119 | case TERMINATED : return "TERMINATED"; |
aoqi@0 | 1120 | default : return "UNKNOWN"; |
aoqi@0 | 1121 | }; |
aoqi@0 | 1122 | } |
aoqi@0 | 1123 | int java_lang_ThreadGroup::_parent_offset = 0; |
aoqi@0 | 1124 | int java_lang_ThreadGroup::_name_offset = 0; |
aoqi@0 | 1125 | int java_lang_ThreadGroup::_threads_offset = 0; |
aoqi@0 | 1126 | int java_lang_ThreadGroup::_groups_offset = 0; |
aoqi@0 | 1127 | int java_lang_ThreadGroup::_maxPriority_offset = 0; |
aoqi@0 | 1128 | int java_lang_ThreadGroup::_destroyed_offset = 0; |
aoqi@0 | 1129 | int java_lang_ThreadGroup::_daemon_offset = 0; |
aoqi@0 | 1130 | int java_lang_ThreadGroup::_vmAllowSuspension_offset = 0; |
aoqi@0 | 1131 | int java_lang_ThreadGroup::_nthreads_offset = 0; |
aoqi@0 | 1132 | int java_lang_ThreadGroup::_ngroups_offset = 0; |
aoqi@0 | 1133 | |
aoqi@0 | 1134 | oop java_lang_ThreadGroup::parent(oop java_thread_group) { |
aoqi@0 | 1135 | assert(java_thread_group->is_oop(), "thread group must be oop"); |
aoqi@0 | 1136 | return java_thread_group->obj_field(_parent_offset); |
aoqi@0 | 1137 | } |
aoqi@0 | 1138 | |
aoqi@0 | 1139 | // ("name as oop" accessor is not necessary) |
aoqi@0 | 1140 | |
aoqi@0 | 1141 | typeArrayOop java_lang_ThreadGroup::name(oop java_thread_group) { |
aoqi@0 | 1142 | oop name = java_thread_group->obj_field(_name_offset); |
aoqi@0 | 1143 | // ThreadGroup.name can be null |
aoqi@0 | 1144 | return name == NULL ? (typeArrayOop)NULL : java_lang_String::value(name); |
aoqi@0 | 1145 | } |
aoqi@0 | 1146 | |
aoqi@0 | 1147 | int java_lang_ThreadGroup::nthreads(oop java_thread_group) { |
aoqi@0 | 1148 | assert(java_thread_group->is_oop(), "thread group must be oop"); |
aoqi@0 | 1149 | return java_thread_group->int_field(_nthreads_offset); |
aoqi@0 | 1150 | } |
aoqi@0 | 1151 | |
aoqi@0 | 1152 | objArrayOop java_lang_ThreadGroup::threads(oop java_thread_group) { |
aoqi@0 | 1153 | oop threads = java_thread_group->obj_field(_threads_offset); |
aoqi@0 | 1154 | assert(threads != NULL, "threadgroups should have threads"); |
aoqi@0 | 1155 | assert(threads->is_objArray(), "just checking"); // Todo: Add better type checking code |
aoqi@0 | 1156 | return objArrayOop(threads); |
aoqi@0 | 1157 | } |
aoqi@0 | 1158 | |
aoqi@0 | 1159 | int java_lang_ThreadGroup::ngroups(oop java_thread_group) { |
aoqi@0 | 1160 | assert(java_thread_group->is_oop(), "thread group must be oop"); |
aoqi@0 | 1161 | return java_thread_group->int_field(_ngroups_offset); |
aoqi@0 | 1162 | } |
aoqi@0 | 1163 | |
aoqi@0 | 1164 | objArrayOop java_lang_ThreadGroup::groups(oop java_thread_group) { |
aoqi@0 | 1165 | oop groups = java_thread_group->obj_field(_groups_offset); |
aoqi@0 | 1166 | assert(groups == NULL || groups->is_objArray(), "just checking"); // Todo: Add better type checking code |
aoqi@0 | 1167 | return objArrayOop(groups); |
aoqi@0 | 1168 | } |
aoqi@0 | 1169 | |
aoqi@0 | 1170 | ThreadPriority java_lang_ThreadGroup::maxPriority(oop java_thread_group) { |
aoqi@0 | 1171 | assert(java_thread_group->is_oop(), "thread group must be oop"); |
aoqi@0 | 1172 | return (ThreadPriority) java_thread_group->int_field(_maxPriority_offset); |
aoqi@0 | 1173 | } |
aoqi@0 | 1174 | |
aoqi@0 | 1175 | bool java_lang_ThreadGroup::is_destroyed(oop java_thread_group) { |
aoqi@0 | 1176 | assert(java_thread_group->is_oop(), "thread group must be oop"); |
aoqi@0 | 1177 | return java_thread_group->bool_field(_destroyed_offset) != 0; |
aoqi@0 | 1178 | } |
aoqi@0 | 1179 | |
aoqi@0 | 1180 | bool java_lang_ThreadGroup::is_daemon(oop java_thread_group) { |
aoqi@0 | 1181 | assert(java_thread_group->is_oop(), "thread group must be oop"); |
aoqi@0 | 1182 | return java_thread_group->bool_field(_daemon_offset) != 0; |
aoqi@0 | 1183 | } |
aoqi@0 | 1184 | |
aoqi@0 | 1185 | bool java_lang_ThreadGroup::is_vmAllowSuspension(oop java_thread_group) { |
aoqi@0 | 1186 | assert(java_thread_group->is_oop(), "thread group must be oop"); |
aoqi@0 | 1187 | return java_thread_group->bool_field(_vmAllowSuspension_offset) != 0; |
aoqi@0 | 1188 | } |
aoqi@0 | 1189 | |
aoqi@0 | 1190 | void java_lang_ThreadGroup::compute_offsets() { |
aoqi@0 | 1191 | assert(_parent_offset == 0, "offsets should be initialized only once"); |
aoqi@0 | 1192 | |
aoqi@0 | 1193 | Klass* k = SystemDictionary::ThreadGroup_klass(); |
aoqi@0 | 1194 | |
aoqi@0 | 1195 | compute_offset(_parent_offset, k, vmSymbols::parent_name(), vmSymbols::threadgroup_signature()); |
aoqi@0 | 1196 | compute_offset(_name_offset, k, vmSymbols::name_name(), vmSymbols::string_signature()); |
aoqi@0 | 1197 | compute_offset(_threads_offset, k, vmSymbols::threads_name(), vmSymbols::thread_array_signature()); |
aoqi@0 | 1198 | compute_offset(_groups_offset, k, vmSymbols::groups_name(), vmSymbols::threadgroup_array_signature()); |
aoqi@0 | 1199 | compute_offset(_maxPriority_offset, k, vmSymbols::maxPriority_name(), vmSymbols::int_signature()); |
aoqi@0 | 1200 | compute_offset(_destroyed_offset, k, vmSymbols::destroyed_name(), vmSymbols::bool_signature()); |
aoqi@0 | 1201 | compute_offset(_daemon_offset, k, vmSymbols::daemon_name(), vmSymbols::bool_signature()); |
aoqi@0 | 1202 | compute_offset(_vmAllowSuspension_offset, k, vmSymbols::vmAllowSuspension_name(), vmSymbols::bool_signature()); |
aoqi@0 | 1203 | compute_offset(_nthreads_offset, k, vmSymbols::nthreads_name(), vmSymbols::int_signature()); |
aoqi@0 | 1204 | compute_offset(_ngroups_offset, k, vmSymbols::ngroups_name(), vmSymbols::int_signature()); |
aoqi@0 | 1205 | } |
aoqi@0 | 1206 | |
aoqi@0 | 1207 | oop java_lang_Throwable::unassigned_stacktrace() { |
aoqi@0 | 1208 | InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::Throwable_klass()); |
aoqi@0 | 1209 | address addr = ik->static_field_addr(static_unassigned_stacktrace_offset); |
aoqi@0 | 1210 | if (UseCompressedOops) { |
aoqi@0 | 1211 | return oopDesc::load_decode_heap_oop((narrowOop *)addr); |
aoqi@0 | 1212 | } else { |
aoqi@0 | 1213 | return oopDesc::load_decode_heap_oop((oop*)addr); |
aoqi@0 | 1214 | } |
aoqi@0 | 1215 | } |
aoqi@0 | 1216 | |
aoqi@0 | 1217 | oop java_lang_Throwable::backtrace(oop throwable) { |
aoqi@0 | 1218 | return throwable->obj_field_acquire(backtrace_offset); |
aoqi@0 | 1219 | } |
aoqi@0 | 1220 | |
aoqi@0 | 1221 | |
aoqi@0 | 1222 | void java_lang_Throwable::set_backtrace(oop throwable, oop value) { |
aoqi@0 | 1223 | throwable->release_obj_field_put(backtrace_offset, value); |
aoqi@0 | 1224 | } |
aoqi@0 | 1225 | |
aoqi@0 | 1226 | |
aoqi@0 | 1227 | oop java_lang_Throwable::message(oop throwable) { |
aoqi@0 | 1228 | return throwable->obj_field(detailMessage_offset); |
aoqi@0 | 1229 | } |
aoqi@0 | 1230 | |
aoqi@0 | 1231 | |
aoqi@0 | 1232 | oop java_lang_Throwable::message(Handle throwable) { |
aoqi@0 | 1233 | return throwable->obj_field(detailMessage_offset); |
aoqi@0 | 1234 | } |
aoqi@0 | 1235 | |
aoqi@0 | 1236 | |
aoqi@0 | 1237 | void java_lang_Throwable::set_message(oop throwable, oop value) { |
aoqi@0 | 1238 | throwable->obj_field_put(detailMessage_offset, value); |
aoqi@0 | 1239 | } |
aoqi@0 | 1240 | |
aoqi@0 | 1241 | |
aoqi@0 | 1242 | void java_lang_Throwable::set_stacktrace(oop throwable, oop st_element_array) { |
aoqi@0 | 1243 | throwable->obj_field_put(stackTrace_offset, st_element_array); |
aoqi@0 | 1244 | } |
aoqi@0 | 1245 | |
aoqi@0 | 1246 | void java_lang_Throwable::clear_stacktrace(oop throwable) { |
aoqi@0 | 1247 | assert(JDK_Version::is_gte_jdk14x_version(), "should only be called in >= 1.4"); |
aoqi@0 | 1248 | set_stacktrace(throwable, NULL); |
aoqi@0 | 1249 | } |
aoqi@0 | 1250 | |
aoqi@0 | 1251 | |
aoqi@0 | 1252 | void java_lang_Throwable::print(oop throwable, outputStream* st) { |
aoqi@0 | 1253 | ResourceMark rm; |
aoqi@0 | 1254 | Klass* k = throwable->klass(); |
aoqi@0 | 1255 | assert(k != NULL, "just checking"); |
aoqi@0 | 1256 | st->print("%s", InstanceKlass::cast(k)->external_name()); |
aoqi@0 | 1257 | oop msg = message(throwable); |
aoqi@0 | 1258 | if (msg != NULL) { |
aoqi@0 | 1259 | st->print(": %s", java_lang_String::as_utf8_string(msg)); |
aoqi@0 | 1260 | } |
aoqi@0 | 1261 | } |
aoqi@0 | 1262 | |
aoqi@0 | 1263 | |
aoqi@0 | 1264 | void java_lang_Throwable::print(Handle throwable, outputStream* st) { |
aoqi@0 | 1265 | ResourceMark rm; |
aoqi@0 | 1266 | Klass* k = throwable->klass(); |
aoqi@0 | 1267 | assert(k != NULL, "just checking"); |
aoqi@0 | 1268 | st->print("%s", InstanceKlass::cast(k)->external_name()); |
aoqi@0 | 1269 | oop msg = message(throwable); |
aoqi@0 | 1270 | if (msg != NULL) { |
aoqi@0 | 1271 | st->print(": %s", java_lang_String::as_utf8_string(msg)); |
aoqi@0 | 1272 | } |
aoqi@0 | 1273 | } |
aoqi@0 | 1274 | |
aoqi@0 | 1275 | // After this many redefines, the stack trace is unreliable. |
aoqi@0 | 1276 | const int MAX_VERSION = USHRT_MAX; |
aoqi@0 | 1277 | |
aoqi@0 | 1278 | // Helper backtrace functions to store bci|version together. |
aoqi@0 | 1279 | static inline int merge_bci_and_version(int bci, int version) { |
aoqi@0 | 1280 | // only store u2 for version, checking for overflow. |
aoqi@0 | 1281 | if (version > USHRT_MAX || version < 0) version = MAX_VERSION; |
aoqi@0 | 1282 | assert((jushort)bci == bci, "bci should be short"); |
aoqi@0 | 1283 | return build_int_from_shorts(version, bci); |
aoqi@0 | 1284 | } |
aoqi@0 | 1285 | |
aoqi@0 | 1286 | static inline int bci_at(unsigned int merged) { |
aoqi@0 | 1287 | return extract_high_short_from_int(merged); |
aoqi@0 | 1288 | } |
aoqi@0 | 1289 | static inline int version_at(unsigned int merged) { |
aoqi@0 | 1290 | return extract_low_short_from_int(merged); |
aoqi@0 | 1291 | } |
aoqi@0 | 1292 | |
aoqi@0 | 1293 | static inline bool version_matches(Method* method, int version) { |
sspitsyn@7683 | 1294 | assert(version < MAX_VERSION, "version is too big"); |
sspitsyn@7683 | 1295 | return method != NULL && (method->constants()->version() == version); |
aoqi@0 | 1296 | } |
aoqi@0 | 1297 | |
aoqi@0 | 1298 | static inline int get_line_number(Method* method, int bci) { |
aoqi@0 | 1299 | int line_number = 0; |
aoqi@0 | 1300 | if (method->is_native()) { |
aoqi@0 | 1301 | // Negative value different from -1 below, enabling Java code in |
aoqi@0 | 1302 | // class java.lang.StackTraceElement to distinguish "native" from |
aoqi@0 | 1303 | // "no LineNumberTable". JDK tests for -2. |
aoqi@0 | 1304 | line_number = -2; |
aoqi@0 | 1305 | } else { |
aoqi@0 | 1306 | // Returns -1 if no LineNumberTable, and otherwise actual line number |
aoqi@0 | 1307 | line_number = method->line_number_from_bci(bci); |
aoqi@0 | 1308 | if (line_number == -1 && ShowHiddenFrames) { |
aoqi@0 | 1309 | line_number = bci + 1000000; |
aoqi@0 | 1310 | } |
aoqi@0 | 1311 | } |
aoqi@0 | 1312 | return line_number; |
aoqi@0 | 1313 | } |
aoqi@0 | 1314 | |
aoqi@0 | 1315 | // This class provides a simple wrapper over the internal structure of |
aoqi@0 | 1316 | // exception backtrace to insulate users of the backtrace from needing |
aoqi@0 | 1317 | // to know what it looks like. |
aoqi@0 | 1318 | class BacktraceBuilder: public StackObj { |
aoqi@0 | 1319 | private: |
aoqi@0 | 1320 | Handle _backtrace; |
aoqi@0 | 1321 | objArrayOop _head; |
aoqi@0 | 1322 | typeArrayOop _methods; |
aoqi@0 | 1323 | typeArrayOop _bcis; |
aoqi@0 | 1324 | objArrayOop _mirrors; |
sspitsyn@7683 | 1325 | typeArrayOop _cprefs; // needed to insulate method name against redefinition |
aoqi@0 | 1326 | int _index; |
aoqi@0 | 1327 | No_Safepoint_Verifier _nsv; |
aoqi@0 | 1328 | |
aoqi@0 | 1329 | public: |
aoqi@0 | 1330 | |
aoqi@0 | 1331 | enum { |
aoqi@0 | 1332 | trace_methods_offset = java_lang_Throwable::trace_methods_offset, |
sspitsyn@7683 | 1333 | trace_bcis_offset = java_lang_Throwable::trace_bcis_offset, |
aoqi@0 | 1334 | trace_mirrors_offset = java_lang_Throwable::trace_mirrors_offset, |
sspitsyn@7683 | 1335 | trace_cprefs_offset = java_lang_Throwable::trace_cprefs_offset, |
aoqi@0 | 1336 | trace_next_offset = java_lang_Throwable::trace_next_offset, |
aoqi@0 | 1337 | trace_size = java_lang_Throwable::trace_size, |
aoqi@0 | 1338 | trace_chunk_size = java_lang_Throwable::trace_chunk_size |
aoqi@0 | 1339 | }; |
aoqi@0 | 1340 | |
aoqi@0 | 1341 | // get info out of chunks |
aoqi@0 | 1342 | static typeArrayOop get_methods(objArrayHandle chunk) { |
aoqi@0 | 1343 | typeArrayOop methods = typeArrayOop(chunk->obj_at(trace_methods_offset)); |
aoqi@0 | 1344 | assert(methods != NULL, "method array should be initialized in backtrace"); |
aoqi@0 | 1345 | return methods; |
aoqi@0 | 1346 | } |
aoqi@0 | 1347 | static typeArrayOop get_bcis(objArrayHandle chunk) { |
aoqi@0 | 1348 | typeArrayOop bcis = typeArrayOop(chunk->obj_at(trace_bcis_offset)); |
aoqi@0 | 1349 | assert(bcis != NULL, "bci array should be initialized in backtrace"); |
aoqi@0 | 1350 | return bcis; |
aoqi@0 | 1351 | } |
aoqi@0 | 1352 | static objArrayOop get_mirrors(objArrayHandle chunk) { |
aoqi@0 | 1353 | objArrayOop mirrors = objArrayOop(chunk->obj_at(trace_mirrors_offset)); |
aoqi@0 | 1354 | assert(mirrors != NULL, "mirror array should be initialized in backtrace"); |
aoqi@0 | 1355 | return mirrors; |
aoqi@0 | 1356 | } |
sspitsyn@7683 | 1357 | static typeArrayOop get_cprefs(objArrayHandle chunk) { |
sspitsyn@7683 | 1358 | typeArrayOop cprefs = typeArrayOop(chunk->obj_at(trace_cprefs_offset)); |
sspitsyn@7683 | 1359 | assert(cprefs != NULL, "cprefs array should be initialized in backtrace"); |
sspitsyn@7683 | 1360 | return cprefs; |
sspitsyn@7683 | 1361 | } |
aoqi@0 | 1362 | |
aoqi@0 | 1363 | // constructor for new backtrace |
sspitsyn@7683 | 1364 | BacktraceBuilder(TRAPS): _methods(NULL), _bcis(NULL), _head(NULL), _mirrors(NULL), _cprefs(NULL) { |
aoqi@0 | 1365 | expand(CHECK); |
aoqi@0 | 1366 | _backtrace = _head; |
aoqi@0 | 1367 | _index = 0; |
aoqi@0 | 1368 | } |
aoqi@0 | 1369 | |
aoqi@0 | 1370 | BacktraceBuilder(objArrayHandle backtrace) { |
aoqi@0 | 1371 | _methods = get_methods(backtrace); |
aoqi@0 | 1372 | _bcis = get_bcis(backtrace); |
aoqi@0 | 1373 | _mirrors = get_mirrors(backtrace); |
sspitsyn@7683 | 1374 | _cprefs = get_cprefs(backtrace); |
aoqi@0 | 1375 | assert(_methods->length() == _bcis->length() && |
aoqi@0 | 1376 | _methods->length() == _mirrors->length(), |
aoqi@0 | 1377 | "method and source information arrays should match"); |
aoqi@0 | 1378 | |
aoqi@0 | 1379 | // head is the preallocated backtrace |
aoqi@0 | 1380 | _backtrace = _head = backtrace(); |
aoqi@0 | 1381 | _index = 0; |
aoqi@0 | 1382 | } |
aoqi@0 | 1383 | |
aoqi@0 | 1384 | void expand(TRAPS) { |
aoqi@0 | 1385 | objArrayHandle old_head(THREAD, _head); |
aoqi@0 | 1386 | Pause_No_Safepoint_Verifier pnsv(&_nsv); |
aoqi@0 | 1387 | |
aoqi@0 | 1388 | objArrayOop head = oopFactory::new_objectArray(trace_size, CHECK); |
aoqi@0 | 1389 | objArrayHandle new_head(THREAD, head); |
aoqi@0 | 1390 | |
aoqi@0 | 1391 | typeArrayOop methods = oopFactory::new_shortArray(trace_chunk_size, CHECK); |
aoqi@0 | 1392 | typeArrayHandle new_methods(THREAD, methods); |
aoqi@0 | 1393 | |
aoqi@0 | 1394 | typeArrayOop bcis = oopFactory::new_intArray(trace_chunk_size, CHECK); |
aoqi@0 | 1395 | typeArrayHandle new_bcis(THREAD, bcis); |
aoqi@0 | 1396 | |
aoqi@0 | 1397 | objArrayOop mirrors = oopFactory::new_objectArray(trace_chunk_size, CHECK); |
aoqi@0 | 1398 | objArrayHandle new_mirrors(THREAD, mirrors); |
aoqi@0 | 1399 | |
sspitsyn@7683 | 1400 | typeArrayOop cprefs = oopFactory::new_shortArray(trace_chunk_size, CHECK); |
sspitsyn@7683 | 1401 | typeArrayHandle new_cprefs(THREAD, cprefs); |
sspitsyn@7683 | 1402 | |
aoqi@0 | 1403 | if (!old_head.is_null()) { |
aoqi@0 | 1404 | old_head->obj_at_put(trace_next_offset, new_head()); |
aoqi@0 | 1405 | } |
aoqi@0 | 1406 | new_head->obj_at_put(trace_methods_offset, new_methods()); |
aoqi@0 | 1407 | new_head->obj_at_put(trace_bcis_offset, new_bcis()); |
aoqi@0 | 1408 | new_head->obj_at_put(trace_mirrors_offset, new_mirrors()); |
sspitsyn@7683 | 1409 | new_head->obj_at_put(trace_cprefs_offset, new_cprefs()); |
aoqi@0 | 1410 | |
aoqi@0 | 1411 | _head = new_head(); |
aoqi@0 | 1412 | _methods = new_methods(); |
aoqi@0 | 1413 | _bcis = new_bcis(); |
aoqi@0 | 1414 | _mirrors = new_mirrors(); |
sspitsyn@7683 | 1415 | _cprefs = new_cprefs(); |
aoqi@0 | 1416 | _index = 0; |
aoqi@0 | 1417 | } |
aoqi@0 | 1418 | |
aoqi@0 | 1419 | oop backtrace() { |
aoqi@0 | 1420 | return _backtrace(); |
aoqi@0 | 1421 | } |
aoqi@0 | 1422 | |
aoqi@0 | 1423 | inline void push(Method* method, int bci, TRAPS) { |
aoqi@0 | 1424 | // Smear the -1 bci to 0 since the array only holds unsigned |
aoqi@0 | 1425 | // shorts. The later line number lookup would just smear the -1 |
aoqi@0 | 1426 | // to a 0 even if it could be recorded. |
aoqi@0 | 1427 | if (bci == SynchronizationEntryBCI) bci = 0; |
aoqi@0 | 1428 | |
aoqi@0 | 1429 | if (_index >= trace_chunk_size) { |
aoqi@0 | 1430 | methodHandle mhandle(THREAD, method); |
aoqi@0 | 1431 | expand(CHECK); |
aoqi@0 | 1432 | method = mhandle(); |
aoqi@0 | 1433 | } |
aoqi@0 | 1434 | |
sspitsyn@7683 | 1435 | _methods->short_at_put(_index, method->orig_method_idnum()); |
aoqi@0 | 1436 | _bcis->int_at_put(_index, merge_bci_and_version(bci, method->constants()->version())); |
sspitsyn@7683 | 1437 | _cprefs->short_at_put(_index, method->name_index()); |
aoqi@0 | 1438 | |
aoqi@0 | 1439 | // We need to save the mirrors in the backtrace to keep the class |
aoqi@0 | 1440 | // from being unloaded while we still have this stack trace. |
aoqi@0 | 1441 | assert(method->method_holder()->java_mirror() != NULL, "never push null for mirror"); |
aoqi@0 | 1442 | _mirrors->obj_at_put(_index, method->method_holder()->java_mirror()); |
aoqi@0 | 1443 | _index++; |
aoqi@0 | 1444 | } |
aoqi@0 | 1445 | |
aoqi@0 | 1446 | }; |
aoqi@0 | 1447 | |
aoqi@0 | 1448 | // Print stack trace element to resource allocated buffer |
aoqi@0 | 1449 | char* java_lang_Throwable::print_stack_element_to_buffer(Handle mirror, |
sspitsyn@7683 | 1450 | int method_id, int version, int bci, int cpref) { |
aoqi@0 | 1451 | |
aoqi@0 | 1452 | // Get strings and string lengths |
aoqi@0 | 1453 | InstanceKlass* holder = InstanceKlass::cast(java_lang_Class::as_Klass(mirror())); |
aoqi@0 | 1454 | const char* klass_name = holder->external_name(); |
aoqi@0 | 1455 | int buf_len = (int)strlen(klass_name); |
aoqi@0 | 1456 | |
sspitsyn@7683 | 1457 | Method* method = holder->method_with_orig_idnum(method_id, version); |
sspitsyn@7683 | 1458 | |
sspitsyn@7683 | 1459 | // The method can be NULL if the requested class version is gone |
sspitsyn@7683 | 1460 | Symbol* sym = (method != NULL) ? method->name() : holder->constants()->symbol_at(cpref); |
sspitsyn@7683 | 1461 | char* method_name = sym->as_C_string(); |
aoqi@0 | 1462 | buf_len += (int)strlen(method_name); |
aoqi@0 | 1463 | |
sspitsyn@7683 | 1464 | // Use a specific ik version as a holder since the mirror might |
sspitsyn@7683 | 1465 | // refer to a version that is now obsolete and no longer accessible |
sspitsyn@7683 | 1466 | // via the previous versions list. |
sspitsyn@7683 | 1467 | holder = holder->get_klass_version(version); |
aoqi@0 | 1468 | char* source_file_name = NULL; |
sspitsyn@7683 | 1469 | if (holder != NULL) { |
aoqi@0 | 1470 | Symbol* source = holder->source_file_name(); |
aoqi@0 | 1471 | if (source != NULL) { |
aoqi@0 | 1472 | source_file_name = source->as_C_string(); |
aoqi@0 | 1473 | buf_len += (int)strlen(source_file_name); |
aoqi@0 | 1474 | } |
aoqi@0 | 1475 | } |
aoqi@0 | 1476 | |
aoqi@0 | 1477 | // Allocate temporary buffer with extra space for formatting and line number |
aoqi@0 | 1478 | char* buf = NEW_RESOURCE_ARRAY(char, buf_len + 64); |
aoqi@0 | 1479 | |
aoqi@0 | 1480 | // Print stack trace line in buffer |
aoqi@0 | 1481 | sprintf(buf, "\tat %s.%s", klass_name, method_name); |
aoqi@0 | 1482 | |
aoqi@0 | 1483 | if (!version_matches(method, version)) { |
aoqi@0 | 1484 | strcat(buf, "(Redefined)"); |
aoqi@0 | 1485 | } else { |
aoqi@0 | 1486 | int line_number = get_line_number(method, bci); |
aoqi@0 | 1487 | if (line_number == -2) { |
aoqi@0 | 1488 | strcat(buf, "(Native Method)"); |
aoqi@0 | 1489 | } else { |
aoqi@0 | 1490 | if (source_file_name != NULL && (line_number != -1)) { |
aoqi@0 | 1491 | // Sourcename and linenumber |
aoqi@0 | 1492 | sprintf(buf + (int)strlen(buf), "(%s:%d)", source_file_name, line_number); |
aoqi@0 | 1493 | } else if (source_file_name != NULL) { |
aoqi@0 | 1494 | // Just sourcename |
aoqi@0 | 1495 | sprintf(buf + (int)strlen(buf), "(%s)", source_file_name); |
aoqi@0 | 1496 | } else { |
aoqi@0 | 1497 | // Neither sourcename nor linenumber |
aoqi@0 | 1498 | sprintf(buf + (int)strlen(buf), "(Unknown Source)"); |
aoqi@0 | 1499 | } |
aoqi@0 | 1500 | nmethod* nm = method->code(); |
aoqi@0 | 1501 | if (WizardMode && nm != NULL) { |
aoqi@0 | 1502 | sprintf(buf + (int)strlen(buf), "(nmethod " INTPTR_FORMAT ")", (intptr_t)nm); |
aoqi@0 | 1503 | } |
aoqi@0 | 1504 | } |
aoqi@0 | 1505 | } |
aoqi@0 | 1506 | |
aoqi@0 | 1507 | return buf; |
aoqi@0 | 1508 | } |
aoqi@0 | 1509 | |
aoqi@0 | 1510 | void java_lang_Throwable::print_stack_element(outputStream *st, Handle mirror, |
sspitsyn@7683 | 1511 | int method_id, int version, int bci, int cpref) { |
aoqi@0 | 1512 | ResourceMark rm; |
sspitsyn@7683 | 1513 | char* buf = print_stack_element_to_buffer(mirror, method_id, version, bci, cpref); |
aoqi@0 | 1514 | st->print_cr("%s", buf); |
aoqi@0 | 1515 | } |
aoqi@0 | 1516 | |
aoqi@0 | 1517 | void java_lang_Throwable::print_stack_element(outputStream *st, methodHandle method, int bci) { |
aoqi@0 | 1518 | Handle mirror = method->method_holder()->java_mirror(); |
sspitsyn@7683 | 1519 | int method_id = method->orig_method_idnum(); |
aoqi@0 | 1520 | int version = method->constants()->version(); |
sspitsyn@7683 | 1521 | int cpref = method->name_index(); |
sspitsyn@7683 | 1522 | print_stack_element(st, mirror, method_id, version, bci, cpref); |
aoqi@0 | 1523 | } |
aoqi@0 | 1524 | |
aoqi@0 | 1525 | const char* java_lang_Throwable::no_stack_trace_message() { |
aoqi@0 | 1526 | return "\t<<no stack trace available>>"; |
aoqi@0 | 1527 | } |
aoqi@0 | 1528 | |
aoqi@0 | 1529 | |
aoqi@0 | 1530 | // Currently used only for exceptions occurring during startup |
aoqi@0 | 1531 | void java_lang_Throwable::print_stack_trace(oop throwable, outputStream* st) { |
aoqi@0 | 1532 | Thread *THREAD = Thread::current(); |
aoqi@0 | 1533 | Handle h_throwable(THREAD, throwable); |
aoqi@0 | 1534 | while (h_throwable.not_null()) { |
aoqi@0 | 1535 | objArrayHandle result (THREAD, objArrayOop(backtrace(h_throwable()))); |
aoqi@0 | 1536 | if (result.is_null()) { |
aoqi@0 | 1537 | st->print_cr("%s", no_stack_trace_message()); |
aoqi@0 | 1538 | return; |
aoqi@0 | 1539 | } |
aoqi@0 | 1540 | |
aoqi@0 | 1541 | while (result.not_null()) { |
aoqi@0 | 1542 | |
aoqi@0 | 1543 | // Get method id, bci, version and mirror from chunk |
aoqi@0 | 1544 | typeArrayHandle methods (THREAD, BacktraceBuilder::get_methods(result)); |
aoqi@0 | 1545 | typeArrayHandle bcis (THREAD, BacktraceBuilder::get_bcis(result)); |
aoqi@0 | 1546 | objArrayHandle mirrors (THREAD, BacktraceBuilder::get_mirrors(result)); |
sspitsyn@7683 | 1547 | typeArrayHandle cprefs (THREAD, BacktraceBuilder::get_cprefs(result)); |
aoqi@0 | 1548 | |
aoqi@0 | 1549 | int length = methods()->length(); |
aoqi@0 | 1550 | for (int index = 0; index < length; index++) { |
aoqi@0 | 1551 | Handle mirror(THREAD, mirrors->obj_at(index)); |
aoqi@0 | 1552 | // NULL mirror means end of stack trace |
aoqi@0 | 1553 | if (mirror.is_null()) goto handle_cause; |
aoqi@0 | 1554 | int method = methods->short_at(index); |
aoqi@0 | 1555 | int version = version_at(bcis->int_at(index)); |
aoqi@0 | 1556 | int bci = bci_at(bcis->int_at(index)); |
sspitsyn@7683 | 1557 | int cpref = cprefs->short_at(index); |
sspitsyn@7683 | 1558 | print_stack_element(st, mirror, method, version, bci, cpref); |
aoqi@0 | 1559 | } |
aoqi@0 | 1560 | result = objArrayHandle(THREAD, objArrayOop(result->obj_at(trace_next_offset))); |
aoqi@0 | 1561 | } |
aoqi@0 | 1562 | handle_cause: |
aoqi@0 | 1563 | { |
aoqi@0 | 1564 | EXCEPTION_MARK; |
aoqi@0 | 1565 | JavaValue cause(T_OBJECT); |
aoqi@0 | 1566 | JavaCalls::call_virtual(&cause, |
aoqi@0 | 1567 | h_throwable, |
aoqi@0 | 1568 | KlassHandle(THREAD, h_throwable->klass()), |
aoqi@0 | 1569 | vmSymbols::getCause_name(), |
aoqi@0 | 1570 | vmSymbols::void_throwable_signature(), |
aoqi@0 | 1571 | THREAD); |
aoqi@0 | 1572 | // Ignore any exceptions. we are in the middle of exception handling. Same as classic VM. |
aoqi@0 | 1573 | if (HAS_PENDING_EXCEPTION) { |
aoqi@0 | 1574 | CLEAR_PENDING_EXCEPTION; |
aoqi@0 | 1575 | h_throwable = Handle(); |
aoqi@0 | 1576 | } else { |
aoqi@0 | 1577 | h_throwable = Handle(THREAD, (oop) cause.get_jobject()); |
aoqi@0 | 1578 | if (h_throwable.not_null()) { |
aoqi@0 | 1579 | st->print("Caused by: "); |
aoqi@0 | 1580 | print(h_throwable, st); |
aoqi@0 | 1581 | st->cr(); |
aoqi@0 | 1582 | } |
aoqi@0 | 1583 | } |
aoqi@0 | 1584 | } |
aoqi@0 | 1585 | } |
aoqi@0 | 1586 | } |
aoqi@0 | 1587 | |
aoqi@0 | 1588 | void java_lang_Throwable::fill_in_stack_trace(Handle throwable, methodHandle method, TRAPS) { |
aoqi@0 | 1589 | if (!StackTraceInThrowable) return; |
aoqi@0 | 1590 | ResourceMark rm(THREAD); |
aoqi@0 | 1591 | |
aoqi@0 | 1592 | // Start out by clearing the backtrace for this object, in case the VM |
aoqi@0 | 1593 | // runs out of memory while allocating the stack trace |
aoqi@0 | 1594 | set_backtrace(throwable(), NULL); |
aoqi@0 | 1595 | if (JDK_Version::is_gte_jdk14x_version()) { |
aoqi@0 | 1596 | // New since 1.4, clear lazily constructed Java level stacktrace if |
aoqi@0 | 1597 | // refilling occurs |
aoqi@0 | 1598 | // This is unnecessary in 1.7+ but harmless |
aoqi@0 | 1599 | clear_stacktrace(throwable()); |
aoqi@0 | 1600 | } |
aoqi@0 | 1601 | |
aoqi@0 | 1602 | int max_depth = MaxJavaStackTraceDepth; |
aoqi@0 | 1603 | JavaThread* thread = (JavaThread*)THREAD; |
aoqi@0 | 1604 | BacktraceBuilder bt(CHECK); |
aoqi@0 | 1605 | |
aoqi@0 | 1606 | // If there is no Java frame just return the method that was being called |
aoqi@0 | 1607 | // with bci 0 |
aoqi@0 | 1608 | if (!thread->has_last_Java_frame()) { |
aoqi@0 | 1609 | if (max_depth >= 1 && method() != NULL) { |
aoqi@0 | 1610 | bt.push(method(), 0, CHECK); |
aoqi@0 | 1611 | set_backtrace(throwable(), bt.backtrace()); |
aoqi@0 | 1612 | } |
aoqi@0 | 1613 | return; |
aoqi@0 | 1614 | } |
aoqi@0 | 1615 | |
aoqi@0 | 1616 | // Instead of using vframe directly, this version of fill_in_stack_trace |
aoqi@0 | 1617 | // basically handles everything by hand. This significantly improved the |
aoqi@0 | 1618 | // speed of this method call up to 28.5% on Solaris sparc. 27.1% on Windows. |
aoqi@0 | 1619 | // See bug 6333838 for more details. |
aoqi@0 | 1620 | // The "ASSERT" here is to verify this method generates the exactly same stack |
aoqi@0 | 1621 | // trace as utilizing vframe. |
aoqi@0 | 1622 | #ifdef ASSERT |
aoqi@0 | 1623 | vframeStream st(thread); |
aoqi@0 | 1624 | methodHandle st_method(THREAD, st.method()); |
aoqi@0 | 1625 | #endif |
aoqi@0 | 1626 | int total_count = 0; |
aoqi@0 | 1627 | RegisterMap map(thread, false); |
aoqi@0 | 1628 | int decode_offset = 0; |
aoqi@0 | 1629 | nmethod* nm = NULL; |
aoqi@0 | 1630 | bool skip_fillInStackTrace_check = false; |
aoqi@0 | 1631 | bool skip_throwableInit_check = false; |
aoqi@0 | 1632 | bool skip_hidden = !ShowHiddenFrames; |
aoqi@0 | 1633 | |
aoqi@0 | 1634 | for (frame fr = thread->last_frame(); max_depth != total_count;) { |
aoqi@0 | 1635 | Method* method = NULL; |
aoqi@0 | 1636 | int bci = 0; |
aoqi@0 | 1637 | |
aoqi@0 | 1638 | // Compiled java method case. |
aoqi@0 | 1639 | if (decode_offset != 0) { |
aoqi@0 | 1640 | DebugInfoReadStream stream(nm, decode_offset); |
aoqi@0 | 1641 | decode_offset = stream.read_int(); |
aoqi@0 | 1642 | method = (Method*)nm->metadata_at(stream.read_int()); |
aoqi@0 | 1643 | bci = stream.read_bci(); |
aoqi@0 | 1644 | } else { |
aoqi@0 | 1645 | if (fr.is_first_frame()) break; |
aoqi@0 | 1646 | address pc = fr.pc(); |
aoqi@0 | 1647 | if (fr.is_interpreted_frame()) { |
aoqi@0 | 1648 | intptr_t bcx = fr.interpreter_frame_bcx(); |
aoqi@0 | 1649 | method = fr.interpreter_frame_method(); |
aoqi@0 | 1650 | bci = fr.is_bci(bcx) ? bcx : method->bci_from((address)bcx); |
aoqi@0 | 1651 | fr = fr.sender(&map); |
aoqi@0 | 1652 | } else { |
aoqi@0 | 1653 | CodeBlob* cb = fr.cb(); |
aoqi@0 | 1654 | // HMMM QQQ might be nice to have frame return nm as NULL if cb is non-NULL |
aoqi@0 | 1655 | // but non nmethod |
aoqi@0 | 1656 | fr = fr.sender(&map); |
aoqi@0 | 1657 | if (cb == NULL || !cb->is_nmethod()) { |
aoqi@0 | 1658 | continue; |
aoqi@0 | 1659 | } |
aoqi@0 | 1660 | nm = (nmethod*)cb; |
aoqi@0 | 1661 | if (nm->method()->is_native()) { |
aoqi@0 | 1662 | method = nm->method(); |
aoqi@0 | 1663 | bci = 0; |
aoqi@0 | 1664 | } else { |
aoqi@0 | 1665 | PcDesc* pd = nm->pc_desc_at(pc); |
aoqi@0 | 1666 | decode_offset = pd->scope_decode_offset(); |
aoqi@0 | 1667 | // if decode_offset is not equal to 0, it will execute the |
aoqi@0 | 1668 | // "compiled java method case" at the beginning of the loop. |
aoqi@0 | 1669 | continue; |
aoqi@0 | 1670 | } |
aoqi@0 | 1671 | } |
aoqi@0 | 1672 | } |
aoqi@0 | 1673 | #ifdef ASSERT |
aoqi@0 | 1674 | assert(st_method() == method && st.bci() == bci, |
aoqi@0 | 1675 | "Wrong stack trace"); |
aoqi@0 | 1676 | st.next(); |
aoqi@0 | 1677 | // vframeStream::method isn't GC-safe so store off a copy |
aoqi@0 | 1678 | // of the Method* in case we GC. |
aoqi@0 | 1679 | if (!st.at_end()) { |
aoqi@0 | 1680 | st_method = st.method(); |
aoqi@0 | 1681 | } |
aoqi@0 | 1682 | #endif |
aoqi@0 | 1683 | |
aoqi@0 | 1684 | // the format of the stacktrace will be: |
aoqi@0 | 1685 | // - 1 or more fillInStackTrace frames for the exception class (skipped) |
aoqi@0 | 1686 | // - 0 or more <init> methods for the exception class (skipped) |
aoqi@0 | 1687 | // - rest of the stack |
aoqi@0 | 1688 | |
aoqi@0 | 1689 | if (!skip_fillInStackTrace_check) { |
aoqi@0 | 1690 | if ((method->name() == vmSymbols::fillInStackTrace_name() || |
aoqi@0 | 1691 | method->name() == vmSymbols::fillInStackTrace0_name()) && |
aoqi@0 | 1692 | throwable->is_a(method->method_holder())) { |
aoqi@0 | 1693 | continue; |
aoqi@0 | 1694 | } |
aoqi@0 | 1695 | else { |
aoqi@0 | 1696 | skip_fillInStackTrace_check = true; // gone past them all |
aoqi@0 | 1697 | } |
aoqi@0 | 1698 | } |
aoqi@0 | 1699 | if (!skip_throwableInit_check) { |
aoqi@0 | 1700 | assert(skip_fillInStackTrace_check, "logic error in backtrace filtering"); |
aoqi@0 | 1701 | |
aoqi@0 | 1702 | // skip <init> methods of the exception class and superclasses |
aoqi@0 | 1703 | // This is simlar to classic VM. |
aoqi@0 | 1704 | if (method->name() == vmSymbols::object_initializer_name() && |
aoqi@0 | 1705 | throwable->is_a(method->method_holder())) { |
aoqi@0 | 1706 | continue; |
aoqi@0 | 1707 | } else { |
aoqi@0 | 1708 | // there are none or we've seen them all - either way stop checking |
aoqi@0 | 1709 | skip_throwableInit_check = true; |
aoqi@0 | 1710 | } |
aoqi@0 | 1711 | } |
aoqi@0 | 1712 | if (method->is_hidden()) { |
aoqi@0 | 1713 | if (skip_hidden) continue; |
aoqi@0 | 1714 | } |
aoqi@0 | 1715 | bt.push(method, bci, CHECK); |
aoqi@0 | 1716 | total_count++; |
aoqi@0 | 1717 | } |
aoqi@0 | 1718 | |
aoqi@0 | 1719 | // Put completed stack trace into throwable object |
aoqi@0 | 1720 | set_backtrace(throwable(), bt.backtrace()); |
aoqi@0 | 1721 | } |
aoqi@0 | 1722 | |
aoqi@0 | 1723 | void java_lang_Throwable::fill_in_stack_trace(Handle throwable, methodHandle method) { |
aoqi@0 | 1724 | // No-op if stack trace is disabled |
aoqi@0 | 1725 | if (!StackTraceInThrowable) { |
aoqi@0 | 1726 | return; |
aoqi@0 | 1727 | } |
aoqi@0 | 1728 | |
aoqi@0 | 1729 | // Disable stack traces for some preallocated out of memory errors |
aoqi@0 | 1730 | if (!Universe::should_fill_in_stack_trace(throwable)) { |
aoqi@0 | 1731 | return; |
aoqi@0 | 1732 | } |
aoqi@0 | 1733 | |
aoqi@0 | 1734 | PRESERVE_EXCEPTION_MARK; |
aoqi@0 | 1735 | |
aoqi@0 | 1736 | JavaThread* thread = JavaThread::active(); |
aoqi@0 | 1737 | fill_in_stack_trace(throwable, method, thread); |
aoqi@0 | 1738 | // ignore exceptions thrown during stack trace filling |
aoqi@0 | 1739 | CLEAR_PENDING_EXCEPTION; |
aoqi@0 | 1740 | } |
aoqi@0 | 1741 | |
aoqi@0 | 1742 | void java_lang_Throwable::allocate_backtrace(Handle throwable, TRAPS) { |
aoqi@0 | 1743 | // Allocate stack trace - backtrace is created but not filled in |
aoqi@0 | 1744 | |
aoqi@0 | 1745 | // No-op if stack trace is disabled |
aoqi@0 | 1746 | if (!StackTraceInThrowable) return; |
aoqi@0 | 1747 | BacktraceBuilder bt(CHECK); // creates a backtrace |
aoqi@0 | 1748 | set_backtrace(throwable(), bt.backtrace()); |
aoqi@0 | 1749 | } |
aoqi@0 | 1750 | |
aoqi@0 | 1751 | |
aoqi@0 | 1752 | void java_lang_Throwable::fill_in_stack_trace_of_preallocated_backtrace(Handle throwable) { |
aoqi@0 | 1753 | // Fill in stack trace into preallocated backtrace (no GC) |
aoqi@0 | 1754 | |
aoqi@0 | 1755 | // No-op if stack trace is disabled |
aoqi@0 | 1756 | if (!StackTraceInThrowable) return; |
aoqi@0 | 1757 | |
aoqi@0 | 1758 | assert(throwable->is_a(SystemDictionary::Throwable_klass()), "sanity check"); |
aoqi@0 | 1759 | |
aoqi@0 | 1760 | JavaThread* THREAD = JavaThread::current(); |
aoqi@0 | 1761 | |
aoqi@0 | 1762 | objArrayHandle backtrace (THREAD, (objArrayOop)java_lang_Throwable::backtrace(throwable())); |
aoqi@0 | 1763 | assert(backtrace.not_null(), "backtrace should have been preallocated"); |
aoqi@0 | 1764 | |
aoqi@0 | 1765 | ResourceMark rm(THREAD); |
aoqi@0 | 1766 | vframeStream st(THREAD); |
aoqi@0 | 1767 | |
aoqi@0 | 1768 | BacktraceBuilder bt(backtrace); |
aoqi@0 | 1769 | |
aoqi@0 | 1770 | // Unlike fill_in_stack_trace we do not skip fillInStackTrace or throwable init |
aoqi@0 | 1771 | // methods as preallocated errors aren't created by "java" code. |
aoqi@0 | 1772 | |
aoqi@0 | 1773 | // fill in as much stack trace as possible |
aoqi@0 | 1774 | typeArrayOop methods = BacktraceBuilder::get_methods(backtrace); |
aoqi@0 | 1775 | int max_chunks = MIN2(methods->length(), (int)MaxJavaStackTraceDepth); |
aoqi@0 | 1776 | int chunk_count = 0; |
aoqi@0 | 1777 | |
aoqi@0 | 1778 | for (;!st.at_end(); st.next()) { |
aoqi@0 | 1779 | bt.push(st.method(), st.bci(), CHECK); |
aoqi@0 | 1780 | chunk_count++; |
aoqi@0 | 1781 | |
aoqi@0 | 1782 | // Bail-out for deep stacks |
aoqi@0 | 1783 | if (chunk_count >= max_chunks) break; |
aoqi@0 | 1784 | } |
aoqi@0 | 1785 | |
aoqi@0 | 1786 | // For Java 7+ we support the Throwable immutability protocol defined for Java 7. This support |
aoqi@0 | 1787 | // was missing in 7u0 so in 7u0 there is a workaround in the Throwable class. That workaround |
aoqi@0 | 1788 | // can be removed in a JDK using this JVM version |
aoqi@0 | 1789 | if (JDK_Version::is_gte_jdk17x_version()) { |
aoqi@0 | 1790 | java_lang_Throwable::set_stacktrace(throwable(), java_lang_Throwable::unassigned_stacktrace()); |
aoqi@0 | 1791 | assert(java_lang_Throwable::unassigned_stacktrace() != NULL, "not initialized"); |
aoqi@0 | 1792 | } |
aoqi@0 | 1793 | } |
aoqi@0 | 1794 | |
aoqi@0 | 1795 | |
aoqi@0 | 1796 | int java_lang_Throwable::get_stack_trace_depth(oop throwable, TRAPS) { |
aoqi@0 | 1797 | if (throwable == NULL) { |
aoqi@0 | 1798 | THROW_0(vmSymbols::java_lang_NullPointerException()); |
aoqi@0 | 1799 | } |
aoqi@0 | 1800 | objArrayOop chunk = objArrayOop(backtrace(throwable)); |
aoqi@0 | 1801 | int depth = 0; |
aoqi@0 | 1802 | if (chunk != NULL) { |
aoqi@0 | 1803 | // Iterate over chunks and count full ones |
aoqi@0 | 1804 | while (true) { |
aoqi@0 | 1805 | objArrayOop next = objArrayOop(chunk->obj_at(trace_next_offset)); |
aoqi@0 | 1806 | if (next == NULL) break; |
aoqi@0 | 1807 | depth += trace_chunk_size; |
aoqi@0 | 1808 | chunk = next; |
aoqi@0 | 1809 | } |
aoqi@0 | 1810 | assert(chunk != NULL && chunk->obj_at(trace_next_offset) == NULL, "sanity check"); |
aoqi@0 | 1811 | // Count element in remaining partial chunk. NULL value for mirror |
aoqi@0 | 1812 | // marks the end of the stack trace elements that are saved. |
aoqi@0 | 1813 | objArrayOop mirrors = BacktraceBuilder::get_mirrors(chunk); |
aoqi@0 | 1814 | assert(mirrors != NULL, "sanity check"); |
aoqi@0 | 1815 | for (int i = 0; i < mirrors->length(); i++) { |
aoqi@0 | 1816 | if (mirrors->obj_at(i) == NULL) break; |
aoqi@0 | 1817 | depth++; |
aoqi@0 | 1818 | } |
aoqi@0 | 1819 | } |
aoqi@0 | 1820 | return depth; |
aoqi@0 | 1821 | } |
aoqi@0 | 1822 | |
aoqi@0 | 1823 | |
aoqi@0 | 1824 | oop java_lang_Throwable::get_stack_trace_element(oop throwable, int index, TRAPS) { |
aoqi@0 | 1825 | if (throwable == NULL) { |
aoqi@0 | 1826 | THROW_0(vmSymbols::java_lang_NullPointerException()); |
aoqi@0 | 1827 | } |
aoqi@0 | 1828 | if (index < 0) { |
aoqi@0 | 1829 | THROW_(vmSymbols::java_lang_IndexOutOfBoundsException(), NULL); |
aoqi@0 | 1830 | } |
aoqi@0 | 1831 | // Compute how many chunks to skip and index into actual chunk |
aoqi@0 | 1832 | objArrayOop chunk = objArrayOop(backtrace(throwable)); |
aoqi@0 | 1833 | int skip_chunks = index / trace_chunk_size; |
aoqi@0 | 1834 | int chunk_index = index % trace_chunk_size; |
aoqi@0 | 1835 | while (chunk != NULL && skip_chunks > 0) { |
aoqi@0 | 1836 | chunk = objArrayOop(chunk->obj_at(trace_next_offset)); |
aoqi@0 | 1837 | skip_chunks--; |
aoqi@0 | 1838 | } |
aoqi@0 | 1839 | if (chunk == NULL) { |
aoqi@0 | 1840 | THROW_(vmSymbols::java_lang_IndexOutOfBoundsException(), NULL); |
aoqi@0 | 1841 | } |
sspitsyn@7683 | 1842 | // Get method id, bci, version, mirror and cpref from chunk |
aoqi@0 | 1843 | typeArrayOop methods = BacktraceBuilder::get_methods(chunk); |
aoqi@0 | 1844 | typeArrayOop bcis = BacktraceBuilder::get_bcis(chunk); |
aoqi@0 | 1845 | objArrayOop mirrors = BacktraceBuilder::get_mirrors(chunk); |
sspitsyn@7683 | 1846 | typeArrayOop cprefs = BacktraceBuilder::get_cprefs(chunk); |
aoqi@0 | 1847 | |
aoqi@0 | 1848 | assert(methods != NULL && bcis != NULL && mirrors != NULL, "sanity check"); |
aoqi@0 | 1849 | |
aoqi@0 | 1850 | int method = methods->short_at(chunk_index); |
aoqi@0 | 1851 | int version = version_at(bcis->int_at(chunk_index)); |
aoqi@0 | 1852 | int bci = bci_at(bcis->int_at(chunk_index)); |
sspitsyn@7683 | 1853 | int cpref = cprefs->short_at(chunk_index); |
aoqi@0 | 1854 | Handle mirror(THREAD, mirrors->obj_at(chunk_index)); |
aoqi@0 | 1855 | |
aoqi@0 | 1856 | // Chunk can be partial full |
aoqi@0 | 1857 | if (mirror.is_null()) { |
aoqi@0 | 1858 | THROW_(vmSymbols::java_lang_IndexOutOfBoundsException(), NULL); |
aoqi@0 | 1859 | } |
sspitsyn@7683 | 1860 | oop element = java_lang_StackTraceElement::create(mirror, method, version, bci, cpref, CHECK_0); |
aoqi@0 | 1861 | return element; |
aoqi@0 | 1862 | } |
aoqi@0 | 1863 | |
aoqi@0 | 1864 | oop java_lang_StackTraceElement::create(Handle mirror, int method_id, |
sspitsyn@7683 | 1865 | int version, int bci, int cpref, TRAPS) { |
aoqi@0 | 1866 | // Allocate java.lang.StackTraceElement instance |
aoqi@0 | 1867 | Klass* k = SystemDictionary::StackTraceElement_klass(); |
aoqi@0 | 1868 | assert(k != NULL, "must be loaded in 1.4+"); |
aoqi@0 | 1869 | instanceKlassHandle ik (THREAD, k); |
aoqi@0 | 1870 | if (ik->should_be_initialized()) { |
aoqi@0 | 1871 | ik->initialize(CHECK_0); |
aoqi@0 | 1872 | } |
aoqi@0 | 1873 | |
aoqi@0 | 1874 | Handle element = ik->allocate_instance_handle(CHECK_0); |
aoqi@0 | 1875 | // Fill in class name |
aoqi@0 | 1876 | ResourceMark rm(THREAD); |
aoqi@0 | 1877 | InstanceKlass* holder = InstanceKlass::cast(java_lang_Class::as_Klass(mirror())); |
aoqi@0 | 1878 | const char* str = holder->external_name(); |
aoqi@0 | 1879 | oop classname = StringTable::intern((char*) str, CHECK_0); |
aoqi@0 | 1880 | java_lang_StackTraceElement::set_declaringClass(element(), classname); |
aoqi@0 | 1881 | |
sspitsyn@7683 | 1882 | Method* method = holder->method_with_orig_idnum(method_id, version); |
sspitsyn@7683 | 1883 | |
sspitsyn@7683 | 1884 | // The method can be NULL if the requested class version is gone |
sspitsyn@7683 | 1885 | Symbol* sym = (method != NULL) ? method->name() : holder->constants()->symbol_at(cpref); |
aoqi@0 | 1886 | |
aoqi@0 | 1887 | // Fill in method name |
sspitsyn@7683 | 1888 | oop methodname = StringTable::intern(sym, CHECK_0); |
aoqi@0 | 1889 | java_lang_StackTraceElement::set_methodName(element(), methodname); |
aoqi@0 | 1890 | |
aoqi@0 | 1891 | if (!version_matches(method, version)) { |
aoqi@0 | 1892 | // The method was redefined, accurate line number information isn't available |
aoqi@0 | 1893 | java_lang_StackTraceElement::set_fileName(element(), NULL); |
aoqi@0 | 1894 | java_lang_StackTraceElement::set_lineNumber(element(), -1); |
aoqi@0 | 1895 | } else { |
aoqi@0 | 1896 | // Fill in source file name and line number. |
sspitsyn@7683 | 1897 | // Use a specific ik version as a holder since the mirror might |
sspitsyn@7683 | 1898 | // refer to a version that is now obsolete and no longer accessible |
sspitsyn@7683 | 1899 | // via the previous versions list. |
sspitsyn@7683 | 1900 | holder = holder->get_klass_version(version); |
sspitsyn@7683 | 1901 | assert(holder != NULL, "sanity check"); |
aoqi@0 | 1902 | Symbol* source = holder->source_file_name(); |
aoqi@0 | 1903 | if (ShowHiddenFrames && source == NULL) |
aoqi@0 | 1904 | source = vmSymbols::unknown_class_name(); |
aoqi@0 | 1905 | oop filename = StringTable::intern(source, CHECK_0); |
aoqi@0 | 1906 | java_lang_StackTraceElement::set_fileName(element(), filename); |
aoqi@0 | 1907 | |
aoqi@0 | 1908 | int line_number = get_line_number(method, bci); |
aoqi@0 | 1909 | java_lang_StackTraceElement::set_lineNumber(element(), line_number); |
aoqi@0 | 1910 | } |
aoqi@0 | 1911 | return element(); |
aoqi@0 | 1912 | } |
aoqi@0 | 1913 | |
aoqi@0 | 1914 | oop java_lang_StackTraceElement::create(methodHandle method, int bci, TRAPS) { |
aoqi@0 | 1915 | Handle mirror (THREAD, method->method_holder()->java_mirror()); |
sspitsyn@7683 | 1916 | int method_id = method->orig_method_idnum(); |
sspitsyn@7683 | 1917 | int cpref = method->name_index(); |
sspitsyn@7683 | 1918 | return create(mirror, method_id, method->constants()->version(), bci, cpref, THREAD); |
aoqi@0 | 1919 | } |
aoqi@0 | 1920 | |
aoqi@0 | 1921 | void java_lang_reflect_AccessibleObject::compute_offsets() { |
aoqi@0 | 1922 | Klass* k = SystemDictionary::reflect_AccessibleObject_klass(); |
aoqi@0 | 1923 | compute_offset(override_offset, k, vmSymbols::override_name(), vmSymbols::bool_signature()); |
aoqi@0 | 1924 | } |
aoqi@0 | 1925 | |
aoqi@0 | 1926 | jboolean java_lang_reflect_AccessibleObject::override(oop reflect) { |
aoqi@0 | 1927 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 1928 | return (jboolean) reflect->bool_field(override_offset); |
aoqi@0 | 1929 | } |
aoqi@0 | 1930 | |
aoqi@0 | 1931 | void java_lang_reflect_AccessibleObject::set_override(oop reflect, jboolean value) { |
aoqi@0 | 1932 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 1933 | reflect->bool_field_put(override_offset, (int) value); |
aoqi@0 | 1934 | } |
aoqi@0 | 1935 | |
aoqi@0 | 1936 | void java_lang_reflect_Method::compute_offsets() { |
aoqi@0 | 1937 | Klass* k = SystemDictionary::reflect_Method_klass(); |
aoqi@0 | 1938 | compute_offset(clazz_offset, k, vmSymbols::clazz_name(), vmSymbols::class_signature()); |
aoqi@0 | 1939 | compute_offset(name_offset, k, vmSymbols::name_name(), vmSymbols::string_signature()); |
aoqi@0 | 1940 | compute_offset(returnType_offset, k, vmSymbols::returnType_name(), vmSymbols::class_signature()); |
aoqi@0 | 1941 | compute_offset(parameterTypes_offset, k, vmSymbols::parameterTypes_name(), vmSymbols::class_array_signature()); |
aoqi@0 | 1942 | compute_offset(exceptionTypes_offset, k, vmSymbols::exceptionTypes_name(), vmSymbols::class_array_signature()); |
aoqi@0 | 1943 | compute_offset(slot_offset, k, vmSymbols::slot_name(), vmSymbols::int_signature()); |
aoqi@0 | 1944 | compute_offset(modifiers_offset, k, vmSymbols::modifiers_name(), vmSymbols::int_signature()); |
aoqi@0 | 1945 | // The generic signature and annotations fields are only present in 1.5 |
aoqi@0 | 1946 | signature_offset = -1; |
aoqi@0 | 1947 | annotations_offset = -1; |
aoqi@0 | 1948 | parameter_annotations_offset = -1; |
aoqi@0 | 1949 | annotation_default_offset = -1; |
aoqi@0 | 1950 | type_annotations_offset = -1; |
aoqi@0 | 1951 | compute_optional_offset(signature_offset, k, vmSymbols::signature_name(), vmSymbols::string_signature()); |
aoqi@0 | 1952 | compute_optional_offset(annotations_offset, k, vmSymbols::annotations_name(), vmSymbols::byte_array_signature()); |
aoqi@0 | 1953 | compute_optional_offset(parameter_annotations_offset, k, vmSymbols::parameter_annotations_name(), vmSymbols::byte_array_signature()); |
aoqi@0 | 1954 | compute_optional_offset(annotation_default_offset, k, vmSymbols::annotation_default_name(), vmSymbols::byte_array_signature()); |
aoqi@0 | 1955 | compute_optional_offset(type_annotations_offset, k, vmSymbols::type_annotations_name(), vmSymbols::byte_array_signature()); |
aoqi@0 | 1956 | } |
aoqi@0 | 1957 | |
aoqi@0 | 1958 | Handle java_lang_reflect_Method::create(TRAPS) { |
aoqi@0 | 1959 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 1960 | Klass* klass = SystemDictionary::reflect_Method_klass(); |
aoqi@0 | 1961 | // This class is eagerly initialized during VM initialization, since we keep a refence |
aoqi@0 | 1962 | // to one of the methods |
aoqi@0 | 1963 | assert(InstanceKlass::cast(klass)->is_initialized(), "must be initialized"); |
phh@9507 | 1964 | return InstanceKlass::cast(klass)->allocate_instance_handle(THREAD); |
aoqi@0 | 1965 | } |
aoqi@0 | 1966 | |
aoqi@0 | 1967 | oop java_lang_reflect_Method::clazz(oop reflect) { |
aoqi@0 | 1968 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 1969 | return reflect->obj_field(clazz_offset); |
aoqi@0 | 1970 | } |
aoqi@0 | 1971 | |
aoqi@0 | 1972 | void java_lang_reflect_Method::set_clazz(oop reflect, oop value) { |
aoqi@0 | 1973 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 1974 | reflect->obj_field_put(clazz_offset, value); |
aoqi@0 | 1975 | } |
aoqi@0 | 1976 | |
aoqi@0 | 1977 | int java_lang_reflect_Method::slot(oop reflect) { |
aoqi@0 | 1978 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 1979 | return reflect->int_field(slot_offset); |
aoqi@0 | 1980 | } |
aoqi@0 | 1981 | |
aoqi@0 | 1982 | void java_lang_reflect_Method::set_slot(oop reflect, int value) { |
aoqi@0 | 1983 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 1984 | reflect->int_field_put(slot_offset, value); |
aoqi@0 | 1985 | } |
aoqi@0 | 1986 | |
aoqi@0 | 1987 | oop java_lang_reflect_Method::name(oop method) { |
aoqi@0 | 1988 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 1989 | return method->obj_field(name_offset); |
aoqi@0 | 1990 | } |
aoqi@0 | 1991 | |
aoqi@0 | 1992 | void java_lang_reflect_Method::set_name(oop method, oop value) { |
aoqi@0 | 1993 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 1994 | method->obj_field_put(name_offset, value); |
aoqi@0 | 1995 | } |
aoqi@0 | 1996 | |
aoqi@0 | 1997 | oop java_lang_reflect_Method::return_type(oop method) { |
aoqi@0 | 1998 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 1999 | return method->obj_field(returnType_offset); |
aoqi@0 | 2000 | } |
aoqi@0 | 2001 | |
aoqi@0 | 2002 | void java_lang_reflect_Method::set_return_type(oop method, oop value) { |
aoqi@0 | 2003 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2004 | method->obj_field_put(returnType_offset, value); |
aoqi@0 | 2005 | } |
aoqi@0 | 2006 | |
aoqi@0 | 2007 | oop java_lang_reflect_Method::parameter_types(oop method) { |
aoqi@0 | 2008 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2009 | return method->obj_field(parameterTypes_offset); |
aoqi@0 | 2010 | } |
aoqi@0 | 2011 | |
aoqi@0 | 2012 | void java_lang_reflect_Method::set_parameter_types(oop method, oop value) { |
aoqi@0 | 2013 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2014 | method->obj_field_put(parameterTypes_offset, value); |
aoqi@0 | 2015 | } |
aoqi@0 | 2016 | |
aoqi@0 | 2017 | oop java_lang_reflect_Method::exception_types(oop method) { |
aoqi@0 | 2018 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2019 | return method->obj_field(exceptionTypes_offset); |
aoqi@0 | 2020 | } |
aoqi@0 | 2021 | |
aoqi@0 | 2022 | void java_lang_reflect_Method::set_exception_types(oop method, oop value) { |
aoqi@0 | 2023 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2024 | method->obj_field_put(exceptionTypes_offset, value); |
aoqi@0 | 2025 | } |
aoqi@0 | 2026 | |
aoqi@0 | 2027 | int java_lang_reflect_Method::modifiers(oop method) { |
aoqi@0 | 2028 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2029 | return method->int_field(modifiers_offset); |
aoqi@0 | 2030 | } |
aoqi@0 | 2031 | |
aoqi@0 | 2032 | void java_lang_reflect_Method::set_modifiers(oop method, int value) { |
aoqi@0 | 2033 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2034 | method->int_field_put(modifiers_offset, value); |
aoqi@0 | 2035 | } |
aoqi@0 | 2036 | |
aoqi@0 | 2037 | bool java_lang_reflect_Method::has_signature_field() { |
aoqi@0 | 2038 | return (signature_offset >= 0); |
aoqi@0 | 2039 | } |
aoqi@0 | 2040 | |
aoqi@0 | 2041 | oop java_lang_reflect_Method::signature(oop method) { |
aoqi@0 | 2042 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2043 | assert(has_signature_field(), "signature field must be present"); |
aoqi@0 | 2044 | return method->obj_field(signature_offset); |
aoqi@0 | 2045 | } |
aoqi@0 | 2046 | |
aoqi@0 | 2047 | void java_lang_reflect_Method::set_signature(oop method, oop value) { |
aoqi@0 | 2048 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2049 | assert(has_signature_field(), "signature field must be present"); |
aoqi@0 | 2050 | method->obj_field_put(signature_offset, value); |
aoqi@0 | 2051 | } |
aoqi@0 | 2052 | |
aoqi@0 | 2053 | bool java_lang_reflect_Method::has_annotations_field() { |
aoqi@0 | 2054 | return (annotations_offset >= 0); |
aoqi@0 | 2055 | } |
aoqi@0 | 2056 | |
aoqi@0 | 2057 | oop java_lang_reflect_Method::annotations(oop method) { |
aoqi@0 | 2058 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2059 | assert(has_annotations_field(), "annotations field must be present"); |
aoqi@0 | 2060 | return method->obj_field(annotations_offset); |
aoqi@0 | 2061 | } |
aoqi@0 | 2062 | |
aoqi@0 | 2063 | void java_lang_reflect_Method::set_annotations(oop method, oop value) { |
aoqi@0 | 2064 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2065 | assert(has_annotations_field(), "annotations field must be present"); |
aoqi@0 | 2066 | method->obj_field_put(annotations_offset, value); |
aoqi@0 | 2067 | } |
aoqi@0 | 2068 | |
aoqi@0 | 2069 | bool java_lang_reflect_Method::has_parameter_annotations_field() { |
aoqi@0 | 2070 | return (parameter_annotations_offset >= 0); |
aoqi@0 | 2071 | } |
aoqi@0 | 2072 | |
aoqi@0 | 2073 | oop java_lang_reflect_Method::parameter_annotations(oop method) { |
aoqi@0 | 2074 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2075 | assert(has_parameter_annotations_field(), "parameter annotations field must be present"); |
aoqi@0 | 2076 | return method->obj_field(parameter_annotations_offset); |
aoqi@0 | 2077 | } |
aoqi@0 | 2078 | |
aoqi@0 | 2079 | void java_lang_reflect_Method::set_parameter_annotations(oop method, oop value) { |
aoqi@0 | 2080 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2081 | assert(has_parameter_annotations_field(), "parameter annotations field must be present"); |
aoqi@0 | 2082 | method->obj_field_put(parameter_annotations_offset, value); |
aoqi@0 | 2083 | } |
aoqi@0 | 2084 | |
aoqi@0 | 2085 | bool java_lang_reflect_Method::has_annotation_default_field() { |
aoqi@0 | 2086 | return (annotation_default_offset >= 0); |
aoqi@0 | 2087 | } |
aoqi@0 | 2088 | |
aoqi@0 | 2089 | oop java_lang_reflect_Method::annotation_default(oop method) { |
aoqi@0 | 2090 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2091 | assert(has_annotation_default_field(), "annotation default field must be present"); |
aoqi@0 | 2092 | return method->obj_field(annotation_default_offset); |
aoqi@0 | 2093 | } |
aoqi@0 | 2094 | |
aoqi@0 | 2095 | void java_lang_reflect_Method::set_annotation_default(oop method, oop value) { |
aoqi@0 | 2096 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2097 | assert(has_annotation_default_field(), "annotation default field must be present"); |
aoqi@0 | 2098 | method->obj_field_put(annotation_default_offset, value); |
aoqi@0 | 2099 | } |
aoqi@0 | 2100 | |
aoqi@0 | 2101 | bool java_lang_reflect_Method::has_type_annotations_field() { |
aoqi@0 | 2102 | return (type_annotations_offset >= 0); |
aoqi@0 | 2103 | } |
aoqi@0 | 2104 | |
aoqi@0 | 2105 | oop java_lang_reflect_Method::type_annotations(oop method) { |
aoqi@0 | 2106 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2107 | assert(has_type_annotations_field(), "type_annotations field must be present"); |
aoqi@0 | 2108 | return method->obj_field(type_annotations_offset); |
aoqi@0 | 2109 | } |
aoqi@0 | 2110 | |
aoqi@0 | 2111 | void java_lang_reflect_Method::set_type_annotations(oop method, oop value) { |
aoqi@0 | 2112 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2113 | assert(has_type_annotations_field(), "type_annotations field must be present"); |
aoqi@0 | 2114 | method->obj_field_put(type_annotations_offset, value); |
aoqi@0 | 2115 | } |
aoqi@0 | 2116 | |
aoqi@0 | 2117 | void java_lang_reflect_Constructor::compute_offsets() { |
aoqi@0 | 2118 | Klass* k = SystemDictionary::reflect_Constructor_klass(); |
aoqi@0 | 2119 | compute_offset(clazz_offset, k, vmSymbols::clazz_name(), vmSymbols::class_signature()); |
aoqi@0 | 2120 | compute_offset(parameterTypes_offset, k, vmSymbols::parameterTypes_name(), vmSymbols::class_array_signature()); |
aoqi@0 | 2121 | compute_offset(exceptionTypes_offset, k, vmSymbols::exceptionTypes_name(), vmSymbols::class_array_signature()); |
aoqi@0 | 2122 | compute_offset(slot_offset, k, vmSymbols::slot_name(), vmSymbols::int_signature()); |
aoqi@0 | 2123 | compute_offset(modifiers_offset, k, vmSymbols::modifiers_name(), vmSymbols::int_signature()); |
aoqi@0 | 2124 | // The generic signature and annotations fields are only present in 1.5 |
aoqi@0 | 2125 | signature_offset = -1; |
aoqi@0 | 2126 | annotations_offset = -1; |
aoqi@0 | 2127 | parameter_annotations_offset = -1; |
aoqi@0 | 2128 | type_annotations_offset = -1; |
aoqi@0 | 2129 | compute_optional_offset(signature_offset, k, vmSymbols::signature_name(), vmSymbols::string_signature()); |
aoqi@0 | 2130 | compute_optional_offset(annotations_offset, k, vmSymbols::annotations_name(), vmSymbols::byte_array_signature()); |
aoqi@0 | 2131 | compute_optional_offset(parameter_annotations_offset, k, vmSymbols::parameter_annotations_name(), vmSymbols::byte_array_signature()); |
aoqi@0 | 2132 | compute_optional_offset(type_annotations_offset, k, vmSymbols::type_annotations_name(), vmSymbols::byte_array_signature()); |
aoqi@0 | 2133 | } |
aoqi@0 | 2134 | |
aoqi@0 | 2135 | Handle java_lang_reflect_Constructor::create(TRAPS) { |
aoqi@0 | 2136 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2137 | Symbol* name = vmSymbols::java_lang_reflect_Constructor(); |
aoqi@0 | 2138 | Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH); |
aoqi@0 | 2139 | instanceKlassHandle klass (THREAD, k); |
aoqi@0 | 2140 | // Ensure it is initialized |
aoqi@0 | 2141 | klass->initialize(CHECK_NH); |
aoqi@0 | 2142 | return klass->allocate_instance_handle(CHECK_NH); |
aoqi@0 | 2143 | } |
aoqi@0 | 2144 | |
aoqi@0 | 2145 | oop java_lang_reflect_Constructor::clazz(oop reflect) { |
aoqi@0 | 2146 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2147 | return reflect->obj_field(clazz_offset); |
aoqi@0 | 2148 | } |
aoqi@0 | 2149 | |
aoqi@0 | 2150 | void java_lang_reflect_Constructor::set_clazz(oop reflect, oop value) { |
aoqi@0 | 2151 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2152 | reflect->obj_field_put(clazz_offset, value); |
aoqi@0 | 2153 | } |
aoqi@0 | 2154 | |
aoqi@0 | 2155 | oop java_lang_reflect_Constructor::parameter_types(oop constructor) { |
aoqi@0 | 2156 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2157 | return constructor->obj_field(parameterTypes_offset); |
aoqi@0 | 2158 | } |
aoqi@0 | 2159 | |
aoqi@0 | 2160 | void java_lang_reflect_Constructor::set_parameter_types(oop constructor, oop value) { |
aoqi@0 | 2161 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2162 | constructor->obj_field_put(parameterTypes_offset, value); |
aoqi@0 | 2163 | } |
aoqi@0 | 2164 | |
aoqi@0 | 2165 | oop java_lang_reflect_Constructor::exception_types(oop constructor) { |
aoqi@0 | 2166 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2167 | return constructor->obj_field(exceptionTypes_offset); |
aoqi@0 | 2168 | } |
aoqi@0 | 2169 | |
aoqi@0 | 2170 | void java_lang_reflect_Constructor::set_exception_types(oop constructor, oop value) { |
aoqi@0 | 2171 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2172 | constructor->obj_field_put(exceptionTypes_offset, value); |
aoqi@0 | 2173 | } |
aoqi@0 | 2174 | |
aoqi@0 | 2175 | int java_lang_reflect_Constructor::slot(oop reflect) { |
aoqi@0 | 2176 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2177 | return reflect->int_field(slot_offset); |
aoqi@0 | 2178 | } |
aoqi@0 | 2179 | |
aoqi@0 | 2180 | void java_lang_reflect_Constructor::set_slot(oop reflect, int value) { |
aoqi@0 | 2181 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2182 | reflect->int_field_put(slot_offset, value); |
aoqi@0 | 2183 | } |
aoqi@0 | 2184 | |
aoqi@0 | 2185 | int java_lang_reflect_Constructor::modifiers(oop constructor) { |
aoqi@0 | 2186 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2187 | return constructor->int_field(modifiers_offset); |
aoqi@0 | 2188 | } |
aoqi@0 | 2189 | |
aoqi@0 | 2190 | void java_lang_reflect_Constructor::set_modifiers(oop constructor, int value) { |
aoqi@0 | 2191 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2192 | constructor->int_field_put(modifiers_offset, value); |
aoqi@0 | 2193 | } |
aoqi@0 | 2194 | |
aoqi@0 | 2195 | bool java_lang_reflect_Constructor::has_signature_field() { |
aoqi@0 | 2196 | return (signature_offset >= 0); |
aoqi@0 | 2197 | } |
aoqi@0 | 2198 | |
aoqi@0 | 2199 | oop java_lang_reflect_Constructor::signature(oop constructor) { |
aoqi@0 | 2200 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2201 | assert(has_signature_field(), "signature field must be present"); |
aoqi@0 | 2202 | return constructor->obj_field(signature_offset); |
aoqi@0 | 2203 | } |
aoqi@0 | 2204 | |
aoqi@0 | 2205 | void java_lang_reflect_Constructor::set_signature(oop constructor, oop value) { |
aoqi@0 | 2206 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2207 | assert(has_signature_field(), "signature field must be present"); |
aoqi@0 | 2208 | constructor->obj_field_put(signature_offset, value); |
aoqi@0 | 2209 | } |
aoqi@0 | 2210 | |
aoqi@0 | 2211 | bool java_lang_reflect_Constructor::has_annotations_field() { |
aoqi@0 | 2212 | return (annotations_offset >= 0); |
aoqi@0 | 2213 | } |
aoqi@0 | 2214 | |
aoqi@0 | 2215 | oop java_lang_reflect_Constructor::annotations(oop constructor) { |
aoqi@0 | 2216 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2217 | assert(has_annotations_field(), "annotations field must be present"); |
aoqi@0 | 2218 | return constructor->obj_field(annotations_offset); |
aoqi@0 | 2219 | } |
aoqi@0 | 2220 | |
aoqi@0 | 2221 | void java_lang_reflect_Constructor::set_annotations(oop constructor, oop value) { |
aoqi@0 | 2222 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2223 | assert(has_annotations_field(), "annotations field must be present"); |
aoqi@0 | 2224 | constructor->obj_field_put(annotations_offset, value); |
aoqi@0 | 2225 | } |
aoqi@0 | 2226 | |
aoqi@0 | 2227 | bool java_lang_reflect_Constructor::has_parameter_annotations_field() { |
aoqi@0 | 2228 | return (parameter_annotations_offset >= 0); |
aoqi@0 | 2229 | } |
aoqi@0 | 2230 | |
aoqi@0 | 2231 | oop java_lang_reflect_Constructor::parameter_annotations(oop method) { |
aoqi@0 | 2232 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2233 | assert(has_parameter_annotations_field(), "parameter annotations field must be present"); |
aoqi@0 | 2234 | return method->obj_field(parameter_annotations_offset); |
aoqi@0 | 2235 | } |
aoqi@0 | 2236 | |
aoqi@0 | 2237 | void java_lang_reflect_Constructor::set_parameter_annotations(oop method, oop value) { |
aoqi@0 | 2238 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2239 | assert(has_parameter_annotations_field(), "parameter annotations field must be present"); |
aoqi@0 | 2240 | method->obj_field_put(parameter_annotations_offset, value); |
aoqi@0 | 2241 | } |
aoqi@0 | 2242 | |
aoqi@0 | 2243 | bool java_lang_reflect_Constructor::has_type_annotations_field() { |
aoqi@0 | 2244 | return (type_annotations_offset >= 0); |
aoqi@0 | 2245 | } |
aoqi@0 | 2246 | |
aoqi@0 | 2247 | oop java_lang_reflect_Constructor::type_annotations(oop constructor) { |
aoqi@0 | 2248 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2249 | assert(has_type_annotations_field(), "type_annotations field must be present"); |
aoqi@0 | 2250 | return constructor->obj_field(type_annotations_offset); |
aoqi@0 | 2251 | } |
aoqi@0 | 2252 | |
aoqi@0 | 2253 | void java_lang_reflect_Constructor::set_type_annotations(oop constructor, oop value) { |
aoqi@0 | 2254 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2255 | assert(has_type_annotations_field(), "type_annotations field must be present"); |
aoqi@0 | 2256 | constructor->obj_field_put(type_annotations_offset, value); |
aoqi@0 | 2257 | } |
aoqi@0 | 2258 | |
aoqi@0 | 2259 | void java_lang_reflect_Field::compute_offsets() { |
aoqi@0 | 2260 | Klass* k = SystemDictionary::reflect_Field_klass(); |
aoqi@0 | 2261 | compute_offset(clazz_offset, k, vmSymbols::clazz_name(), vmSymbols::class_signature()); |
aoqi@0 | 2262 | compute_offset(name_offset, k, vmSymbols::name_name(), vmSymbols::string_signature()); |
aoqi@0 | 2263 | compute_offset(type_offset, k, vmSymbols::type_name(), vmSymbols::class_signature()); |
aoqi@0 | 2264 | compute_offset(slot_offset, k, vmSymbols::slot_name(), vmSymbols::int_signature()); |
aoqi@0 | 2265 | compute_offset(modifiers_offset, k, vmSymbols::modifiers_name(), vmSymbols::int_signature()); |
aoqi@0 | 2266 | // The generic signature and annotations fields are only present in 1.5 |
aoqi@0 | 2267 | signature_offset = -1; |
aoqi@0 | 2268 | annotations_offset = -1; |
aoqi@0 | 2269 | type_annotations_offset = -1; |
aoqi@0 | 2270 | compute_optional_offset(signature_offset, k, vmSymbols::signature_name(), vmSymbols::string_signature()); |
aoqi@0 | 2271 | compute_optional_offset(annotations_offset, k, vmSymbols::annotations_name(), vmSymbols::byte_array_signature()); |
aoqi@0 | 2272 | compute_optional_offset(type_annotations_offset, k, vmSymbols::type_annotations_name(), vmSymbols::byte_array_signature()); |
aoqi@0 | 2273 | } |
aoqi@0 | 2274 | |
aoqi@0 | 2275 | Handle java_lang_reflect_Field::create(TRAPS) { |
aoqi@0 | 2276 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2277 | Symbol* name = vmSymbols::java_lang_reflect_Field(); |
aoqi@0 | 2278 | Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH); |
aoqi@0 | 2279 | instanceKlassHandle klass (THREAD, k); |
aoqi@0 | 2280 | // Ensure it is initialized |
aoqi@0 | 2281 | klass->initialize(CHECK_NH); |
aoqi@0 | 2282 | return klass->allocate_instance_handle(CHECK_NH); |
aoqi@0 | 2283 | } |
aoqi@0 | 2284 | |
aoqi@0 | 2285 | oop java_lang_reflect_Field::clazz(oop reflect) { |
aoqi@0 | 2286 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2287 | return reflect->obj_field(clazz_offset); |
aoqi@0 | 2288 | } |
aoqi@0 | 2289 | |
aoqi@0 | 2290 | void java_lang_reflect_Field::set_clazz(oop reflect, oop value) { |
aoqi@0 | 2291 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2292 | reflect->obj_field_put(clazz_offset, value); |
aoqi@0 | 2293 | } |
aoqi@0 | 2294 | |
aoqi@0 | 2295 | oop java_lang_reflect_Field::name(oop field) { |
aoqi@0 | 2296 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2297 | return field->obj_field(name_offset); |
aoqi@0 | 2298 | } |
aoqi@0 | 2299 | |
aoqi@0 | 2300 | void java_lang_reflect_Field::set_name(oop field, oop value) { |
aoqi@0 | 2301 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2302 | field->obj_field_put(name_offset, value); |
aoqi@0 | 2303 | } |
aoqi@0 | 2304 | |
aoqi@0 | 2305 | oop java_lang_reflect_Field::type(oop field) { |
aoqi@0 | 2306 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2307 | return field->obj_field(type_offset); |
aoqi@0 | 2308 | } |
aoqi@0 | 2309 | |
aoqi@0 | 2310 | void java_lang_reflect_Field::set_type(oop field, oop value) { |
aoqi@0 | 2311 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2312 | field->obj_field_put(type_offset, value); |
aoqi@0 | 2313 | } |
aoqi@0 | 2314 | |
aoqi@0 | 2315 | int java_lang_reflect_Field::slot(oop reflect) { |
aoqi@0 | 2316 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2317 | return reflect->int_field(slot_offset); |
aoqi@0 | 2318 | } |
aoqi@0 | 2319 | |
aoqi@0 | 2320 | void java_lang_reflect_Field::set_slot(oop reflect, int value) { |
aoqi@0 | 2321 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2322 | reflect->int_field_put(slot_offset, value); |
aoqi@0 | 2323 | } |
aoqi@0 | 2324 | |
aoqi@0 | 2325 | int java_lang_reflect_Field::modifiers(oop field) { |
aoqi@0 | 2326 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2327 | return field->int_field(modifiers_offset); |
aoqi@0 | 2328 | } |
aoqi@0 | 2329 | |
aoqi@0 | 2330 | void java_lang_reflect_Field::set_modifiers(oop field, int value) { |
aoqi@0 | 2331 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2332 | field->int_field_put(modifiers_offset, value); |
aoqi@0 | 2333 | } |
aoqi@0 | 2334 | |
aoqi@0 | 2335 | bool java_lang_reflect_Field::has_signature_field() { |
aoqi@0 | 2336 | return (signature_offset >= 0); |
aoqi@0 | 2337 | } |
aoqi@0 | 2338 | |
aoqi@0 | 2339 | oop java_lang_reflect_Field::signature(oop field) { |
aoqi@0 | 2340 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2341 | assert(has_signature_field(), "signature field must be present"); |
aoqi@0 | 2342 | return field->obj_field(signature_offset); |
aoqi@0 | 2343 | } |
aoqi@0 | 2344 | |
aoqi@0 | 2345 | void java_lang_reflect_Field::set_signature(oop field, oop value) { |
aoqi@0 | 2346 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2347 | assert(has_signature_field(), "signature field must be present"); |
aoqi@0 | 2348 | field->obj_field_put(signature_offset, value); |
aoqi@0 | 2349 | } |
aoqi@0 | 2350 | |
aoqi@0 | 2351 | bool java_lang_reflect_Field::has_annotations_field() { |
aoqi@0 | 2352 | return (annotations_offset >= 0); |
aoqi@0 | 2353 | } |
aoqi@0 | 2354 | |
aoqi@0 | 2355 | oop java_lang_reflect_Field::annotations(oop field) { |
aoqi@0 | 2356 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2357 | assert(has_annotations_field(), "annotations field must be present"); |
aoqi@0 | 2358 | return field->obj_field(annotations_offset); |
aoqi@0 | 2359 | } |
aoqi@0 | 2360 | |
aoqi@0 | 2361 | void java_lang_reflect_Field::set_annotations(oop field, oop value) { |
aoqi@0 | 2362 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2363 | assert(has_annotations_field(), "annotations field must be present"); |
aoqi@0 | 2364 | field->obj_field_put(annotations_offset, value); |
aoqi@0 | 2365 | } |
aoqi@0 | 2366 | |
aoqi@0 | 2367 | bool java_lang_reflect_Field::has_type_annotations_field() { |
aoqi@0 | 2368 | return (type_annotations_offset >= 0); |
aoqi@0 | 2369 | } |
aoqi@0 | 2370 | |
aoqi@0 | 2371 | oop java_lang_reflect_Field::type_annotations(oop field) { |
aoqi@0 | 2372 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2373 | assert(has_type_annotations_field(), "type_annotations field must be present"); |
aoqi@0 | 2374 | return field->obj_field(type_annotations_offset); |
aoqi@0 | 2375 | } |
aoqi@0 | 2376 | |
aoqi@0 | 2377 | void java_lang_reflect_Field::set_type_annotations(oop field, oop value) { |
aoqi@0 | 2378 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2379 | assert(has_type_annotations_field(), "type_annotations field must be present"); |
aoqi@0 | 2380 | field->obj_field_put(type_annotations_offset, value); |
aoqi@0 | 2381 | } |
aoqi@0 | 2382 | |
aoqi@0 | 2383 | void sun_reflect_ConstantPool::compute_offsets() { |
aoqi@0 | 2384 | Klass* k = SystemDictionary::reflect_ConstantPool_klass(); |
aoqi@0 | 2385 | // This null test can be removed post beta |
aoqi@0 | 2386 | if (k != NULL) { |
aoqi@0 | 2387 | // The field is called ConstantPool* in the sun.reflect.ConstantPool class. |
aoqi@0 | 2388 | compute_offset(_oop_offset, k, vmSymbols::ConstantPool_name(), vmSymbols::object_signature()); |
aoqi@0 | 2389 | } |
aoqi@0 | 2390 | } |
aoqi@0 | 2391 | |
aoqi@0 | 2392 | void java_lang_reflect_Parameter::compute_offsets() { |
aoqi@0 | 2393 | Klass* k = SystemDictionary::reflect_Parameter_klass(); |
aoqi@0 | 2394 | if(NULL != k) { |
aoqi@0 | 2395 | compute_offset(name_offset, k, vmSymbols::name_name(), vmSymbols::string_signature()); |
aoqi@0 | 2396 | compute_offset(modifiers_offset, k, vmSymbols::modifiers_name(), vmSymbols::int_signature()); |
aoqi@0 | 2397 | compute_offset(index_offset, k, vmSymbols::index_name(), vmSymbols::int_signature()); |
aoqi@0 | 2398 | compute_offset(executable_offset, k, vmSymbols::executable_name(), vmSymbols::executable_signature()); |
aoqi@0 | 2399 | } |
aoqi@0 | 2400 | } |
aoqi@0 | 2401 | |
aoqi@0 | 2402 | Handle java_lang_reflect_Parameter::create(TRAPS) { |
aoqi@0 | 2403 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2404 | Symbol* name = vmSymbols::java_lang_reflect_Parameter(); |
aoqi@0 | 2405 | Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH); |
aoqi@0 | 2406 | instanceKlassHandle klass (THREAD, k); |
aoqi@0 | 2407 | // Ensure it is initialized |
aoqi@0 | 2408 | klass->initialize(CHECK_NH); |
aoqi@0 | 2409 | return klass->allocate_instance_handle(CHECK_NH); |
aoqi@0 | 2410 | } |
aoqi@0 | 2411 | |
aoqi@0 | 2412 | oop java_lang_reflect_Parameter::name(oop param) { |
aoqi@0 | 2413 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2414 | return param->obj_field(name_offset); |
aoqi@0 | 2415 | } |
aoqi@0 | 2416 | |
aoqi@0 | 2417 | void java_lang_reflect_Parameter::set_name(oop param, oop value) { |
aoqi@0 | 2418 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2419 | param->obj_field_put(name_offset, value); |
aoqi@0 | 2420 | } |
aoqi@0 | 2421 | |
aoqi@0 | 2422 | int java_lang_reflect_Parameter::modifiers(oop param) { |
aoqi@0 | 2423 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2424 | return param->int_field(modifiers_offset); |
aoqi@0 | 2425 | } |
aoqi@0 | 2426 | |
aoqi@0 | 2427 | void java_lang_reflect_Parameter::set_modifiers(oop param, int value) { |
aoqi@0 | 2428 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2429 | param->int_field_put(modifiers_offset, value); |
aoqi@0 | 2430 | } |
aoqi@0 | 2431 | |
aoqi@0 | 2432 | int java_lang_reflect_Parameter::index(oop param) { |
aoqi@0 | 2433 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2434 | return param->int_field(index_offset); |
aoqi@0 | 2435 | } |
aoqi@0 | 2436 | |
aoqi@0 | 2437 | void java_lang_reflect_Parameter::set_index(oop param, int value) { |
aoqi@0 | 2438 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2439 | param->int_field_put(index_offset, value); |
aoqi@0 | 2440 | } |
aoqi@0 | 2441 | |
aoqi@0 | 2442 | oop java_lang_reflect_Parameter::executable(oop param) { |
aoqi@0 | 2443 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2444 | return param->obj_field(executable_offset); |
aoqi@0 | 2445 | } |
aoqi@0 | 2446 | |
aoqi@0 | 2447 | void java_lang_reflect_Parameter::set_executable(oop param, oop value) { |
aoqi@0 | 2448 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2449 | param->obj_field_put(executable_offset, value); |
aoqi@0 | 2450 | } |
aoqi@0 | 2451 | |
aoqi@0 | 2452 | |
aoqi@0 | 2453 | Handle sun_reflect_ConstantPool::create(TRAPS) { |
aoqi@0 | 2454 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2455 | Klass* k = SystemDictionary::reflect_ConstantPool_klass(); |
aoqi@0 | 2456 | instanceKlassHandle klass (THREAD, k); |
aoqi@0 | 2457 | // Ensure it is initialized |
aoqi@0 | 2458 | klass->initialize(CHECK_NH); |
aoqi@0 | 2459 | return klass->allocate_instance_handle(CHECK_NH); |
aoqi@0 | 2460 | } |
aoqi@0 | 2461 | |
aoqi@0 | 2462 | |
aoqi@0 | 2463 | void sun_reflect_ConstantPool::set_cp(oop reflect, ConstantPool* value) { |
aoqi@0 | 2464 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2465 | oop mirror = value->pool_holder()->java_mirror(); |
aoqi@0 | 2466 | // Save the mirror to get back the constant pool. |
aoqi@0 | 2467 | reflect->obj_field_put(_oop_offset, mirror); |
aoqi@0 | 2468 | } |
aoqi@0 | 2469 | |
aoqi@0 | 2470 | ConstantPool* sun_reflect_ConstantPool::get_cp(oop reflect) { |
aoqi@0 | 2471 | assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); |
aoqi@0 | 2472 | |
aoqi@0 | 2473 | oop mirror = reflect->obj_field(_oop_offset); |
aoqi@0 | 2474 | Klass* k = java_lang_Class::as_Klass(mirror); |
aoqi@0 | 2475 | assert(k->oop_is_instance(), "Must be"); |
aoqi@0 | 2476 | |
aoqi@0 | 2477 | // Get the constant pool back from the klass. Since class redefinition |
aoqi@0 | 2478 | // merges the new constant pool into the old, this is essentially the |
aoqi@0 | 2479 | // same constant pool as the original. If constant pool merging is |
aoqi@0 | 2480 | // no longer done in the future, this will have to change to save |
aoqi@0 | 2481 | // the original. |
aoqi@0 | 2482 | return InstanceKlass::cast(k)->constants(); |
aoqi@0 | 2483 | } |
aoqi@0 | 2484 | |
aoqi@0 | 2485 | void sun_reflect_UnsafeStaticFieldAccessorImpl::compute_offsets() { |
aoqi@0 | 2486 | Klass* k = SystemDictionary::reflect_UnsafeStaticFieldAccessorImpl_klass(); |
aoqi@0 | 2487 | // This null test can be removed post beta |
aoqi@0 | 2488 | if (k != NULL) { |
aoqi@0 | 2489 | compute_offset(_base_offset, k, |
aoqi@0 | 2490 | vmSymbols::base_name(), vmSymbols::object_signature()); |
aoqi@0 | 2491 | } |
aoqi@0 | 2492 | } |
aoqi@0 | 2493 | |
aoqi@0 | 2494 | oop java_lang_boxing_object::initialize_and_allocate(BasicType type, TRAPS) { |
aoqi@0 | 2495 | Klass* k = SystemDictionary::box_klass(type); |
aoqi@0 | 2496 | if (k == NULL) return NULL; |
aoqi@0 | 2497 | instanceKlassHandle h (THREAD, k); |
aoqi@0 | 2498 | if (!h->is_initialized()) h->initialize(CHECK_0); |
aoqi@0 | 2499 | return h->allocate_instance(THREAD); |
aoqi@0 | 2500 | } |
aoqi@0 | 2501 | |
aoqi@0 | 2502 | |
aoqi@0 | 2503 | oop java_lang_boxing_object::create(BasicType type, jvalue* value, TRAPS) { |
aoqi@0 | 2504 | oop box = initialize_and_allocate(type, CHECK_0); |
aoqi@0 | 2505 | if (box == NULL) return NULL; |
aoqi@0 | 2506 | switch (type) { |
aoqi@0 | 2507 | case T_BOOLEAN: |
aoqi@0 | 2508 | box->bool_field_put(value_offset, value->z); |
aoqi@0 | 2509 | break; |
aoqi@0 | 2510 | case T_CHAR: |
aoqi@0 | 2511 | box->char_field_put(value_offset, value->c); |
aoqi@0 | 2512 | break; |
aoqi@0 | 2513 | case T_FLOAT: |
aoqi@0 | 2514 | box->float_field_put(value_offset, value->f); |
aoqi@0 | 2515 | break; |
aoqi@0 | 2516 | case T_DOUBLE: |
aoqi@0 | 2517 | box->double_field_put(long_value_offset, value->d); |
aoqi@0 | 2518 | break; |
aoqi@0 | 2519 | case T_BYTE: |
aoqi@0 | 2520 | box->byte_field_put(value_offset, value->b); |
aoqi@0 | 2521 | break; |
aoqi@0 | 2522 | case T_SHORT: |
aoqi@0 | 2523 | box->short_field_put(value_offset, value->s); |
aoqi@0 | 2524 | break; |
aoqi@0 | 2525 | case T_INT: |
aoqi@0 | 2526 | box->int_field_put(value_offset, value->i); |
aoqi@0 | 2527 | break; |
aoqi@0 | 2528 | case T_LONG: |
aoqi@0 | 2529 | box->long_field_put(long_value_offset, value->j); |
aoqi@0 | 2530 | break; |
aoqi@0 | 2531 | default: |
aoqi@0 | 2532 | return NULL; |
aoqi@0 | 2533 | } |
aoqi@0 | 2534 | return box; |
aoqi@0 | 2535 | } |
aoqi@0 | 2536 | |
aoqi@0 | 2537 | |
aoqi@0 | 2538 | BasicType java_lang_boxing_object::basic_type(oop box) { |
aoqi@0 | 2539 | if (box == NULL) return T_ILLEGAL; |
aoqi@0 | 2540 | BasicType type = SystemDictionary::box_klass_type(box->klass()); |
aoqi@0 | 2541 | if (type == T_OBJECT) // 'unknown' value returned by SD::bkt |
aoqi@0 | 2542 | return T_ILLEGAL; |
aoqi@0 | 2543 | return type; |
aoqi@0 | 2544 | } |
aoqi@0 | 2545 | |
aoqi@0 | 2546 | |
aoqi@0 | 2547 | BasicType java_lang_boxing_object::get_value(oop box, jvalue* value) { |
aoqi@0 | 2548 | BasicType type = SystemDictionary::box_klass_type(box->klass()); |
aoqi@0 | 2549 | switch (type) { |
aoqi@0 | 2550 | case T_BOOLEAN: |
aoqi@0 | 2551 | value->z = box->bool_field(value_offset); |
aoqi@0 | 2552 | break; |
aoqi@0 | 2553 | case T_CHAR: |
aoqi@0 | 2554 | value->c = box->char_field(value_offset); |
aoqi@0 | 2555 | break; |
aoqi@0 | 2556 | case T_FLOAT: |
aoqi@0 | 2557 | value->f = box->float_field(value_offset); |
aoqi@0 | 2558 | break; |
aoqi@0 | 2559 | case T_DOUBLE: |
aoqi@0 | 2560 | value->d = box->double_field(long_value_offset); |
aoqi@0 | 2561 | break; |
aoqi@0 | 2562 | case T_BYTE: |
aoqi@0 | 2563 | value->b = box->byte_field(value_offset); |
aoqi@0 | 2564 | break; |
aoqi@0 | 2565 | case T_SHORT: |
aoqi@0 | 2566 | value->s = box->short_field(value_offset); |
aoqi@0 | 2567 | break; |
aoqi@0 | 2568 | case T_INT: |
aoqi@0 | 2569 | value->i = box->int_field(value_offset); |
aoqi@0 | 2570 | break; |
aoqi@0 | 2571 | case T_LONG: |
aoqi@0 | 2572 | value->j = box->long_field(long_value_offset); |
aoqi@0 | 2573 | break; |
aoqi@0 | 2574 | default: |
aoqi@0 | 2575 | return T_ILLEGAL; |
aoqi@0 | 2576 | } // end switch |
aoqi@0 | 2577 | return type; |
aoqi@0 | 2578 | } |
aoqi@0 | 2579 | |
aoqi@0 | 2580 | |
aoqi@0 | 2581 | BasicType java_lang_boxing_object::set_value(oop box, jvalue* value) { |
aoqi@0 | 2582 | BasicType type = SystemDictionary::box_klass_type(box->klass()); |
aoqi@0 | 2583 | switch (type) { |
aoqi@0 | 2584 | case T_BOOLEAN: |
aoqi@0 | 2585 | box->bool_field_put(value_offset, value->z); |
aoqi@0 | 2586 | break; |
aoqi@0 | 2587 | case T_CHAR: |
aoqi@0 | 2588 | box->char_field_put(value_offset, value->c); |
aoqi@0 | 2589 | break; |
aoqi@0 | 2590 | case T_FLOAT: |
aoqi@0 | 2591 | box->float_field_put(value_offset, value->f); |
aoqi@0 | 2592 | break; |
aoqi@0 | 2593 | case T_DOUBLE: |
aoqi@0 | 2594 | box->double_field_put(long_value_offset, value->d); |
aoqi@0 | 2595 | break; |
aoqi@0 | 2596 | case T_BYTE: |
aoqi@0 | 2597 | box->byte_field_put(value_offset, value->b); |
aoqi@0 | 2598 | break; |
aoqi@0 | 2599 | case T_SHORT: |
aoqi@0 | 2600 | box->short_field_put(value_offset, value->s); |
aoqi@0 | 2601 | break; |
aoqi@0 | 2602 | case T_INT: |
aoqi@0 | 2603 | box->int_field_put(value_offset, value->i); |
aoqi@0 | 2604 | break; |
aoqi@0 | 2605 | case T_LONG: |
aoqi@0 | 2606 | box->long_field_put(long_value_offset, value->j); |
aoqi@0 | 2607 | break; |
aoqi@0 | 2608 | default: |
aoqi@0 | 2609 | return T_ILLEGAL; |
aoqi@0 | 2610 | } // end switch |
aoqi@0 | 2611 | return type; |
aoqi@0 | 2612 | } |
aoqi@0 | 2613 | |
aoqi@0 | 2614 | |
aoqi@0 | 2615 | void java_lang_boxing_object::print(BasicType type, jvalue* value, outputStream* st) { |
aoqi@0 | 2616 | switch (type) { |
aoqi@0 | 2617 | case T_BOOLEAN: st->print("%s", value->z ? "true" : "false"); break; |
aoqi@0 | 2618 | case T_CHAR: st->print("%d", value->c); break; |
aoqi@0 | 2619 | case T_BYTE: st->print("%d", value->b); break; |
aoqi@0 | 2620 | case T_SHORT: st->print("%d", value->s); break; |
aoqi@0 | 2621 | case T_INT: st->print("%d", value->i); break; |
aoqi@0 | 2622 | case T_LONG: st->print(INT64_FORMAT, value->j); break; |
aoqi@0 | 2623 | case T_FLOAT: st->print("%f", value->f); break; |
aoqi@0 | 2624 | case T_DOUBLE: st->print("%lf", value->d); break; |
aoqi@0 | 2625 | default: st->print("type %d?", type); break; |
aoqi@0 | 2626 | } |
aoqi@0 | 2627 | } |
aoqi@0 | 2628 | |
aoqi@0 | 2629 | |
aoqi@0 | 2630 | // Support for java_lang_ref_Reference |
aoqi@0 | 2631 | HeapWord *java_lang_ref_Reference::pending_list_lock_addr() { |
aoqi@0 | 2632 | InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::Reference_klass()); |
aoqi@0 | 2633 | address addr = ik->static_field_addr(static_lock_offset); |
aoqi@0 | 2634 | return (HeapWord*) addr; |
aoqi@0 | 2635 | } |
aoqi@0 | 2636 | |
aoqi@0 | 2637 | oop java_lang_ref_Reference::pending_list_lock() { |
aoqi@0 | 2638 | InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::Reference_klass()); |
aoqi@0 | 2639 | address addr = ik->static_field_addr(static_lock_offset); |
aoqi@0 | 2640 | if (UseCompressedOops) { |
aoqi@0 | 2641 | return oopDesc::load_decode_heap_oop((narrowOop *)addr); |
aoqi@0 | 2642 | } else { |
aoqi@0 | 2643 | return oopDesc::load_decode_heap_oop((oop*)addr); |
aoqi@0 | 2644 | } |
aoqi@0 | 2645 | } |
aoqi@0 | 2646 | |
aoqi@0 | 2647 | HeapWord *java_lang_ref_Reference::pending_list_addr() { |
aoqi@0 | 2648 | InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::Reference_klass()); |
aoqi@0 | 2649 | address addr = ik->static_field_addr(static_pending_offset); |
aoqi@0 | 2650 | // XXX This might not be HeapWord aligned, almost rather be char *. |
aoqi@0 | 2651 | return (HeapWord*)addr; |
aoqi@0 | 2652 | } |
aoqi@0 | 2653 | |
aoqi@0 | 2654 | oop java_lang_ref_Reference::pending_list() { |
aoqi@0 | 2655 | char *addr = (char *)pending_list_addr(); |
aoqi@0 | 2656 | if (UseCompressedOops) { |
aoqi@0 | 2657 | return oopDesc::load_decode_heap_oop((narrowOop *)addr); |
aoqi@0 | 2658 | } else { |
aoqi@0 | 2659 | return oopDesc::load_decode_heap_oop((oop*)addr); |
aoqi@0 | 2660 | } |
aoqi@0 | 2661 | } |
aoqi@0 | 2662 | |
aoqi@0 | 2663 | |
aoqi@0 | 2664 | // Support for java_lang_ref_SoftReference |
aoqi@0 | 2665 | |
aoqi@0 | 2666 | jlong java_lang_ref_SoftReference::timestamp(oop ref) { |
aoqi@0 | 2667 | return ref->long_field(timestamp_offset); |
aoqi@0 | 2668 | } |
aoqi@0 | 2669 | |
aoqi@0 | 2670 | jlong java_lang_ref_SoftReference::clock() { |
aoqi@0 | 2671 | InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::SoftReference_klass()); |
aoqi@0 | 2672 | jlong* offset = (jlong*)ik->static_field_addr(static_clock_offset); |
aoqi@0 | 2673 | return *offset; |
aoqi@0 | 2674 | } |
aoqi@0 | 2675 | |
aoqi@0 | 2676 | void java_lang_ref_SoftReference::set_clock(jlong value) { |
aoqi@0 | 2677 | InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::SoftReference_klass()); |
aoqi@0 | 2678 | jlong* offset = (jlong*)ik->static_field_addr(static_clock_offset); |
aoqi@0 | 2679 | *offset = value; |
aoqi@0 | 2680 | } |
aoqi@0 | 2681 | |
kbarrett@9099 | 2682 | // Support for java_lang_ref_ReferenceQueue |
kbarrett@9099 | 2683 | |
kbarrett@9099 | 2684 | oop java_lang_ref_ReferenceQueue::NULL_queue() { |
kbarrett@9099 | 2685 | InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::ReferenceQueue_klass()); |
kbarrett@9099 | 2686 | oop mirror = ik->java_mirror(); |
kbarrett@9099 | 2687 | return mirror->obj_field(static_NULL_queue_offset); |
kbarrett@9099 | 2688 | } |
kbarrett@9099 | 2689 | |
kbarrett@9099 | 2690 | oop java_lang_ref_ReferenceQueue::ENQUEUED_queue() { |
kbarrett@9099 | 2691 | InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::ReferenceQueue_klass()); |
kbarrett@9099 | 2692 | oop mirror = ik->java_mirror(); |
kbarrett@9099 | 2693 | return mirror->obj_field(static_ENQUEUED_queue_offset); |
kbarrett@9099 | 2694 | } |
kbarrett@9099 | 2695 | |
kbarrett@9099 | 2696 | void java_lang_ref_ReferenceQueue::compute_offsets() { |
kbarrett@9099 | 2697 | Klass* k = SystemDictionary::ReferenceQueue_klass(); |
kbarrett@9099 | 2698 | compute_offset(static_NULL_queue_offset, |
kbarrett@9099 | 2699 | k, |
kbarrett@9099 | 2700 | vmSymbols::referencequeue_null_name(), |
kbarrett@9099 | 2701 | vmSymbols::referencequeue_signature()); |
kbarrett@9099 | 2702 | compute_offset(static_ENQUEUED_queue_offset, |
kbarrett@9099 | 2703 | k, |
kbarrett@9099 | 2704 | vmSymbols::referencequeue_enqueued_name(), |
kbarrett@9099 | 2705 | vmSymbols::referencequeue_signature()); |
kbarrett@9099 | 2706 | } |
kbarrett@9099 | 2707 | |
aoqi@0 | 2708 | // Support for java_lang_invoke_DirectMethodHandle |
aoqi@0 | 2709 | |
aoqi@0 | 2710 | int java_lang_invoke_DirectMethodHandle::_member_offset; |
aoqi@0 | 2711 | |
aoqi@0 | 2712 | oop java_lang_invoke_DirectMethodHandle::member(oop dmh) { |
aoqi@0 | 2713 | oop member_name = NULL; |
aoqi@0 | 2714 | bool is_dmh = dmh->is_oop() && java_lang_invoke_DirectMethodHandle::is_instance(dmh); |
aoqi@0 | 2715 | assert(is_dmh, "a DirectMethodHandle oop is expected"); |
aoqi@0 | 2716 | if (is_dmh) { |
aoqi@0 | 2717 | member_name = dmh->obj_field(member_offset_in_bytes()); |
aoqi@0 | 2718 | } |
aoqi@0 | 2719 | return member_name; |
aoqi@0 | 2720 | } |
aoqi@0 | 2721 | |
aoqi@0 | 2722 | void java_lang_invoke_DirectMethodHandle::compute_offsets() { |
aoqi@0 | 2723 | Klass* klass_oop = SystemDictionary::DirectMethodHandle_klass(); |
aoqi@0 | 2724 | if (klass_oop != NULL && EnableInvokeDynamic) { |
aoqi@0 | 2725 | compute_offset(_member_offset, klass_oop, vmSymbols::member_name(), vmSymbols::java_lang_invoke_MemberName_signature()); |
aoqi@0 | 2726 | } |
aoqi@0 | 2727 | } |
aoqi@0 | 2728 | |
aoqi@0 | 2729 | // Support for java_lang_invoke_MethodHandle |
aoqi@0 | 2730 | |
aoqi@0 | 2731 | int java_lang_invoke_MethodHandle::_type_offset; |
aoqi@0 | 2732 | int java_lang_invoke_MethodHandle::_form_offset; |
aoqi@0 | 2733 | |
aoqi@0 | 2734 | int java_lang_invoke_MemberName::_clazz_offset; |
aoqi@0 | 2735 | int java_lang_invoke_MemberName::_name_offset; |
aoqi@0 | 2736 | int java_lang_invoke_MemberName::_type_offset; |
aoqi@0 | 2737 | int java_lang_invoke_MemberName::_flags_offset; |
aoqi@0 | 2738 | int java_lang_invoke_MemberName::_vmtarget_offset; |
aoqi@0 | 2739 | int java_lang_invoke_MemberName::_vmloader_offset; |
aoqi@0 | 2740 | int java_lang_invoke_MemberName::_vmindex_offset; |
aoqi@0 | 2741 | |
aoqi@0 | 2742 | int java_lang_invoke_LambdaForm::_vmentry_offset; |
aoqi@0 | 2743 | |
aoqi@0 | 2744 | void java_lang_invoke_MethodHandle::compute_offsets() { |
aoqi@0 | 2745 | Klass* klass_oop = SystemDictionary::MethodHandle_klass(); |
aoqi@0 | 2746 | if (klass_oop != NULL && EnableInvokeDynamic) { |
aoqi@0 | 2747 | compute_offset(_type_offset, klass_oop, vmSymbols::type_name(), vmSymbols::java_lang_invoke_MethodType_signature()); |
aoqi@0 | 2748 | compute_optional_offset(_form_offset, klass_oop, vmSymbols::form_name(), vmSymbols::java_lang_invoke_LambdaForm_signature()); |
aoqi@0 | 2749 | if (_form_offset == 0) { |
aoqi@0 | 2750 | EnableInvokeDynamic = false; |
aoqi@0 | 2751 | } |
aoqi@0 | 2752 | } |
aoqi@0 | 2753 | } |
aoqi@0 | 2754 | |
aoqi@0 | 2755 | void java_lang_invoke_MemberName::compute_offsets() { |
aoqi@0 | 2756 | Klass* klass_oop = SystemDictionary::MemberName_klass(); |
aoqi@0 | 2757 | if (klass_oop != NULL && EnableInvokeDynamic) { |
aoqi@0 | 2758 | compute_offset(_clazz_offset, klass_oop, vmSymbols::clazz_name(), vmSymbols::class_signature()); |
aoqi@0 | 2759 | compute_offset(_name_offset, klass_oop, vmSymbols::name_name(), vmSymbols::string_signature()); |
aoqi@0 | 2760 | compute_offset(_type_offset, klass_oop, vmSymbols::type_name(), vmSymbols::object_signature()); |
aoqi@0 | 2761 | compute_offset(_flags_offset, klass_oop, vmSymbols::flags_name(), vmSymbols::int_signature()); |
aoqi@0 | 2762 | MEMBERNAME_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET); |
aoqi@0 | 2763 | } |
aoqi@0 | 2764 | } |
aoqi@0 | 2765 | |
aoqi@0 | 2766 | void java_lang_invoke_LambdaForm::compute_offsets() { |
aoqi@0 | 2767 | Klass* klass_oop = SystemDictionary::LambdaForm_klass(); |
aoqi@0 | 2768 | if (klass_oop != NULL && EnableInvokeDynamic) { |
aoqi@0 | 2769 | compute_offset(_vmentry_offset, klass_oop, vmSymbols::vmentry_name(), vmSymbols::java_lang_invoke_MemberName_signature()); |
aoqi@0 | 2770 | } |
aoqi@0 | 2771 | } |
aoqi@0 | 2772 | |
aoqi@0 | 2773 | oop java_lang_invoke_MethodHandle::type(oop mh) { |
aoqi@0 | 2774 | return mh->obj_field(_type_offset); |
aoqi@0 | 2775 | } |
aoqi@0 | 2776 | |
aoqi@0 | 2777 | void java_lang_invoke_MethodHandle::set_type(oop mh, oop mtype) { |
aoqi@0 | 2778 | mh->obj_field_put(_type_offset, mtype); |
aoqi@0 | 2779 | } |
aoqi@0 | 2780 | |
aoqi@0 | 2781 | oop java_lang_invoke_MethodHandle::form(oop mh) { |
aoqi@0 | 2782 | assert(_form_offset != 0, ""); |
aoqi@0 | 2783 | return mh->obj_field(_form_offset); |
aoqi@0 | 2784 | } |
aoqi@0 | 2785 | |
aoqi@0 | 2786 | void java_lang_invoke_MethodHandle::set_form(oop mh, oop lform) { |
aoqi@0 | 2787 | assert(_form_offset != 0, ""); |
aoqi@0 | 2788 | mh->obj_field_put(_form_offset, lform); |
aoqi@0 | 2789 | } |
aoqi@0 | 2790 | |
aoqi@0 | 2791 | /// MemberName accessors |
aoqi@0 | 2792 | |
aoqi@0 | 2793 | oop java_lang_invoke_MemberName::clazz(oop mname) { |
aoqi@0 | 2794 | assert(is_instance(mname), "wrong type"); |
aoqi@0 | 2795 | return mname->obj_field(_clazz_offset); |
aoqi@0 | 2796 | } |
aoqi@0 | 2797 | |
aoqi@0 | 2798 | void java_lang_invoke_MemberName::set_clazz(oop mname, oop clazz) { |
aoqi@0 | 2799 | assert(is_instance(mname), "wrong type"); |
aoqi@0 | 2800 | mname->obj_field_put(_clazz_offset, clazz); |
aoqi@0 | 2801 | } |
aoqi@0 | 2802 | |
aoqi@0 | 2803 | oop java_lang_invoke_MemberName::name(oop mname) { |
aoqi@0 | 2804 | assert(is_instance(mname), "wrong type"); |
aoqi@0 | 2805 | return mname->obj_field(_name_offset); |
aoqi@0 | 2806 | } |
aoqi@0 | 2807 | |
aoqi@0 | 2808 | void java_lang_invoke_MemberName::set_name(oop mname, oop name) { |
aoqi@0 | 2809 | assert(is_instance(mname), "wrong type"); |
aoqi@0 | 2810 | mname->obj_field_put(_name_offset, name); |
aoqi@0 | 2811 | } |
aoqi@0 | 2812 | |
aoqi@0 | 2813 | oop java_lang_invoke_MemberName::type(oop mname) { |
aoqi@0 | 2814 | assert(is_instance(mname), "wrong type"); |
aoqi@0 | 2815 | return mname->obj_field(_type_offset); |
aoqi@0 | 2816 | } |
aoqi@0 | 2817 | |
aoqi@0 | 2818 | void java_lang_invoke_MemberName::set_type(oop mname, oop type) { |
aoqi@0 | 2819 | assert(is_instance(mname), "wrong type"); |
aoqi@0 | 2820 | mname->obj_field_put(_type_offset, type); |
aoqi@0 | 2821 | } |
aoqi@0 | 2822 | |
aoqi@0 | 2823 | int java_lang_invoke_MemberName::flags(oop mname) { |
aoqi@0 | 2824 | assert(is_instance(mname), "wrong type"); |
aoqi@0 | 2825 | return mname->int_field(_flags_offset); |
aoqi@0 | 2826 | } |
aoqi@0 | 2827 | |
aoqi@0 | 2828 | void java_lang_invoke_MemberName::set_flags(oop mname, int flags) { |
aoqi@0 | 2829 | assert(is_instance(mname), "wrong type"); |
aoqi@0 | 2830 | mname->int_field_put(_flags_offset, flags); |
aoqi@0 | 2831 | } |
aoqi@0 | 2832 | |
aoqi@0 | 2833 | Metadata* java_lang_invoke_MemberName::vmtarget(oop mname) { |
aoqi@0 | 2834 | assert(is_instance(mname), "wrong type"); |
aoqi@0 | 2835 | return (Metadata*)mname->address_field(_vmtarget_offset); |
aoqi@0 | 2836 | } |
aoqi@0 | 2837 | |
coleenp@7391 | 2838 | bool java_lang_invoke_MemberName::is_method(oop mname) { |
coleenp@7391 | 2839 | assert(is_instance(mname), "must be MemberName"); |
coleenp@7391 | 2840 | return (flags(mname) & (MN_IS_METHOD | MN_IS_CONSTRUCTOR)) > 0; |
coleenp@7391 | 2841 | } |
coleenp@7391 | 2842 | |
aoqi@0 | 2843 | void java_lang_invoke_MemberName::set_vmtarget(oop mname, Metadata* ref) { |
aoqi@0 | 2844 | assert(is_instance(mname), "wrong type"); |
aoqi@0 | 2845 | // check the type of the vmtarget |
aoqi@0 | 2846 | oop dependency = NULL; |
aoqi@0 | 2847 | if (ref != NULL) { |
aoqi@0 | 2848 | switch (flags(mname) & (MN_IS_METHOD | |
aoqi@0 | 2849 | MN_IS_CONSTRUCTOR | |
aoqi@0 | 2850 | MN_IS_FIELD)) { |
aoqi@0 | 2851 | case MN_IS_METHOD: |
aoqi@0 | 2852 | case MN_IS_CONSTRUCTOR: |
aoqi@0 | 2853 | assert(ref->is_method(), "should be a method"); |
aoqi@0 | 2854 | dependency = ((Method*)ref)->method_holder()->java_mirror(); |
aoqi@0 | 2855 | break; |
aoqi@0 | 2856 | case MN_IS_FIELD: |
aoqi@0 | 2857 | assert(ref->is_klass(), "should be a class"); |
aoqi@0 | 2858 | dependency = ((Klass*)ref)->java_mirror(); |
aoqi@0 | 2859 | break; |
aoqi@0 | 2860 | default: |
aoqi@0 | 2861 | ShouldNotReachHere(); |
aoqi@0 | 2862 | } |
aoqi@0 | 2863 | } |
aoqi@0 | 2864 | mname->address_field_put(_vmtarget_offset, (address)ref); |
aoqi@0 | 2865 | // Add a reference to the loader (actually mirror because anonymous classes will not have |
aoqi@0 | 2866 | // distinct loaders) to ensure the metadata is kept alive |
aoqi@0 | 2867 | // This mirror may be different than the one in clazz field. |
aoqi@0 | 2868 | mname->obj_field_put(_vmloader_offset, dependency); |
aoqi@0 | 2869 | } |
aoqi@0 | 2870 | |
aoqi@0 | 2871 | intptr_t java_lang_invoke_MemberName::vmindex(oop mname) { |
aoqi@0 | 2872 | assert(is_instance(mname), "wrong type"); |
aoqi@0 | 2873 | return (intptr_t) mname->address_field(_vmindex_offset); |
aoqi@0 | 2874 | } |
aoqi@0 | 2875 | |
aoqi@0 | 2876 | void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) { |
aoqi@0 | 2877 | assert(is_instance(mname), "wrong type"); |
aoqi@0 | 2878 | mname->address_field_put(_vmindex_offset, (address) index); |
aoqi@0 | 2879 | } |
aoqi@0 | 2880 | |
kevinw@8721 | 2881 | bool java_lang_invoke_MemberName::equals(oop mn1, oop mn2) { |
kevinw@8721 | 2882 | if (mn1 == mn2) { |
kevinw@8721 | 2883 | return true; |
kevinw@8721 | 2884 | } |
kevinw@8721 | 2885 | return (vmtarget(mn1) == vmtarget(mn2) && flags(mn1) == flags(mn2) && |
kevinw@8721 | 2886 | vmindex(mn1) == vmindex(mn2) && |
kevinw@8721 | 2887 | clazz(mn1) == clazz(mn2)); |
kevinw@8721 | 2888 | } |
kevinw@8721 | 2889 | |
aoqi@0 | 2890 | oop java_lang_invoke_LambdaForm::vmentry(oop lform) { |
aoqi@0 | 2891 | assert(is_instance(lform), "wrong type"); |
aoqi@0 | 2892 | return lform->obj_field(_vmentry_offset); |
aoqi@0 | 2893 | } |
aoqi@0 | 2894 | |
aoqi@0 | 2895 | |
aoqi@0 | 2896 | // Support for java_lang_invoke_MethodType |
aoqi@0 | 2897 | |
aoqi@0 | 2898 | int java_lang_invoke_MethodType::_rtype_offset; |
aoqi@0 | 2899 | int java_lang_invoke_MethodType::_ptypes_offset; |
aoqi@0 | 2900 | |
aoqi@0 | 2901 | void java_lang_invoke_MethodType::compute_offsets() { |
aoqi@0 | 2902 | Klass* k = SystemDictionary::MethodType_klass(); |
aoqi@0 | 2903 | if (k != NULL) { |
aoqi@0 | 2904 | compute_offset(_rtype_offset, k, vmSymbols::rtype_name(), vmSymbols::class_signature()); |
aoqi@0 | 2905 | compute_offset(_ptypes_offset, k, vmSymbols::ptypes_name(), vmSymbols::class_array_signature()); |
aoqi@0 | 2906 | } |
aoqi@0 | 2907 | } |
aoqi@0 | 2908 | |
aoqi@0 | 2909 | void java_lang_invoke_MethodType::print_signature(oop mt, outputStream* st) { |
aoqi@0 | 2910 | st->print("("); |
aoqi@0 | 2911 | objArrayOop pts = ptypes(mt); |
aoqi@0 | 2912 | for (int i = 0, limit = pts->length(); i < limit; i++) { |
aoqi@0 | 2913 | java_lang_Class::print_signature(pts->obj_at(i), st); |
aoqi@0 | 2914 | } |
aoqi@0 | 2915 | st->print(")"); |
aoqi@0 | 2916 | java_lang_Class::print_signature(rtype(mt), st); |
aoqi@0 | 2917 | } |
aoqi@0 | 2918 | |
aoqi@0 | 2919 | Symbol* java_lang_invoke_MethodType::as_signature(oop mt, bool intern_if_not_found, TRAPS) { |
aoqi@0 | 2920 | ResourceMark rm; |
aoqi@0 | 2921 | stringStream buffer(128); |
aoqi@0 | 2922 | print_signature(mt, &buffer); |
aoqi@0 | 2923 | const char* sigstr = buffer.base(); |
aoqi@0 | 2924 | int siglen = (int) buffer.size(); |
aoqi@0 | 2925 | Symbol *name; |
aoqi@0 | 2926 | if (!intern_if_not_found) { |
aoqi@0 | 2927 | name = SymbolTable::probe(sigstr, siglen); |
aoqi@0 | 2928 | } else { |
aoqi@0 | 2929 | name = SymbolTable::new_symbol(sigstr, siglen, THREAD); |
aoqi@0 | 2930 | } |
aoqi@0 | 2931 | return name; |
aoqi@0 | 2932 | } |
aoqi@0 | 2933 | |
aoqi@0 | 2934 | bool java_lang_invoke_MethodType::equals(oop mt1, oop mt2) { |
aoqi@0 | 2935 | if (mt1 == mt2) |
aoqi@0 | 2936 | return true; |
aoqi@0 | 2937 | if (rtype(mt1) != rtype(mt2)) |
aoqi@0 | 2938 | return false; |
aoqi@0 | 2939 | if (ptype_count(mt1) != ptype_count(mt2)) |
aoqi@0 | 2940 | return false; |
aoqi@0 | 2941 | for (int i = ptype_count(mt1) - 1; i >= 0; i--) { |
aoqi@0 | 2942 | if (ptype(mt1, i) != ptype(mt2, i)) |
aoqi@0 | 2943 | return false; |
aoqi@0 | 2944 | } |
aoqi@0 | 2945 | return true; |
aoqi@0 | 2946 | } |
aoqi@0 | 2947 | |
aoqi@0 | 2948 | oop java_lang_invoke_MethodType::rtype(oop mt) { |
aoqi@0 | 2949 | assert(is_instance(mt), "must be a MethodType"); |
aoqi@0 | 2950 | return mt->obj_field(_rtype_offset); |
aoqi@0 | 2951 | } |
aoqi@0 | 2952 | |
aoqi@0 | 2953 | objArrayOop java_lang_invoke_MethodType::ptypes(oop mt) { |
aoqi@0 | 2954 | assert(is_instance(mt), "must be a MethodType"); |
aoqi@0 | 2955 | return (objArrayOop) mt->obj_field(_ptypes_offset); |
aoqi@0 | 2956 | } |
aoqi@0 | 2957 | |
aoqi@0 | 2958 | oop java_lang_invoke_MethodType::ptype(oop mt, int idx) { |
aoqi@0 | 2959 | return ptypes(mt)->obj_at(idx); |
aoqi@0 | 2960 | } |
aoqi@0 | 2961 | |
aoqi@0 | 2962 | int java_lang_invoke_MethodType::ptype_count(oop mt) { |
aoqi@0 | 2963 | return ptypes(mt)->length(); |
aoqi@0 | 2964 | } |
aoqi@0 | 2965 | |
aoqi@0 | 2966 | int java_lang_invoke_MethodType::ptype_slot_count(oop mt) { |
aoqi@0 | 2967 | objArrayOop pts = ptypes(mt); |
aoqi@0 | 2968 | int count = pts->length(); |
aoqi@0 | 2969 | int slots = 0; |
aoqi@0 | 2970 | for (int i = 0; i < count; i++) { |
aoqi@0 | 2971 | BasicType bt = java_lang_Class::as_BasicType(pts->obj_at(i)); |
aoqi@0 | 2972 | slots += type2size[bt]; |
aoqi@0 | 2973 | } |
aoqi@0 | 2974 | return slots; |
aoqi@0 | 2975 | } |
aoqi@0 | 2976 | |
aoqi@0 | 2977 | int java_lang_invoke_MethodType::rtype_slot_count(oop mt) { |
aoqi@0 | 2978 | BasicType bt = java_lang_Class::as_BasicType(rtype(mt)); |
aoqi@0 | 2979 | return type2size[bt]; |
aoqi@0 | 2980 | } |
aoqi@0 | 2981 | |
aoqi@0 | 2982 | |
aoqi@0 | 2983 | // Support for java_lang_invoke_CallSite |
aoqi@0 | 2984 | |
aoqi@0 | 2985 | int java_lang_invoke_CallSite::_target_offset; |
aoqi@0 | 2986 | |
aoqi@0 | 2987 | void java_lang_invoke_CallSite::compute_offsets() { |
aoqi@0 | 2988 | if (!EnableInvokeDynamic) return; |
aoqi@0 | 2989 | Klass* k = SystemDictionary::CallSite_klass(); |
aoqi@0 | 2990 | if (k != NULL) { |
aoqi@0 | 2991 | compute_offset(_target_offset, k, vmSymbols::target_name(), vmSymbols::java_lang_invoke_MethodHandle_signature()); |
aoqi@0 | 2992 | } |
aoqi@0 | 2993 | } |
aoqi@0 | 2994 | |
aoqi@0 | 2995 | |
aoqi@0 | 2996 | // Support for java_security_AccessControlContext |
aoqi@0 | 2997 | |
aoqi@0 | 2998 | int java_security_AccessControlContext::_context_offset = 0; |
aoqi@0 | 2999 | int java_security_AccessControlContext::_privilegedContext_offset = 0; |
aoqi@0 | 3000 | int java_security_AccessControlContext::_isPrivileged_offset = 0; |
aoqi@0 | 3001 | int java_security_AccessControlContext::_isAuthorized_offset = -1; |
aoqi@0 | 3002 | |
aoqi@0 | 3003 | void java_security_AccessControlContext::compute_offsets() { |
aoqi@0 | 3004 | assert(_isPrivileged_offset == 0, "offsets should be initialized only once"); |
aoqi@0 | 3005 | fieldDescriptor fd; |
aoqi@0 | 3006 | InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::AccessControlContext_klass()); |
aoqi@0 | 3007 | |
aoqi@0 | 3008 | if (!ik->find_local_field(vmSymbols::context_name(), vmSymbols::protectiondomain_signature(), &fd)) { |
aoqi@0 | 3009 | fatal("Invalid layout of java.security.AccessControlContext"); |
aoqi@0 | 3010 | } |
aoqi@0 | 3011 | _context_offset = fd.offset(); |
aoqi@0 | 3012 | |
aoqi@0 | 3013 | if (!ik->find_local_field(vmSymbols::privilegedContext_name(), vmSymbols::accesscontrolcontext_signature(), &fd)) { |
aoqi@0 | 3014 | fatal("Invalid layout of java.security.AccessControlContext"); |
aoqi@0 | 3015 | } |
aoqi@0 | 3016 | _privilegedContext_offset = fd.offset(); |
aoqi@0 | 3017 | |
aoqi@0 | 3018 | if (!ik->find_local_field(vmSymbols::isPrivileged_name(), vmSymbols::bool_signature(), &fd)) { |
aoqi@0 | 3019 | fatal("Invalid layout of java.security.AccessControlContext"); |
aoqi@0 | 3020 | } |
aoqi@0 | 3021 | _isPrivileged_offset = fd.offset(); |
aoqi@0 | 3022 | |
aoqi@0 | 3023 | // The offset may not be present for bootstrapping with older JDK. |
aoqi@0 | 3024 | if (ik->find_local_field(vmSymbols::isAuthorized_name(), vmSymbols::bool_signature(), &fd)) { |
aoqi@0 | 3025 | _isAuthorized_offset = fd.offset(); |
aoqi@0 | 3026 | } |
aoqi@0 | 3027 | } |
aoqi@0 | 3028 | |
aoqi@0 | 3029 | |
aoqi@0 | 3030 | bool java_security_AccessControlContext::is_authorized(Handle context) { |
aoqi@0 | 3031 | assert(context.not_null() && context->klass() == SystemDictionary::AccessControlContext_klass(), "Invalid type"); |
aoqi@0 | 3032 | assert(_isAuthorized_offset != -1, "should be set"); |
aoqi@0 | 3033 | return context->bool_field(_isAuthorized_offset) != 0; |
aoqi@0 | 3034 | } |
aoqi@0 | 3035 | |
aoqi@0 | 3036 | oop java_security_AccessControlContext::create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS) { |
aoqi@0 | 3037 | assert(_isPrivileged_offset != 0, "offsets should have been initialized"); |
aoqi@0 | 3038 | // Ensure klass is initialized |
aoqi@0 | 3039 | InstanceKlass::cast(SystemDictionary::AccessControlContext_klass())->initialize(CHECK_0); |
aoqi@0 | 3040 | // Allocate result |
aoqi@0 | 3041 | oop result = InstanceKlass::cast(SystemDictionary::AccessControlContext_klass())->allocate_instance(CHECK_0); |
aoqi@0 | 3042 | // Fill in values |
aoqi@0 | 3043 | result->obj_field_put(_context_offset, context()); |
aoqi@0 | 3044 | result->obj_field_put(_privilegedContext_offset, privileged_context()); |
aoqi@0 | 3045 | result->bool_field_put(_isPrivileged_offset, isPrivileged); |
aoqi@0 | 3046 | // whitelist AccessControlContexts created by the JVM if present |
aoqi@0 | 3047 | if (_isAuthorized_offset != -1) { |
aoqi@0 | 3048 | result->bool_field_put(_isAuthorized_offset, true); |
aoqi@0 | 3049 | } |
aoqi@0 | 3050 | return result; |
aoqi@0 | 3051 | } |
aoqi@0 | 3052 | |
aoqi@0 | 3053 | |
aoqi@0 | 3054 | // Support for java_lang_ClassLoader |
aoqi@0 | 3055 | |
aoqi@0 | 3056 | bool java_lang_ClassLoader::offsets_computed = false; |
aoqi@0 | 3057 | int java_lang_ClassLoader::_loader_data_offset = -1; |
aoqi@0 | 3058 | int java_lang_ClassLoader::parallelCapable_offset = -1; |
aoqi@0 | 3059 | |
aoqi@0 | 3060 | ClassLoaderData** java_lang_ClassLoader::loader_data_addr(oop loader) { |
aoqi@0 | 3061 | assert(loader != NULL && loader->is_oop(), "loader must be oop"); |
aoqi@0 | 3062 | return (ClassLoaderData**) loader->address_field_addr(_loader_data_offset); |
aoqi@0 | 3063 | } |
aoqi@0 | 3064 | |
aoqi@0 | 3065 | ClassLoaderData* java_lang_ClassLoader::loader_data(oop loader) { |
aoqi@0 | 3066 | return *java_lang_ClassLoader::loader_data_addr(loader); |
aoqi@0 | 3067 | } |
aoqi@0 | 3068 | |
aoqi@0 | 3069 | void java_lang_ClassLoader::compute_offsets() { |
aoqi@0 | 3070 | assert(!offsets_computed, "offsets should be initialized only once"); |
aoqi@0 | 3071 | offsets_computed = true; |
aoqi@0 | 3072 | |
aoqi@0 | 3073 | // The field indicating parallelCapable (parallelLockMap) is only present starting in 7, |
aoqi@0 | 3074 | Klass* k1 = SystemDictionary::ClassLoader_klass(); |
aoqi@0 | 3075 | compute_optional_offset(parallelCapable_offset, |
aoqi@0 | 3076 | k1, vmSymbols::parallelCapable_name(), vmSymbols::concurrenthashmap_signature()); |
aoqi@0 | 3077 | |
aoqi@0 | 3078 | CLASSLOADER_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET); |
aoqi@0 | 3079 | } |
aoqi@0 | 3080 | |
aoqi@0 | 3081 | oop java_lang_ClassLoader::parent(oop loader) { |
aoqi@0 | 3082 | assert(is_instance(loader), "loader must be oop"); |
aoqi@0 | 3083 | return loader->obj_field(parent_offset); |
aoqi@0 | 3084 | } |
aoqi@0 | 3085 | |
aoqi@0 | 3086 | bool java_lang_ClassLoader::isAncestor(oop loader, oop cl) { |
aoqi@0 | 3087 | assert(is_instance(loader), "loader must be oop"); |
aoqi@0 | 3088 | assert(cl == NULL || is_instance(cl), "cl argument must be oop"); |
aoqi@0 | 3089 | oop acl = loader; |
aoqi@0 | 3090 | debug_only(jint loop_count = 0); |
aoqi@0 | 3091 | // This loop taken verbatim from ClassLoader.java: |
aoqi@0 | 3092 | do { |
aoqi@0 | 3093 | acl = parent(acl); |
aoqi@0 | 3094 | if (cl == acl) { |
aoqi@0 | 3095 | return true; |
aoqi@0 | 3096 | } |
aoqi@0 | 3097 | assert(++loop_count > 0, "loop_count overflow"); |
aoqi@0 | 3098 | } while (acl != NULL); |
aoqi@0 | 3099 | return false; |
aoqi@0 | 3100 | } |
aoqi@0 | 3101 | |
aoqi@0 | 3102 | |
aoqi@0 | 3103 | // For class loader classes, parallelCapable defined |
aoqi@0 | 3104 | // based on non-null field |
aoqi@0 | 3105 | // Written to by java.lang.ClassLoader, vm only reads this field, doesn't set it |
aoqi@0 | 3106 | bool java_lang_ClassLoader::parallelCapable(oop class_loader) { |
aoqi@0 | 3107 | if (!JDK_Version::is_gte_jdk17x_version() |
aoqi@0 | 3108 | || parallelCapable_offset == -1) { |
aoqi@0 | 3109 | // Default for backward compatibility is false |
aoqi@0 | 3110 | return false; |
aoqi@0 | 3111 | } |
aoqi@0 | 3112 | return (class_loader->obj_field(parallelCapable_offset) != NULL); |
aoqi@0 | 3113 | } |
aoqi@0 | 3114 | |
aoqi@0 | 3115 | bool java_lang_ClassLoader::is_trusted_loader(oop loader) { |
aoqi@0 | 3116 | // Fix for 4474172; see evaluation for more details |
aoqi@0 | 3117 | loader = non_reflection_class_loader(loader); |
aoqi@0 | 3118 | |
aoqi@0 | 3119 | oop cl = SystemDictionary::java_system_loader(); |
aoqi@0 | 3120 | while(cl != NULL) { |
aoqi@0 | 3121 | if (cl == loader) return true; |
aoqi@0 | 3122 | cl = parent(cl); |
aoqi@0 | 3123 | } |
aoqi@0 | 3124 | return false; |
aoqi@0 | 3125 | } |
aoqi@0 | 3126 | |
aoqi@0 | 3127 | oop java_lang_ClassLoader::non_reflection_class_loader(oop loader) { |
aoqi@0 | 3128 | if (loader != NULL) { |
aoqi@0 | 3129 | // See whether this is one of the class loaders associated with |
aoqi@0 | 3130 | // the generated bytecodes for reflection, and if so, "magically" |
aoqi@0 | 3131 | // delegate to its parent to prevent class loading from occurring |
aoqi@0 | 3132 | // in places where applications using reflection didn't expect it. |
aoqi@0 | 3133 | Klass* delegating_cl_class = SystemDictionary::reflect_DelegatingClassLoader_klass(); |
aoqi@0 | 3134 | // This might be null in non-1.4 JDKs |
aoqi@0 | 3135 | if (delegating_cl_class != NULL && loader->is_a(delegating_cl_class)) { |
aoqi@0 | 3136 | return parent(loader); |
aoqi@0 | 3137 | } |
aoqi@0 | 3138 | } |
aoqi@0 | 3139 | return loader; |
aoqi@0 | 3140 | } |
aoqi@0 | 3141 | |
aoqi@0 | 3142 | |
aoqi@0 | 3143 | // Support for java_lang_System |
aoqi@0 | 3144 | int java_lang_System::in_offset_in_bytes() { |
aoqi@0 | 3145 | return (InstanceMirrorKlass::offset_of_static_fields() + static_in_offset); |
aoqi@0 | 3146 | } |
aoqi@0 | 3147 | |
aoqi@0 | 3148 | |
aoqi@0 | 3149 | int java_lang_System::out_offset_in_bytes() { |
aoqi@0 | 3150 | return (InstanceMirrorKlass::offset_of_static_fields() + static_out_offset); |
aoqi@0 | 3151 | } |
aoqi@0 | 3152 | |
aoqi@0 | 3153 | |
aoqi@0 | 3154 | int java_lang_System::err_offset_in_bytes() { |
aoqi@0 | 3155 | return (InstanceMirrorKlass::offset_of_static_fields() + static_err_offset); |
aoqi@0 | 3156 | } |
aoqi@0 | 3157 | |
aoqi@0 | 3158 | |
aoqi@0 | 3159 | bool java_lang_System::has_security_manager() { |
aoqi@0 | 3160 | InstanceKlass* ik = InstanceKlass::cast(SystemDictionary::System_klass()); |
aoqi@0 | 3161 | address addr = ik->static_field_addr(static_security_offset); |
aoqi@0 | 3162 | if (UseCompressedOops) { |
aoqi@0 | 3163 | return oopDesc::load_decode_heap_oop((narrowOop *)addr) != NULL; |
aoqi@0 | 3164 | } else { |
aoqi@0 | 3165 | return oopDesc::load_decode_heap_oop((oop*)addr) != NULL; |
aoqi@0 | 3166 | } |
aoqi@0 | 3167 | } |
aoqi@0 | 3168 | |
aoqi@0 | 3169 | int java_lang_Class::_klass_offset; |
aoqi@0 | 3170 | int java_lang_Class::_array_klass_offset; |
aoqi@0 | 3171 | int java_lang_Class::_oop_size_offset; |
aoqi@0 | 3172 | int java_lang_Class::_static_oop_field_count_offset; |
coleenp@7129 | 3173 | int java_lang_Class::_class_loader_offset; |
aoqi@0 | 3174 | int java_lang_Class::_protection_domain_offset; |
aoqi@0 | 3175 | int java_lang_Class::_init_lock_offset; |
aoqi@0 | 3176 | int java_lang_Class::_signers_offset; |
aoqi@0 | 3177 | GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL; |
aoqi@0 | 3178 | int java_lang_Throwable::backtrace_offset; |
aoqi@0 | 3179 | int java_lang_Throwable::detailMessage_offset; |
aoqi@0 | 3180 | int java_lang_Throwable::cause_offset; |
aoqi@0 | 3181 | int java_lang_Throwable::stackTrace_offset; |
aoqi@0 | 3182 | int java_lang_Throwable::static_unassigned_stacktrace_offset; |
aoqi@0 | 3183 | int java_lang_reflect_AccessibleObject::override_offset; |
aoqi@0 | 3184 | int java_lang_reflect_Method::clazz_offset; |
aoqi@0 | 3185 | int java_lang_reflect_Method::name_offset; |
aoqi@0 | 3186 | int java_lang_reflect_Method::returnType_offset; |
aoqi@0 | 3187 | int java_lang_reflect_Method::parameterTypes_offset; |
aoqi@0 | 3188 | int java_lang_reflect_Method::exceptionTypes_offset; |
aoqi@0 | 3189 | int java_lang_reflect_Method::slot_offset; |
aoqi@0 | 3190 | int java_lang_reflect_Method::modifiers_offset; |
aoqi@0 | 3191 | int java_lang_reflect_Method::signature_offset; |
aoqi@0 | 3192 | int java_lang_reflect_Method::annotations_offset; |
aoqi@0 | 3193 | int java_lang_reflect_Method::parameter_annotations_offset; |
aoqi@0 | 3194 | int java_lang_reflect_Method::annotation_default_offset; |
aoqi@0 | 3195 | int java_lang_reflect_Method::type_annotations_offset; |
aoqi@0 | 3196 | int java_lang_reflect_Constructor::clazz_offset; |
aoqi@0 | 3197 | int java_lang_reflect_Constructor::parameterTypes_offset; |
aoqi@0 | 3198 | int java_lang_reflect_Constructor::exceptionTypes_offset; |
aoqi@0 | 3199 | int java_lang_reflect_Constructor::slot_offset; |
aoqi@0 | 3200 | int java_lang_reflect_Constructor::modifiers_offset; |
aoqi@0 | 3201 | int java_lang_reflect_Constructor::signature_offset; |
aoqi@0 | 3202 | int java_lang_reflect_Constructor::annotations_offset; |
aoqi@0 | 3203 | int java_lang_reflect_Constructor::parameter_annotations_offset; |
aoqi@0 | 3204 | int java_lang_reflect_Constructor::type_annotations_offset; |
aoqi@0 | 3205 | int java_lang_reflect_Field::clazz_offset; |
aoqi@0 | 3206 | int java_lang_reflect_Field::name_offset; |
aoqi@0 | 3207 | int java_lang_reflect_Field::type_offset; |
aoqi@0 | 3208 | int java_lang_reflect_Field::slot_offset; |
aoqi@0 | 3209 | int java_lang_reflect_Field::modifiers_offset; |
aoqi@0 | 3210 | int java_lang_reflect_Field::signature_offset; |
aoqi@0 | 3211 | int java_lang_reflect_Field::annotations_offset; |
aoqi@0 | 3212 | int java_lang_reflect_Field::type_annotations_offset; |
aoqi@0 | 3213 | int java_lang_reflect_Parameter::name_offset; |
aoqi@0 | 3214 | int java_lang_reflect_Parameter::modifiers_offset; |
aoqi@0 | 3215 | int java_lang_reflect_Parameter::index_offset; |
aoqi@0 | 3216 | int java_lang_reflect_Parameter::executable_offset; |
aoqi@0 | 3217 | int java_lang_boxing_object::value_offset; |
aoqi@0 | 3218 | int java_lang_boxing_object::long_value_offset; |
aoqi@0 | 3219 | int java_lang_ref_Reference::referent_offset; |
aoqi@0 | 3220 | int java_lang_ref_Reference::queue_offset; |
aoqi@0 | 3221 | int java_lang_ref_Reference::next_offset; |
aoqi@0 | 3222 | int java_lang_ref_Reference::discovered_offset; |
aoqi@0 | 3223 | int java_lang_ref_Reference::static_lock_offset; |
aoqi@0 | 3224 | int java_lang_ref_Reference::static_pending_offset; |
aoqi@0 | 3225 | int java_lang_ref_Reference::number_of_fake_oop_fields; |
kbarrett@9099 | 3226 | int java_lang_ref_ReferenceQueue::static_NULL_queue_offset; |
kbarrett@9099 | 3227 | int java_lang_ref_ReferenceQueue::static_ENQUEUED_queue_offset; |
aoqi@0 | 3228 | int java_lang_ref_SoftReference::timestamp_offset; |
aoqi@0 | 3229 | int java_lang_ref_SoftReference::static_clock_offset; |
aoqi@0 | 3230 | int java_lang_ClassLoader::parent_offset; |
aoqi@0 | 3231 | int java_lang_System::static_in_offset; |
aoqi@0 | 3232 | int java_lang_System::static_out_offset; |
aoqi@0 | 3233 | int java_lang_System::static_err_offset; |
aoqi@0 | 3234 | int java_lang_System::static_security_offset; |
aoqi@0 | 3235 | int java_lang_StackTraceElement::declaringClass_offset; |
aoqi@0 | 3236 | int java_lang_StackTraceElement::methodName_offset; |
aoqi@0 | 3237 | int java_lang_StackTraceElement::fileName_offset; |
aoqi@0 | 3238 | int java_lang_StackTraceElement::lineNumber_offset; |
aoqi@0 | 3239 | int java_lang_AssertionStatusDirectives::classes_offset; |
aoqi@0 | 3240 | int java_lang_AssertionStatusDirectives::classEnabled_offset; |
aoqi@0 | 3241 | int java_lang_AssertionStatusDirectives::packages_offset; |
aoqi@0 | 3242 | int java_lang_AssertionStatusDirectives::packageEnabled_offset; |
aoqi@0 | 3243 | int java_lang_AssertionStatusDirectives::deflt_offset; |
aoqi@0 | 3244 | int java_nio_Buffer::_limit_offset; |
aoqi@0 | 3245 | int java_util_concurrent_locks_AbstractOwnableSynchronizer::_owner_offset = 0; |
aoqi@0 | 3246 | int sun_reflect_ConstantPool::_oop_offset; |
aoqi@0 | 3247 | int sun_reflect_UnsafeStaticFieldAccessorImpl::_base_offset; |
aoqi@0 | 3248 | |
aoqi@0 | 3249 | |
aoqi@0 | 3250 | // Support for java_lang_StackTraceElement |
aoqi@0 | 3251 | |
aoqi@0 | 3252 | void java_lang_StackTraceElement::set_fileName(oop element, oop value) { |
aoqi@0 | 3253 | element->obj_field_put(fileName_offset, value); |
aoqi@0 | 3254 | } |
aoqi@0 | 3255 | |
aoqi@0 | 3256 | void java_lang_StackTraceElement::set_declaringClass(oop element, oop value) { |
aoqi@0 | 3257 | element->obj_field_put(declaringClass_offset, value); |
aoqi@0 | 3258 | } |
aoqi@0 | 3259 | |
aoqi@0 | 3260 | void java_lang_StackTraceElement::set_methodName(oop element, oop value) { |
aoqi@0 | 3261 | element->obj_field_put(methodName_offset, value); |
aoqi@0 | 3262 | } |
aoqi@0 | 3263 | |
aoqi@0 | 3264 | void java_lang_StackTraceElement::set_lineNumber(oop element, int value) { |
aoqi@0 | 3265 | element->int_field_put(lineNumber_offset, value); |
aoqi@0 | 3266 | } |
aoqi@0 | 3267 | |
aoqi@0 | 3268 | |
aoqi@0 | 3269 | // Support for java Assertions - java_lang_AssertionStatusDirectives. |
aoqi@0 | 3270 | |
aoqi@0 | 3271 | void java_lang_AssertionStatusDirectives::set_classes(oop o, oop val) { |
aoqi@0 | 3272 | o->obj_field_put(classes_offset, val); |
aoqi@0 | 3273 | } |
aoqi@0 | 3274 | |
aoqi@0 | 3275 | void java_lang_AssertionStatusDirectives::set_classEnabled(oop o, oop val) { |
aoqi@0 | 3276 | o->obj_field_put(classEnabled_offset, val); |
aoqi@0 | 3277 | } |
aoqi@0 | 3278 | |
aoqi@0 | 3279 | void java_lang_AssertionStatusDirectives::set_packages(oop o, oop val) { |
aoqi@0 | 3280 | o->obj_field_put(packages_offset, val); |
aoqi@0 | 3281 | } |
aoqi@0 | 3282 | |
aoqi@0 | 3283 | void java_lang_AssertionStatusDirectives::set_packageEnabled(oop o, oop val) { |
aoqi@0 | 3284 | o->obj_field_put(packageEnabled_offset, val); |
aoqi@0 | 3285 | } |
aoqi@0 | 3286 | |
aoqi@0 | 3287 | void java_lang_AssertionStatusDirectives::set_deflt(oop o, bool val) { |
aoqi@0 | 3288 | o->bool_field_put(deflt_offset, val); |
aoqi@0 | 3289 | } |
aoqi@0 | 3290 | |
aoqi@0 | 3291 | |
aoqi@0 | 3292 | // Support for intrinsification of java.nio.Buffer.checkIndex |
aoqi@0 | 3293 | int java_nio_Buffer::limit_offset() { |
aoqi@0 | 3294 | return _limit_offset; |
aoqi@0 | 3295 | } |
aoqi@0 | 3296 | |
aoqi@0 | 3297 | |
aoqi@0 | 3298 | void java_nio_Buffer::compute_offsets() { |
aoqi@0 | 3299 | Klass* k = SystemDictionary::nio_Buffer_klass(); |
aoqi@0 | 3300 | assert(k != NULL, "must be loaded in 1.4+"); |
aoqi@0 | 3301 | compute_offset(_limit_offset, k, vmSymbols::limit_name(), vmSymbols::int_signature()); |
aoqi@0 | 3302 | } |
aoqi@0 | 3303 | |
aoqi@0 | 3304 | void java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(TRAPS) { |
aoqi@0 | 3305 | if (_owner_offset != 0) return; |
aoqi@0 | 3306 | |
aoqi@0 | 3307 | assert(JDK_Version::is_gte_jdk16x_version(), "Must be JDK 1.6 or later"); |
aoqi@0 | 3308 | SystemDictionary::load_abstract_ownable_synchronizer_klass(CHECK); |
aoqi@0 | 3309 | Klass* k = SystemDictionary::abstract_ownable_synchronizer_klass(); |
aoqi@0 | 3310 | compute_offset(_owner_offset, k, |
aoqi@0 | 3311 | vmSymbols::exclusive_owner_thread_name(), vmSymbols::thread_signature()); |
aoqi@0 | 3312 | } |
aoqi@0 | 3313 | |
aoqi@0 | 3314 | oop java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(oop obj) { |
aoqi@0 | 3315 | assert(_owner_offset != 0, "Must be initialized"); |
aoqi@0 | 3316 | return obj->obj_field(_owner_offset); |
aoqi@0 | 3317 | } |
aoqi@0 | 3318 | |
aoqi@0 | 3319 | // Compute hard-coded offsets |
aoqi@0 | 3320 | // Invoked before SystemDictionary::initialize, so pre-loaded classes |
aoqi@0 | 3321 | // are not available to determine the offset_of_static_fields. |
aoqi@0 | 3322 | void JavaClasses::compute_hard_coded_offsets() { |
aoqi@0 | 3323 | const int x = heapOopSize; |
aoqi@0 | 3324 | const int header = instanceOopDesc::base_offset_in_bytes(); |
aoqi@0 | 3325 | |
aoqi@0 | 3326 | // Throwable Class |
aoqi@0 | 3327 | java_lang_Throwable::backtrace_offset = java_lang_Throwable::hc_backtrace_offset * x + header; |
aoqi@0 | 3328 | java_lang_Throwable::detailMessage_offset = java_lang_Throwable::hc_detailMessage_offset * x + header; |
aoqi@0 | 3329 | java_lang_Throwable::cause_offset = java_lang_Throwable::hc_cause_offset * x + header; |
aoqi@0 | 3330 | java_lang_Throwable::stackTrace_offset = java_lang_Throwable::hc_stackTrace_offset * x + header; |
aoqi@0 | 3331 | java_lang_Throwable::static_unassigned_stacktrace_offset = java_lang_Throwable::hc_static_unassigned_stacktrace_offset * x; |
aoqi@0 | 3332 | |
aoqi@0 | 3333 | // java_lang_boxing_object |
aoqi@0 | 3334 | java_lang_boxing_object::value_offset = java_lang_boxing_object::hc_value_offset + header; |
aoqi@0 | 3335 | java_lang_boxing_object::long_value_offset = align_size_up((java_lang_boxing_object::hc_value_offset + header), BytesPerLong); |
aoqi@0 | 3336 | |
aoqi@0 | 3337 | // java_lang_ref_Reference: |
aoqi@0 | 3338 | java_lang_ref_Reference::referent_offset = java_lang_ref_Reference::hc_referent_offset * x + header; |
aoqi@0 | 3339 | java_lang_ref_Reference::queue_offset = java_lang_ref_Reference::hc_queue_offset * x + header; |
aoqi@0 | 3340 | java_lang_ref_Reference::next_offset = java_lang_ref_Reference::hc_next_offset * x + header; |
aoqi@0 | 3341 | java_lang_ref_Reference::discovered_offset = java_lang_ref_Reference::hc_discovered_offset * x + header; |
aoqi@0 | 3342 | java_lang_ref_Reference::static_lock_offset = java_lang_ref_Reference::hc_static_lock_offset * x; |
aoqi@0 | 3343 | java_lang_ref_Reference::static_pending_offset = java_lang_ref_Reference::hc_static_pending_offset * x; |
aoqi@0 | 3344 | // Artificial fields for java_lang_ref_Reference |
aoqi@0 | 3345 | // The first field is for the discovered field added in 1.4 |
aoqi@0 | 3346 | java_lang_ref_Reference::number_of_fake_oop_fields = 1; |
aoqi@0 | 3347 | |
aoqi@0 | 3348 | // java_lang_ref_SoftReference Class |
aoqi@0 | 3349 | java_lang_ref_SoftReference::timestamp_offset = align_size_up((java_lang_ref_SoftReference::hc_timestamp_offset * x + header), BytesPerLong); |
aoqi@0 | 3350 | // Don't multiply static fields because they are always in wordSize units |
aoqi@0 | 3351 | java_lang_ref_SoftReference::static_clock_offset = java_lang_ref_SoftReference::hc_static_clock_offset * x; |
aoqi@0 | 3352 | |
aoqi@0 | 3353 | // java_lang_ClassLoader |
aoqi@0 | 3354 | java_lang_ClassLoader::parent_offset = java_lang_ClassLoader::hc_parent_offset * x + header; |
aoqi@0 | 3355 | |
aoqi@0 | 3356 | // java_lang_System |
aoqi@0 | 3357 | java_lang_System::static_in_offset = java_lang_System::hc_static_in_offset * x; |
aoqi@0 | 3358 | java_lang_System::static_out_offset = java_lang_System::hc_static_out_offset * x; |
aoqi@0 | 3359 | java_lang_System::static_err_offset = java_lang_System::hc_static_err_offset * x; |
aoqi@0 | 3360 | java_lang_System::static_security_offset = java_lang_System::hc_static_security_offset * x; |
aoqi@0 | 3361 | |
aoqi@0 | 3362 | // java_lang_StackTraceElement |
aoqi@0 | 3363 | java_lang_StackTraceElement::declaringClass_offset = java_lang_StackTraceElement::hc_declaringClass_offset * x + header; |
aoqi@0 | 3364 | java_lang_StackTraceElement::methodName_offset = java_lang_StackTraceElement::hc_methodName_offset * x + header; |
aoqi@0 | 3365 | java_lang_StackTraceElement::fileName_offset = java_lang_StackTraceElement::hc_fileName_offset * x + header; |
aoqi@0 | 3366 | java_lang_StackTraceElement::lineNumber_offset = java_lang_StackTraceElement::hc_lineNumber_offset * x + header; |
aoqi@0 | 3367 | java_lang_AssertionStatusDirectives::classes_offset = java_lang_AssertionStatusDirectives::hc_classes_offset * x + header; |
aoqi@0 | 3368 | java_lang_AssertionStatusDirectives::classEnabled_offset = java_lang_AssertionStatusDirectives::hc_classEnabled_offset * x + header; |
aoqi@0 | 3369 | java_lang_AssertionStatusDirectives::packages_offset = java_lang_AssertionStatusDirectives::hc_packages_offset * x + header; |
aoqi@0 | 3370 | java_lang_AssertionStatusDirectives::packageEnabled_offset = java_lang_AssertionStatusDirectives::hc_packageEnabled_offset * x + header; |
aoqi@0 | 3371 | java_lang_AssertionStatusDirectives::deflt_offset = java_lang_AssertionStatusDirectives::hc_deflt_offset * x + header; |
aoqi@0 | 3372 | |
aoqi@0 | 3373 | } |
aoqi@0 | 3374 | |
aoqi@0 | 3375 | |
aoqi@0 | 3376 | // Compute non-hard-coded field offsets of all the classes in this file |
aoqi@0 | 3377 | void JavaClasses::compute_offsets() { |
aoqi@0 | 3378 | // java_lang_Class::compute_offsets was called earlier in bootstrap |
aoqi@0 | 3379 | java_lang_ClassLoader::compute_offsets(); |
aoqi@0 | 3380 | java_lang_Thread::compute_offsets(); |
aoqi@0 | 3381 | java_lang_ThreadGroup::compute_offsets(); |
aoqi@0 | 3382 | if (EnableInvokeDynamic) { |
aoqi@0 | 3383 | java_lang_invoke_MethodHandle::compute_offsets(); |
aoqi@0 | 3384 | java_lang_invoke_DirectMethodHandle::compute_offsets(); |
aoqi@0 | 3385 | java_lang_invoke_MemberName::compute_offsets(); |
aoqi@0 | 3386 | java_lang_invoke_LambdaForm::compute_offsets(); |
aoqi@0 | 3387 | java_lang_invoke_MethodType::compute_offsets(); |
aoqi@0 | 3388 | java_lang_invoke_CallSite::compute_offsets(); |
aoqi@0 | 3389 | } |
aoqi@0 | 3390 | java_security_AccessControlContext::compute_offsets(); |
aoqi@0 | 3391 | // Initialize reflection classes. The layouts of these classes |
aoqi@0 | 3392 | // changed with the new reflection implementation in JDK 1.4, and |
aoqi@0 | 3393 | // since the Universe doesn't know what JDK version it is until this |
aoqi@0 | 3394 | // point we defer computation of these offsets until now. |
aoqi@0 | 3395 | java_lang_reflect_AccessibleObject::compute_offsets(); |
aoqi@0 | 3396 | java_lang_reflect_Method::compute_offsets(); |
aoqi@0 | 3397 | java_lang_reflect_Constructor::compute_offsets(); |
aoqi@0 | 3398 | java_lang_reflect_Field::compute_offsets(); |
aoqi@0 | 3399 | if (JDK_Version::is_gte_jdk14x_version()) { |
aoqi@0 | 3400 | java_nio_Buffer::compute_offsets(); |
aoqi@0 | 3401 | } |
aoqi@0 | 3402 | if (JDK_Version::is_gte_jdk15x_version()) { |
aoqi@0 | 3403 | sun_reflect_ConstantPool::compute_offsets(); |
aoqi@0 | 3404 | sun_reflect_UnsafeStaticFieldAccessorImpl::compute_offsets(); |
aoqi@0 | 3405 | } |
aoqi@0 | 3406 | if (JDK_Version::is_jdk18x_version()) |
aoqi@0 | 3407 | java_lang_reflect_Parameter::compute_offsets(); |
aoqi@0 | 3408 | |
kbarrett@9099 | 3409 | java_lang_ref_ReferenceQueue::compute_offsets(); |
kbarrett@9099 | 3410 | |
aoqi@0 | 3411 | // generated interpreter code wants to know about the offsets we just computed: |
aoqi@0 | 3412 | AbstractAssembler::update_delayed_values(); |
aoqi@0 | 3413 | } |
aoqi@0 | 3414 | |
aoqi@0 | 3415 | #ifndef PRODUCT |
aoqi@0 | 3416 | |
aoqi@0 | 3417 | // These functions exist to assert the validity of hard-coded field offsets to guard |
aoqi@0 | 3418 | // against changes in the class files |
aoqi@0 | 3419 | |
aoqi@0 | 3420 | bool JavaClasses::check_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) { |
aoqi@0 | 3421 | EXCEPTION_MARK; |
aoqi@0 | 3422 | fieldDescriptor fd; |
aoqi@0 | 3423 | TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name, CATCH); |
aoqi@0 | 3424 | Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH); |
aoqi@0 | 3425 | instanceKlassHandle h_klass (THREAD, k); |
aoqi@0 | 3426 | TempNewSymbol f_name = SymbolTable::new_symbol(field_name, CATCH); |
aoqi@0 | 3427 | TempNewSymbol f_sig = SymbolTable::new_symbol(field_sig, CATCH); |
aoqi@0 | 3428 | if (!h_klass->find_local_field(f_name, f_sig, &fd)) { |
aoqi@0 | 3429 | tty->print_cr("Nonstatic field %s.%s not found", klass_name, field_name); |
aoqi@0 | 3430 | return false; |
aoqi@0 | 3431 | } |
aoqi@0 | 3432 | if (fd.is_static()) { |
aoqi@0 | 3433 | tty->print_cr("Nonstatic field %s.%s appears to be static", klass_name, field_name); |
aoqi@0 | 3434 | return false; |
aoqi@0 | 3435 | } |
aoqi@0 | 3436 | if (fd.offset() == hardcoded_offset ) { |
aoqi@0 | 3437 | return true; |
aoqi@0 | 3438 | } else { |
aoqi@0 | 3439 | tty->print_cr("Offset of nonstatic field %s.%s is hardcoded as %d but should really be %d.", |
aoqi@0 | 3440 | klass_name, field_name, hardcoded_offset, fd.offset()); |
aoqi@0 | 3441 | return false; |
aoqi@0 | 3442 | } |
aoqi@0 | 3443 | } |
aoqi@0 | 3444 | |
aoqi@0 | 3445 | |
aoqi@0 | 3446 | bool JavaClasses::check_static_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) { |
aoqi@0 | 3447 | EXCEPTION_MARK; |
aoqi@0 | 3448 | fieldDescriptor fd; |
aoqi@0 | 3449 | TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name, CATCH); |
aoqi@0 | 3450 | Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH); |
aoqi@0 | 3451 | instanceKlassHandle h_klass (THREAD, k); |
aoqi@0 | 3452 | TempNewSymbol f_name = SymbolTable::new_symbol(field_name, CATCH); |
aoqi@0 | 3453 | TempNewSymbol f_sig = SymbolTable::new_symbol(field_sig, CATCH); |
aoqi@0 | 3454 | if (!h_klass->find_local_field(f_name, f_sig, &fd)) { |
aoqi@0 | 3455 | tty->print_cr("Static field %s.%s not found", klass_name, field_name); |
aoqi@0 | 3456 | return false; |
aoqi@0 | 3457 | } |
aoqi@0 | 3458 | if (!fd.is_static()) { |
aoqi@0 | 3459 | tty->print_cr("Static field %s.%s appears to be nonstatic", klass_name, field_name); |
aoqi@0 | 3460 | return false; |
aoqi@0 | 3461 | } |
aoqi@0 | 3462 | if (fd.offset() == hardcoded_offset + InstanceMirrorKlass::offset_of_static_fields()) { |
aoqi@0 | 3463 | return true; |
aoqi@0 | 3464 | } else { |
aoqi@0 | 3465 | tty->print_cr("Offset of static field %s.%s is hardcoded as %d but should really be %d.", klass_name, field_name, hardcoded_offset, fd.offset() - InstanceMirrorKlass::offset_of_static_fields()); |
aoqi@0 | 3466 | return false; |
aoqi@0 | 3467 | } |
aoqi@0 | 3468 | } |
aoqi@0 | 3469 | |
aoqi@0 | 3470 | |
aoqi@0 | 3471 | bool JavaClasses::check_constant(const char *klass_name, int hardcoded_constant, const char *field_name, const char* field_sig) { |
aoqi@0 | 3472 | EXCEPTION_MARK; |
aoqi@0 | 3473 | fieldDescriptor fd; |
aoqi@0 | 3474 | TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name, CATCH); |
aoqi@0 | 3475 | Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH); |
aoqi@0 | 3476 | instanceKlassHandle h_klass (THREAD, k); |
aoqi@0 | 3477 | TempNewSymbol f_name = SymbolTable::new_symbol(field_name, CATCH); |
aoqi@0 | 3478 | TempNewSymbol f_sig = SymbolTable::new_symbol(field_sig, CATCH); |
aoqi@0 | 3479 | if (!h_klass->find_local_field(f_name, f_sig, &fd)) { |
aoqi@0 | 3480 | tty->print_cr("Static field %s.%s not found", klass_name, field_name); |
aoqi@0 | 3481 | return false; |
aoqi@0 | 3482 | } |
aoqi@0 | 3483 | if (!fd.is_static() || !fd.has_initial_value()) { |
aoqi@0 | 3484 | tty->print_cr("Static field %s.%s appears to be non-constant", klass_name, field_name); |
aoqi@0 | 3485 | return false; |
aoqi@0 | 3486 | } |
aoqi@0 | 3487 | if (!fd.initial_value_tag().is_int()) { |
aoqi@0 | 3488 | tty->print_cr("Static field %s.%s is not an int", klass_name, field_name); |
aoqi@0 | 3489 | return false; |
aoqi@0 | 3490 | } |
aoqi@0 | 3491 | jint field_value = fd.int_initial_value(); |
aoqi@0 | 3492 | if (field_value == hardcoded_constant) { |
aoqi@0 | 3493 | return true; |
aoqi@0 | 3494 | } else { |
aoqi@0 | 3495 | tty->print_cr("Constant value of static field %s.%s is hardcoded as %d but should really be %d.", klass_name, field_name, hardcoded_constant, field_value); |
aoqi@0 | 3496 | return false; |
aoqi@0 | 3497 | } |
aoqi@0 | 3498 | } |
aoqi@0 | 3499 | |
aoqi@0 | 3500 | |
aoqi@0 | 3501 | // Check the hard-coded field offsets of all the classes in this file |
aoqi@0 | 3502 | |
aoqi@0 | 3503 | void JavaClasses::check_offsets() { |
aoqi@0 | 3504 | bool valid = true; |
aoqi@0 | 3505 | HandleMark hm; |
aoqi@0 | 3506 | |
aoqi@0 | 3507 | #define CHECK_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \ |
aoqi@0 | 3508 | valid &= check_offset(klass_name, cpp_klass_name :: field_name ## _offset, #field_name, field_sig) |
aoqi@0 | 3509 | |
aoqi@0 | 3510 | #define CHECK_LONG_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \ |
aoqi@0 | 3511 | valid &= check_offset(klass_name, cpp_klass_name :: long_ ## field_name ## _offset, #field_name, field_sig) |
aoqi@0 | 3512 | |
aoqi@0 | 3513 | #define CHECK_STATIC_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \ |
aoqi@0 | 3514 | valid &= check_static_offset(klass_name, cpp_klass_name :: static_ ## field_name ## _offset, #field_name, field_sig) |
aoqi@0 | 3515 | |
aoqi@0 | 3516 | #define CHECK_CONSTANT(klass_name, cpp_klass_name, field_name, field_sig) \ |
aoqi@0 | 3517 | valid &= check_constant(klass_name, cpp_klass_name :: field_name, #field_name, field_sig) |
aoqi@0 | 3518 | |
aoqi@0 | 3519 | // java.lang.String |
aoqi@0 | 3520 | |
aoqi@0 | 3521 | CHECK_OFFSET("java/lang/String", java_lang_String, value, "[C"); |
aoqi@0 | 3522 | if (java_lang_String::has_offset_field()) { |
aoqi@0 | 3523 | CHECK_OFFSET("java/lang/String", java_lang_String, offset, "I"); |
aoqi@0 | 3524 | CHECK_OFFSET("java/lang/String", java_lang_String, count, "I"); |
aoqi@0 | 3525 | } |
aoqi@0 | 3526 | if (java_lang_String::has_hash_field()) { |
aoqi@0 | 3527 | CHECK_OFFSET("java/lang/String", java_lang_String, hash, "I"); |
aoqi@0 | 3528 | } |
aoqi@0 | 3529 | |
aoqi@0 | 3530 | // java.lang.Class |
aoqi@0 | 3531 | |
aoqi@0 | 3532 | // Fake fields |
aoqi@0 | 3533 | // CHECK_OFFSET("java/lang/Class", java_lang_Class, klass); // %%% this needs to be checked |
aoqi@0 | 3534 | // CHECK_OFFSET("java/lang/Class", java_lang_Class, array_klass); // %%% this needs to be checked |
aoqi@0 | 3535 | |
aoqi@0 | 3536 | // java.lang.Throwable |
aoqi@0 | 3537 | |
aoqi@0 | 3538 | CHECK_OFFSET("java/lang/Throwable", java_lang_Throwable, backtrace, "Ljava/lang/Object;"); |
aoqi@0 | 3539 | CHECK_OFFSET("java/lang/Throwable", java_lang_Throwable, detailMessage, "Ljava/lang/String;"); |
aoqi@0 | 3540 | CHECK_OFFSET("java/lang/Throwable", java_lang_Throwable, cause, "Ljava/lang/Throwable;"); |
aoqi@0 | 3541 | CHECK_OFFSET("java/lang/Throwable", java_lang_Throwable, stackTrace, "[Ljava/lang/StackTraceElement;"); |
aoqi@0 | 3542 | |
aoqi@0 | 3543 | // Boxed primitive objects (java_lang_boxing_object) |
aoqi@0 | 3544 | |
aoqi@0 | 3545 | CHECK_OFFSET("java/lang/Boolean", java_lang_boxing_object, value, "Z"); |
aoqi@0 | 3546 | CHECK_OFFSET("java/lang/Character", java_lang_boxing_object, value, "C"); |
aoqi@0 | 3547 | CHECK_OFFSET("java/lang/Float", java_lang_boxing_object, value, "F"); |
aoqi@0 | 3548 | CHECK_LONG_OFFSET("java/lang/Double", java_lang_boxing_object, value, "D"); |
aoqi@0 | 3549 | CHECK_OFFSET("java/lang/Byte", java_lang_boxing_object, value, "B"); |
aoqi@0 | 3550 | CHECK_OFFSET("java/lang/Short", java_lang_boxing_object, value, "S"); |
aoqi@0 | 3551 | CHECK_OFFSET("java/lang/Integer", java_lang_boxing_object, value, "I"); |
aoqi@0 | 3552 | CHECK_LONG_OFFSET("java/lang/Long", java_lang_boxing_object, value, "J"); |
aoqi@0 | 3553 | |
aoqi@0 | 3554 | // java.lang.ClassLoader |
aoqi@0 | 3555 | |
aoqi@0 | 3556 | CHECK_OFFSET("java/lang/ClassLoader", java_lang_ClassLoader, parent, "Ljava/lang/ClassLoader;"); |
aoqi@0 | 3557 | |
aoqi@0 | 3558 | // java.lang.System |
aoqi@0 | 3559 | |
aoqi@0 | 3560 | CHECK_STATIC_OFFSET("java/lang/System", java_lang_System, in, "Ljava/io/InputStream;"); |
aoqi@0 | 3561 | CHECK_STATIC_OFFSET("java/lang/System", java_lang_System, out, "Ljava/io/PrintStream;"); |
aoqi@0 | 3562 | CHECK_STATIC_OFFSET("java/lang/System", java_lang_System, err, "Ljava/io/PrintStream;"); |
aoqi@0 | 3563 | CHECK_STATIC_OFFSET("java/lang/System", java_lang_System, security, "Ljava/lang/SecurityManager;"); |
aoqi@0 | 3564 | |
aoqi@0 | 3565 | // java.lang.StackTraceElement |
aoqi@0 | 3566 | |
aoqi@0 | 3567 | CHECK_OFFSET("java/lang/StackTraceElement", java_lang_StackTraceElement, declaringClass, "Ljava/lang/String;"); |
aoqi@0 | 3568 | CHECK_OFFSET("java/lang/StackTraceElement", java_lang_StackTraceElement, methodName, "Ljava/lang/String;"); |
aoqi@0 | 3569 | CHECK_OFFSET("java/lang/StackTraceElement", java_lang_StackTraceElement, fileName, "Ljava/lang/String;"); |
aoqi@0 | 3570 | CHECK_OFFSET("java/lang/StackTraceElement", java_lang_StackTraceElement, lineNumber, "I"); |
aoqi@0 | 3571 | |
aoqi@0 | 3572 | // java.lang.ref.Reference |
aoqi@0 | 3573 | |
aoqi@0 | 3574 | CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, referent, "Ljava/lang/Object;"); |
aoqi@0 | 3575 | CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, queue, "Ljava/lang/ref/ReferenceQueue;"); |
aoqi@0 | 3576 | CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, next, "Ljava/lang/ref/Reference;"); |
aoqi@0 | 3577 | // Fake field |
aoqi@0 | 3578 | //CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, discovered, "Ljava/lang/ref/Reference;"); |
aoqi@0 | 3579 | CHECK_STATIC_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, lock, "Ljava/lang/ref/Reference$Lock;"); |
aoqi@0 | 3580 | CHECK_STATIC_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, pending, "Ljava/lang/ref/Reference;"); |
aoqi@0 | 3581 | |
aoqi@0 | 3582 | // java.lang.ref.SoftReference |
aoqi@0 | 3583 | |
aoqi@0 | 3584 | CHECK_OFFSET("java/lang/ref/SoftReference", java_lang_ref_SoftReference, timestamp, "J"); |
aoqi@0 | 3585 | CHECK_STATIC_OFFSET("java/lang/ref/SoftReference", java_lang_ref_SoftReference, clock, "J"); |
aoqi@0 | 3586 | |
aoqi@0 | 3587 | // java.lang.AssertionStatusDirectives |
aoqi@0 | 3588 | // |
aoqi@0 | 3589 | // The CheckAssertionStatusDirectives boolean can be removed from here and |
aoqi@0 | 3590 | // globals.hpp after the AssertionStatusDirectives class has been integrated |
aoqi@0 | 3591 | // into merlin "for some time." Without it, the vm will fail with early |
aoqi@0 | 3592 | // merlin builds. |
aoqi@0 | 3593 | |
aoqi@0 | 3594 | if (CheckAssertionStatusDirectives && JDK_Version::is_gte_jdk14x_version()) { |
aoqi@0 | 3595 | const char* nm = "java/lang/AssertionStatusDirectives"; |
aoqi@0 | 3596 | const char* sig = "[Ljava/lang/String;"; |
aoqi@0 | 3597 | CHECK_OFFSET(nm, java_lang_AssertionStatusDirectives, classes, sig); |
aoqi@0 | 3598 | CHECK_OFFSET(nm, java_lang_AssertionStatusDirectives, classEnabled, "[Z"); |
aoqi@0 | 3599 | CHECK_OFFSET(nm, java_lang_AssertionStatusDirectives, packages, sig); |
aoqi@0 | 3600 | CHECK_OFFSET(nm, java_lang_AssertionStatusDirectives, packageEnabled, "[Z"); |
aoqi@0 | 3601 | CHECK_OFFSET(nm, java_lang_AssertionStatusDirectives, deflt, "Z"); |
aoqi@0 | 3602 | } |
aoqi@0 | 3603 | |
aoqi@0 | 3604 | if (!valid) vm_exit_during_initialization("Hard-coded field offset verification failed"); |
aoqi@0 | 3605 | } |
aoqi@0 | 3606 | |
aoqi@0 | 3607 | #endif // PRODUCT |
aoqi@0 | 3608 | |
aoqi@0 | 3609 | int InjectedField::compute_offset() { |
aoqi@0 | 3610 | Klass* klass_oop = klass(); |
aoqi@0 | 3611 | for (AllFieldStream fs(InstanceKlass::cast(klass_oop)); !fs.done(); fs.next()) { |
aoqi@0 | 3612 | if (!may_be_java && !fs.access_flags().is_internal()) { |
aoqi@0 | 3613 | // Only look at injected fields |
aoqi@0 | 3614 | continue; |
aoqi@0 | 3615 | } |
aoqi@0 | 3616 | if (fs.name() == name() && fs.signature() == signature()) { |
aoqi@0 | 3617 | return fs.offset(); |
aoqi@0 | 3618 | } |
aoqi@0 | 3619 | } |
aoqi@0 | 3620 | ResourceMark rm; |
aoqi@0 | 3621 | 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)" : ""); |
aoqi@0 | 3622 | #ifndef PRODUCT |
aoqi@0 | 3623 | klass_oop->print(); |
aoqi@0 | 3624 | tty->print_cr("all fields:"); |
aoqi@0 | 3625 | for (AllFieldStream fs(InstanceKlass::cast(klass_oop)); !fs.done(); fs.next()) { |
aoqi@0 | 3626 | tty->print_cr(" name: %s, sig: %s, flags: %08x", fs.name()->as_C_string(), fs.signature()->as_C_string(), fs.access_flags().as_int()); |
aoqi@0 | 3627 | } |
aoqi@0 | 3628 | #endif //PRODUCT |
dbuck@7788 | 3629 | vm_exit_during_initialization("Invalid layout of preloaded class: use -XX:+TraceClassLoading to see the origin of the problem class"); |
aoqi@0 | 3630 | return -1; |
aoqi@0 | 3631 | } |
aoqi@0 | 3632 | |
aoqi@0 | 3633 | void javaClasses_init() { |
aoqi@0 | 3634 | JavaClasses::compute_offsets(); |
aoqi@0 | 3635 | JavaClasses::check_offsets(); |
aoqi@0 | 3636 | FilteredFieldsMap::initialize(); // must be done after computing offsets. |
aoqi@0 | 3637 | } |