annotate src/share/vm/classfile/javaClasses.cpp @ 2645:0b80db433fcb

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