1 /* 2 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "classfile/altHashing.hpp" 27 #include "classfile/classLoaderData.inline.hpp" 28 #include "classfile/javaClasses.inline.hpp" 29 #include "classfile/moduleEntry.hpp" 30 #include "classfile/stringTable.hpp" 31 #include "classfile/vmSymbols.hpp" 32 #include "code/debugInfo.hpp" 33 #include "code/dependencyContext.hpp" 34 #include "code/pcDesc.hpp" 35 #include "interpreter/interpreter.hpp" 36 #include "interpreter/linkResolver.hpp" 37 #include "logging/log.hpp" 38 #include "logging/logStream.hpp" 39 #include "memory/heapShared.inline.hpp" 40 #include "memory/metaspaceShared.hpp" 41 #include "memory/oopFactory.hpp" 42 #include "memory/resourceArea.hpp" 43 #include "memory/universe.hpp" 44 #include "oops/fieldStreams.hpp" 45 #include "oops/instanceKlass.hpp" 46 #include "oops/instanceMirrorKlass.hpp" 47 #include "oops/klass.hpp" 48 #include "oops/method.inline.hpp" 49 #include "oops/objArrayOop.inline.hpp" 50 #include "oops/oop.inline.hpp" 51 #include "oops/symbol.hpp" 52 #include "oops/typeArrayOop.inline.hpp" 53 #include "prims/jvmtiExport.hpp" 54 #include "prims/resolvedMethodTable.hpp" 55 #include "runtime/fieldDescriptor.inline.hpp" 56 #include "runtime/frame.inline.hpp" 57 #include "runtime/handles.inline.hpp" 58 #include "runtime/interfaceSupport.inline.hpp" 59 #include "runtime/java.hpp" 60 #include "runtime/javaCalls.hpp" 61 #include "runtime/jniHandles.inline.hpp" 62 #include "runtime/safepoint.hpp" 63 #include "runtime/safepointVerifiers.hpp" 64 #include "runtime/thread.inline.hpp" 65 #include "runtime/vframe.inline.hpp" 66 #include "utilities/align.hpp" 67 #include "utilities/preserveException.hpp" 68 #if INCLUDE_JVMCI 69 #include "jvmci/jvmciJavaClasses.hpp" 70 #endif 71 72 #define INJECTED_FIELD_COMPUTE_OFFSET(klass, name, signature, may_be_java) \ 73 klass::_##name##_offset = JavaClasses::compute_injected_offset(JavaClasses::klass##_##name##_enum); 74 75 #if INCLUDE_CDS 76 #define INJECTED_FIELD_SERIALIZE_OFFSET(klass, name, signature, may_be_java) \ 77 f->do_u4((u4*)&_##name##_offset); 78 #endif 79 80 #define DECLARE_INJECTED_FIELD(klass, name, signature, may_be_java) \ 81 { SystemDictionary::WK_KLASS_ENUM_NAME(klass), vmSymbols::VM_SYMBOL_ENUM_NAME(name##_name), vmSymbols::VM_SYMBOL_ENUM_NAME(signature), may_be_java }, 82 83 InjectedField JavaClasses::_injected_fields[] = { 84 ALL_INJECTED_FIELDS(DECLARE_INJECTED_FIELD) 85 }; 86 87 int JavaClasses::compute_injected_offset(InjectedFieldID id) { 88 return _injected_fields[id].compute_offset(); 89 } 90 91 InjectedField* JavaClasses::get_injected(Symbol* class_name, int* field_count) { 92 *field_count = 0; 93 94 vmSymbols::SID sid = vmSymbols::find_sid(class_name); 95 if (sid == vmSymbols::NO_SID) { 96 // Only well known classes can inject fields 97 return NULL; 98 } 99 100 int count = 0; 101 int start = -1; 102 103 #define LOOKUP_INJECTED_FIELD(klass, name, signature, may_be_java) \ 104 if (sid == vmSymbols::VM_SYMBOL_ENUM_NAME(klass)) { \ 105 count++; \ 106 if (start == -1) start = klass##_##name##_enum; \ 107 } 108 ALL_INJECTED_FIELDS(LOOKUP_INJECTED_FIELD); 109 #undef LOOKUP_INJECTED_FIELD 110 111 if (start != -1) { 112 *field_count = count; 113 return _injected_fields + start; 114 } 115 return NULL; 116 } 117 118 119 // Helpful routine for computing field offsets at run time rather than hardcoding them 120 // Finds local fields only, including static fields. Static field offsets are from the 121 // beginning of the mirror. 122 static void compute_offset(int &dest_offset, 123 InstanceKlass* ik, Symbol* name_symbol, Symbol* signature_symbol, 124 bool is_static = false) { 125 fieldDescriptor fd; 126 if (ik == NULL) { 127 ResourceMark rm; 128 log_error(class)("Mismatch JDK version for field: %s type: %s", name_symbol->as_C_string(), signature_symbol->as_C_string()); 129 vm_exit_during_initialization("Invalid layout of well-known class"); 130 } 131 132 if (!ik->find_local_field(name_symbol, signature_symbol, &fd) || fd.is_static() != is_static) { 133 ResourceMark rm; 134 log_error(class)("Invalid layout of %s field: %s type: %s", ik->external_name(), 135 name_symbol->as_C_string(), signature_symbol->as_C_string()); 136 #ifndef PRODUCT 137 // Prints all fields and offsets 138 Log(class) lt; 139 LogStream ls(lt.error()); 140 ik->print_on(&ls); 141 #endif //PRODUCT 142 vm_exit_during_initialization("Invalid layout of well-known class: use -Xlog:class+load=info to see the origin of the problem class"); 143 } 144 dest_offset = fd.offset(); 145 } 146 147 // Overloading to pass name as a string. 148 static void compute_offset(int& dest_offset, InstanceKlass* ik, 149 const char* name_string, Symbol* signature_symbol, 150 bool is_static = false) { 151 TempNewSymbol name = SymbolTable::probe(name_string, (int)strlen(name_string)); 152 if (name == NULL) { 153 ResourceMark rm; 154 log_error(class)("Name %s should be in the SymbolTable since its class is loaded", name_string); 155 vm_exit_during_initialization("Invalid layout of well-known class", ik->external_name()); 156 } 157 compute_offset(dest_offset, ik, name, signature_symbol, is_static); 158 } 159 160 int java_lang_String::value_offset = 0; 161 int java_lang_String::hash_offset = 0; 162 int java_lang_String::coder_offset = 0; 163 164 bool java_lang_String::initialized = false; 165 166 bool java_lang_String::is_instance(oop obj) { 167 return is_instance_inlined(obj); 168 } 169 170 #if INCLUDE_CDS 171 #define FIELD_SERIALIZE_OFFSET(offset, klass, name, signature, is_static) \ 172 f->do_u4((u4*)&offset) 173 #endif 174 175 #define FIELD_COMPUTE_OFFSET(offset, klass, name, signature, is_static) \ 176 compute_offset(offset, klass, name, vmSymbols::signature(), is_static) 177 178 #define STRING_FIELDS_DO(macro) \ 179 macro(value_offset, k, vmSymbols::value_name(), byte_array_signature, false); \ 180 macro(hash_offset, k, "hash", int_signature, false); \ 181 macro(coder_offset, k, "coder", byte_signature, false) 182 183 void java_lang_String::compute_offsets() { 184 if (initialized) { 185 return; 186 } 187 188 InstanceKlass* k = SystemDictionary::String_klass(); 189 STRING_FIELDS_DO(FIELD_COMPUTE_OFFSET); 190 191 initialized = true; 192 } 193 194 #if INCLUDE_CDS 195 void java_lang_String::serialize_offsets(SerializeClosure* f) { 196 STRING_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 197 f->do_u4((u4*)&initialized); 198 } 199 #endif 200 201 class CompactStringsFixup : public FieldClosure { 202 private: 203 bool _value; 204 205 public: 206 CompactStringsFixup(bool value) : _value(value) {} 207 208 void do_field(fieldDescriptor* fd) { 209 if (fd->name() == vmSymbols::compact_strings_name()) { 210 oop mirror = fd->field_holder()->java_mirror(); 211 assert(fd->field_holder() == SystemDictionary::String_klass(), "Should be String"); 212 assert(mirror != NULL, "String must have mirror already"); 213 mirror->bool_field_put(fd->offset(), _value); 214 } 215 } 216 }; 217 218 void java_lang_String::set_compact_strings(bool value) { 219 CompactStringsFixup fix(value); 220 InstanceKlass::cast(SystemDictionary::String_klass())->do_local_static_fields(&fix); 221 } 222 223 Handle java_lang_String::basic_create(int length, bool is_latin1, TRAPS) { 224 assert(initialized, "Must be initialized"); 225 assert(CompactStrings || !is_latin1, "Must be UTF16 without CompactStrings"); 226 227 // Create the String object first, so there's a chance that the String 228 // and the char array it points to end up in the same cache line. 229 oop obj; 230 obj = SystemDictionary::String_klass()->allocate_instance(CHECK_NH); 231 232 // Create the char array. The String object must be handlized here 233 // because GC can happen as a result of the allocation attempt. 234 Handle h_obj(THREAD, obj); 235 int arr_length = is_latin1 ? length : length << 1; // 2 bytes per UTF16. 236 typeArrayOop buffer = oopFactory::new_byteArray(arr_length, CHECK_NH);; 237 238 // Point the String at the char array 239 obj = h_obj(); 240 set_value(obj, buffer); 241 // No need to zero the offset, allocation zero'ed the entire String object 242 set_coder(obj, is_latin1 ? CODER_LATIN1 : CODER_UTF16); 243 return h_obj; 244 } 245 246 Handle java_lang_String::create_from_unicode(const jchar* unicode, int length, TRAPS) { 247 bool is_latin1 = CompactStrings && UNICODE::is_latin1(unicode, length); 248 Handle h_obj = basic_create(length, is_latin1, CHECK_NH); 249 typeArrayOop buffer = value(h_obj()); 250 assert(TypeArrayKlass::cast(buffer->klass())->element_type() == T_BYTE, "only byte[]"); 251 if (is_latin1) { 252 for (int index = 0; index < length; index++) { 253 buffer->byte_at_put(index, (jbyte)unicode[index]); 254 } 255 } else { 256 for (int index = 0; index < length; index++) { 257 buffer->char_at_put(index, unicode[index]); 258 } 259 } 260 261 #ifdef ASSERT 262 { 263 ResourceMark rm; 264 char* expected = UNICODE::as_utf8(unicode, length); 265 char* actual = as_utf8_string(h_obj()); 266 if (strcmp(expected, actual) != 0) { 267 tty->print_cr("Unicode conversion failure: %s --> %s", expected, actual); 268 ShouldNotReachHere(); 269 } 270 } 271 #endif 272 273 return h_obj; 274 } 275 276 oop java_lang_String::create_oop_from_unicode(const jchar* unicode, int length, TRAPS) { 277 Handle h_obj = create_from_unicode(unicode, length, CHECK_0); 278 return h_obj(); 279 } 280 281 Handle java_lang_String::create_from_str(const char* utf8_str, TRAPS) { 282 if (utf8_str == NULL) { 283 return Handle(); 284 } 285 bool has_multibyte, is_latin1; 286 int length = UTF8::unicode_length(utf8_str, is_latin1, has_multibyte); 287 if (!CompactStrings) { 288 has_multibyte = true; 289 is_latin1 = false; 290 } 291 292 Handle h_obj = basic_create(length, is_latin1, CHECK_NH); 293 if (length > 0) { 294 if (!has_multibyte) { 295 const jbyte* src = reinterpret_cast<const jbyte*>(utf8_str); 296 ArrayAccess<>::arraycopy_from_native(src, value(h_obj()), typeArrayOopDesc::element_offset<jbyte>(0), length); 297 } else if (is_latin1) { 298 UTF8::convert_to_unicode(utf8_str, value(h_obj())->byte_at_addr(0), length); 299 } else { 300 UTF8::convert_to_unicode(utf8_str, value(h_obj())->char_at_addr(0), length); 301 } 302 } 303 304 #ifdef ASSERT 305 // This check is too strict because the input string is not necessarily valid UTF8. 306 // For example, it may be created with arbitrary content via jni_NewStringUTF. 307 /* 308 { 309 ResourceMark rm; 310 const char* expected = utf8_str; 311 char* actual = as_utf8_string(h_obj()); 312 if (strcmp(expected, actual) != 0) { 313 tty->print_cr("String conversion failure: %s --> %s", expected, actual); 314 ShouldNotReachHere(); 315 } 316 } 317 */ 318 #endif 319 320 return h_obj; 321 } 322 323 oop java_lang_String::create_oop_from_str(const char* utf8_str, TRAPS) { 324 Handle h_obj = create_from_str(utf8_str, CHECK_0); 325 return h_obj(); 326 } 327 328 Handle java_lang_String::create_from_symbol(Symbol* symbol, TRAPS) { 329 const char* utf8_str = (char*)symbol->bytes(); 330 int utf8_len = symbol->utf8_length(); 331 332 bool has_multibyte, is_latin1; 333 int length = UTF8::unicode_length(utf8_str, utf8_len, is_latin1, has_multibyte); 334 if (!CompactStrings) { 335 has_multibyte = true; 336 is_latin1 = false; 337 } 338 339 Handle h_obj = basic_create(length, is_latin1, CHECK_NH); 340 if (length > 0) { 341 if (!has_multibyte) { 342 const jbyte* src = reinterpret_cast<const jbyte*>(utf8_str); 343 ArrayAccess<>::arraycopy_from_native(src, value(h_obj()), typeArrayOopDesc::element_offset<jbyte>(0), length); 344 } else if (is_latin1) { 345 UTF8::convert_to_unicode(utf8_str, value(h_obj())->byte_at_addr(0), length); 346 } else { 347 UTF8::convert_to_unicode(utf8_str, value(h_obj())->char_at_addr(0), length); 348 } 349 } 350 351 #ifdef ASSERT 352 { 353 ResourceMark rm; 354 const char* expected = symbol->as_utf8(); 355 char* actual = as_utf8_string(h_obj()); 356 if (strncmp(expected, actual, utf8_len) != 0) { 357 tty->print_cr("Symbol conversion failure: %s --> %s", expected, actual); 358 ShouldNotReachHere(); 359 } 360 } 361 #endif 362 363 return h_obj; 364 } 365 366 // Converts a C string to a Java String based on current encoding 367 Handle java_lang_String::create_from_platform_dependent_str(const char* str, TRAPS) { 368 assert(str != NULL, "bad arguments"); 369 370 typedef jstring (*to_java_string_fn_t)(JNIEnv*, const char *); 371 static to_java_string_fn_t _to_java_string_fn = NULL; 372 373 if (_to_java_string_fn == NULL) { 374 void *lib_handle = os::native_java_library(); 375 _to_java_string_fn = CAST_TO_FN_PTR(to_java_string_fn_t, os::dll_lookup(lib_handle, "NewStringPlatform")); 376 if (_to_java_string_fn == NULL) { 377 fatal("NewStringPlatform missing"); 378 } 379 } 380 381 jstring js = NULL; 382 { JavaThread* thread = (JavaThread*)THREAD; 383 assert(thread->is_Java_thread(), "must be java thread"); 384 HandleMark hm(thread); 385 ThreadToNativeFromVM ttn(thread); 386 js = (_to_java_string_fn)(thread->jni_environment(), str); 387 } 388 return Handle(THREAD, JNIHandles::resolve(js)); 389 } 390 391 // Converts a Java String to a native C string that can be used for 392 // native OS calls. 393 char* java_lang_String::as_platform_dependent_str(Handle java_string, TRAPS) { 394 typedef char* (*to_platform_string_fn_t)(JNIEnv*, jstring, bool*); 395 static to_platform_string_fn_t _to_platform_string_fn = NULL; 396 397 if (_to_platform_string_fn == NULL) { 398 void *lib_handle = os::native_java_library(); 399 _to_platform_string_fn = CAST_TO_FN_PTR(to_platform_string_fn_t, os::dll_lookup(lib_handle, "GetStringPlatformChars")); 400 if (_to_platform_string_fn == NULL) { 401 fatal("GetStringPlatformChars missing"); 402 } 403 } 404 405 char *native_platform_string; 406 { JavaThread* thread = (JavaThread*)THREAD; 407 assert(thread->is_Java_thread(), "must be java thread"); 408 JNIEnv *env = thread->jni_environment(); 409 jstring js = (jstring) JNIHandles::make_local(env, java_string()); 410 bool is_copy; 411 HandleMark hm(thread); 412 ThreadToNativeFromVM ttn(thread); 413 native_platform_string = (_to_platform_string_fn)(env, js, &is_copy); 414 assert(is_copy == JNI_TRUE, "is_copy value changed"); 415 JNIHandles::destroy_local(js); 416 } 417 return native_platform_string; 418 } 419 420 Handle java_lang_String::char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS) { 421 oop obj = java_string(); 422 // Typical usage is to convert all '/' to '.' in string. 423 typeArrayOop value = java_lang_String::value(obj); 424 int length = java_lang_String::length(obj); 425 bool is_latin1 = java_lang_String::is_latin1(obj); 426 427 // First check if any from_char exist 428 int index; // Declared outside, used later 429 for (index = 0; index < length; index++) { 430 jchar c = !is_latin1 ? value->char_at(index) : 431 ((jchar) value->byte_at(index)) & 0xff; 432 if (c == from_char) { 433 break; 434 } 435 } 436 if (index == length) { 437 // No from_char, so do not copy. 438 return java_string; 439 } 440 441 // Check if result string will be latin1 442 bool to_is_latin1 = false; 443 444 // Replacement char must be latin1 445 if (CompactStrings && UNICODE::is_latin1(to_char)) { 446 if (is_latin1) { 447 // Source string is latin1 as well 448 to_is_latin1 = true; 449 } else if (!UNICODE::is_latin1(from_char)) { 450 // We are replacing an UTF16 char. Scan string to 451 // check if result can be latin1 encoded. 452 to_is_latin1 = true; 453 for (index = 0; index < length; index++) { 454 jchar c = value->char_at(index); 455 if (c != from_char && !UNICODE::is_latin1(c)) { 456 to_is_latin1 = false; 457 break; 458 } 459 } 460 } 461 } 462 463 // Create new UNICODE (or byte) buffer. Must handlize value because GC 464 // may happen during String and char array creation. 465 typeArrayHandle h_value(THREAD, value); 466 Handle string = basic_create(length, to_is_latin1, CHECK_NH); 467 typeArrayOop from_buffer = h_value(); 468 typeArrayOop to_buffer = java_lang_String::value(string()); 469 470 // Copy contents 471 for (index = 0; index < length; index++) { 472 jchar c = (!is_latin1) ? from_buffer->char_at(index) : 473 ((jchar) from_buffer->byte_at(index)) & 0xff; 474 if (c == from_char) { 475 c = to_char; 476 } 477 if (!to_is_latin1) { 478 to_buffer->char_at_put(index, c); 479 } else { 480 to_buffer->byte_at_put(index, (jbyte) c); 481 } 482 } 483 return string; 484 } 485 486 jchar* java_lang_String::as_unicode_string(oop java_string, int& length, TRAPS) { 487 typeArrayOop value = java_lang_String::value(java_string); 488 length = java_lang_String::length(java_string); 489 bool is_latin1 = java_lang_String::is_latin1(java_string); 490 491 jchar* result = NEW_RESOURCE_ARRAY_RETURN_NULL(jchar, length); 492 if (result != NULL) { 493 if (!is_latin1) { 494 for (int index = 0; index < length; index++) { 495 result[index] = value->char_at(index); 496 } 497 } else { 498 for (int index = 0; index < length; index++) { 499 result[index] = ((jchar) value->byte_at(index)) & 0xff; 500 } 501 } 502 } else { 503 THROW_MSG_0(vmSymbols::java_lang_OutOfMemoryError(), "could not allocate Unicode string"); 504 } 505 return result; 506 } 507 508 unsigned int java_lang_String::hash_code(oop java_string) { 509 int length = java_lang_String::length(java_string); 510 // Zero length string will hash to zero with String.hashCode() function. 511 if (length == 0) return 0; 512 513 typeArrayOop value = java_lang_String::value(java_string); 514 bool is_latin1 = java_lang_String::is_latin1(java_string); 515 516 if (is_latin1) { 517 return java_lang_String::hash_code(value->byte_at_addr(0), length); 518 } else { 519 return java_lang_String::hash_code(value->char_at_addr(0), length); 520 } 521 } 522 523 char* java_lang_String::as_quoted_ascii(oop java_string) { 524 typeArrayOop value = java_lang_String::value(java_string); 525 int length = java_lang_String::length(java_string); 526 bool is_latin1 = java_lang_String::is_latin1(java_string); 527 528 if (length == 0) return NULL; 529 530 char* result; 531 int result_length; 532 if (!is_latin1) { 533 jchar* base = value->char_at_addr(0); 534 result_length = UNICODE::quoted_ascii_length(base, length) + 1; 535 result = NEW_RESOURCE_ARRAY(char, result_length); 536 UNICODE::as_quoted_ascii(base, length, result, result_length); 537 } else { 538 jbyte* base = value->byte_at_addr(0); 539 result_length = UNICODE::quoted_ascii_length(base, length) + 1; 540 result = NEW_RESOURCE_ARRAY(char, result_length); 541 UNICODE::as_quoted_ascii(base, length, result, result_length); 542 } 543 assert(result_length >= length + 1, "must not be shorter"); 544 assert(result_length == (int)strlen(result) + 1, "must match"); 545 return result; 546 } 547 548 Symbol* java_lang_String::as_symbol(oop java_string, TRAPS) { 549 typeArrayOop value = java_lang_String::value(java_string); 550 int length = java_lang_String::length(java_string); 551 bool is_latin1 = java_lang_String::is_latin1(java_string); 552 if (!is_latin1) { 553 jchar* base = (length == 0) ? NULL : value->char_at_addr(0); 554 Symbol* sym = SymbolTable::lookup_unicode(base, length, THREAD); 555 return sym; 556 } else { 557 ResourceMark rm; 558 jbyte* position = (length == 0) ? NULL : value->byte_at_addr(0); 559 const char* base = UNICODE::as_utf8(position, length); 560 Symbol* sym = SymbolTable::lookup(base, length, THREAD); 561 return sym; 562 } 563 } 564 565 Symbol* java_lang_String::as_symbol_or_null(oop java_string) { 566 typeArrayOop value = java_lang_String::value(java_string); 567 int length = java_lang_String::length(java_string); 568 bool is_latin1 = java_lang_String::is_latin1(java_string); 569 if (!is_latin1) { 570 jchar* base = (length == 0) ? NULL : value->char_at_addr(0); 571 return SymbolTable::probe_unicode(base, length); 572 } else { 573 ResourceMark rm; 574 jbyte* position = (length == 0) ? NULL : value->byte_at_addr(0); 575 const char* base = UNICODE::as_utf8(position, length); 576 return SymbolTable::probe(base, length); 577 } 578 } 579 580 int java_lang_String::utf8_length(oop java_string) { 581 typeArrayOop value = java_lang_String::value(java_string); 582 int length = java_lang_String::length(java_string); 583 bool is_latin1 = java_lang_String::is_latin1(java_string); 584 if (length == 0) { 585 return 0; 586 } 587 if (!is_latin1) { 588 return UNICODE::utf8_length(value->char_at_addr(0), length); 589 } else { 590 return UNICODE::utf8_length(value->byte_at_addr(0), length); 591 } 592 } 593 594 char* java_lang_String::as_utf8_string(oop java_string) { 595 typeArrayOop value = java_lang_String::value(java_string); 596 int length = java_lang_String::length(java_string); 597 bool is_latin1 = java_lang_String::is_latin1(java_string); 598 if (!is_latin1) { 599 jchar* position = (length == 0) ? NULL : value->char_at_addr(0); 600 return UNICODE::as_utf8(position, length); 601 } else { 602 jbyte* position = (length == 0) ? NULL : value->byte_at_addr(0); 603 return UNICODE::as_utf8(position, length); 604 } 605 } 606 607 char* java_lang_String::as_utf8_string(oop java_string, char* buf, int buflen) { 608 typeArrayOop value = java_lang_String::value(java_string); 609 int length = java_lang_String::length(java_string); 610 bool is_latin1 = java_lang_String::is_latin1(java_string); 611 if (!is_latin1) { 612 jchar* position = (length == 0) ? NULL : value->char_at_addr(0); 613 return UNICODE::as_utf8(position, length, buf, buflen); 614 } else { 615 jbyte* position = (length == 0) ? NULL : value->byte_at_addr(0); 616 return UNICODE::as_utf8(position, length, buf, buflen); 617 } 618 } 619 620 char* java_lang_String::as_utf8_string(oop java_string, int start, int len) { 621 typeArrayOop value = java_lang_String::value(java_string); 622 int length = java_lang_String::length(java_string); 623 assert(start + len <= length, "just checking"); 624 bool is_latin1 = java_lang_String::is_latin1(java_string); 625 if (!is_latin1) { 626 jchar* position = value->char_at_addr(start); 627 return UNICODE::as_utf8(position, len); 628 } else { 629 jbyte* position = value->byte_at_addr(start); 630 return UNICODE::as_utf8(position, len); 631 } 632 } 633 634 char* java_lang_String::as_utf8_string(oop java_string, int start, int len, char* buf, int buflen) { 635 typeArrayOop value = java_lang_String::value(java_string); 636 int length = java_lang_String::length(java_string); 637 assert(start + len <= length, "just checking"); 638 bool is_latin1 = java_lang_String::is_latin1(java_string); 639 if (!is_latin1) { 640 jchar* position = value->char_at_addr(start); 641 return UNICODE::as_utf8(position, len, buf, buflen); 642 } else { 643 jbyte* position = value->byte_at_addr(start); 644 return UNICODE::as_utf8(position, len, buf, buflen); 645 } 646 } 647 648 bool java_lang_String::equals(oop java_string, const jchar* chars, int len) { 649 assert(java_string->klass() == SystemDictionary::String_klass(), 650 "must be java_string"); 651 typeArrayOop value = java_lang_String::value_no_keepalive(java_string); 652 int length = java_lang_String::length(java_string); 653 if (length != len) { 654 return false; 655 } 656 bool is_latin1 = java_lang_String::is_latin1(java_string); 657 if (!is_latin1) { 658 for (int i = 0; i < len; i++) { 659 if (value->char_at(i) != chars[i]) { 660 return false; 661 } 662 } 663 } else { 664 for (int i = 0; i < len; i++) { 665 if ((((jchar) value->byte_at(i)) & 0xff) != chars[i]) { 666 return false; 667 } 668 } 669 } 670 return true; 671 } 672 673 bool java_lang_String::equals(oop str1, oop str2) { 674 assert(str1->klass() == SystemDictionary::String_klass(), 675 "must be java String"); 676 assert(str2->klass() == SystemDictionary::String_klass(), 677 "must be java String"); 678 typeArrayOop value1 = java_lang_String::value_no_keepalive(str1); 679 int length1 = java_lang_String::length(str1); 680 bool is_latin1 = java_lang_String::is_latin1(str1); 681 typeArrayOop value2 = java_lang_String::value_no_keepalive(str2); 682 int length2 = java_lang_String::length(str2); 683 bool is_latin2 = java_lang_String::is_latin1(str2); 684 685 if ((length1 != length2) || (is_latin1 != is_latin2)) { 686 // Strings of different size or with different 687 // coders are never equal. 688 return false; 689 } 690 int blength1 = value1->length(); 691 for (int i = 0; i < blength1; i++) { 692 if (value1->byte_at(i) != value2->byte_at(i)) { 693 return false; 694 } 695 } 696 return true; 697 } 698 699 void java_lang_String::print(oop java_string, outputStream* st) { 700 assert(java_string->klass() == SystemDictionary::String_klass(), "must be java_string"); 701 typeArrayOop value = java_lang_String::value_no_keepalive(java_string); 702 703 if (value == NULL) { 704 // This can happen if, e.g., printing a String 705 // object before its initializer has been called 706 st->print("NULL"); 707 return; 708 } 709 710 int length = java_lang_String::length(java_string); 711 bool is_latin1 = java_lang_String::is_latin1(java_string); 712 713 st->print("\""); 714 for (int index = 0; index < length; index++) { 715 st->print("%c", (!is_latin1) ? value->char_at(index) : 716 ((jchar) value->byte_at(index)) & 0xff ); 717 } 718 st->print("\""); 719 } 720 721 722 static void initialize_static_field(fieldDescriptor* fd, Handle mirror, TRAPS) { 723 assert(mirror.not_null() && fd->is_static(), "just checking"); 724 if (fd->has_initial_value()) { 725 BasicType t = fd->field_type(); 726 switch (t) { 727 case T_BYTE: 728 mirror()->byte_field_put(fd->offset(), fd->int_initial_value()); 729 break; 730 case T_BOOLEAN: 731 mirror()->bool_field_put(fd->offset(), fd->int_initial_value()); 732 break; 733 case T_CHAR: 734 mirror()->char_field_put(fd->offset(), fd->int_initial_value()); 735 break; 736 case T_SHORT: 737 mirror()->short_field_put(fd->offset(), fd->int_initial_value()); 738 break; 739 case T_INT: 740 mirror()->int_field_put(fd->offset(), fd->int_initial_value()); 741 break; 742 case T_FLOAT: 743 mirror()->float_field_put(fd->offset(), fd->float_initial_value()); 744 break; 745 case T_DOUBLE: 746 mirror()->double_field_put(fd->offset(), fd->double_initial_value()); 747 break; 748 case T_LONG: 749 mirror()->long_field_put(fd->offset(), fd->long_initial_value()); 750 break; 751 case T_OBJECT: 752 { 753 assert(fd->signature() == vmSymbols::string_signature(), 754 "just checking"); 755 if (DumpSharedSpaces && HeapShared::is_archived_object(mirror())) { 756 // Archive the String field and update the pointer. 757 oop s = mirror()->obj_field(fd->offset()); 758 oop archived_s = StringTable::create_archived_string(s, CHECK); 759 mirror()->obj_field_put(fd->offset(), archived_s); 760 } else { 761 oop string = fd->string_initial_value(CHECK); 762 mirror()->obj_field_put(fd->offset(), string); 763 } 764 } 765 break; 766 default: 767 THROW_MSG(vmSymbols::java_lang_ClassFormatError(), 768 "Illegal ConstantValue attribute in class file"); 769 } 770 } 771 } 772 773 774 void java_lang_Class::fixup_mirror(Klass* k, TRAPS) { 775 assert(InstanceMirrorKlass::offset_of_static_fields() != 0, "must have been computed already"); 776 777 // If the offset was read from the shared archive, it was fixed up already 778 if (!k->is_shared()) { 779 if (k->is_instance_klass()) { 780 // During bootstrap, java.lang.Class wasn't loaded so static field 781 // offsets were computed without the size added it. Go back and 782 // update all the static field offsets to included the size. 783 for (JavaFieldStream fs(InstanceKlass::cast(k)); !fs.done(); fs.next()) { 784 if (fs.access_flags().is_static()) { 785 int real_offset = fs.offset() + InstanceMirrorKlass::offset_of_static_fields(); 786 fs.set_offset(real_offset); 787 } 788 } 789 } 790 } 791 792 if (k->is_shared() && k->has_raw_archived_mirror()) { 793 if (HeapShared::open_archive_heap_region_mapped()) { 794 bool present = restore_archived_mirror(k, Handle(), Handle(), Handle(), CHECK); 795 assert(present, "Missing archived mirror for %s", k->external_name()); 796 return; 797 } else { 798 k->set_java_mirror_handle(NULL); 799 k->clear_has_raw_archived_mirror(); 800 } 801 } 802 create_mirror(k, Handle(), Handle(), Handle(), CHECK); 803 } 804 805 void java_lang_Class::initialize_mirror_fields(Klass* k, 806 Handle mirror, 807 Handle protection_domain, 808 TRAPS) { 809 // Allocate a simple java object for a lock. 810 // This needs to be a java object because during class initialization 811 // it can be held across a java call. 812 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK); 813 set_init_lock(mirror(), r); 814 815 // Set protection domain also 816 set_protection_domain(mirror(), protection_domain()); 817 818 // Initialize static fields 819 InstanceKlass::cast(k)->do_local_static_fields(&initialize_static_field, mirror, CHECK); 820 } 821 822 // Set the java.lang.Module module field in the java_lang_Class mirror 823 void java_lang_Class::set_mirror_module_field(Klass* k, Handle mirror, Handle module, TRAPS) { 824 if (module.is_null()) { 825 // During startup, the module may be NULL only if java.base has not been defined yet. 826 // Put the class on the fixup_module_list to patch later when the java.lang.Module 827 // for java.base is known. 828 assert(!Universe::is_module_initialized(), "Incorrect java.lang.Module pre module system initialization"); 829 830 bool javabase_was_defined = false; 831 { 832 MutexLocker m1(Module_lock, THREAD); 833 // Keep list of classes needing java.base module fixup 834 if (!ModuleEntryTable::javabase_defined()) { 835 assert(k->java_mirror() != NULL, "Class's mirror is null"); 836 k->class_loader_data()->inc_keep_alive(); 837 assert(fixup_module_field_list() != NULL, "fixup_module_field_list not initialized"); 838 fixup_module_field_list()->push(k); 839 } else { 840 javabase_was_defined = true; 841 } 842 } 843 844 // If java.base was already defined then patch this particular class with java.base. 845 if (javabase_was_defined) { 846 ModuleEntry *javabase_entry = ModuleEntryTable::javabase_moduleEntry(); 847 assert(javabase_entry != NULL && javabase_entry->module() != NULL, 848 "Setting class module field, " JAVA_BASE_NAME " should be defined"); 849 Handle javabase_handle(THREAD, javabase_entry->module()); 850 set_module(mirror(), javabase_handle()); 851 } 852 } else { 853 assert(Universe::is_module_initialized() || 854 (ModuleEntryTable::javabase_defined() && 855 (oopDesc::equals(module(), ModuleEntryTable::javabase_moduleEntry()->module()))), 856 "Incorrect java.lang.Module specification while creating mirror"); 857 set_module(mirror(), module()); 858 } 859 } 860 861 // Statically allocate fixup lists because they always get created. 862 void java_lang_Class::allocate_fixup_lists() { 863 GrowableArray<Klass*>* mirror_list = 864 new (ResourceObj::C_HEAP, mtClass) GrowableArray<Klass*>(40, true); 865 set_fixup_mirror_list(mirror_list); 866 867 GrowableArray<Klass*>* module_list = 868 new (ResourceObj::C_HEAP, mtModule) GrowableArray<Klass*>(500, true); 869 set_fixup_module_field_list(module_list); 870 } 871 872 void java_lang_Class::create_mirror(Klass* k, Handle class_loader, 873 Handle module, Handle protection_domain, TRAPS) { 874 assert(k != NULL, "Use create_basic_type_mirror for primitive types"); 875 assert(k->java_mirror() == NULL, "should only assign mirror once"); 876 877 // Use this moment of initialization to cache modifier_flags also, 878 // to support Class.getModifiers(). Instance classes recalculate 879 // the cached flags after the class file is parsed, but before the 880 // class is put into the system dictionary. 881 int computed_modifiers = k->compute_modifier_flags(CHECK); 882 k->set_modifier_flags(computed_modifiers); 883 // Class_klass has to be loaded because it is used to allocate 884 // the mirror. 885 if (SystemDictionary::Class_klass_loaded()) { 886 // Allocate mirror (java.lang.Class instance) 887 oop mirror_oop = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK); 888 Handle mirror(THREAD, mirror_oop); 889 Handle comp_mirror; 890 891 // Setup indirection from mirror->klass 892 java_lang_Class::set_klass(mirror(), k); 893 894 InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass()); 895 assert(oop_size(mirror()) == mk->instance_size(k), "should have been set"); 896 897 java_lang_Class::set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror())); 898 899 // It might also have a component mirror. This mirror must already exist. 900 if (k->is_array_klass()) { 901 if (k->is_typeArray_klass()) { 902 BasicType type = TypeArrayKlass::cast(k)->element_type(); 903 comp_mirror = Handle(THREAD, Universe::java_mirror(type)); 904 } else { 905 assert(k->is_objArray_klass(), "Must be"); 906 Klass* element_klass = ObjArrayKlass::cast(k)->element_klass(); 907 assert(element_klass != NULL, "Must have an element klass"); 908 comp_mirror = Handle(THREAD, element_klass->java_mirror()); 909 } 910 assert(comp_mirror() != NULL, "must have a mirror"); 911 912 // Two-way link between the array klass and its component mirror: 913 // (array_klass) k -> mirror -> component_mirror -> array_klass -> k 914 set_component_mirror(mirror(), comp_mirror()); 915 // See below for ordering dependencies between field array_klass in component mirror 916 // and java_mirror in this klass. 917 } else { 918 assert(k->is_instance_klass(), "Must be"); 919 920 initialize_mirror_fields(k, mirror, protection_domain, THREAD); 921 if (HAS_PENDING_EXCEPTION) { 922 // If any of the fields throws an exception like OOM remove the klass field 923 // from the mirror so GC doesn't follow it after the klass has been deallocated. 924 // This mirror looks like a primitive type, which logically it is because it 925 // it represents no class. 926 java_lang_Class::set_klass(mirror(), NULL); 927 return; 928 } 929 } 930 931 // set the classLoader field in the java_lang_Class instance 932 assert(oopDesc::equals(class_loader(), k->class_loader()), "should be same"); 933 set_class_loader(mirror(), class_loader()); 934 935 // Setup indirection from klass->mirror 936 // after any exceptions can happen during allocations. 937 k->set_java_mirror(mirror); 938 939 // Set the module field in the java_lang_Class instance. This must be done 940 // after the mirror is set. 941 set_mirror_module_field(k, mirror, module, THREAD); 942 943 if (comp_mirror() != NULL) { 944 // Set after k->java_mirror() is published, because compiled code running 945 // concurrently doesn't expect a k to have a null java_mirror. 946 release_set_array_klass(comp_mirror(), k); 947 } 948 } else { 949 assert(fixup_mirror_list() != NULL, "fixup_mirror_list not initialized"); 950 fixup_mirror_list()->push(k); 951 } 952 } 953 954 #if INCLUDE_CDS_JAVA_HEAP 955 // Clears mirror fields. Static final fields with initial values are reloaded 956 // from constant pool. The object identity hash is in the object header and is 957 // not affected. 958 class ResetMirrorField: public FieldClosure { 959 private: 960 Handle _m; 961 962 public: 963 ResetMirrorField(Handle mirror) : _m(mirror) {} 964 965 void do_field(fieldDescriptor* fd) { 966 assert(DumpSharedSpaces, "dump time only"); 967 assert(_m.not_null(), "Mirror cannot be NULL"); 968 969 if (fd->is_static() && fd->has_initial_value()) { 970 initialize_static_field(fd, _m, Thread::current()); 971 return; 972 } 973 974 BasicType ft = fd->field_type(); 975 switch (ft) { 976 case T_BYTE: 977 _m()->byte_field_put(fd->offset(), 0); 978 break; 979 case T_CHAR: 980 _m()->char_field_put(fd->offset(), 0); 981 break; 982 case T_DOUBLE: 983 _m()->double_field_put(fd->offset(), 0); 984 break; 985 case T_FLOAT: 986 _m()->float_field_put(fd->offset(), 0); 987 break; 988 case T_INT: 989 _m()->int_field_put(fd->offset(), 0); 990 break; 991 case T_LONG: 992 _m()->long_field_put(fd->offset(), 0); 993 break; 994 case T_SHORT: 995 _m()->short_field_put(fd->offset(), 0); 996 break; 997 case T_BOOLEAN: 998 _m()->bool_field_put(fd->offset(), false); 999 break; 1000 case T_ARRAY: 1001 case T_OBJECT: { 1002 // It might be useful to cache the String field, but 1003 // for now just clear out any reference field 1004 oop o = _m()->obj_field(fd->offset()); 1005 _m()->obj_field_put(fd->offset(), NULL); 1006 break; 1007 } 1008 default: 1009 ShouldNotReachHere(); 1010 break; 1011 } 1012 } 1013 }; 1014 1015 void java_lang_Class::archive_basic_type_mirrors(TRAPS) { 1016 assert(HeapShared::is_heap_object_archiving_allowed(), 1017 "HeapShared::is_heap_object_archiving_allowed() must be true"); 1018 1019 for (int t = 0; t <= T_VOID; t++) { 1020 oop m = Universe::_mirrors[t]; 1021 if (m != NULL) { 1022 // Update the field at _array_klass_offset to point to the relocated array klass. 1023 oop archived_m = HeapShared::archive_heap_object(m, THREAD); 1024 assert(archived_m != NULL, "sanity"); 1025 Klass *ak = (Klass*)(archived_m->metadata_field(_array_klass_offset)); 1026 assert(ak != NULL || t == T_VOID, "should not be NULL"); 1027 if (ak != NULL) { 1028 Klass *reloc_ak = MetaspaceShared::get_relocated_klass(ak); 1029 archived_m->metadata_field_put(_array_klass_offset, reloc_ak); 1030 } 1031 1032 // Clear the fields. Just to be safe 1033 Klass *k = m->klass(); 1034 Handle archived_mirror_h(THREAD, archived_m); 1035 ResetMirrorField reset(archived_mirror_h); 1036 InstanceKlass::cast(k)->do_nonstatic_fields(&reset); 1037 1038 log_trace(cds, heap, mirror)( 1039 "Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT, 1040 type2name((BasicType)t), p2i(Universe::_mirrors[t]), p2i(archived_m)); 1041 1042 Universe::_mirrors[t] = archived_m; 1043 } 1044 } 1045 1046 assert(Universe::_mirrors[T_INT] != NULL && 1047 Universe::_mirrors[T_FLOAT] != NULL && 1048 Universe::_mirrors[T_DOUBLE] != NULL && 1049 Universe::_mirrors[T_BYTE] != NULL && 1050 Universe::_mirrors[T_BOOLEAN] != NULL && 1051 Universe::_mirrors[T_CHAR] != NULL && 1052 Universe::_mirrors[T_LONG] != NULL && 1053 Universe::_mirrors[T_SHORT] != NULL && 1054 Universe::_mirrors[T_VOID] != NULL, "sanity"); 1055 1056 Universe::set_int_mirror(Universe::_mirrors[T_INT]); 1057 Universe::set_float_mirror(Universe::_mirrors[T_FLOAT]); 1058 Universe::set_double_mirror(Universe::_mirrors[T_DOUBLE]); 1059 Universe::set_byte_mirror(Universe::_mirrors[T_BYTE]); 1060 Universe::set_bool_mirror(Universe::_mirrors[T_BOOLEAN]); 1061 Universe::set_char_mirror(Universe::_mirrors[T_CHAR]); 1062 Universe::set_long_mirror(Universe::_mirrors[T_LONG]); 1063 Universe::set_short_mirror(Universe::_mirrors[T_SHORT]); 1064 Universe::set_void_mirror(Universe::_mirrors[T_VOID]); 1065 } 1066 1067 // 1068 // After the mirror object is successfully archived, the archived 1069 // klass is set with _has_archived_raw_mirror flag. 1070 // 1071 // The _has_archived_raw_mirror flag is cleared at runtime when the 1072 // archived mirror is restored. If archived java heap data cannot 1073 // be used at runtime, new mirror object is created for the shared 1074 // class. The _has_archived_raw_mirror is cleared also during the process. 1075 oop java_lang_Class::archive_mirror(Klass* k, TRAPS) { 1076 assert(HeapShared::is_heap_object_archiving_allowed(), 1077 "HeapShared::is_heap_object_archiving_allowed() must be true"); 1078 1079 // Mirror is already archived 1080 if (k->has_raw_archived_mirror()) { 1081 assert(k->archived_java_mirror_raw() != NULL, "no archived mirror"); 1082 return k->archived_java_mirror_raw(); 1083 } 1084 1085 // No mirror 1086 oop mirror = k->java_mirror(); 1087 if (mirror == NULL) { 1088 return NULL; 1089 } 1090 1091 if (k->is_instance_klass()) { 1092 InstanceKlass *ik = InstanceKlass::cast(k); 1093 assert(ik->signers() == NULL, "class with signer should have been excluded"); 1094 1095 if (!(ik->is_shared_boot_class() || ik->is_shared_platform_class() || 1096 ik->is_shared_app_class())) { 1097 // Archiving mirror for classes from non-builtin loaders is not 1098 // supported. Clear the _java_mirror within the archived class. 1099 k->set_java_mirror_handle(NULL); 1100 return NULL; 1101 } 1102 } 1103 1104 // Now start archiving the mirror object 1105 oop archived_mirror = HeapShared::archive_heap_object(mirror, THREAD); 1106 if (archived_mirror == NULL) { 1107 return NULL; 1108 } 1109 1110 archived_mirror = process_archived_mirror(k, mirror, archived_mirror, THREAD); 1111 if (archived_mirror == NULL) { 1112 return NULL; 1113 } 1114 1115 k->set_archived_java_mirror_raw(archived_mirror); 1116 1117 k->set_has_raw_archived_mirror(); 1118 1119 ResourceMark rm; 1120 log_trace(cds, heap, mirror)( 1121 "Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT, 1122 k->external_name(), p2i(mirror), p2i(archived_mirror)); 1123 1124 return archived_mirror; 1125 } 1126 1127 // The process is based on create_mirror(). 1128 oop java_lang_Class::process_archived_mirror(Klass* k, oop mirror, 1129 oop archived_mirror, 1130 Thread *THREAD) { 1131 // Clear nonstatic fields in archived mirror. Some of the fields will be set 1132 // to archived metadata and objects below. 1133 Klass *c = archived_mirror->klass(); 1134 Handle archived_mirror_h(THREAD, archived_mirror); 1135 ResetMirrorField reset(archived_mirror_h); 1136 InstanceKlass::cast(c)->do_nonstatic_fields(&reset); 1137 1138 if (k->is_array_klass()) { 1139 oop archived_comp_mirror; 1140 if (k->is_typeArray_klass()) { 1141 // The primitive type mirrors are already archived. Get the archived mirror. 1142 oop comp_mirror = java_lang_Class::component_mirror(mirror); 1143 archived_comp_mirror = HeapShared::find_archived_heap_object(comp_mirror); 1144 assert(archived_comp_mirror != NULL, "Must be"); 1145 } else { 1146 assert(k->is_objArray_klass(), "Must be"); 1147 Klass* element_klass = ObjArrayKlass::cast(k)->element_klass(); 1148 assert(element_klass != NULL, "Must have an element klass"); 1149 archived_comp_mirror = archive_mirror(element_klass, THREAD); 1150 if (archived_comp_mirror == NULL) { 1151 return NULL; 1152 } 1153 } 1154 java_lang_Class::set_component_mirror(archived_mirror, archived_comp_mirror); 1155 } else { 1156 assert(k->is_instance_klass(), "Must be"); 1157 1158 // Reset local static fields in the mirror 1159 InstanceKlass::cast(k)->do_local_static_fields(&reset); 1160 1161 java_lang_Class:set_init_lock(archived_mirror, NULL); 1162 1163 set_protection_domain(archived_mirror, NULL); 1164 } 1165 1166 // clear class loader and mirror_module_field 1167 set_class_loader(archived_mirror, NULL); 1168 set_module(archived_mirror, NULL); 1169 1170 // The archived mirror's field at _klass_offset is still pointing to the original 1171 // klass. Updated the field in the archived mirror to point to the relocated 1172 // klass in the archive. 1173 Klass *reloc_k = MetaspaceShared::get_relocated_klass(as_Klass(mirror)); 1174 log_debug(cds, heap, mirror)( 1175 "Relocate mirror metadata field at _klass_offset from " PTR_FORMAT " ==> " PTR_FORMAT, 1176 p2i(as_Klass(mirror)), p2i(reloc_k)); 1177 archived_mirror->metadata_field_put(_klass_offset, reloc_k); 1178 1179 // The field at _array_klass_offset is pointing to the original one dimension 1180 // higher array klass if exists. Relocate the pointer. 1181 Klass *arr = array_klass_acquire(mirror); 1182 if (arr != NULL) { 1183 Klass *reloc_arr = MetaspaceShared::get_relocated_klass(arr); 1184 log_debug(cds, heap, mirror)( 1185 "Relocate mirror metadata field at _array_klass_offset from " PTR_FORMAT " ==> " PTR_FORMAT, 1186 p2i(arr), p2i(reloc_arr)); 1187 archived_mirror->metadata_field_put(_array_klass_offset, reloc_arr); 1188 } 1189 return archived_mirror; 1190 } 1191 1192 // Returns true if the mirror is updated, false if no archived mirror 1193 // data is present. After the archived mirror object is restored, the 1194 // shared klass' _has_raw_archived_mirror flag is cleared. 1195 bool java_lang_Class::restore_archived_mirror(Klass *k, 1196 Handle class_loader, Handle module, 1197 Handle protection_domain, TRAPS) { 1198 // Postpone restoring archived mirror until java.lang.Class is loaded. Please 1199 // see more details in SystemDictionary::resolve_well_known_classes(). 1200 if (!SystemDictionary::Class_klass_loaded()) { 1201 assert(fixup_mirror_list() != NULL, "fixup_mirror_list not initialized"); 1202 fixup_mirror_list()->push(k); 1203 return true; 1204 } 1205 1206 oop m = HeapShared::materialize_archived_object(k->archived_java_mirror_raw_narrow()); 1207 1208 if (m == NULL) { 1209 return false; 1210 } 1211 1212 log_debug(cds, mirror)("Archived mirror is: " PTR_FORMAT, p2i(m)); 1213 1214 // mirror is archived, restore 1215 assert(HeapShared::is_archived_object(m), "must be archived mirror object"); 1216 Handle mirror(THREAD, m); 1217 1218 if (!k->is_array_klass()) { 1219 // - local static final fields with initial values were initialized at dump time 1220 1221 // create the init_lock 1222 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK_(false)); 1223 set_init_lock(mirror(), r); 1224 1225 if (protection_domain.not_null()) { 1226 set_protection_domain(mirror(), protection_domain()); 1227 } 1228 } 1229 1230 assert(class_loader() == k->class_loader(), "should be same"); 1231 if (class_loader.not_null()) { 1232 set_class_loader(mirror(), class_loader()); 1233 } 1234 1235 k->set_java_mirror(mirror); 1236 k->clear_has_raw_archived_mirror(); 1237 1238 set_mirror_module_field(k, mirror, module, THREAD); 1239 1240 ResourceMark rm; 1241 log_trace(cds, heap, mirror)( 1242 "Restored %s archived mirror " PTR_FORMAT, k->external_name(), p2i(mirror())); 1243 1244 return true; 1245 } 1246 #endif // INCLUDE_CDS_JAVA_HEAP 1247 1248 void java_lang_Class::fixup_module_field(Klass* k, Handle module) { 1249 assert(_module_offset != 0, "must have been computed already"); 1250 java_lang_Class::set_module(k->java_mirror(), module()); 1251 } 1252 1253 int java_lang_Class::oop_size(oop java_class) { 1254 assert(_oop_size_offset != 0, "must be set"); 1255 int size = java_class->int_field(_oop_size_offset); 1256 assert(size > 0, "Oop size must be greater than zero, not %d", size); 1257 return size; 1258 } 1259 1260 int java_lang_Class::oop_size_raw(oop java_class) { 1261 assert(_oop_size_offset != 0, "must be set"); 1262 int size = java_class->int_field_raw(_oop_size_offset); 1263 assert(size > 0, "Oop size must be greater than zero, not %d", size); 1264 return size; 1265 } 1266 1267 void java_lang_Class::set_oop_size(HeapWord* java_class, int size) { 1268 assert(_oop_size_offset != 0, "must be set"); 1269 assert(size > 0, "Oop size must be greater than zero, not %d", size); 1270 *(int*)(((char*)java_class) + _oop_size_offset) = size; 1271 } 1272 1273 int java_lang_Class::static_oop_field_count(oop java_class) { 1274 assert(_static_oop_field_count_offset != 0, "must be set"); 1275 return java_class->int_field(_static_oop_field_count_offset); 1276 } 1277 1278 int java_lang_Class::static_oop_field_count_raw(oop java_class) { 1279 assert(_static_oop_field_count_offset != 0, "must be set"); 1280 return java_class->int_field_raw(_static_oop_field_count_offset); 1281 } 1282 1283 void java_lang_Class::set_static_oop_field_count(oop java_class, int size) { 1284 assert(_static_oop_field_count_offset != 0, "must be set"); 1285 java_class->int_field_put(_static_oop_field_count_offset, size); 1286 } 1287 1288 oop java_lang_Class::protection_domain(oop java_class) { 1289 assert(_protection_domain_offset != 0, "must be set"); 1290 return java_class->obj_field(_protection_domain_offset); 1291 } 1292 void java_lang_Class::set_protection_domain(oop java_class, oop pd) { 1293 assert(_protection_domain_offset != 0, "must be set"); 1294 java_class->obj_field_put(_protection_domain_offset, pd); 1295 } 1296 1297 void java_lang_Class::set_component_mirror(oop java_class, oop comp_mirror) { 1298 assert(_component_mirror_offset != 0, "must be set"); 1299 java_class->obj_field_put(_component_mirror_offset, comp_mirror); 1300 } 1301 oop java_lang_Class::component_mirror(oop java_class) { 1302 assert(_component_mirror_offset != 0, "must be set"); 1303 return java_class->obj_field(_component_mirror_offset); 1304 } 1305 1306 oop java_lang_Class::init_lock(oop java_class) { 1307 assert(_init_lock_offset != 0, "must be set"); 1308 return java_class->obj_field(_init_lock_offset); 1309 } 1310 void java_lang_Class::set_init_lock(oop java_class, oop init_lock) { 1311 assert(_init_lock_offset != 0, "must be set"); 1312 java_class->obj_field_put(_init_lock_offset, init_lock); 1313 } 1314 1315 objArrayOop java_lang_Class::signers(oop java_class) { 1316 assert(_signers_offset != 0, "must be set"); 1317 return (objArrayOop)java_class->obj_field(_signers_offset); 1318 } 1319 void java_lang_Class::set_signers(oop java_class, objArrayOop signers) { 1320 assert(_signers_offset != 0, "must be set"); 1321 java_class->obj_field_put(_signers_offset, (oop)signers); 1322 } 1323 1324 1325 void java_lang_Class::set_class_loader(oop java_class, oop loader) { 1326 // jdk7 runs Queens in bootstrapping and jdk8-9 has no coordinated pushes yet. 1327 if (_class_loader_offset != 0) { 1328 java_class->obj_field_put(_class_loader_offset, loader); 1329 } 1330 } 1331 1332 oop java_lang_Class::class_loader(oop java_class) { 1333 assert(_class_loader_offset != 0, "must be set"); 1334 return java_class->obj_field(_class_loader_offset); 1335 } 1336 1337 oop java_lang_Class::module(oop java_class) { 1338 assert(_module_offset != 0, "must be set"); 1339 return java_class->obj_field(_module_offset); 1340 } 1341 1342 void java_lang_Class::set_module(oop java_class, oop module) { 1343 assert(_module_offset != 0, "must be set"); 1344 java_class->obj_field_put(_module_offset, module); 1345 } 1346 1347 oop java_lang_Class::name(Handle java_class, TRAPS) { 1348 assert(_name_offset != 0, "must be set"); 1349 oop o = java_class->obj_field(_name_offset); 1350 if (o == NULL) { 1351 o = StringTable::intern(java_lang_Class::as_external_name(java_class()), THREAD); 1352 java_class->obj_field_put(_name_offset, o); 1353 } 1354 return o; 1355 } 1356 1357 oop java_lang_Class::create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS) { 1358 // This should be improved by adding a field at the Java level or by 1359 // introducing a new VM klass (see comment in ClassFileParser) 1360 oop java_class = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(NULL, CHECK_0); 1361 if (type != T_VOID) { 1362 Klass* aklass = Universe::typeArrayKlassObj(type); 1363 assert(aklass != NULL, "correct bootstrap"); 1364 release_set_array_klass(java_class, aklass); 1365 } 1366 #ifdef ASSERT 1367 InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(SystemDictionary::Class_klass()); 1368 assert(java_lang_Class::static_oop_field_count(java_class) == 0, "should have been zeroed by allocation"); 1369 #endif 1370 return java_class; 1371 } 1372 1373 1374 Klass* java_lang_Class::as_Klass(oop java_class) { 1375 //%note memory_2 1376 assert(java_lang_Class::is_instance(java_class), "must be a Class object"); 1377 Klass* k = ((Klass*)java_class->metadata_field(_klass_offset)); 1378 assert(k == NULL || k->is_klass(), "type check"); 1379 return k; 1380 } 1381 1382 Klass* java_lang_Class::as_Klass_raw(oop java_class) { 1383 //%note memory_2 1384 assert(java_lang_Class::is_instance(java_class), "must be a Class object"); 1385 Klass* k = ((Klass*)java_class->metadata_field_raw(_klass_offset)); 1386 assert(k == NULL || k->is_klass(), "type check"); 1387 return k; 1388 } 1389 1390 1391 void java_lang_Class::set_klass(oop java_class, Klass* klass) { 1392 assert(java_lang_Class::is_instance(java_class), "must be a Class object"); 1393 java_class->metadata_field_put(_klass_offset, klass); 1394 } 1395 1396 1397 void java_lang_Class::print_signature(oop java_class, outputStream* st) { 1398 assert(java_lang_Class::is_instance(java_class), "must be a Class object"); 1399 Symbol* name = NULL; 1400 bool is_instance = false; 1401 if (is_primitive(java_class)) { 1402 name = vmSymbols::type_signature(primitive_type(java_class)); 1403 } else { 1404 Klass* k = as_Klass(java_class); 1405 is_instance = k->is_instance_klass(); 1406 name = k->name(); 1407 } 1408 if (name == NULL) { 1409 st->print("<null>"); 1410 return; 1411 } 1412 if (is_instance) st->print("L"); 1413 st->write((char*) name->base(), (int) name->utf8_length()); 1414 if (is_instance) st->print(";"); 1415 } 1416 1417 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found, TRAPS) { 1418 assert(java_lang_Class::is_instance(java_class), "must be a Class object"); 1419 Symbol* name; 1420 if (is_primitive(java_class)) { 1421 name = vmSymbols::type_signature(primitive_type(java_class)); 1422 // Because this can create a new symbol, the caller has to decrement 1423 // the refcount, so make adjustment here and below for symbols returned 1424 // that are not created or incremented due to a successful lookup. 1425 name->increment_refcount(); 1426 } else { 1427 Klass* k = as_Klass(java_class); 1428 if (!k->is_instance_klass()) { 1429 name = k->name(); 1430 name->increment_refcount(); 1431 } else { 1432 ResourceMark rm; 1433 const char* sigstr = k->signature_name(); 1434 int siglen = (int) strlen(sigstr); 1435 if (!intern_if_not_found) { 1436 name = SymbolTable::probe(sigstr, siglen); 1437 } else { 1438 name = SymbolTable::new_symbol(sigstr, siglen, THREAD); 1439 } 1440 } 1441 } 1442 return name; 1443 } 1444 1445 // Returns the Java name for this Java mirror (Resource allocated) 1446 // See Klass::external_name(). 1447 // For primitive type Java mirrors, its type name is returned. 1448 const char* java_lang_Class::as_external_name(oop java_class) { 1449 assert(java_lang_Class::is_instance(java_class), "must be a Class object"); 1450 const char* name = NULL; 1451 if (is_primitive(java_class)) { 1452 name = type2name(primitive_type(java_class)); 1453 } else { 1454 name = as_Klass(java_class)->external_name(); 1455 } 1456 if (name == NULL) { 1457 name = "<null>"; 1458 } 1459 return name; 1460 } 1461 1462 Klass* java_lang_Class::array_klass_acquire(oop java_class) { 1463 Klass* k = ((Klass*)java_class->metadata_field_acquire(_array_klass_offset)); 1464 assert(k == NULL || k->is_klass() && k->is_array_klass(), "should be array klass"); 1465 return k; 1466 } 1467 1468 1469 void java_lang_Class::release_set_array_klass(oop java_class, Klass* klass) { 1470 assert(klass->is_klass() && klass->is_array_klass(), "should be array klass"); 1471 java_class->release_metadata_field_put(_array_klass_offset, klass); 1472 } 1473 1474 1475 BasicType java_lang_Class::primitive_type(oop java_class) { 1476 assert(java_lang_Class::is_primitive(java_class), "just checking"); 1477 Klass* ak = ((Klass*)java_class->metadata_field(_array_klass_offset)); 1478 BasicType type = T_VOID; 1479 if (ak != NULL) { 1480 // Note: create_basic_type_mirror above initializes ak to a non-null value. 1481 type = ArrayKlass::cast(ak)->element_type(); 1482 } else { 1483 assert(oopDesc::equals(java_class, Universe::void_mirror()), "only valid non-array primitive"); 1484 } 1485 assert(oopDesc::equals(Universe::java_mirror(type), java_class), "must be consistent"); 1486 return type; 1487 } 1488 1489 BasicType java_lang_Class::as_BasicType(oop java_class, Klass** reference_klass) { 1490 assert(java_lang_Class::is_instance(java_class), "must be a Class object"); 1491 if (is_primitive(java_class)) { 1492 if (reference_klass != NULL) 1493 (*reference_klass) = NULL; 1494 return primitive_type(java_class); 1495 } else { 1496 if (reference_klass != NULL) 1497 (*reference_klass) = as_Klass(java_class); 1498 return T_OBJECT; 1499 } 1500 } 1501 1502 1503 oop java_lang_Class::primitive_mirror(BasicType t) { 1504 oop mirror = Universe::java_mirror(t); 1505 assert(mirror != NULL && mirror->is_a(SystemDictionary::Class_klass()), "must be a Class"); 1506 assert(java_lang_Class::is_primitive(mirror), "must be primitive"); 1507 return mirror; 1508 } 1509 1510 bool java_lang_Class::offsets_computed = false; 1511 int java_lang_Class::classRedefinedCount_offset = -1; 1512 1513 #define CLASS_FIELDS_DO(macro) \ 1514 macro(classRedefinedCount_offset, k, "classRedefinedCount", int_signature, false) ; \ 1515 macro(_class_loader_offset, k, "classLoader", classloader_signature, false); \ 1516 macro(_component_mirror_offset, k, "componentType", class_signature, false); \ 1517 macro(_module_offset, k, "module", module_signature, false); \ 1518 macro(_name_offset, k, "name", string_signature, false); \ 1519 1520 void java_lang_Class::compute_offsets() { 1521 if (offsets_computed) { 1522 return; 1523 } 1524 1525 offsets_computed = true; 1526 1527 InstanceKlass* k = SystemDictionary::Class_klass(); 1528 CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET); 1529 1530 // Init lock is a C union with component_mirror. Only instanceKlass mirrors have 1531 // init_lock and only ArrayKlass mirrors have component_mirror. Since both are oops 1532 // GC treats them the same. 1533 _init_lock_offset = _component_mirror_offset; 1534 1535 CLASS_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET); 1536 } 1537 1538 #if INCLUDE_CDS 1539 void java_lang_Class::serialize_offsets(SerializeClosure* f) { 1540 f->do_u4((u4*)&offsets_computed); 1541 f->do_u4((u4*)&_init_lock_offset); 1542 1543 CLASS_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 1544 1545 CLASS_INJECTED_FIELDS(INJECTED_FIELD_SERIALIZE_OFFSET); 1546 } 1547 #endif 1548 1549 int java_lang_Class::classRedefinedCount(oop the_class_mirror) { 1550 if (classRedefinedCount_offset == -1) { 1551 // If we don't have an offset for it then just return -1 as a marker. 1552 return -1; 1553 } 1554 1555 return the_class_mirror->int_field(classRedefinedCount_offset); 1556 } 1557 1558 void java_lang_Class::set_classRedefinedCount(oop the_class_mirror, int value) { 1559 if (classRedefinedCount_offset == -1) { 1560 // If we don't have an offset for it then nothing to set. 1561 return; 1562 } 1563 1564 the_class_mirror->int_field_put(classRedefinedCount_offset, value); 1565 } 1566 1567 1568 // Note: JDK1.1 and before had a privateInfo_offset field which was used for the 1569 // platform thread structure, and a eetop offset which was used for thread 1570 // local storage (and unused by the HotSpot VM). In JDK1.2 the two structures 1571 // merged, so in the HotSpot VM we just use the eetop field for the thread 1572 // instead of the privateInfo_offset. 1573 // 1574 // Note: The stackSize field is only present starting in 1.4. 1575 1576 int java_lang_Thread::_name_offset = 0; 1577 int java_lang_Thread::_group_offset = 0; 1578 int java_lang_Thread::_contextClassLoader_offset = 0; 1579 int java_lang_Thread::_inheritedAccessControlContext_offset = 0; 1580 int java_lang_Thread::_priority_offset = 0; 1581 int java_lang_Thread::_eetop_offset = 0; 1582 int java_lang_Thread::_daemon_offset = 0; 1583 int java_lang_Thread::_stillborn_offset = 0; 1584 int java_lang_Thread::_stackSize_offset = 0; 1585 int java_lang_Thread::_tid_offset = 0; 1586 int java_lang_Thread::_thread_status_offset = 0; 1587 int java_lang_Thread::_park_blocker_offset = 0; 1588 int java_lang_Thread::_park_event_offset = 0 ; 1589 1590 #define THREAD_FIELDS_DO(macro) \ 1591 macro(_name_offset, k, vmSymbols::name_name(), string_signature, false); \ 1592 macro(_group_offset, k, vmSymbols::group_name(), threadgroup_signature, false); \ 1593 macro(_contextClassLoader_offset, k, vmSymbols::contextClassLoader_name(), classloader_signature, false); \ 1594 macro(_inheritedAccessControlContext_offset, k, vmSymbols::inheritedAccessControlContext_name(), accesscontrolcontext_signature, false); \ 1595 macro(_priority_offset, k, vmSymbols::priority_name(), int_signature, false); \ 1596 macro(_daemon_offset, k, vmSymbols::daemon_name(), bool_signature, false); \ 1597 macro(_eetop_offset, k, "eetop", long_signature, false); \ 1598 macro(_stillborn_offset, k, "stillborn", bool_signature, false); \ 1599 macro(_stackSize_offset, k, "stackSize", long_signature, false); \ 1600 macro(_tid_offset, k, "tid", long_signature, false); \ 1601 macro(_thread_status_offset, k, "threadStatus", int_signature, false); \ 1602 macro(_park_blocker_offset, k, "parkBlocker", object_signature, false); \ 1603 macro(_park_event_offset, k, "nativeParkEventPointer", long_signature, false) 1604 1605 void java_lang_Thread::compute_offsets() { 1606 assert(_group_offset == 0, "offsets should be initialized only once"); 1607 1608 InstanceKlass* k = SystemDictionary::Thread_klass(); 1609 THREAD_FIELDS_DO(FIELD_COMPUTE_OFFSET); 1610 } 1611 1612 #if INCLUDE_CDS 1613 void java_lang_Thread::serialize_offsets(SerializeClosure* f) { 1614 THREAD_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 1615 } 1616 #endif 1617 1618 JavaThread* java_lang_Thread::thread(oop java_thread) { 1619 return (JavaThread*)java_thread->address_field(_eetop_offset); 1620 } 1621 1622 1623 void java_lang_Thread::set_thread(oop java_thread, JavaThread* thread) { 1624 java_thread->address_field_put(_eetop_offset, (address)thread); 1625 } 1626 1627 1628 oop java_lang_Thread::name(oop java_thread) { 1629 return java_thread->obj_field(_name_offset); 1630 } 1631 1632 1633 void java_lang_Thread::set_name(oop java_thread, oop name) { 1634 java_thread->obj_field_put(_name_offset, name); 1635 } 1636 1637 1638 ThreadPriority java_lang_Thread::priority(oop java_thread) { 1639 return (ThreadPriority)java_thread->int_field(_priority_offset); 1640 } 1641 1642 1643 void java_lang_Thread::set_priority(oop java_thread, ThreadPriority priority) { 1644 java_thread->int_field_put(_priority_offset, priority); 1645 } 1646 1647 1648 oop java_lang_Thread::threadGroup(oop java_thread) { 1649 return java_thread->obj_field(_group_offset); 1650 } 1651 1652 1653 bool java_lang_Thread::is_stillborn(oop java_thread) { 1654 return java_thread->bool_field(_stillborn_offset) != 0; 1655 } 1656 1657 1658 // We never have reason to turn the stillborn bit off 1659 void java_lang_Thread::set_stillborn(oop java_thread) { 1660 java_thread->bool_field_put(_stillborn_offset, true); 1661 } 1662 1663 1664 bool java_lang_Thread::is_alive(oop java_thread) { 1665 JavaThread* thr = java_lang_Thread::thread(java_thread); 1666 return (thr != NULL); 1667 } 1668 1669 1670 bool java_lang_Thread::is_daemon(oop java_thread) { 1671 return java_thread->bool_field(_daemon_offset) != 0; 1672 } 1673 1674 1675 void java_lang_Thread::set_daemon(oop java_thread) { 1676 java_thread->bool_field_put(_daemon_offset, true); 1677 } 1678 1679 oop java_lang_Thread::context_class_loader(oop java_thread) { 1680 return java_thread->obj_field(_contextClassLoader_offset); 1681 } 1682 1683 oop java_lang_Thread::inherited_access_control_context(oop java_thread) { 1684 return java_thread->obj_field(_inheritedAccessControlContext_offset); 1685 } 1686 1687 1688 jlong java_lang_Thread::stackSize(oop java_thread) { 1689 if (_stackSize_offset > 0) { 1690 return java_thread->long_field(_stackSize_offset); 1691 } else { 1692 return 0; 1693 } 1694 } 1695 1696 // Write the thread status value to threadStatus field in java.lang.Thread java class. 1697 void java_lang_Thread::set_thread_status(oop java_thread, 1698 java_lang_Thread::ThreadStatus status) { 1699 // The threadStatus is only present starting in 1.5 1700 if (_thread_status_offset > 0) { 1701 java_thread->int_field_put(_thread_status_offset, status); 1702 } 1703 } 1704 1705 // Read thread status value from threadStatus field in java.lang.Thread java class. 1706 java_lang_Thread::ThreadStatus java_lang_Thread::get_thread_status(oop java_thread) { 1707 // Make sure the caller is operating on behalf of the VM or is 1708 // running VM code (state == _thread_in_vm). 1709 assert(Threads_lock->owned_by_self() || Thread::current()->is_VM_thread() || 1710 JavaThread::current()->thread_state() == _thread_in_vm, 1711 "Java Thread is not running in vm"); 1712 // The threadStatus is only present starting in 1.5 1713 if (_thread_status_offset > 0) { 1714 return (java_lang_Thread::ThreadStatus)java_thread->int_field(_thread_status_offset); 1715 } else { 1716 // All we can easily figure out is if it is alive, but that is 1717 // enough info for a valid unknown status. 1718 // These aren't restricted to valid set ThreadStatus values, so 1719 // use JVMTI values and cast. 1720 JavaThread* thr = java_lang_Thread::thread(java_thread); 1721 if (thr == NULL) { 1722 // the thread hasn't run yet or is in the process of exiting 1723 return NEW; 1724 } 1725 return (java_lang_Thread::ThreadStatus)JVMTI_THREAD_STATE_ALIVE; 1726 } 1727 } 1728 1729 1730 jlong java_lang_Thread::thread_id(oop java_thread) { 1731 // The thread ID field is only present starting in 1.5 1732 if (_tid_offset > 0) { 1733 return java_thread->long_field(_tid_offset); 1734 } else { 1735 return 0; 1736 } 1737 } 1738 1739 oop java_lang_Thread::park_blocker(oop java_thread) { 1740 assert(JDK_Version::current().supports_thread_park_blocker() && 1741 _park_blocker_offset != 0, "Must support parkBlocker field"); 1742 1743 if (_park_blocker_offset > 0) { 1744 return java_thread->obj_field(_park_blocker_offset); 1745 } 1746 1747 return NULL; 1748 } 1749 1750 jlong java_lang_Thread::park_event(oop java_thread) { 1751 if (_park_event_offset > 0) { 1752 return java_thread->long_field(_park_event_offset); 1753 } 1754 return 0; 1755 } 1756 1757 bool java_lang_Thread::set_park_event(oop java_thread, jlong ptr) { 1758 if (_park_event_offset > 0) { 1759 java_thread->long_field_put(_park_event_offset, ptr); 1760 return true; 1761 } 1762 return false; 1763 } 1764 1765 1766 const char* java_lang_Thread::thread_status_name(oop java_thread) { 1767 assert(_thread_status_offset != 0, "Must have thread status"); 1768 ThreadStatus status = (java_lang_Thread::ThreadStatus)java_thread->int_field(_thread_status_offset); 1769 switch (status) { 1770 case NEW : return "NEW"; 1771 case RUNNABLE : return "RUNNABLE"; 1772 case SLEEPING : return "TIMED_WAITING (sleeping)"; 1773 case IN_OBJECT_WAIT : return "WAITING (on object monitor)"; 1774 case IN_OBJECT_WAIT_TIMED : return "TIMED_WAITING (on object monitor)"; 1775 case PARKED : return "WAITING (parking)"; 1776 case PARKED_TIMED : return "TIMED_WAITING (parking)"; 1777 case BLOCKED_ON_MONITOR_ENTER : return "BLOCKED (on object monitor)"; 1778 case TERMINATED : return "TERMINATED"; 1779 default : return "UNKNOWN"; 1780 }; 1781 } 1782 int java_lang_ThreadGroup::_parent_offset = 0; 1783 int java_lang_ThreadGroup::_name_offset = 0; 1784 int java_lang_ThreadGroup::_threads_offset = 0; 1785 int java_lang_ThreadGroup::_groups_offset = 0; 1786 int java_lang_ThreadGroup::_maxPriority_offset = 0; 1787 int java_lang_ThreadGroup::_destroyed_offset = 0; 1788 int java_lang_ThreadGroup::_daemon_offset = 0; 1789 int java_lang_ThreadGroup::_nthreads_offset = 0; 1790 int java_lang_ThreadGroup::_ngroups_offset = 0; 1791 1792 oop java_lang_ThreadGroup::parent(oop java_thread_group) { 1793 assert(oopDesc::is_oop(java_thread_group), "thread group must be oop"); 1794 return java_thread_group->obj_field(_parent_offset); 1795 } 1796 1797 // ("name as oop" accessor is not necessary) 1798 1799 const char* java_lang_ThreadGroup::name(oop java_thread_group) { 1800 oop name = java_thread_group->obj_field(_name_offset); 1801 // ThreadGroup.name can be null 1802 if (name != NULL) { 1803 return java_lang_String::as_utf8_string(name); 1804 } 1805 return NULL; 1806 } 1807 1808 int java_lang_ThreadGroup::nthreads(oop java_thread_group) { 1809 assert(oopDesc::is_oop(java_thread_group), "thread group must be oop"); 1810 return java_thread_group->int_field(_nthreads_offset); 1811 } 1812 1813 objArrayOop java_lang_ThreadGroup::threads(oop java_thread_group) { 1814 oop threads = java_thread_group->obj_field(_threads_offset); 1815 assert(threads != NULL, "threadgroups should have threads"); 1816 assert(threads->is_objArray(), "just checking"); // Todo: Add better type checking code 1817 return objArrayOop(threads); 1818 } 1819 1820 int java_lang_ThreadGroup::ngroups(oop java_thread_group) { 1821 assert(oopDesc::is_oop(java_thread_group), "thread group must be oop"); 1822 return java_thread_group->int_field(_ngroups_offset); 1823 } 1824 1825 objArrayOop java_lang_ThreadGroup::groups(oop java_thread_group) { 1826 oop groups = java_thread_group->obj_field(_groups_offset); 1827 assert(groups == NULL || groups->is_objArray(), "just checking"); // Todo: Add better type checking code 1828 return objArrayOop(groups); 1829 } 1830 1831 ThreadPriority java_lang_ThreadGroup::maxPriority(oop java_thread_group) { 1832 assert(oopDesc::is_oop(java_thread_group), "thread group must be oop"); 1833 return (ThreadPriority) java_thread_group->int_field(_maxPriority_offset); 1834 } 1835 1836 bool java_lang_ThreadGroup::is_destroyed(oop java_thread_group) { 1837 assert(oopDesc::is_oop(java_thread_group), "thread group must be oop"); 1838 return java_thread_group->bool_field(_destroyed_offset) != 0; 1839 } 1840 1841 bool java_lang_ThreadGroup::is_daemon(oop java_thread_group) { 1842 assert(oopDesc::is_oop(java_thread_group), "thread group must be oop"); 1843 return java_thread_group->bool_field(_daemon_offset) != 0; 1844 } 1845 1846 #define THREADGROUP_FIELDS_DO(macro) \ 1847 macro(_parent_offset, k, vmSymbols::parent_name(), threadgroup_signature, false); \ 1848 macro(_name_offset, k, vmSymbols::name_name(), string_signature, false); \ 1849 macro(_threads_offset, k, vmSymbols::threads_name(), thread_array_signature, false); \ 1850 macro(_groups_offset, k, vmSymbols::groups_name(), threadgroup_array_signature, false); \ 1851 macro(_maxPriority_offset, k, vmSymbols::maxPriority_name(), int_signature, false); \ 1852 macro(_destroyed_offset, k, vmSymbols::destroyed_name(), bool_signature, false); \ 1853 macro(_daemon_offset, k, vmSymbols::daemon_name(), bool_signature, false); \ 1854 macro(_nthreads_offset, k, vmSymbols::nthreads_name(), int_signature, false); \ 1855 macro(_ngroups_offset, k, vmSymbols::ngroups_name(), int_signature, false) 1856 1857 void java_lang_ThreadGroup::compute_offsets() { 1858 assert(_parent_offset == 0, "offsets should be initialized only once"); 1859 1860 InstanceKlass* k = SystemDictionary::ThreadGroup_klass(); 1861 THREADGROUP_FIELDS_DO(FIELD_COMPUTE_OFFSET); 1862 } 1863 1864 #if INCLUDE_CDS 1865 void java_lang_ThreadGroup::serialize_offsets(SerializeClosure* f) { 1866 THREADGROUP_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 1867 } 1868 #endif 1869 1870 #define THROWABLE_FIELDS_DO(macro) \ 1871 macro(backtrace_offset, k, "backtrace", object_signature, false); \ 1872 macro(detailMessage_offset, k, "detailMessage", string_signature, false); \ 1873 macro(stackTrace_offset, k, "stackTrace", java_lang_StackTraceElement_array, false); \ 1874 macro(depth_offset, k, "depth", int_signature, false); \ 1875 macro(static_unassigned_stacktrace_offset, k, "UNASSIGNED_STACK", java_lang_StackTraceElement_array, true) 1876 1877 void java_lang_Throwable::compute_offsets() { 1878 InstanceKlass* k = SystemDictionary::Throwable_klass(); 1879 THROWABLE_FIELDS_DO(FIELD_COMPUTE_OFFSET); 1880 } 1881 1882 #if INCLUDE_CDS 1883 void java_lang_Throwable::serialize_offsets(SerializeClosure* f) { 1884 THROWABLE_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 1885 } 1886 #endif 1887 1888 oop java_lang_Throwable::unassigned_stacktrace() { 1889 InstanceKlass* ik = SystemDictionary::Throwable_klass(); 1890 oop base = ik->static_field_base_raw(); 1891 return base->obj_field(static_unassigned_stacktrace_offset); 1892 } 1893 1894 oop java_lang_Throwable::backtrace(oop throwable) { 1895 return throwable->obj_field_acquire(backtrace_offset); 1896 } 1897 1898 1899 void java_lang_Throwable::set_backtrace(oop throwable, oop value) { 1900 throwable->release_obj_field_put(backtrace_offset, value); 1901 } 1902 1903 int java_lang_Throwable::depth(oop throwable) { 1904 return throwable->int_field(depth_offset); 1905 } 1906 1907 void java_lang_Throwable::set_depth(oop throwable, int value) { 1908 throwable->int_field_put(depth_offset, value); 1909 } 1910 1911 oop java_lang_Throwable::message(oop throwable) { 1912 return throwable->obj_field(detailMessage_offset); 1913 } 1914 1915 1916 // Return Symbol for detailed_message or NULL 1917 Symbol* java_lang_Throwable::detail_message(oop throwable) { 1918 PRESERVE_EXCEPTION_MARK; // Keep original exception 1919 oop detailed_message = java_lang_Throwable::message(throwable); 1920 if (detailed_message != NULL) { 1921 return java_lang_String::as_symbol(detailed_message, THREAD); 1922 } 1923 return NULL; 1924 } 1925 1926 void java_lang_Throwable::set_message(oop throwable, oop value) { 1927 throwable->obj_field_put(detailMessage_offset, value); 1928 } 1929 1930 1931 void java_lang_Throwable::set_stacktrace(oop throwable, oop st_element_array) { 1932 throwable->obj_field_put(stackTrace_offset, st_element_array); 1933 } 1934 1935 void java_lang_Throwable::clear_stacktrace(oop throwable) { 1936 set_stacktrace(throwable, NULL); 1937 } 1938 1939 1940 void java_lang_Throwable::print(oop throwable, outputStream* st) { 1941 ResourceMark rm; 1942 Klass* k = throwable->klass(); 1943 assert(k != NULL, "just checking"); 1944 st->print("%s", k->external_name()); 1945 oop msg = message(throwable); 1946 if (msg != NULL) { 1947 st->print(": %s", java_lang_String::as_utf8_string(msg)); 1948 } 1949 } 1950 1951 // After this many redefines, the stack trace is unreliable. 1952 const int MAX_VERSION = USHRT_MAX; 1953 1954 static inline bool version_matches(Method* method, int version) { 1955 assert(version < MAX_VERSION, "version is too big"); 1956 return method != NULL && (method->constants()->version() == version); 1957 } 1958 1959 1960 // This class provides a simple wrapper over the internal structure of 1961 // exception backtrace to insulate users of the backtrace from needing 1962 // to know what it looks like. 1963 class BacktraceBuilder: public StackObj { 1964 friend class BacktraceIterator; 1965 private: 1966 Handle _backtrace; 1967 objArrayOop _head; 1968 typeArrayOop _methods; 1969 typeArrayOop _bcis; 1970 objArrayOop _mirrors; 1971 typeArrayOop _names; // needed to insulate method name against redefinition 1972 int _index; 1973 NoSafepointVerifier _nsv; 1974 1975 enum { 1976 trace_methods_offset = java_lang_Throwable::trace_methods_offset, 1977 trace_bcis_offset = java_lang_Throwable::trace_bcis_offset, 1978 trace_mirrors_offset = java_lang_Throwable::trace_mirrors_offset, 1979 trace_names_offset = java_lang_Throwable::trace_names_offset, 1980 trace_next_offset = java_lang_Throwable::trace_next_offset, 1981 trace_size = java_lang_Throwable::trace_size, 1982 trace_chunk_size = java_lang_Throwable::trace_chunk_size 1983 }; 1984 1985 // get info out of chunks 1986 static typeArrayOop get_methods(objArrayHandle chunk) { 1987 typeArrayOop methods = typeArrayOop(chunk->obj_at(trace_methods_offset)); 1988 assert(methods != NULL, "method array should be initialized in backtrace"); 1989 return methods; 1990 } 1991 static typeArrayOop get_bcis(objArrayHandle chunk) { 1992 typeArrayOop bcis = typeArrayOop(chunk->obj_at(trace_bcis_offset)); 1993 assert(bcis != NULL, "bci array should be initialized in backtrace"); 1994 return bcis; 1995 } 1996 static objArrayOop get_mirrors(objArrayHandle chunk) { 1997 objArrayOop mirrors = objArrayOop(chunk->obj_at(trace_mirrors_offset)); 1998 assert(mirrors != NULL, "mirror array should be initialized in backtrace"); 1999 return mirrors; 2000 } 2001 static typeArrayOop get_names(objArrayHandle chunk) { 2002 typeArrayOop names = typeArrayOop(chunk->obj_at(trace_names_offset)); 2003 assert(names != NULL, "names array should be initialized in backtrace"); 2004 return names; 2005 } 2006 2007 public: 2008 2009 // constructor for new backtrace 2010 BacktraceBuilder(TRAPS): _head(NULL), _methods(NULL), _bcis(NULL), _mirrors(NULL), _names(NULL) { 2011 expand(CHECK); 2012 _backtrace = Handle(THREAD, _head); 2013 _index = 0; 2014 } 2015 2016 BacktraceBuilder(Thread* thread, objArrayHandle backtrace) { 2017 _methods = get_methods(backtrace); 2018 _bcis = get_bcis(backtrace); 2019 _mirrors = get_mirrors(backtrace); 2020 _names = get_names(backtrace); 2021 assert(_methods->length() == _bcis->length() && 2022 _methods->length() == _mirrors->length() && 2023 _mirrors->length() == _names->length(), 2024 "method and source information arrays should match"); 2025 2026 // head is the preallocated backtrace 2027 _head = backtrace(); 2028 _backtrace = Handle(thread, _head); 2029 _index = 0; 2030 } 2031 2032 void expand(TRAPS) { 2033 objArrayHandle old_head(THREAD, _head); 2034 PauseNoSafepointVerifier pnsv(&_nsv); 2035 2036 objArrayOop head = oopFactory::new_objectArray(trace_size, CHECK); 2037 objArrayHandle new_head(THREAD, head); 2038 2039 typeArrayOop methods = oopFactory::new_shortArray(trace_chunk_size, CHECK); 2040 typeArrayHandle new_methods(THREAD, methods); 2041 2042 typeArrayOop bcis = oopFactory::new_intArray(trace_chunk_size, CHECK); 2043 typeArrayHandle new_bcis(THREAD, bcis); 2044 2045 objArrayOop mirrors = oopFactory::new_objectArray(trace_chunk_size, CHECK); 2046 objArrayHandle new_mirrors(THREAD, mirrors); 2047 2048 typeArrayOop names = oopFactory::new_symbolArray(trace_chunk_size, CHECK); 2049 typeArrayHandle new_names(THREAD, names); 2050 2051 if (!old_head.is_null()) { 2052 old_head->obj_at_put(trace_next_offset, new_head()); 2053 } 2054 new_head->obj_at_put(trace_methods_offset, new_methods()); 2055 new_head->obj_at_put(trace_bcis_offset, new_bcis()); 2056 new_head->obj_at_put(trace_mirrors_offset, new_mirrors()); 2057 new_head->obj_at_put(trace_names_offset, new_names()); 2058 2059 _head = new_head(); 2060 _methods = new_methods(); 2061 _bcis = new_bcis(); 2062 _mirrors = new_mirrors(); 2063 _names = new_names(); 2064 _index = 0; 2065 } 2066 2067 oop backtrace() { 2068 return _backtrace(); 2069 } 2070 2071 inline void push(Method* method, int bci, TRAPS) { 2072 // Smear the -1 bci to 0 since the array only holds unsigned 2073 // shorts. The later line number lookup would just smear the -1 2074 // to a 0 even if it could be recorded. 2075 if (bci == SynchronizationEntryBCI) bci = 0; 2076 2077 if (_index >= trace_chunk_size) { 2078 methodHandle mhandle(THREAD, method); 2079 expand(CHECK); 2080 method = mhandle(); 2081 } 2082 2083 _methods->ushort_at_put(_index, method->orig_method_idnum()); 2084 _bcis->int_at_put(_index, Backtrace::merge_bci_and_version(bci, method->constants()->version())); 2085 2086 // Note:this doesn't leak symbols because the mirror in the backtrace keeps the 2087 // klass owning the symbols alive so their refcounts aren't decremented. 2088 Symbol* name = method->name(); 2089 _names->symbol_at_put(_index, name); 2090 2091 // We need to save the mirrors in the backtrace to keep the class 2092 // from being unloaded while we still have this stack trace. 2093 assert(method->method_holder()->java_mirror() != NULL, "never push null for mirror"); 2094 _mirrors->obj_at_put(_index, method->method_holder()->java_mirror()); 2095 _index++; 2096 } 2097 2098 }; 2099 2100 struct BacktraceElement : public StackObj { 2101 int _method_id; 2102 int _bci; 2103 int _version; 2104 Symbol* _name; 2105 Handle _mirror; 2106 BacktraceElement(Handle mirror, int mid, int version, int bci, Symbol* name) : 2107 _method_id(mid), _bci(bci), _version(version), _name(name), _mirror(mirror) {} 2108 }; 2109 2110 class BacktraceIterator : public StackObj { 2111 int _index; 2112 objArrayHandle _result; 2113 objArrayHandle _mirrors; 2114 typeArrayHandle _methods; 2115 typeArrayHandle _bcis; 2116 typeArrayHandle _names; 2117 2118 void init(objArrayHandle result, Thread* thread) { 2119 // Get method id, bci, version and mirror from chunk 2120 _result = result; 2121 if (_result.not_null()) { 2122 _methods = typeArrayHandle(thread, BacktraceBuilder::get_methods(_result)); 2123 _bcis = typeArrayHandle(thread, BacktraceBuilder::get_bcis(_result)); 2124 _mirrors = objArrayHandle(thread, BacktraceBuilder::get_mirrors(_result)); 2125 _names = typeArrayHandle(thread, BacktraceBuilder::get_names(_result)); 2126 _index = 0; 2127 } 2128 } 2129 public: 2130 BacktraceIterator(objArrayHandle result, Thread* thread) { 2131 init(result, thread); 2132 assert(_methods.is_null() || _methods->length() == java_lang_Throwable::trace_chunk_size, "lengths don't match"); 2133 } 2134 2135 BacktraceElement next(Thread* thread) { 2136 BacktraceElement e (Handle(thread, _mirrors->obj_at(_index)), 2137 _methods->ushort_at(_index), 2138 Backtrace::version_at(_bcis->int_at(_index)), 2139 Backtrace::bci_at(_bcis->int_at(_index)), 2140 _names->symbol_at(_index)); 2141 _index++; 2142 2143 if (_index >= java_lang_Throwable::trace_chunk_size) { 2144 int next_offset = java_lang_Throwable::trace_next_offset; 2145 // Get next chunk 2146 objArrayHandle result (thread, objArrayOop(_result->obj_at(next_offset))); 2147 init(result, thread); 2148 } 2149 return e; 2150 } 2151 2152 bool repeat() { 2153 return _result.not_null() && _mirrors->obj_at(_index) != NULL; 2154 } 2155 }; 2156 2157 2158 // Print stack trace element to resource allocated buffer 2159 static void print_stack_element_to_stream(outputStream* st, Handle mirror, int method_id, 2160 int version, int bci, Symbol* name) { 2161 ResourceMark rm; 2162 2163 // Get strings and string lengths 2164 InstanceKlass* holder = InstanceKlass::cast(java_lang_Class::as_Klass(mirror())); 2165 const char* klass_name = holder->external_name(); 2166 int buf_len = (int)strlen(klass_name); 2167 2168 char* method_name = name->as_C_string(); 2169 buf_len += (int)strlen(method_name); 2170 2171 char* source_file_name = NULL; 2172 Symbol* source = Backtrace::get_source_file_name(holder, version); 2173 if (source != NULL) { 2174 source_file_name = source->as_C_string(); 2175 buf_len += (int)strlen(source_file_name); 2176 } 2177 2178 char *module_name = NULL, *module_version = NULL; 2179 ModuleEntry* module = holder->module(); 2180 if (module->is_named()) { 2181 module_name = module->name()->as_C_string(); 2182 buf_len += (int)strlen(module_name); 2183 if (module->version() != NULL) { 2184 module_version = module->version()->as_C_string(); 2185 buf_len += (int)strlen(module_version); 2186 } 2187 } 2188 2189 // Allocate temporary buffer with extra space for formatting and line number 2190 char* buf = NEW_RESOURCE_ARRAY(char, buf_len + 64); 2191 2192 // Print stack trace line in buffer 2193 sprintf(buf, "\tat %s.%s(", klass_name, method_name); 2194 2195 // Print module information 2196 if (module_name != NULL) { 2197 if (module_version != NULL) { 2198 sprintf(buf + (int)strlen(buf), "%s@%s/", module_name, module_version); 2199 } else { 2200 sprintf(buf + (int)strlen(buf), "%s/", module_name); 2201 } 2202 } 2203 2204 // The method can be NULL if the requested class version is gone 2205 Method* method = holder->method_with_orig_idnum(method_id, version); 2206 if (!version_matches(method, version)) { 2207 strcat(buf, "Redefined)"); 2208 } else { 2209 int line_number = Backtrace::get_line_number(method, bci); 2210 if (line_number == -2) { 2211 strcat(buf, "Native Method)"); 2212 } else { 2213 if (source_file_name != NULL && (line_number != -1)) { 2214 // Sourcename and linenumber 2215 sprintf(buf + (int)strlen(buf), "%s:%d)", source_file_name, line_number); 2216 } else if (source_file_name != NULL) { 2217 // Just sourcename 2218 sprintf(buf + (int)strlen(buf), "%s)", source_file_name); 2219 } else { 2220 // Neither sourcename nor linenumber 2221 sprintf(buf + (int)strlen(buf), "Unknown Source)"); 2222 } 2223 CompiledMethod* nm = method->code(); 2224 if (WizardMode && nm != NULL) { 2225 sprintf(buf + (int)strlen(buf), "(nmethod " INTPTR_FORMAT ")", (intptr_t)nm); 2226 } 2227 } 2228 } 2229 2230 st->print_cr("%s", buf); 2231 } 2232 2233 void java_lang_Throwable::print_stack_element(outputStream *st, const methodHandle& method, int bci) { 2234 Handle mirror (Thread::current(), method->method_holder()->java_mirror()); 2235 int method_id = method->orig_method_idnum(); 2236 int version = method->constants()->version(); 2237 print_stack_element_to_stream(st, mirror, method_id, version, bci, method->name()); 2238 } 2239 2240 /** 2241 * Print the throwable message and its stack trace plus all causes by walking the 2242 * cause chain. The output looks the same as of Throwable.printStackTrace(). 2243 */ 2244 void java_lang_Throwable::print_stack_trace(Handle throwable, outputStream* st) { 2245 // First, print the message. 2246 print(throwable(), st); 2247 st->cr(); 2248 2249 // Now print the stack trace. 2250 Thread* THREAD = Thread::current(); 2251 while (throwable.not_null()) { 2252 objArrayHandle result (THREAD, objArrayOop(backtrace(throwable()))); 2253 if (result.is_null()) { 2254 st->print_raw_cr("\t<<no stack trace available>>"); 2255 return; 2256 } 2257 BacktraceIterator iter(result, THREAD); 2258 2259 while (iter.repeat()) { 2260 BacktraceElement bte = iter.next(THREAD); 2261 print_stack_element_to_stream(st, bte._mirror, bte._method_id, bte._version, bte._bci, bte._name); 2262 } 2263 { 2264 // Call getCause() which doesn't necessarily return the _cause field. 2265 EXCEPTION_MARK; 2266 JavaValue cause(T_OBJECT); 2267 JavaCalls::call_virtual(&cause, 2268 throwable, 2269 throwable->klass(), 2270 vmSymbols::getCause_name(), 2271 vmSymbols::void_throwable_signature(), 2272 THREAD); 2273 // Ignore any exceptions. we are in the middle of exception handling. Same as classic VM. 2274 if (HAS_PENDING_EXCEPTION) { 2275 CLEAR_PENDING_EXCEPTION; 2276 throwable = Handle(); 2277 } else { 2278 throwable = Handle(THREAD, (oop) cause.get_jobject()); 2279 if (throwable.not_null()) { 2280 st->print("Caused by: "); 2281 print(throwable(), st); 2282 st->cr(); 2283 } 2284 } 2285 } 2286 } 2287 } 2288 2289 /** 2290 * Print the throwable stack trace by calling the Java method java.lang.Throwable.printStackTrace(). 2291 */ 2292 void java_lang_Throwable::java_printStackTrace(Handle throwable, TRAPS) { 2293 assert(throwable->is_a(SystemDictionary::Throwable_klass()), "Throwable instance expected"); 2294 JavaValue result(T_VOID); 2295 JavaCalls::call_virtual(&result, 2296 throwable, 2297 SystemDictionary::Throwable_klass(), 2298 vmSymbols::printStackTrace_name(), 2299 vmSymbols::void_method_signature(), 2300 THREAD); 2301 } 2302 2303 void java_lang_Throwable::fill_in_stack_trace(Handle throwable, const methodHandle& method, TRAPS) { 2304 if (!StackTraceInThrowable) return; 2305 ResourceMark rm(THREAD); 2306 2307 // Start out by clearing the backtrace for this object, in case the VM 2308 // runs out of memory while allocating the stack trace 2309 set_backtrace(throwable(), NULL); 2310 // Clear lazily constructed Java level stacktrace if refilling occurs 2311 // This is unnecessary in 1.7+ but harmless 2312 clear_stacktrace(throwable()); 2313 2314 int max_depth = MaxJavaStackTraceDepth; 2315 JavaThread* thread = (JavaThread*)THREAD; 2316 2317 BacktraceBuilder bt(CHECK); 2318 2319 // If there is no Java frame just return the method that was being called 2320 // with bci 0 2321 if (!thread->has_last_Java_frame()) { 2322 if (max_depth >= 1 && method() != NULL) { 2323 bt.push(method(), 0, CHECK); 2324 log_info(stacktrace)("%s, %d", throwable->klass()->external_name(), 1); 2325 set_depth(throwable(), 1); 2326 set_backtrace(throwable(), bt.backtrace()); 2327 } 2328 return; 2329 } 2330 2331 // Instead of using vframe directly, this version of fill_in_stack_trace 2332 // basically handles everything by hand. This significantly improved the 2333 // speed of this method call up to 28.5% on Solaris sparc. 27.1% on Windows. 2334 // See bug 6333838 for more details. 2335 // The "ASSERT" here is to verify this method generates the exactly same stack 2336 // trace as utilizing vframe. 2337 #ifdef ASSERT 2338 vframeStream st(thread); 2339 methodHandle st_method(THREAD, st.method()); 2340 #endif 2341 int total_count = 0; 2342 RegisterMap map(thread, false); 2343 int decode_offset = 0; 2344 CompiledMethod* nm = NULL; 2345 bool skip_fillInStackTrace_check = false; 2346 bool skip_throwableInit_check = false; 2347 bool skip_hidden = !ShowHiddenFrames; 2348 2349 for (frame fr = thread->last_frame(); max_depth == 0 || max_depth != total_count;) { 2350 Method* method = NULL; 2351 int bci = 0; 2352 2353 // Compiled java method case. 2354 if (decode_offset != 0) { 2355 DebugInfoReadStream stream(nm, decode_offset); 2356 decode_offset = stream.read_int(); 2357 method = (Method*)nm->metadata_at(stream.read_int()); 2358 bci = stream.read_bci(); 2359 } else { 2360 if (fr.is_first_frame()) break; 2361 address pc = fr.pc(); 2362 if (fr.is_interpreted_frame()) { 2363 address bcp = fr.interpreter_frame_bcp(); 2364 method = fr.interpreter_frame_method(); 2365 bci = method->bci_from(bcp); 2366 fr = fr.sender(&map); 2367 } else { 2368 CodeBlob* cb = fr.cb(); 2369 // HMMM QQQ might be nice to have frame return nm as NULL if cb is non-NULL 2370 // but non nmethod 2371 fr = fr.sender(&map); 2372 if (cb == NULL || !cb->is_compiled()) { 2373 continue; 2374 } 2375 nm = cb->as_compiled_method(); 2376 if (nm->method()->is_native()) { 2377 method = nm->method(); 2378 bci = 0; 2379 } else { 2380 PcDesc* pd = nm->pc_desc_at(pc); 2381 decode_offset = pd->scope_decode_offset(); 2382 // if decode_offset is not equal to 0, it will execute the 2383 // "compiled java method case" at the beginning of the loop. 2384 continue; 2385 } 2386 } 2387 } 2388 #ifdef ASSERT 2389 assert(st_method() == method && st.bci() == bci, 2390 "Wrong stack trace"); 2391 st.next(); 2392 // vframeStream::method isn't GC-safe so store off a copy 2393 // of the Method* in case we GC. 2394 if (!st.at_end()) { 2395 st_method = st.method(); 2396 } 2397 #endif 2398 2399 // the format of the stacktrace will be: 2400 // - 1 or more fillInStackTrace frames for the exception class (skipped) 2401 // - 0 or more <init> methods for the exception class (skipped) 2402 // - rest of the stack 2403 2404 if (!skip_fillInStackTrace_check) { 2405 if (method->name() == vmSymbols::fillInStackTrace_name() && 2406 throwable->is_a(method->method_holder())) { 2407 continue; 2408 } 2409 else { 2410 skip_fillInStackTrace_check = true; // gone past them all 2411 } 2412 } 2413 if (!skip_throwableInit_check) { 2414 assert(skip_fillInStackTrace_check, "logic error in backtrace filtering"); 2415 2416 // skip <init> methods of the exception class and superclasses 2417 // This is simlar to classic VM. 2418 if (method->name() == vmSymbols::object_initializer_name() && 2419 throwable->is_a(method->method_holder())) { 2420 continue; 2421 } else { 2422 // there are none or we've seen them all - either way stop checking 2423 skip_throwableInit_check = true; 2424 } 2425 } 2426 if (method->is_hidden()) { 2427 if (skip_hidden) continue; 2428 } 2429 bt.push(method, bci, CHECK); 2430 total_count++; 2431 } 2432 2433 log_info(stacktrace)("%s, %d", throwable->klass()->external_name(), total_count); 2434 2435 // Put completed stack trace into throwable object 2436 set_backtrace(throwable(), bt.backtrace()); 2437 set_depth(throwable(), total_count); 2438 } 2439 2440 void java_lang_Throwable::fill_in_stack_trace(Handle throwable, const methodHandle& method) { 2441 // No-op if stack trace is disabled 2442 if (!StackTraceInThrowable) { 2443 return; 2444 } 2445 2446 // Disable stack traces for some preallocated out of memory errors 2447 if (!Universe::should_fill_in_stack_trace(throwable)) { 2448 return; 2449 } 2450 2451 PRESERVE_EXCEPTION_MARK; 2452 2453 JavaThread* thread = JavaThread::active(); 2454 fill_in_stack_trace(throwable, method, thread); 2455 // ignore exceptions thrown during stack trace filling 2456 CLEAR_PENDING_EXCEPTION; 2457 } 2458 2459 void java_lang_Throwable::allocate_backtrace(Handle throwable, TRAPS) { 2460 // Allocate stack trace - backtrace is created but not filled in 2461 2462 // No-op if stack trace is disabled 2463 if (!StackTraceInThrowable) return; 2464 BacktraceBuilder bt(CHECK); // creates a backtrace 2465 set_backtrace(throwable(), bt.backtrace()); 2466 } 2467 2468 2469 void java_lang_Throwable::fill_in_stack_trace_of_preallocated_backtrace(Handle throwable) { 2470 // Fill in stack trace into preallocated backtrace (no GC) 2471 2472 // No-op if stack trace is disabled 2473 if (!StackTraceInThrowable) return; 2474 2475 assert(throwable->is_a(SystemDictionary::Throwable_klass()), "sanity check"); 2476 2477 JavaThread* THREAD = JavaThread::current(); 2478 2479 objArrayHandle backtrace (THREAD, (objArrayOop)java_lang_Throwable::backtrace(throwable())); 2480 assert(backtrace.not_null(), "backtrace should have been preallocated"); 2481 2482 ResourceMark rm(THREAD); 2483 vframeStream st(THREAD); 2484 2485 BacktraceBuilder bt(THREAD, backtrace); 2486 2487 // Unlike fill_in_stack_trace we do not skip fillInStackTrace or throwable init 2488 // methods as preallocated errors aren't created by "java" code. 2489 2490 // fill in as much stack trace as possible 2491 int chunk_count = 0; 2492 for (;!st.at_end(); st.next()) { 2493 bt.push(st.method(), st.bci(), CHECK); 2494 chunk_count++; 2495 2496 // Bail-out for deep stacks 2497 if (chunk_count >= trace_chunk_size) break; 2498 } 2499 set_depth(throwable(), chunk_count); 2500 log_info(stacktrace)("%s, %d", throwable->klass()->external_name(), chunk_count); 2501 2502 // We support the Throwable immutability protocol defined for Java 7. 2503 java_lang_Throwable::set_stacktrace(throwable(), java_lang_Throwable::unassigned_stacktrace()); 2504 assert(java_lang_Throwable::unassigned_stacktrace() != NULL, "not initialized"); 2505 } 2506 2507 void java_lang_Throwable::get_stack_trace_elements(Handle throwable, 2508 objArrayHandle stack_trace_array_h, TRAPS) { 2509 2510 if (throwable.is_null() || stack_trace_array_h.is_null()) { 2511 THROW(vmSymbols::java_lang_NullPointerException()); 2512 } 2513 2514 assert(stack_trace_array_h->is_objArray(), "Stack trace array should be an array of StackTraceElenent"); 2515 2516 if (stack_trace_array_h->length() != depth(throwable())) { 2517 THROW(vmSymbols::java_lang_IndexOutOfBoundsException()); 2518 } 2519 2520 objArrayHandle result(THREAD, objArrayOop(backtrace(throwable()))); 2521 BacktraceIterator iter(result, THREAD); 2522 2523 int index = 0; 2524 while (iter.repeat()) { 2525 BacktraceElement bte = iter.next(THREAD); 2526 2527 Handle stack_trace_element(THREAD, stack_trace_array_h->obj_at(index++)); 2528 2529 if (stack_trace_element.is_null()) { 2530 THROW(vmSymbols::java_lang_NullPointerException()); 2531 } 2532 2533 InstanceKlass* holder = InstanceKlass::cast(java_lang_Class::as_Klass(bte._mirror())); 2534 methodHandle method (THREAD, holder->method_with_orig_idnum(bte._method_id, bte._version)); 2535 2536 java_lang_StackTraceElement::fill_in(stack_trace_element, holder, 2537 method, 2538 bte._version, 2539 bte._bci, 2540 bte._name, CHECK); 2541 } 2542 } 2543 2544 oop java_lang_StackTraceElement::create(const methodHandle& method, int bci, TRAPS) { 2545 // Allocate java.lang.StackTraceElement instance 2546 InstanceKlass* k = SystemDictionary::StackTraceElement_klass(); 2547 assert(k != NULL, "must be loaded in 1.4+"); 2548 if (k->should_be_initialized()) { 2549 k->initialize(CHECK_0); 2550 } 2551 2552 Handle element = k->allocate_instance_handle(CHECK_0); 2553 2554 int version = method->constants()->version(); 2555 fill_in(element, method->method_holder(), method, version, bci, method->name(), CHECK_0); 2556 return element(); 2557 } 2558 2559 void java_lang_StackTraceElement::fill_in(Handle element, 2560 InstanceKlass* holder, const methodHandle& method, 2561 int version, int bci, Symbol* name, TRAPS) { 2562 assert(element->is_a(SystemDictionary::StackTraceElement_klass()), "sanity check"); 2563 2564 ResourceMark rm(THREAD); 2565 HandleMark hm(THREAD); 2566 2567 // Fill in class name 2568 Handle java_class(THREAD, holder->java_mirror()); 2569 oop classname = java_lang_Class::name(java_class, CHECK); 2570 java_lang_StackTraceElement::set_declaringClass(element(), classname); 2571 java_lang_StackTraceElement::set_declaringClassObject(element(), java_class()); 2572 2573 oop loader = holder->class_loader(); 2574 if (loader != NULL) { 2575 oop loader_name = java_lang_ClassLoader::name(loader); 2576 if (loader_name != NULL) 2577 java_lang_StackTraceElement::set_classLoaderName(element(), loader_name); 2578 } 2579 2580 // Fill in method name 2581 oop methodname = StringTable::intern(name, CHECK); 2582 java_lang_StackTraceElement::set_methodName(element(), methodname); 2583 2584 // Fill in module name and version 2585 ModuleEntry* module = holder->module(); 2586 if (module->is_named()) { 2587 oop module_name = StringTable::intern(module->name(), CHECK); 2588 java_lang_StackTraceElement::set_moduleName(element(), module_name); 2589 oop module_version; 2590 if (module->version() != NULL) { 2591 module_version = StringTable::intern(module->version(), CHECK); 2592 } else { 2593 module_version = NULL; 2594 } 2595 java_lang_StackTraceElement::set_moduleVersion(element(), module_version); 2596 } 2597 2598 if (method() == NULL || !version_matches(method(), version)) { 2599 // The method was redefined, accurate line number information isn't available 2600 java_lang_StackTraceElement::set_fileName(element(), NULL); 2601 java_lang_StackTraceElement::set_lineNumber(element(), -1); 2602 } else { 2603 // Fill in source file name and line number. 2604 Symbol* source = Backtrace::get_source_file_name(holder, version); 2605 if (ShowHiddenFrames && source == NULL) 2606 source = vmSymbols::unknown_class_name(); 2607 oop filename = StringTable::intern(source, CHECK); 2608 java_lang_StackTraceElement::set_fileName(element(), filename); 2609 2610 int line_number = Backtrace::get_line_number(method, bci); 2611 java_lang_StackTraceElement::set_lineNumber(element(), line_number); 2612 } 2613 } 2614 2615 Method* java_lang_StackFrameInfo::get_method(Handle stackFrame, InstanceKlass* holder, TRAPS) { 2616 HandleMark hm(THREAD); 2617 Handle mname(THREAD, stackFrame->obj_field(_memberName_offset)); 2618 Method* method = (Method*)java_lang_invoke_MemberName::vmtarget(mname()); 2619 // we should expand MemberName::name when Throwable uses StackTrace 2620 // MethodHandles::expand_MemberName(mname, MethodHandles::_suppress_defc|MethodHandles::_suppress_type, CHECK_NULL); 2621 return method; 2622 } 2623 2624 void java_lang_StackFrameInfo::set_method_and_bci(Handle stackFrame, const methodHandle& method, int bci, TRAPS) { 2625 // set Method* or mid/cpref 2626 HandleMark hm(THREAD); 2627 Handle mname(Thread::current(), stackFrame->obj_field(_memberName_offset)); 2628 InstanceKlass* ik = method->method_holder(); 2629 CallInfo info(method(), ik, CHECK); 2630 MethodHandles::init_method_MemberName(mname, info); 2631 // set bci 2632 java_lang_StackFrameInfo::set_bci(stackFrame(), bci); 2633 // method may be redefined; store the version 2634 int version = method->constants()->version(); 2635 assert((jushort)version == version, "version should be short"); 2636 java_lang_StackFrameInfo::set_version(stackFrame(), (short)version); 2637 } 2638 2639 void java_lang_StackFrameInfo::to_stack_trace_element(Handle stackFrame, Handle stack_trace_element, TRAPS) { 2640 ResourceMark rm(THREAD); 2641 HandleMark hm(THREAD); 2642 Handle mname(THREAD, stackFrame->obj_field(java_lang_StackFrameInfo::_memberName_offset)); 2643 Klass* clazz = java_lang_Class::as_Klass(java_lang_invoke_MemberName::clazz(mname())); 2644 InstanceKlass* holder = InstanceKlass::cast(clazz); 2645 Method* method = java_lang_StackFrameInfo::get_method(stackFrame, holder, CHECK); 2646 2647 short version = stackFrame->short_field(_version_offset); 2648 short bci = stackFrame->short_field(_bci_offset); 2649 Symbol* name = method->name(); 2650 java_lang_StackTraceElement::fill_in(stack_trace_element, holder, method, version, bci, name, CHECK); 2651 } 2652 2653 #define STACKFRAMEINFO_FIELDS_DO(macro) \ 2654 macro(_memberName_offset, k, "memberName", object_signature, false); \ 2655 macro(_bci_offset, k, "bci", short_signature, false) 2656 2657 void java_lang_StackFrameInfo::compute_offsets() { 2658 InstanceKlass* k = SystemDictionary::StackFrameInfo_klass(); 2659 STACKFRAMEINFO_FIELDS_DO(FIELD_COMPUTE_OFFSET); 2660 STACKFRAMEINFO_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET); 2661 } 2662 2663 #if INCLUDE_CDS 2664 void java_lang_StackFrameInfo::serialize_offsets(SerializeClosure* f) { 2665 STACKFRAMEINFO_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 2666 STACKFRAMEINFO_INJECTED_FIELDS(INJECTED_FIELD_SERIALIZE_OFFSET); 2667 } 2668 #endif 2669 2670 #define LIVESTACKFRAMEINFO_FIELDS_DO(macro) \ 2671 macro(_monitors_offset, k, "monitors", object_array_signature, false); \ 2672 macro(_locals_offset, k, "locals", object_array_signature, false); \ 2673 macro(_operands_offset, k, "operands", object_array_signature, false); \ 2674 macro(_mode_offset, k, "mode", int_signature, false) 2675 2676 void java_lang_LiveStackFrameInfo::compute_offsets() { 2677 InstanceKlass* k = SystemDictionary::LiveStackFrameInfo_klass(); 2678 LIVESTACKFRAMEINFO_FIELDS_DO(FIELD_COMPUTE_OFFSET); 2679 } 2680 2681 #if INCLUDE_CDS 2682 void java_lang_LiveStackFrameInfo::serialize_offsets(SerializeClosure* f) { 2683 LIVESTACKFRAMEINFO_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 2684 } 2685 #endif 2686 2687 #define ACCESSIBLEOBJECT_FIELDS_DO(macro) \ 2688 macro(override_offset, k, "override", bool_signature, false) 2689 2690 void java_lang_reflect_AccessibleObject::compute_offsets() { 2691 InstanceKlass* k = SystemDictionary::reflect_AccessibleObject_klass(); 2692 ACCESSIBLEOBJECT_FIELDS_DO(FIELD_COMPUTE_OFFSET); 2693 } 2694 2695 #if INCLUDE_CDS 2696 void java_lang_reflect_AccessibleObject::serialize_offsets(SerializeClosure* f) { 2697 ACCESSIBLEOBJECT_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 2698 } 2699 #endif 2700 2701 jboolean java_lang_reflect_AccessibleObject::override(oop reflect) { 2702 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2703 return (jboolean) reflect->bool_field(override_offset); 2704 } 2705 2706 void java_lang_reflect_AccessibleObject::set_override(oop reflect, jboolean value) { 2707 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2708 reflect->bool_field_put(override_offset, (int) value); 2709 } 2710 2711 #define METHOD_FIELDS_DO(macro) \ 2712 macro(clazz_offset, k, vmSymbols::clazz_name(), class_signature, false); \ 2713 macro(name_offset, k, vmSymbols::name_name(), string_signature, false); \ 2714 macro(returnType_offset, k, vmSymbols::returnType_name(), class_signature, false); \ 2715 macro(parameterTypes_offset, k, vmSymbols::parameterTypes_name(), class_array_signature, false); \ 2716 macro(exceptionTypes_offset, k, vmSymbols::exceptionTypes_name(), class_array_signature, false); \ 2717 macro(slot_offset, k, vmSymbols::slot_name(), int_signature, false); \ 2718 macro(modifiers_offset, k, vmSymbols::modifiers_name(), int_signature, false); \ 2719 macro(signature_offset, k, vmSymbols::signature_name(), string_signature, false); \ 2720 macro(annotations_offset, k, vmSymbols::annotations_name(), byte_array_signature, false); \ 2721 macro(parameter_annotations_offset, k, vmSymbols::parameter_annotations_name(), byte_array_signature, false); \ 2722 macro(annotation_default_offset, k, vmSymbols::annotation_default_name(), byte_array_signature, false); 2723 2724 void java_lang_reflect_Method::compute_offsets() { 2725 InstanceKlass* k = SystemDictionary::reflect_Method_klass(); 2726 METHOD_FIELDS_DO(FIELD_COMPUTE_OFFSET); 2727 } 2728 2729 #if INCLUDE_CDS 2730 void java_lang_reflect_Method::serialize_offsets(SerializeClosure* f) { 2731 METHOD_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 2732 } 2733 #endif 2734 2735 Handle java_lang_reflect_Method::create(TRAPS) { 2736 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2737 Klass* klass = SystemDictionary::reflect_Method_klass(); 2738 // This class is eagerly initialized during VM initialization, since we keep a refence 2739 // to one of the methods 2740 assert(InstanceKlass::cast(klass)->is_initialized(), "must be initialized"); 2741 return InstanceKlass::cast(klass)->allocate_instance_handle(THREAD); 2742 } 2743 2744 oop java_lang_reflect_Method::clazz(oop reflect) { 2745 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2746 return reflect->obj_field(clazz_offset); 2747 } 2748 2749 void java_lang_reflect_Method::set_clazz(oop reflect, oop value) { 2750 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2751 reflect->obj_field_put(clazz_offset, value); 2752 } 2753 2754 int java_lang_reflect_Method::slot(oop reflect) { 2755 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2756 return reflect->int_field(slot_offset); 2757 } 2758 2759 void java_lang_reflect_Method::set_slot(oop reflect, int value) { 2760 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2761 reflect->int_field_put(slot_offset, value); 2762 } 2763 2764 void java_lang_reflect_Method::set_name(oop method, oop value) { 2765 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2766 method->obj_field_put(name_offset, value); 2767 } 2768 2769 oop java_lang_reflect_Method::return_type(oop method) { 2770 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2771 return method->obj_field(returnType_offset); 2772 } 2773 2774 void java_lang_reflect_Method::set_return_type(oop method, oop value) { 2775 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2776 method->obj_field_put(returnType_offset, value); 2777 } 2778 2779 oop java_lang_reflect_Method::parameter_types(oop method) { 2780 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2781 return method->obj_field(parameterTypes_offset); 2782 } 2783 2784 void java_lang_reflect_Method::set_parameter_types(oop method, oop value) { 2785 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2786 method->obj_field_put(parameterTypes_offset, value); 2787 } 2788 2789 void java_lang_reflect_Method::set_exception_types(oop method, oop value) { 2790 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2791 method->obj_field_put(exceptionTypes_offset, value); 2792 } 2793 2794 void java_lang_reflect_Method::set_modifiers(oop method, int value) { 2795 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2796 method->int_field_put(modifiers_offset, value); 2797 } 2798 2799 void java_lang_reflect_Method::set_signature(oop method, oop value) { 2800 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2801 method->obj_field_put(signature_offset, value); 2802 } 2803 2804 void java_lang_reflect_Method::set_annotations(oop method, oop value) { 2805 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2806 method->obj_field_put(annotations_offset, value); 2807 } 2808 2809 void java_lang_reflect_Method::set_parameter_annotations(oop method, oop value) { 2810 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2811 method->obj_field_put(parameter_annotations_offset, value); 2812 } 2813 2814 void java_lang_reflect_Method::set_annotation_default(oop method, oop value) { 2815 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2816 method->obj_field_put(annotation_default_offset, value); 2817 } 2818 2819 #define CONSTRUCTOR_FIELDS_DO(macro) \ 2820 macro(clazz_offset, k, vmSymbols::clazz_name(), class_signature, false); \ 2821 macro(parameterTypes_offset, k, vmSymbols::parameterTypes_name(), class_array_signature, false); \ 2822 macro(exceptionTypes_offset, k, vmSymbols::exceptionTypes_name(), class_array_signature, false); \ 2823 macro(slot_offset, k, vmSymbols::slot_name(), int_signature, false); \ 2824 macro(modifiers_offset, k, vmSymbols::modifiers_name(), int_signature, false); \ 2825 macro(signature_offset, k, vmSymbols::signature_name(), string_signature, false); \ 2826 macro(annotations_offset, k, vmSymbols::annotations_name(), byte_array_signature, false); \ 2827 macro(parameter_annotations_offset, k, vmSymbols::parameter_annotations_name(), byte_array_signature, false); 2828 2829 void java_lang_reflect_Constructor::compute_offsets() { 2830 InstanceKlass* k = SystemDictionary::reflect_Constructor_klass(); 2831 CONSTRUCTOR_FIELDS_DO(FIELD_COMPUTE_OFFSET); 2832 } 2833 2834 #if INCLUDE_CDS 2835 void java_lang_reflect_Constructor::serialize_offsets(SerializeClosure* f) { 2836 CONSTRUCTOR_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 2837 } 2838 #endif 2839 2840 Handle java_lang_reflect_Constructor::create(TRAPS) { 2841 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2842 Symbol* name = vmSymbols::java_lang_reflect_Constructor(); 2843 Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH); 2844 InstanceKlass* ik = InstanceKlass::cast(k); 2845 // Ensure it is initialized 2846 ik->initialize(CHECK_NH); 2847 return ik->allocate_instance_handle(THREAD); 2848 } 2849 2850 oop java_lang_reflect_Constructor::clazz(oop reflect) { 2851 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2852 return reflect->obj_field(clazz_offset); 2853 } 2854 2855 void java_lang_reflect_Constructor::set_clazz(oop reflect, oop value) { 2856 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2857 reflect->obj_field_put(clazz_offset, value); 2858 } 2859 2860 oop java_lang_reflect_Constructor::parameter_types(oop constructor) { 2861 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2862 return constructor->obj_field(parameterTypes_offset); 2863 } 2864 2865 void java_lang_reflect_Constructor::set_parameter_types(oop constructor, oop value) { 2866 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2867 constructor->obj_field_put(parameterTypes_offset, value); 2868 } 2869 2870 void java_lang_reflect_Constructor::set_exception_types(oop constructor, oop value) { 2871 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2872 constructor->obj_field_put(exceptionTypes_offset, value); 2873 } 2874 2875 int java_lang_reflect_Constructor::slot(oop reflect) { 2876 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2877 return reflect->int_field(slot_offset); 2878 } 2879 2880 void java_lang_reflect_Constructor::set_slot(oop reflect, int value) { 2881 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2882 reflect->int_field_put(slot_offset, value); 2883 } 2884 2885 void java_lang_reflect_Constructor::set_modifiers(oop constructor, int value) { 2886 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2887 constructor->int_field_put(modifiers_offset, value); 2888 } 2889 2890 void java_lang_reflect_Constructor::set_signature(oop constructor, oop value) { 2891 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2892 constructor->obj_field_put(signature_offset, value); 2893 } 2894 2895 void java_lang_reflect_Constructor::set_annotations(oop constructor, oop value) { 2896 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2897 constructor->obj_field_put(annotations_offset, value); 2898 } 2899 2900 void java_lang_reflect_Constructor::set_parameter_annotations(oop method, oop value) { 2901 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2902 method->obj_field_put(parameter_annotations_offset, value); 2903 } 2904 2905 #define FIELD_FIELDS_DO(macro) \ 2906 macro(clazz_offset, k, vmSymbols::clazz_name(), class_signature, false); \ 2907 macro(name_offset, k, vmSymbols::name_name(), string_signature, false); \ 2908 macro(type_offset, k, vmSymbols::type_name(), class_signature, false); \ 2909 macro(slot_offset, k, vmSymbols::slot_name(), int_signature, false); \ 2910 macro(modifiers_offset, k, vmSymbols::modifiers_name(), int_signature, false); \ 2911 macro(signature_offset, k, vmSymbols::signature_name(), string_signature, false); \ 2912 macro(annotations_offset, k, vmSymbols::annotations_name(), byte_array_signature, false); 2913 2914 void java_lang_reflect_Field::compute_offsets() { 2915 InstanceKlass* k = SystemDictionary::reflect_Field_klass(); 2916 FIELD_FIELDS_DO(FIELD_COMPUTE_OFFSET); 2917 } 2918 2919 #if INCLUDE_CDS 2920 void java_lang_reflect_Field::serialize_offsets(SerializeClosure* f) { 2921 FIELD_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 2922 } 2923 #endif 2924 2925 Handle java_lang_reflect_Field::create(TRAPS) { 2926 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2927 Symbol* name = vmSymbols::java_lang_reflect_Field(); 2928 Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH); 2929 InstanceKlass* ik = InstanceKlass::cast(k); 2930 // Ensure it is initialized 2931 ik->initialize(CHECK_NH); 2932 return ik->allocate_instance_handle(THREAD); 2933 } 2934 2935 oop java_lang_reflect_Field::clazz(oop reflect) { 2936 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2937 return reflect->obj_field(clazz_offset); 2938 } 2939 2940 void java_lang_reflect_Field::set_clazz(oop reflect, oop value) { 2941 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2942 reflect->obj_field_put(clazz_offset, value); 2943 } 2944 2945 oop java_lang_reflect_Field::name(oop field) { 2946 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2947 return field->obj_field(name_offset); 2948 } 2949 2950 void java_lang_reflect_Field::set_name(oop field, oop value) { 2951 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2952 field->obj_field_put(name_offset, value); 2953 } 2954 2955 oop java_lang_reflect_Field::type(oop field) { 2956 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2957 return field->obj_field(type_offset); 2958 } 2959 2960 void java_lang_reflect_Field::set_type(oop field, oop value) { 2961 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2962 field->obj_field_put(type_offset, value); 2963 } 2964 2965 int java_lang_reflect_Field::slot(oop reflect) { 2966 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2967 return reflect->int_field(slot_offset); 2968 } 2969 2970 void java_lang_reflect_Field::set_slot(oop reflect, int value) { 2971 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2972 reflect->int_field_put(slot_offset, value); 2973 } 2974 2975 int java_lang_reflect_Field::modifiers(oop field) { 2976 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2977 return field->int_field(modifiers_offset); 2978 } 2979 2980 void java_lang_reflect_Field::set_modifiers(oop field, int value) { 2981 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2982 field->int_field_put(modifiers_offset, value); 2983 } 2984 2985 void java_lang_reflect_Field::set_signature(oop field, oop value) { 2986 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2987 field->obj_field_put(signature_offset, value); 2988 } 2989 2990 void java_lang_reflect_Field::set_annotations(oop field, oop value) { 2991 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 2992 field->obj_field_put(annotations_offset, value); 2993 } 2994 2995 #define CONSTANTPOOL_FIELDS_DO(macro) \ 2996 macro(_oop_offset, k, "constantPoolOop", object_signature, false) 2997 2998 void reflect_ConstantPool::compute_offsets() { 2999 InstanceKlass* k = SystemDictionary::reflect_ConstantPool_klass(); 3000 // The field is called ConstantPool* in the sun.reflect.ConstantPool class. 3001 CONSTANTPOOL_FIELDS_DO(FIELD_COMPUTE_OFFSET); 3002 } 3003 3004 #if INCLUDE_CDS 3005 void reflect_ConstantPool::serialize_offsets(SerializeClosure* f) { 3006 CONSTANTPOOL_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 3007 } 3008 #endif 3009 3010 #define PARAMETER_FIELDS_DO(macro) \ 3011 macro(name_offset, k, vmSymbols::name_name(), string_signature, false); \ 3012 macro(modifiers_offset, k, vmSymbols::modifiers_name(), int_signature, false); \ 3013 macro(index_offset, k, vmSymbols::index_name(), int_signature, false); \ 3014 macro(executable_offset, k, vmSymbols::executable_name(), executable_signature, false) 3015 3016 void java_lang_reflect_Parameter::compute_offsets() { 3017 InstanceKlass* k = SystemDictionary::reflect_Parameter_klass(); 3018 PARAMETER_FIELDS_DO(FIELD_COMPUTE_OFFSET); 3019 } 3020 3021 #if INCLUDE_CDS 3022 void java_lang_reflect_Parameter::serialize_offsets(SerializeClosure* f) { 3023 PARAMETER_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 3024 } 3025 #endif 3026 3027 Handle java_lang_reflect_Parameter::create(TRAPS) { 3028 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 3029 Symbol* name = vmSymbols::java_lang_reflect_Parameter(); 3030 Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH); 3031 InstanceKlass* ik = InstanceKlass::cast(k); 3032 // Ensure it is initialized 3033 ik->initialize(CHECK_NH); 3034 return ik->allocate_instance_handle(THREAD); 3035 } 3036 3037 oop java_lang_reflect_Parameter::name(oop param) { 3038 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 3039 return param->obj_field(name_offset); 3040 } 3041 3042 void java_lang_reflect_Parameter::set_name(oop param, oop value) { 3043 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 3044 param->obj_field_put(name_offset, value); 3045 } 3046 3047 int java_lang_reflect_Parameter::modifiers(oop param) { 3048 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 3049 return param->int_field(modifiers_offset); 3050 } 3051 3052 void java_lang_reflect_Parameter::set_modifiers(oop param, int value) { 3053 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 3054 param->int_field_put(modifiers_offset, value); 3055 } 3056 3057 int java_lang_reflect_Parameter::index(oop param) { 3058 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 3059 return param->int_field(index_offset); 3060 } 3061 3062 void java_lang_reflect_Parameter::set_index(oop param, int value) { 3063 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 3064 param->int_field_put(index_offset, value); 3065 } 3066 3067 oop java_lang_reflect_Parameter::executable(oop param) { 3068 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 3069 return param->obj_field(executable_offset); 3070 } 3071 3072 void java_lang_reflect_Parameter::set_executable(oop param, oop value) { 3073 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 3074 param->obj_field_put(executable_offset, value); 3075 } 3076 3077 3078 int java_lang_Module::loader_offset; 3079 int java_lang_Module::name_offset; 3080 int java_lang_Module::_module_entry_offset = -1; 3081 3082 Handle java_lang_Module::create(Handle loader, Handle module_name, TRAPS) { 3083 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 3084 return JavaCalls::construct_new_instance(SystemDictionary::Module_klass(), 3085 vmSymbols::java_lang_module_init_signature(), 3086 loader, module_name, CHECK_NH); 3087 } 3088 3089 #define MODULE_FIELDS_DO(macro) \ 3090 macro(loader_offset, k, vmSymbols::loader_name(), classloader_signature, false); \ 3091 macro(name_offset, k, vmSymbols::name_name(), string_signature, false) 3092 3093 void java_lang_Module::compute_offsets() { 3094 InstanceKlass* k = SystemDictionary::Module_klass(); 3095 MODULE_FIELDS_DO(FIELD_COMPUTE_OFFSET); 3096 MODULE_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET); 3097 } 3098 3099 #if INCLUDE_CDS 3100 void java_lang_Module::serialize_offsets(SerializeClosure* f) { 3101 MODULE_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 3102 MODULE_INJECTED_FIELDS(INJECTED_FIELD_SERIALIZE_OFFSET); 3103 } 3104 #endif 3105 3106 oop java_lang_Module::loader(oop module) { 3107 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 3108 return module->obj_field(loader_offset); 3109 } 3110 3111 void java_lang_Module::set_loader(oop module, oop value) { 3112 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 3113 module->obj_field_put(loader_offset, value); 3114 } 3115 3116 oop java_lang_Module::name(oop module) { 3117 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 3118 return module->obj_field(name_offset); 3119 } 3120 3121 void java_lang_Module::set_name(oop module, oop value) { 3122 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 3123 module->obj_field_put(name_offset, value); 3124 } 3125 3126 ModuleEntry* java_lang_Module::module_entry(oop module) { 3127 assert(_module_entry_offset != -1, "Uninitialized module_entry_offset"); 3128 assert(module != NULL, "module can't be null"); 3129 assert(oopDesc::is_oop(module), "module must be oop"); 3130 3131 ModuleEntry* module_entry = (ModuleEntry*)module->address_field(_module_entry_offset); 3132 if (module_entry == NULL) { 3133 // If the inject field containing the ModuleEntry* is null then return the 3134 // class loader's unnamed module. 3135 oop loader = java_lang_Module::loader(module); 3136 Handle h_loader = Handle(Thread::current(), loader); 3137 ClassLoaderData* loader_cld = SystemDictionary::register_loader(h_loader); 3138 return loader_cld->unnamed_module(); 3139 } 3140 return module_entry; 3141 } 3142 3143 void java_lang_Module::set_module_entry(oop module, ModuleEntry* module_entry) { 3144 assert(_module_entry_offset != -1, "Uninitialized module_entry_offset"); 3145 assert(module != NULL, "module can't be null"); 3146 assert(oopDesc::is_oop(module), "module must be oop"); 3147 module->address_field_put(_module_entry_offset, (address)module_entry); 3148 } 3149 3150 Handle reflect_ConstantPool::create(TRAPS) { 3151 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 3152 InstanceKlass* k = SystemDictionary::reflect_ConstantPool_klass(); 3153 // Ensure it is initialized 3154 k->initialize(CHECK_NH); 3155 return k->allocate_instance_handle(THREAD); 3156 } 3157 3158 3159 void reflect_ConstantPool::set_cp(oop reflect, ConstantPool* value) { 3160 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 3161 oop mirror = value->pool_holder()->java_mirror(); 3162 // Save the mirror to get back the constant pool. 3163 reflect->obj_field_put(_oop_offset, mirror); 3164 } 3165 3166 ConstantPool* reflect_ConstantPool::get_cp(oop reflect) { 3167 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem"); 3168 3169 oop mirror = reflect->obj_field(_oop_offset); 3170 Klass* k = java_lang_Class::as_Klass(mirror); 3171 assert(k->is_instance_klass(), "Must be"); 3172 3173 // Get the constant pool back from the klass. Since class redefinition 3174 // merges the new constant pool into the old, this is essentially the 3175 // same constant pool as the original. If constant pool merging is 3176 // no longer done in the future, this will have to change to save 3177 // the original. 3178 return InstanceKlass::cast(k)->constants(); 3179 } 3180 3181 #define UNSAFESTATICFIELDACCESSORIMPL_FIELDS_DO(macro) \ 3182 macro(_base_offset, k, "base", object_signature, false) 3183 3184 void reflect_UnsafeStaticFieldAccessorImpl::compute_offsets() { 3185 InstanceKlass* k = SystemDictionary::reflect_UnsafeStaticFieldAccessorImpl_klass(); 3186 UNSAFESTATICFIELDACCESSORIMPL_FIELDS_DO(FIELD_COMPUTE_OFFSET); 3187 } 3188 3189 #if INCLUDE_CDS 3190 void reflect_UnsafeStaticFieldAccessorImpl::serialize_offsets(SerializeClosure* f) { 3191 UNSAFESTATICFIELDACCESSORIMPL_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 3192 } 3193 #endif 3194 3195 oop java_lang_boxing_object::initialize_and_allocate(BasicType type, TRAPS) { 3196 Klass* k = SystemDictionary::box_klass(type); 3197 if (k == NULL) return NULL; 3198 InstanceKlass* ik = InstanceKlass::cast(k); 3199 if (!ik->is_initialized()) ik->initialize(CHECK_0); 3200 return ik->allocate_instance(THREAD); 3201 } 3202 3203 3204 oop java_lang_boxing_object::create(BasicType type, jvalue* value, TRAPS) { 3205 oop box = initialize_and_allocate(type, CHECK_0); 3206 if (box == NULL) return NULL; 3207 switch (type) { 3208 case T_BOOLEAN: 3209 box->bool_field_put(value_offset, value->z); 3210 break; 3211 case T_CHAR: 3212 box->char_field_put(value_offset, value->c); 3213 break; 3214 case T_FLOAT: 3215 box->float_field_put(value_offset, value->f); 3216 break; 3217 case T_DOUBLE: 3218 box->double_field_put(long_value_offset, value->d); 3219 break; 3220 case T_BYTE: 3221 box->byte_field_put(value_offset, value->b); 3222 break; 3223 case T_SHORT: 3224 box->short_field_put(value_offset, value->s); 3225 break; 3226 case T_INT: 3227 box->int_field_put(value_offset, value->i); 3228 break; 3229 case T_LONG: 3230 box->long_field_put(long_value_offset, value->j); 3231 break; 3232 default: 3233 return NULL; 3234 } 3235 return box; 3236 } 3237 3238 3239 BasicType java_lang_boxing_object::basic_type(oop box) { 3240 if (box == NULL) return T_ILLEGAL; 3241 BasicType type = SystemDictionary::box_klass_type(box->klass()); 3242 if (type == T_OBJECT) // 'unknown' value returned by SD::bkt 3243 return T_ILLEGAL; 3244 return type; 3245 } 3246 3247 3248 BasicType java_lang_boxing_object::get_value(oop box, jvalue* value) { 3249 BasicType type = SystemDictionary::box_klass_type(box->klass()); 3250 switch (type) { 3251 case T_BOOLEAN: 3252 value->z = box->bool_field(value_offset); 3253 break; 3254 case T_CHAR: 3255 value->c = box->char_field(value_offset); 3256 break; 3257 case T_FLOAT: 3258 value->f = box->float_field(value_offset); 3259 break; 3260 case T_DOUBLE: 3261 value->d = box->double_field(long_value_offset); 3262 break; 3263 case T_BYTE: 3264 value->b = box->byte_field(value_offset); 3265 break; 3266 case T_SHORT: 3267 value->s = box->short_field(value_offset); 3268 break; 3269 case T_INT: 3270 value->i = box->int_field(value_offset); 3271 break; 3272 case T_LONG: 3273 value->j = box->long_field(long_value_offset); 3274 break; 3275 default: 3276 return T_ILLEGAL; 3277 } // end switch 3278 return type; 3279 } 3280 3281 3282 BasicType java_lang_boxing_object::set_value(oop box, jvalue* value) { 3283 BasicType type = SystemDictionary::box_klass_type(box->klass()); 3284 switch (type) { 3285 case T_BOOLEAN: 3286 box->bool_field_put(value_offset, value->z); 3287 break; 3288 case T_CHAR: 3289 box->char_field_put(value_offset, value->c); 3290 break; 3291 case T_FLOAT: 3292 box->float_field_put(value_offset, value->f); 3293 break; 3294 case T_DOUBLE: 3295 box->double_field_put(long_value_offset, value->d); 3296 break; 3297 case T_BYTE: 3298 box->byte_field_put(value_offset, value->b); 3299 break; 3300 case T_SHORT: 3301 box->short_field_put(value_offset, value->s); 3302 break; 3303 case T_INT: 3304 box->int_field_put(value_offset, value->i); 3305 break; 3306 case T_LONG: 3307 box->long_field_put(long_value_offset, value->j); 3308 break; 3309 default: 3310 return T_ILLEGAL; 3311 } // end switch 3312 return type; 3313 } 3314 3315 3316 void java_lang_boxing_object::print(BasicType type, jvalue* value, outputStream* st) { 3317 switch (type) { 3318 case T_BOOLEAN: st->print("%s", value->z ? "true" : "false"); break; 3319 case T_CHAR: st->print("%d", value->c); break; 3320 case T_BYTE: st->print("%d", value->b); break; 3321 case T_SHORT: st->print("%d", value->s); break; 3322 case T_INT: st->print("%d", value->i); break; 3323 case T_LONG: st->print(JLONG_FORMAT, value->j); break; 3324 case T_FLOAT: st->print("%f", value->f); break; 3325 case T_DOUBLE: st->print("%lf", value->d); break; 3326 default: st->print("type %d?", type); break; 3327 } 3328 } 3329 3330 // Support for java_lang_ref_Reference 3331 3332 bool java_lang_ref_Reference::is_referent_field(oop obj, ptrdiff_t offset) { 3333 assert(obj != NULL, "sanity"); 3334 if (offset != java_lang_ref_Reference::referent_offset) { 3335 return false; 3336 } 3337 3338 Klass* k = obj->klass(); 3339 if (!k->is_instance_klass()) { 3340 return false; 3341 } 3342 3343 InstanceKlass* ik = InstanceKlass::cast(obj->klass()); 3344 bool is_reference = ik->reference_type() != REF_NONE; 3345 assert(!is_reference || ik->is_subclass_of(SystemDictionary::Reference_klass()), "sanity"); 3346 return is_reference; 3347 } 3348 3349 // Support for java_lang_ref_SoftReference 3350 // 3351 3352 #define SOFTREFERENCE_FIELDS_DO(macro) \ 3353 macro(timestamp_offset, k, "timestamp", long_signature, false); \ 3354 macro(static_clock_offset, k, "clock", long_signature, true) 3355 3356 void java_lang_ref_SoftReference::compute_offsets() { 3357 InstanceKlass* k = SystemDictionary::SoftReference_klass(); 3358 SOFTREFERENCE_FIELDS_DO(FIELD_COMPUTE_OFFSET); 3359 } 3360 3361 #if INCLUDE_CDS 3362 void java_lang_ref_SoftReference::serialize_offsets(SerializeClosure* f) { 3363 SOFTREFERENCE_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 3364 } 3365 #endif 3366 3367 jlong java_lang_ref_SoftReference::timestamp(oop ref) { 3368 return ref->long_field(timestamp_offset); 3369 } 3370 3371 jlong java_lang_ref_SoftReference::clock() { 3372 InstanceKlass* ik = SystemDictionary::SoftReference_klass(); 3373 oop base = ik->static_field_base_raw(); 3374 return base->long_field(static_clock_offset); 3375 } 3376 3377 void java_lang_ref_SoftReference::set_clock(jlong value) { 3378 InstanceKlass* ik = SystemDictionary::SoftReference_klass(); 3379 oop base = ik->static_field_base_raw(); 3380 base->long_field_put(static_clock_offset, value); 3381 } 3382 3383 // Support for java_lang_invoke_DirectMethodHandle 3384 3385 int java_lang_invoke_DirectMethodHandle::_member_offset; 3386 3387 oop java_lang_invoke_DirectMethodHandle::member(oop dmh) { 3388 oop member_name = NULL; 3389 assert(oopDesc::is_oop(dmh) && java_lang_invoke_DirectMethodHandle::is_instance(dmh), 3390 "a DirectMethodHandle oop is expected"); 3391 return dmh->obj_field(member_offset_in_bytes()); 3392 } 3393 3394 #define DIRECTMETHODHANDLE_FIELDS_DO(macro) \ 3395 macro(_member_offset, k, "member", java_lang_invoke_MemberName_signature, false) 3396 3397 void java_lang_invoke_DirectMethodHandle::compute_offsets() { 3398 InstanceKlass* k = SystemDictionary::DirectMethodHandle_klass(); 3399 DIRECTMETHODHANDLE_FIELDS_DO(FIELD_COMPUTE_OFFSET); 3400 } 3401 3402 #if INCLUDE_CDS 3403 void java_lang_invoke_DirectMethodHandle::serialize_offsets(SerializeClosure* f) { 3404 DIRECTMETHODHANDLE_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 3405 } 3406 #endif 3407 3408 // Support for java_lang_invoke_MethodHandle 3409 3410 int java_lang_invoke_MethodHandle::_type_offset; 3411 int java_lang_invoke_MethodHandle::_form_offset; 3412 3413 int java_lang_invoke_MemberName::_clazz_offset; 3414 int java_lang_invoke_MemberName::_name_offset; 3415 int java_lang_invoke_MemberName::_type_offset; 3416 int java_lang_invoke_MemberName::_flags_offset; 3417 int java_lang_invoke_MemberName::_method_offset; 3418 int java_lang_invoke_MemberName::_vmindex_offset; 3419 3420 int java_lang_invoke_ResolvedMethodName::_vmtarget_offset; 3421 int java_lang_invoke_ResolvedMethodName::_vmholder_offset; 3422 3423 int java_lang_invoke_LambdaForm::_vmentry_offset; 3424 3425 #define METHODHANDLE_FIELDS_DO(macro) \ 3426 macro(_type_offset, k, vmSymbols::type_name(), java_lang_invoke_MethodType_signature, false); \ 3427 macro(_form_offset, k, "form", java_lang_invoke_LambdaForm_signature, false) 3428 3429 void java_lang_invoke_MethodHandle::compute_offsets() { 3430 InstanceKlass* k = SystemDictionary::MethodHandle_klass(); 3431 METHODHANDLE_FIELDS_DO(FIELD_COMPUTE_OFFSET); 3432 } 3433 3434 #if INCLUDE_CDS 3435 void java_lang_invoke_MethodHandle::serialize_offsets(SerializeClosure* f) { 3436 METHODHANDLE_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 3437 } 3438 #endif 3439 3440 #define MEMBERNAME_FIELDS_DO(macro) \ 3441 macro(_clazz_offset, k, vmSymbols::clazz_name(), class_signature, false); \ 3442 macro(_name_offset, k, vmSymbols::name_name(), string_signature, false); \ 3443 macro(_type_offset, k, vmSymbols::type_name(), object_signature, false); \ 3444 macro(_flags_offset, k, vmSymbols::flags_name(), int_signature, false); \ 3445 macro(_method_offset, k, vmSymbols::method_name(), java_lang_invoke_ResolvedMethodName_signature, false) 3446 3447 void java_lang_invoke_MemberName::compute_offsets() { 3448 InstanceKlass* k = SystemDictionary::MemberName_klass(); 3449 MEMBERNAME_FIELDS_DO(FIELD_COMPUTE_OFFSET); 3450 MEMBERNAME_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET); 3451 } 3452 3453 #if INCLUDE_CDS 3454 void java_lang_invoke_MemberName::serialize_offsets(SerializeClosure* f) { 3455 MEMBERNAME_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 3456 MEMBERNAME_INJECTED_FIELDS(INJECTED_FIELD_SERIALIZE_OFFSET); 3457 } 3458 #endif 3459 3460 void java_lang_invoke_ResolvedMethodName::compute_offsets() { 3461 InstanceKlass* k = SystemDictionary::ResolvedMethodName_klass(); 3462 assert(k != NULL, "jdk mismatch"); 3463 RESOLVEDMETHOD_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET); 3464 } 3465 3466 #if INCLUDE_CDS 3467 void java_lang_invoke_ResolvedMethodName::serialize_offsets(SerializeClosure* f) { 3468 RESOLVEDMETHOD_INJECTED_FIELDS(INJECTED_FIELD_SERIALIZE_OFFSET); 3469 } 3470 #endif 3471 3472 #define LAMBDAFORM_FIELDS_DO(macro) \ 3473 macro(_vmentry_offset, k, "vmentry", java_lang_invoke_MemberName_signature, false) 3474 3475 void java_lang_invoke_LambdaForm::compute_offsets() { 3476 InstanceKlass* k = SystemDictionary::LambdaForm_klass(); 3477 assert (k != NULL, "jdk mismatch"); 3478 LAMBDAFORM_FIELDS_DO(FIELD_COMPUTE_OFFSET); 3479 } 3480 3481 #if INCLUDE_CDS 3482 void java_lang_invoke_LambdaForm::serialize_offsets(SerializeClosure* f) { 3483 LAMBDAFORM_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 3484 } 3485 #endif 3486 3487 bool java_lang_invoke_LambdaForm::is_instance(oop obj) { 3488 return obj != NULL && is_subclass(obj->klass()); 3489 } 3490 3491 3492 oop java_lang_invoke_MethodHandle::type(oop mh) { 3493 return mh->obj_field(_type_offset); 3494 } 3495 3496 void java_lang_invoke_MethodHandle::set_type(oop mh, oop mtype) { 3497 mh->obj_field_put(_type_offset, mtype); 3498 } 3499 3500 oop java_lang_invoke_MethodHandle::form(oop mh) { 3501 assert(_form_offset != 0, ""); 3502 return mh->obj_field(_form_offset); 3503 } 3504 3505 void java_lang_invoke_MethodHandle::set_form(oop mh, oop lform) { 3506 assert(_form_offset != 0, ""); 3507 mh->obj_field_put(_form_offset, lform); 3508 } 3509 3510 /// MemberName accessors 3511 3512 oop java_lang_invoke_MemberName::clazz(oop mname) { 3513 assert(is_instance(mname), "wrong type"); 3514 return mname->obj_field(_clazz_offset); 3515 } 3516 3517 void java_lang_invoke_MemberName::set_clazz(oop mname, oop clazz) { 3518 assert(is_instance(mname), "wrong type"); 3519 mname->obj_field_put(_clazz_offset, clazz); 3520 } 3521 3522 oop java_lang_invoke_MemberName::name(oop mname) { 3523 assert(is_instance(mname), "wrong type"); 3524 return mname->obj_field(_name_offset); 3525 } 3526 3527 void java_lang_invoke_MemberName::set_name(oop mname, oop name) { 3528 assert(is_instance(mname), "wrong type"); 3529 mname->obj_field_put(_name_offset, name); 3530 } 3531 3532 oop java_lang_invoke_MemberName::type(oop mname) { 3533 assert(is_instance(mname), "wrong type"); 3534 return mname->obj_field(_type_offset); 3535 } 3536 3537 void java_lang_invoke_MemberName::set_type(oop mname, oop type) { 3538 assert(is_instance(mname), "wrong type"); 3539 mname->obj_field_put(_type_offset, type); 3540 } 3541 3542 int java_lang_invoke_MemberName::flags(oop mname) { 3543 assert(is_instance(mname), "wrong type"); 3544 return mname->int_field(_flags_offset); 3545 } 3546 3547 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) { 3548 assert(is_instance(mname), "wrong type"); 3549 mname->int_field_put(_flags_offset, flags); 3550 } 3551 3552 3553 // Return vmtarget from ResolvedMethodName method field through indirection 3554 Method* java_lang_invoke_MemberName::vmtarget(oop mname) { 3555 assert(is_instance(mname), "wrong type"); 3556 oop method = mname->obj_field(_method_offset); 3557 return method == NULL ? NULL : java_lang_invoke_ResolvedMethodName::vmtarget(method); 3558 } 3559 3560 bool java_lang_invoke_MemberName::is_method(oop mname) { 3561 assert(is_instance(mname), "must be MemberName"); 3562 return (flags(mname) & (MN_IS_METHOD | MN_IS_CONSTRUCTOR)) > 0; 3563 } 3564 3565 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) { 3566 assert(is_instance(mname), "wrong type"); 3567 mname->obj_field_put(_method_offset, resolved_method); 3568 } 3569 3570 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) { 3571 assert(is_instance(mname), "wrong type"); 3572 return (intptr_t) mname->address_field(_vmindex_offset); 3573 } 3574 3575 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) { 3576 assert(is_instance(mname), "wrong type"); 3577 mname->address_field_put(_vmindex_offset, (address) index); 3578 } 3579 3580 3581 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) { 3582 assert(is_instance(resolved_method), "wrong type"); 3583 Method* m = (Method*)resolved_method->address_field(_vmtarget_offset); 3584 assert(m->is_method(), "must be"); 3585 return m; 3586 } 3587 3588 // Used by redefinition to change Method* to new Method* with same hash (name, signature) 3589 void java_lang_invoke_ResolvedMethodName::set_vmtarget(oop resolved_method, Method* m) { 3590 assert(is_instance(resolved_method), "wrong type"); 3591 resolved_method->address_field_put(_vmtarget_offset, (address)m); 3592 } 3593 3594 oop java_lang_invoke_ResolvedMethodName::find_resolved_method(const methodHandle& m, TRAPS) { 3595 // lookup ResolvedMethod oop in the table, or create a new one and intern it 3596 oop resolved_method = ResolvedMethodTable::find_method(m()); 3597 if (resolved_method == NULL) { 3598 InstanceKlass* k = SystemDictionary::ResolvedMethodName_klass(); 3599 if (!k->is_initialized()) { 3600 k->initialize(CHECK_NULL); 3601 } 3602 oop new_resolved_method = k->allocate_instance(CHECK_NULL); 3603 new_resolved_method->address_field_put(_vmtarget_offset, (address)m()); 3604 // Add a reference to the loader (actually mirror because unsafe anonymous classes will not have 3605 // distinct loaders) to ensure the metadata is kept alive. 3606 // This mirror may be different than the one in clazz field. 3607 new_resolved_method->obj_field_put(_vmholder_offset, m->method_holder()->java_mirror()); 3608 resolved_method = ResolvedMethodTable::add_method(Handle(THREAD, new_resolved_method)); 3609 } 3610 return resolved_method; 3611 } 3612 3613 oop java_lang_invoke_LambdaForm::vmentry(oop lform) { 3614 assert(is_instance(lform), "wrong type"); 3615 return lform->obj_field(_vmentry_offset); 3616 } 3617 3618 3619 // Support for java_lang_invoke_MethodType 3620 3621 int java_lang_invoke_MethodType::_rtype_offset; 3622 int java_lang_invoke_MethodType::_ptypes_offset; 3623 3624 #define METHODTYPE_FIELDS_DO(macro) \ 3625 macro(_rtype_offset, k, "rtype", class_signature, false); \ 3626 macro(_ptypes_offset, k, "ptypes", class_array_signature, false) 3627 3628 void java_lang_invoke_MethodType::compute_offsets() { 3629 InstanceKlass* k = SystemDictionary::MethodType_klass(); 3630 METHODTYPE_FIELDS_DO(FIELD_COMPUTE_OFFSET); 3631 } 3632 3633 #if INCLUDE_CDS 3634 void java_lang_invoke_MethodType::serialize_offsets(SerializeClosure* f) { 3635 METHODTYPE_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 3636 } 3637 #endif 3638 3639 void java_lang_invoke_MethodType::print_signature(oop mt, outputStream* st) { 3640 st->print("("); 3641 objArrayOop pts = ptypes(mt); 3642 for (int i = 0, limit = pts->length(); i < limit; i++) { 3643 java_lang_Class::print_signature(pts->obj_at(i), st); 3644 } 3645 st->print(")"); 3646 java_lang_Class::print_signature(rtype(mt), st); 3647 } 3648 3649 Symbol* java_lang_invoke_MethodType::as_signature(oop mt, bool intern_if_not_found, TRAPS) { 3650 ResourceMark rm; 3651 stringStream buffer(128); 3652 print_signature(mt, &buffer); 3653 const char* sigstr = buffer.base(); 3654 int siglen = (int) buffer.size(); 3655 Symbol *name; 3656 if (!intern_if_not_found) { 3657 name = SymbolTable::probe(sigstr, siglen); 3658 } else { 3659 name = SymbolTable::new_symbol(sigstr, siglen, THREAD); 3660 } 3661 return name; 3662 } 3663 3664 bool java_lang_invoke_MethodType::equals(oop mt1, oop mt2) { 3665 if (oopDesc::equals(mt1, mt2)) 3666 return true; 3667 if (!oopDesc::equals(rtype(mt1), rtype(mt2))) 3668 return false; 3669 if (ptype_count(mt1) != ptype_count(mt2)) 3670 return false; 3671 for (int i = ptype_count(mt1) - 1; i >= 0; i--) { 3672 if (!oopDesc::equals(ptype(mt1, i), ptype(mt2, i))) 3673 return false; 3674 } 3675 return true; 3676 } 3677 3678 oop java_lang_invoke_MethodType::rtype(oop mt) { 3679 assert(is_instance(mt), "must be a MethodType"); 3680 return mt->obj_field(_rtype_offset); 3681 } 3682 3683 objArrayOop java_lang_invoke_MethodType::ptypes(oop mt) { 3684 assert(is_instance(mt), "must be a MethodType"); 3685 return (objArrayOop) mt->obj_field(_ptypes_offset); 3686 } 3687 3688 oop java_lang_invoke_MethodType::ptype(oop mt, int idx) { 3689 return ptypes(mt)->obj_at(idx); 3690 } 3691 3692 int java_lang_invoke_MethodType::ptype_count(oop mt) { 3693 return ptypes(mt)->length(); 3694 } 3695 3696 int java_lang_invoke_MethodType::ptype_slot_count(oop mt) { 3697 objArrayOop pts = ptypes(mt); 3698 int count = pts->length(); 3699 int slots = 0; 3700 for (int i = 0; i < count; i++) { 3701 BasicType bt = java_lang_Class::as_BasicType(pts->obj_at(i)); 3702 slots += type2size[bt]; 3703 } 3704 return slots; 3705 } 3706 3707 int java_lang_invoke_MethodType::rtype_slot_count(oop mt) { 3708 BasicType bt = java_lang_Class::as_BasicType(rtype(mt)); 3709 return type2size[bt]; 3710 } 3711 3712 3713 // Support for java_lang_invoke_CallSite 3714 3715 int java_lang_invoke_CallSite::_target_offset; 3716 int java_lang_invoke_CallSite::_context_offset; 3717 3718 #define CALLSITE_FIELDS_DO(macro) \ 3719 macro(_target_offset, k, "target", java_lang_invoke_MethodHandle_signature, false); \ 3720 macro(_context_offset, k, "context", java_lang_invoke_MethodHandleNatives_CallSiteContext_signature, false) 3721 3722 void java_lang_invoke_CallSite::compute_offsets() { 3723 InstanceKlass* k = SystemDictionary::CallSite_klass(); 3724 CALLSITE_FIELDS_DO(FIELD_COMPUTE_OFFSET); 3725 } 3726 3727 #if INCLUDE_CDS 3728 void java_lang_invoke_CallSite::serialize_offsets(SerializeClosure* f) { 3729 CALLSITE_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 3730 } 3731 #endif 3732 3733 oop java_lang_invoke_CallSite::context_no_keepalive(oop call_site) { 3734 assert(java_lang_invoke_CallSite::is_instance(call_site), ""); 3735 3736 oop dep_oop = call_site->obj_field_access<AS_NO_KEEPALIVE>(_context_offset); 3737 return dep_oop; 3738 } 3739 3740 // Support for java_lang_invoke_MethodHandleNatives_CallSiteContext 3741 3742 int java_lang_invoke_MethodHandleNatives_CallSiteContext::_vmdependencies_offset; 3743 int java_lang_invoke_MethodHandleNatives_CallSiteContext::_last_cleanup_offset; 3744 3745 void java_lang_invoke_MethodHandleNatives_CallSiteContext::compute_offsets() { 3746 InstanceKlass* k = SystemDictionary::Context_klass(); 3747 CALLSITECONTEXT_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET); 3748 } 3749 3750 #if INCLUDE_CDS 3751 void java_lang_invoke_MethodHandleNatives_CallSiteContext::serialize_offsets(SerializeClosure* f) { 3752 CALLSITECONTEXT_INJECTED_FIELDS(INJECTED_FIELD_SERIALIZE_OFFSET); 3753 } 3754 #endif 3755 3756 DependencyContext java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(oop call_site) { 3757 assert(java_lang_invoke_MethodHandleNatives_CallSiteContext::is_instance(call_site), ""); 3758 nmethodBucket* volatile* vmdeps_addr = (nmethodBucket* volatile*)call_site->field_addr(_vmdependencies_offset); 3759 volatile uint64_t* last_cleanup_addr = (volatile uint64_t*)call_site->field_addr(_last_cleanup_offset); 3760 DependencyContext dep_ctx(vmdeps_addr, last_cleanup_addr); 3761 return dep_ctx; 3762 } 3763 3764 // Support for java_security_AccessControlContext 3765 3766 int java_security_AccessControlContext::_context_offset = 0; 3767 int java_security_AccessControlContext::_privilegedContext_offset = 0; 3768 int java_security_AccessControlContext::_isPrivileged_offset = 0; 3769 int java_security_AccessControlContext::_isAuthorized_offset = -1; 3770 3771 #define ACCESSCONTROLCONTEXT_FIELDS_DO(macro) \ 3772 macro(_context_offset, k, "context", protectiondomain_signature, false); \ 3773 macro(_privilegedContext_offset, k, "privilegedContext", accesscontrolcontext_signature, false); \ 3774 macro(_isPrivileged_offset, k, "isPrivileged", bool_signature, false); \ 3775 macro(_isAuthorized_offset, k, "isAuthorized", bool_signature, false) 3776 3777 void java_security_AccessControlContext::compute_offsets() { 3778 assert(_isPrivileged_offset == 0, "offsets should be initialized only once"); 3779 InstanceKlass* k = SystemDictionary::AccessControlContext_klass(); 3780 ACCESSCONTROLCONTEXT_FIELDS_DO(FIELD_COMPUTE_OFFSET); 3781 } 3782 3783 #if INCLUDE_CDS 3784 void java_security_AccessControlContext::serialize_offsets(SerializeClosure* f) { 3785 ACCESSCONTROLCONTEXT_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 3786 } 3787 #endif 3788 3789 oop java_security_AccessControlContext::create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS) { 3790 assert(_isPrivileged_offset != 0, "offsets should have been initialized"); 3791 // Ensure klass is initialized 3792 SystemDictionary::AccessControlContext_klass()->initialize(CHECK_0); 3793 // Allocate result 3794 oop result = SystemDictionary::AccessControlContext_klass()->allocate_instance(CHECK_0); 3795 // Fill in values 3796 result->obj_field_put(_context_offset, context()); 3797 result->obj_field_put(_privilegedContext_offset, privileged_context()); 3798 result->bool_field_put(_isPrivileged_offset, isPrivileged); 3799 // whitelist AccessControlContexts created by the JVM if present 3800 if (_isAuthorized_offset != -1) { 3801 result->bool_field_put(_isAuthorized_offset, true); 3802 } 3803 return result; 3804 } 3805 3806 3807 // Support for java_lang_ClassLoader 3808 3809 bool java_lang_ClassLoader::offsets_computed = false; 3810 int java_lang_ClassLoader::_loader_data_offset = -1; 3811 int java_lang_ClassLoader::parallelCapable_offset = -1; 3812 int java_lang_ClassLoader::name_offset = -1; 3813 int java_lang_ClassLoader::nameAndId_offset = -1; 3814 int java_lang_ClassLoader::unnamedModule_offset = -1; 3815 3816 ClassLoaderData* java_lang_ClassLoader::loader_data_acquire(oop loader) { 3817 assert(loader != NULL && oopDesc::is_oop(loader), "loader must be oop"); 3818 return HeapAccess<MO_ACQUIRE>::load_at(loader, _loader_data_offset); 3819 } 3820 3821 ClassLoaderData* java_lang_ClassLoader::loader_data_raw(oop loader) { 3822 assert(loader != NULL && oopDesc::is_oop(loader), "loader must be oop"); 3823 return RawAccess<>::load_at(loader, _loader_data_offset); 3824 } 3825 3826 void java_lang_ClassLoader::release_set_loader_data(oop loader, ClassLoaderData* new_data) { 3827 assert(loader != NULL && oopDesc::is_oop(loader), "loader must be oop"); 3828 HeapAccess<MO_RELEASE>::store_at(loader, _loader_data_offset, new_data); 3829 } 3830 3831 #define CLASSLOADER_FIELDS_DO(macro) \ 3832 macro(parallelCapable_offset, k1, "parallelLockMap", concurrenthashmap_signature, false); \ 3833 macro(name_offset, k1, vmSymbols::name_name(), string_signature, false); \ 3834 macro(nameAndId_offset, k1, "nameAndId", string_signature, false); \ 3835 macro(unnamedModule_offset, k1, "unnamedModule", module_signature, false); \ 3836 macro(parent_offset, k1, "parent", classloader_signature, false) 3837 3838 void java_lang_ClassLoader::compute_offsets() { 3839 assert(!offsets_computed, "offsets should be initialized only once"); 3840 offsets_computed = true; 3841 3842 InstanceKlass* k1 = SystemDictionary::ClassLoader_klass(); 3843 CLASSLOADER_FIELDS_DO(FIELD_COMPUTE_OFFSET); 3844 3845 CLASSLOADER_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET); 3846 } 3847 3848 #if INCLUDE_CDS 3849 void java_lang_ClassLoader::serialize_offsets(SerializeClosure* f) { 3850 CLASSLOADER_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 3851 CLASSLOADER_INJECTED_FIELDS(INJECTED_FIELD_SERIALIZE_OFFSET); 3852 } 3853 #endif 3854 3855 oop java_lang_ClassLoader::parent(oop loader) { 3856 assert(is_instance(loader), "loader must be oop"); 3857 return loader->obj_field(parent_offset); 3858 } 3859 3860 // Returns the name field of this class loader. If the name field has not 3861 // been set, null will be returned. 3862 oop java_lang_ClassLoader::name(oop loader) { 3863 assert(is_instance(loader), "loader must be oop"); 3864 return loader->obj_field(name_offset); 3865 } 3866 3867 // Returns the nameAndId field of this class loader. The format is 3868 // as follows: 3869 // If the defining loader has a name explicitly set then '<loader-name>' @<id> 3870 // If the defining loader has no name then <qualified-class-name> @<id> 3871 // If built-in loader, then omit '@<id>' as there is only one instance. 3872 // Use ClassLoader::loader_name_id() to obtain this String as a char*. 3873 oop java_lang_ClassLoader::nameAndId(oop loader) { 3874 assert(is_instance(loader), "loader must be oop"); 3875 return loader->obj_field(nameAndId_offset); 3876 } 3877 3878 bool java_lang_ClassLoader::isAncestor(oop loader, oop cl) { 3879 assert(is_instance(loader), "loader must be oop"); 3880 assert(cl == NULL || is_instance(cl), "cl argument must be oop"); 3881 oop acl = loader; 3882 debug_only(jint loop_count = 0); 3883 // This loop taken verbatim from ClassLoader.java: 3884 do { 3885 acl = parent(acl); 3886 if (oopDesc::equals(cl, acl)) { 3887 return true; 3888 } 3889 assert(++loop_count > 0, "loop_count overflow"); 3890 } while (acl != NULL); 3891 return false; 3892 } 3893 3894 bool java_lang_ClassLoader::is_instance(oop obj) { 3895 return obj != NULL && is_subclass(obj->klass()); 3896 } 3897 3898 3899 // For class loader classes, parallelCapable defined 3900 // based on non-null field 3901 // Written to by java.lang.ClassLoader, vm only reads this field, doesn't set it 3902 bool java_lang_ClassLoader::parallelCapable(oop class_loader) { 3903 if (parallelCapable_offset == -1) { 3904 // Default for backward compatibility is false 3905 return false; 3906 } 3907 return (class_loader->obj_field(parallelCapable_offset) != NULL); 3908 } 3909 3910 bool java_lang_ClassLoader::is_trusted_loader(oop loader) { 3911 // Fix for 4474172; see evaluation for more details 3912 loader = non_reflection_class_loader(loader); 3913 3914 oop cl = SystemDictionary::java_system_loader(); 3915 while(cl != NULL) { 3916 if (oopDesc::equals(cl, loader)) return true; 3917 cl = parent(cl); 3918 } 3919 return false; 3920 } 3921 3922 // Return true if this is one of the class loaders associated with 3923 // the generated bytecodes for reflection. 3924 bool java_lang_ClassLoader::is_reflection_class_loader(oop loader) { 3925 if (loader != NULL) { 3926 Klass* delegating_cl_class = SystemDictionary::reflect_DelegatingClassLoader_klass(); 3927 // This might be null in non-1.4 JDKs 3928 return (delegating_cl_class != NULL && loader->is_a(delegating_cl_class)); 3929 } 3930 return false; 3931 } 3932 3933 oop java_lang_ClassLoader::non_reflection_class_loader(oop loader) { 3934 // See whether this is one of the class loaders associated with 3935 // the generated bytecodes for reflection, and if so, "magically" 3936 // delegate to its parent to prevent class loading from occurring 3937 // in places where applications using reflection didn't expect it. 3938 if (is_reflection_class_loader(loader)) { 3939 return parent(loader); 3940 } 3941 return loader; 3942 } 3943 3944 oop java_lang_ClassLoader::unnamedModule(oop loader) { 3945 assert(is_instance(loader), "loader must be oop"); 3946 return loader->obj_field(unnamedModule_offset); 3947 } 3948 3949 // Support for java_lang_System 3950 // 3951 #define SYSTEM_FIELDS_DO(macro) \ 3952 macro(static_in_offset, k, "in", input_stream_signature, true); \ 3953 macro(static_out_offset, k, "out", print_stream_signature, true); \ 3954 macro(static_err_offset, k, "err", print_stream_signature, true); \ 3955 macro(static_security_offset, k, "security", security_manager_signature, true) 3956 3957 void java_lang_System::compute_offsets() { 3958 InstanceKlass* k = SystemDictionary::System_klass(); 3959 SYSTEM_FIELDS_DO(FIELD_COMPUTE_OFFSET); 3960 } 3961 3962 #if INCLUDE_CDS 3963 void java_lang_System::serialize_offsets(SerializeClosure* f) { 3964 SYSTEM_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 3965 } 3966 #endif 3967 3968 int java_lang_System::in_offset_in_bytes() { return static_in_offset; } 3969 int java_lang_System::out_offset_in_bytes() { return static_out_offset; } 3970 int java_lang_System::err_offset_in_bytes() { return static_err_offset; } 3971 3972 int java_lang_Class::_klass_offset; 3973 int java_lang_Class::_array_klass_offset; 3974 int java_lang_Class::_oop_size_offset; 3975 int java_lang_Class::_static_oop_field_count_offset; 3976 int java_lang_Class::_class_loader_offset; 3977 int java_lang_Class::_module_offset; 3978 int java_lang_Class::_protection_domain_offset; 3979 int java_lang_Class::_component_mirror_offset; 3980 int java_lang_Class::_init_lock_offset; 3981 int java_lang_Class::_signers_offset; 3982 int java_lang_Class::_name_offset; 3983 GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL; 3984 GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = NULL; 3985 int java_lang_Throwable::backtrace_offset; 3986 int java_lang_Throwable::detailMessage_offset; 3987 int java_lang_Throwable::stackTrace_offset; 3988 int java_lang_Throwable::depth_offset; 3989 int java_lang_Throwable::static_unassigned_stacktrace_offset; 3990 int java_lang_reflect_AccessibleObject::override_offset; 3991 int java_lang_reflect_Method::clazz_offset; 3992 int java_lang_reflect_Method::name_offset; 3993 int java_lang_reflect_Method::returnType_offset; 3994 int java_lang_reflect_Method::parameterTypes_offset; 3995 int java_lang_reflect_Method::exceptionTypes_offset; 3996 int java_lang_reflect_Method::slot_offset; 3997 int java_lang_reflect_Method::modifiers_offset; 3998 int java_lang_reflect_Method::signature_offset; 3999 int java_lang_reflect_Method::annotations_offset; 4000 int java_lang_reflect_Method::parameter_annotations_offset; 4001 int java_lang_reflect_Method::annotation_default_offset; 4002 int java_lang_reflect_Constructor::clazz_offset; 4003 int java_lang_reflect_Constructor::parameterTypes_offset; 4004 int java_lang_reflect_Constructor::exceptionTypes_offset; 4005 int java_lang_reflect_Constructor::slot_offset; 4006 int java_lang_reflect_Constructor::modifiers_offset; 4007 int java_lang_reflect_Constructor::signature_offset; 4008 int java_lang_reflect_Constructor::annotations_offset; 4009 int java_lang_reflect_Constructor::parameter_annotations_offset; 4010 int java_lang_reflect_Field::clazz_offset; 4011 int java_lang_reflect_Field::name_offset; 4012 int java_lang_reflect_Field::type_offset; 4013 int java_lang_reflect_Field::slot_offset; 4014 int java_lang_reflect_Field::modifiers_offset; 4015 int java_lang_reflect_Field::signature_offset; 4016 int java_lang_reflect_Field::annotations_offset; 4017 int java_lang_reflect_Parameter::name_offset; 4018 int java_lang_reflect_Parameter::modifiers_offset; 4019 int java_lang_reflect_Parameter::index_offset; 4020 int java_lang_reflect_Parameter::executable_offset; 4021 int java_lang_boxing_object::value_offset; 4022 int java_lang_boxing_object::long_value_offset; 4023 int java_lang_ref_Reference::referent_offset; 4024 int java_lang_ref_Reference::queue_offset; 4025 int java_lang_ref_Reference::next_offset; 4026 int java_lang_ref_Reference::discovered_offset; 4027 int java_lang_ref_SoftReference::timestamp_offset; 4028 int java_lang_ref_SoftReference::static_clock_offset; 4029 int java_lang_ClassLoader::parent_offset; 4030 int java_lang_System::static_in_offset; 4031 int java_lang_System::static_out_offset; 4032 int java_lang_System::static_err_offset; 4033 int java_lang_System::static_security_offset; 4034 int java_lang_StackTraceElement::methodName_offset; 4035 int java_lang_StackTraceElement::fileName_offset; 4036 int java_lang_StackTraceElement::lineNumber_offset; 4037 int java_lang_StackTraceElement::moduleName_offset; 4038 int java_lang_StackTraceElement::moduleVersion_offset; 4039 int java_lang_StackTraceElement::classLoaderName_offset; 4040 int java_lang_StackTraceElement::declaringClass_offset; 4041 int java_lang_StackTraceElement::declaringClassObject_offset; 4042 int java_lang_StackFrameInfo::_memberName_offset; 4043 int java_lang_StackFrameInfo::_bci_offset; 4044 int java_lang_StackFrameInfo::_version_offset; 4045 int java_lang_LiveStackFrameInfo::_monitors_offset; 4046 int java_lang_LiveStackFrameInfo::_locals_offset; 4047 int java_lang_LiveStackFrameInfo::_operands_offset; 4048 int java_lang_LiveStackFrameInfo::_mode_offset; 4049 int java_lang_AssertionStatusDirectives::classes_offset; 4050 int java_lang_AssertionStatusDirectives::classEnabled_offset; 4051 int java_lang_AssertionStatusDirectives::packages_offset; 4052 int java_lang_AssertionStatusDirectives::packageEnabled_offset; 4053 int java_lang_AssertionStatusDirectives::deflt_offset; 4054 int java_nio_Buffer::_limit_offset; 4055 int java_util_concurrent_locks_AbstractOwnableSynchronizer::_owner_offset; 4056 int reflect_ConstantPool::_oop_offset; 4057 int reflect_UnsafeStaticFieldAccessorImpl::_base_offset; 4058 4059 4060 #define STACKTRACEELEMENT_FIELDS_DO(macro) \ 4061 macro(declaringClassObject_offset, k, "declaringClassObject", class_signature, false); \ 4062 macro(classLoaderName_offset, k, "classLoaderName", string_signature, false); \ 4063 macro(moduleName_offset, k, "moduleName", string_signature, false); \ 4064 macro(moduleVersion_offset, k, "moduleVersion", string_signature, false); \ 4065 macro(declaringClass_offset, k, "declaringClass", string_signature, false); \ 4066 macro(methodName_offset, k, "methodName", string_signature, false); \ 4067 macro(fileName_offset, k, "fileName", string_signature, false); \ 4068 macro(lineNumber_offset, k, "lineNumber", int_signature, false) 4069 4070 // Support for java_lang_StackTraceElement 4071 void java_lang_StackTraceElement::compute_offsets() { 4072 InstanceKlass* k = SystemDictionary::StackTraceElement_klass(); 4073 STACKTRACEELEMENT_FIELDS_DO(FIELD_COMPUTE_OFFSET); 4074 } 4075 4076 #if INCLUDE_CDS 4077 void java_lang_StackTraceElement::serialize_offsets(SerializeClosure* f) { 4078 STACKTRACEELEMENT_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 4079 } 4080 #endif 4081 4082 void java_lang_StackTraceElement::set_fileName(oop element, oop value) { 4083 element->obj_field_put(fileName_offset, value); 4084 } 4085 4086 void java_lang_StackTraceElement::set_declaringClass(oop element, oop value) { 4087 element->obj_field_put(declaringClass_offset, value); 4088 } 4089 4090 void java_lang_StackTraceElement::set_methodName(oop element, oop value) { 4091 element->obj_field_put(methodName_offset, value); 4092 } 4093 4094 void java_lang_StackTraceElement::set_lineNumber(oop element, int value) { 4095 element->int_field_put(lineNumber_offset, value); 4096 } 4097 4098 void java_lang_StackTraceElement::set_moduleName(oop element, oop value) { 4099 element->obj_field_put(moduleName_offset, value); 4100 } 4101 4102 void java_lang_StackTraceElement::set_moduleVersion(oop element, oop value) { 4103 element->obj_field_put(moduleVersion_offset, value); 4104 } 4105 4106 void java_lang_StackTraceElement::set_classLoaderName(oop element, oop value) { 4107 element->obj_field_put(classLoaderName_offset, value); 4108 } 4109 4110 void java_lang_StackTraceElement::set_declaringClassObject(oop element, oop value) { 4111 element->obj_field_put(declaringClassObject_offset, value); 4112 } 4113 4114 void java_lang_StackFrameInfo::set_version(oop element, short value) { 4115 element->short_field_put(_version_offset, value); 4116 } 4117 4118 void java_lang_StackFrameInfo::set_bci(oop element, int value) { 4119 element->int_field_put(_bci_offset, value); 4120 } 4121 4122 void java_lang_LiveStackFrameInfo::set_monitors(oop element, oop value) { 4123 element->obj_field_put(_monitors_offset, value); 4124 } 4125 4126 void java_lang_LiveStackFrameInfo::set_locals(oop element, oop value) { 4127 element->obj_field_put(_locals_offset, value); 4128 } 4129 4130 void java_lang_LiveStackFrameInfo::set_operands(oop element, oop value) { 4131 element->obj_field_put(_operands_offset, value); 4132 } 4133 4134 void java_lang_LiveStackFrameInfo::set_mode(oop element, int value) { 4135 element->int_field_put(_mode_offset, value); 4136 } 4137 4138 // Support for java Assertions - java_lang_AssertionStatusDirectives. 4139 #define ASSERTIONSTATUSDIRECTIVES_FIELDS_DO(macro) \ 4140 macro(classes_offset, k, "classes", string_array_signature, false); \ 4141 macro(classEnabled_offset, k, "classEnabled", bool_array_signature, false); \ 4142 macro(packages_offset, k, "packages", string_array_signature, false); \ 4143 macro(packageEnabled_offset, k, "packageEnabled", bool_array_signature, false); \ 4144 macro(deflt_offset, k, "deflt", bool_signature, false) 4145 4146 void java_lang_AssertionStatusDirectives::compute_offsets() { 4147 InstanceKlass* k = SystemDictionary::AssertionStatusDirectives_klass(); 4148 ASSERTIONSTATUSDIRECTIVES_FIELDS_DO(FIELD_COMPUTE_OFFSET); 4149 } 4150 4151 #if INCLUDE_CDS 4152 void java_lang_AssertionStatusDirectives::serialize_offsets(SerializeClosure* f) { 4153 ASSERTIONSTATUSDIRECTIVES_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 4154 } 4155 #endif 4156 4157 void java_lang_AssertionStatusDirectives::set_classes(oop o, oop val) { 4158 o->obj_field_put(classes_offset, val); 4159 } 4160 4161 void java_lang_AssertionStatusDirectives::set_classEnabled(oop o, oop val) { 4162 o->obj_field_put(classEnabled_offset, val); 4163 } 4164 4165 void java_lang_AssertionStatusDirectives::set_packages(oop o, oop val) { 4166 o->obj_field_put(packages_offset, val); 4167 } 4168 4169 void java_lang_AssertionStatusDirectives::set_packageEnabled(oop o, oop val) { 4170 o->obj_field_put(packageEnabled_offset, val); 4171 } 4172 4173 void java_lang_AssertionStatusDirectives::set_deflt(oop o, bool val) { 4174 o->bool_field_put(deflt_offset, val); 4175 } 4176 4177 4178 // Support for intrinsification of java.nio.Buffer.checkIndex 4179 int java_nio_Buffer::limit_offset() { 4180 return _limit_offset; 4181 } 4182 4183 #define BUFFER_FIELDS_DO(macro) \ 4184 macro(_limit_offset, k, "limit", int_signature, false) 4185 4186 void java_nio_Buffer::compute_offsets() { 4187 InstanceKlass* k = SystemDictionary::nio_Buffer_klass(); 4188 assert(k != NULL, "must be loaded in 1.4+"); 4189 BUFFER_FIELDS_DO(FIELD_COMPUTE_OFFSET); 4190 } 4191 4192 #if INCLUDE_CDS 4193 void java_nio_Buffer::serialize_offsets(SerializeClosure* f) { 4194 BUFFER_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 4195 } 4196 #endif 4197 4198 #define AOS_FIELDS_DO(macro) \ 4199 macro(_owner_offset, k, "exclusiveOwnerThread", thread_signature, false) 4200 4201 void java_util_concurrent_locks_AbstractOwnableSynchronizer::compute_offsets() { 4202 InstanceKlass* k = SystemDictionary::java_util_concurrent_locks_AbstractOwnableSynchronizer_klass(); 4203 AOS_FIELDS_DO(FIELD_COMPUTE_OFFSET); 4204 } 4205 4206 oop java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(oop obj) { 4207 assert(_owner_offset != 0, "Must be initialized"); 4208 return obj->obj_field(_owner_offset); 4209 } 4210 4211 #if INCLUDE_CDS 4212 void java_util_concurrent_locks_AbstractOwnableSynchronizer::serialize_offsets(SerializeClosure* f) { 4213 AOS_FIELDS_DO(FIELD_SERIALIZE_OFFSET); 4214 } 4215 #endif 4216 4217 static int member_offset(int hardcoded_offset) { 4218 return (hardcoded_offset * heapOopSize) + instanceOopDesc::base_offset_in_bytes(); 4219 } 4220 4221 // Compute hard-coded offsets 4222 // Invoked before SystemDictionary::initialize, so pre-loaded classes 4223 // are not available to determine the offset_of_static_fields. 4224 void JavaClasses::compute_hard_coded_offsets() { 4225 4226 // java_lang_boxing_object 4227 java_lang_boxing_object::value_offset = member_offset(java_lang_boxing_object::hc_value_offset); 4228 java_lang_boxing_object::long_value_offset = align_up(member_offset(java_lang_boxing_object::hc_value_offset), BytesPerLong); 4229 4230 // java_lang_ref_Reference 4231 java_lang_ref_Reference::referent_offset = member_offset(java_lang_ref_Reference::hc_referent_offset); 4232 java_lang_ref_Reference::queue_offset = member_offset(java_lang_ref_Reference::hc_queue_offset); 4233 java_lang_ref_Reference::next_offset = member_offset(java_lang_ref_Reference::hc_next_offset); 4234 java_lang_ref_Reference::discovered_offset = member_offset(java_lang_ref_Reference::hc_discovered_offset); 4235 } 4236 4237 #define DO_COMPUTE_OFFSETS(k) k::compute_offsets(); 4238 4239 // Compute non-hard-coded field offsets of all the classes in this file 4240 void JavaClasses::compute_offsets() { 4241 if (UseSharedSpaces) { 4242 assert(JvmtiExport::is_early_phase() && !(JvmtiExport::should_post_class_file_load_hook() && 4243 JvmtiExport::has_early_class_hook_env()), 4244 "JavaClasses::compute_offsets() must be called in early JVMTI phase."); 4245 // None of the classes used by the rest of this function can be replaced by 4246 // JMVTI ClassFileLoadHook. 4247 // We are safe to use the archived offsets, which have already been restored 4248 // by JavaClasses::serialize_offsets, without computing the offsets again. 4249 return; 4250 } 4251 4252 // We have already called the compute_offsets() of the 4253 // BASIC_JAVA_CLASSES_DO_PART1 classes (java_lang_String and java_lang_Class) 4254 // earlier inside SystemDictionary::resolve_well_known_classes() 4255 BASIC_JAVA_CLASSES_DO_PART2(DO_COMPUTE_OFFSETS); 4256 4257 // generated interpreter code wants to know about the offsets we just computed: 4258 AbstractAssembler::update_delayed_values(); 4259 } 4260 4261 #if INCLUDE_CDS 4262 #define DO_SERIALIZE_OFFSETS(k) k::serialize_offsets(soc); 4263 4264 void JavaClasses::serialize_offsets(SerializeClosure* soc) { 4265 BASIC_JAVA_CLASSES_DO(DO_SERIALIZE_OFFSETS); 4266 } 4267 #endif 4268 4269 4270 #ifndef PRODUCT 4271 4272 // These functions exist to assert the validity of hard-coded field offsets to guard 4273 // against changes in the class files 4274 4275 bool JavaClasses::check_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) { 4276 EXCEPTION_MARK; 4277 fieldDescriptor fd; 4278 TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name, CATCH); 4279 Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH); 4280 InstanceKlass* ik = InstanceKlass::cast(k); 4281 TempNewSymbol f_name = SymbolTable::new_symbol(field_name, CATCH); 4282 TempNewSymbol f_sig = SymbolTable::new_symbol(field_sig, CATCH); 4283 if (!ik->find_local_field(f_name, f_sig, &fd)) { 4284 tty->print_cr("Nonstatic field %s.%s not found", klass_name, field_name); 4285 return false; 4286 } 4287 if (fd.is_static()) { 4288 tty->print_cr("Nonstatic field %s.%s appears to be static", klass_name, field_name); 4289 return false; 4290 } 4291 if (fd.offset() == hardcoded_offset ) { 4292 return true; 4293 } else { 4294 tty->print_cr("Offset of nonstatic field %s.%s is hardcoded as %d but should really be %d.", 4295 klass_name, field_name, hardcoded_offset, fd.offset()); 4296 return false; 4297 } 4298 } 4299 4300 // Check the hard-coded field offsets of all the classes in this file 4301 4302 void JavaClasses::check_offsets() { 4303 bool valid = true; 4304 4305 #define CHECK_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \ 4306 valid &= check_offset(klass_name, cpp_klass_name :: field_name ## _offset, #field_name, field_sig) 4307 4308 #define CHECK_LONG_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \ 4309 valid &= check_offset(klass_name, cpp_klass_name :: long_ ## field_name ## _offset, #field_name, field_sig) 4310 4311 // Boxed primitive objects (java_lang_boxing_object) 4312 4313 CHECK_OFFSET("java/lang/Boolean", java_lang_boxing_object, value, "Z"); 4314 CHECK_OFFSET("java/lang/Character", java_lang_boxing_object, value, "C"); 4315 CHECK_OFFSET("java/lang/Float", java_lang_boxing_object, value, "F"); 4316 CHECK_LONG_OFFSET("java/lang/Double", java_lang_boxing_object, value, "D"); 4317 CHECK_OFFSET("java/lang/Byte", java_lang_boxing_object, value, "B"); 4318 CHECK_OFFSET("java/lang/Short", java_lang_boxing_object, value, "S"); 4319 CHECK_OFFSET("java/lang/Integer", java_lang_boxing_object, value, "I"); 4320 CHECK_LONG_OFFSET("java/lang/Long", java_lang_boxing_object, value, "J"); 4321 4322 // java.lang.ref.Reference 4323 4324 CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, referent, "Ljava/lang/Object;"); 4325 CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, queue, "Ljava/lang/ref/ReferenceQueue;"); 4326 CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, next, "Ljava/lang/ref/Reference;"); 4327 // Fake field 4328 //CHECK_OFFSET("java/lang/ref/Reference", java_lang_ref_Reference, discovered, "Ljava/lang/ref/Reference;"); 4329 4330 if (!valid) vm_exit_during_initialization("Hard-coded field offset verification failed"); 4331 } 4332 4333 #endif // PRODUCT 4334 4335 int InjectedField::compute_offset() { 4336 InstanceKlass* ik = InstanceKlass::cast(klass()); 4337 for (AllFieldStream fs(ik); !fs.done(); fs.next()) { 4338 if (!may_be_java && !fs.access_flags().is_internal()) { 4339 // Only look at injected fields 4340 continue; 4341 } 4342 if (fs.name() == name() && fs.signature() == signature()) { 4343 return fs.offset(); 4344 } 4345 } 4346 ResourceMark rm; 4347 tty->print_cr("Invalid layout of %s at %s/%s%s", ik->external_name(), name()->as_C_string(), signature()->as_C_string(), may_be_java ? " (may_be_java)" : ""); 4348 #ifndef PRODUCT 4349 ik->print(); 4350 tty->print_cr("all fields:"); 4351 for (AllFieldStream fs(ik); !fs.done(); fs.next()) { 4352 tty->print_cr(" name: %s, sig: %s, flags: %08x", fs.name()->as_C_string(), fs.signature()->as_C_string(), fs.access_flags().as_int()); 4353 } 4354 #endif //PRODUCT 4355 vm_exit_during_initialization("Invalid layout of well-known class: use -Xlog:class+load=info to see the origin of the problem class"); 4356 return -1; 4357 } 4358 4359 void javaClasses_init() { 4360 JavaClasses::compute_offsets(); 4361 JavaClasses::check_offsets(); 4362 FilteredFieldsMap::initialize(); // must be done after computing offsets. 4363 }