src/share/vm/classfile/javaClasses.cpp

Mon, 13 Sep 2010 23:24:30 -0700

author
jrose
date
Mon, 13 Sep 2010 23:24:30 -0700
changeset 2148
d257356e35f0
parent 1907
c18cbe5936b8
child 2314
f95d63e2154a
permissions
-rw-r--r--

6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
Reviewed-by: never

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

mercurial