src/share/vm/classfile/javaClasses.cpp

Thu, 07 Apr 2011 17:02:30 -0700

author
jrose
date
Thu, 07 Apr 2011 17:02:30 -0700
changeset 2742
ed69575596ac
parent 2700
352622fd140a
child 2759
3449f5e02cc4
permissions
-rw-r--r--

6981791: remove experimental code for JSR 292
Reviewed-by: twisti

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

mercurial