annotate src/share/vm/classfile/javaClasses.cpp @ 1142:4ce7240d622c

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