src/share/vm/classfile/javaClasses.cpp

Tue, 08 Feb 2011 09:11:37 -0800

author
mchung
date
Tue, 08 Feb 2011 09:11:37 -0800
changeset 2518
f36c9fe788b8
parent 2497
3582bf76420e
child 2638
72dee110246f
permissions
-rw-r--r--

7017673: Remove setting of the sun.jkernel.DownloadManager as a boot classloader hook
Reviewed-by: alanb, dcubed, coleenp

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

mercurial