src/share/vm/runtime/fieldDescriptor.cpp

Thu, 10 Apr 2008 15:49:16 -0400

author
sbohne
date
Thu, 10 Apr 2008 15:49:16 -0400
changeset 528
c6ff24ceec1c
parent 435
a61af66fc99e
child 1100
c89f86385056
permissions
-rw-r--r--

6686407: Fix for 6666698 broke -XX:BiasedLockingStartupDelay=0
Summary: Stack allocated VM_EnableBiasedLocking op must be marked as such
Reviewed-by: xlu, acorn, never, dholmes

duke@435 1 /*
duke@435 2 * Copyright 1997-2005 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 #include "incls/_fieldDescriptor.cpp.incl"
duke@435 27
duke@435 28
duke@435 29 oop fieldDescriptor::loader() const {
duke@435 30 return instanceKlass::cast(_cp->pool_holder())->class_loader();
duke@435 31 }
duke@435 32
duke@435 33 typeArrayOop fieldDescriptor::annotations() const {
duke@435 34 instanceKlass* ik = instanceKlass::cast(field_holder());
duke@435 35 objArrayOop md = ik->fields_annotations();
duke@435 36 if (md == NULL)
duke@435 37 return NULL;
duke@435 38 assert((index() % instanceKlass::next_offset) == 0, "");
duke@435 39 return typeArrayOop(md->obj_at(index() / instanceKlass::next_offset));
duke@435 40 }
duke@435 41
duke@435 42 constantTag fieldDescriptor::initial_value_tag() const {
duke@435 43 return constants()->tag_at(_initial_value_index);
duke@435 44 }
duke@435 45
duke@435 46 jint fieldDescriptor::int_initial_value() const {
duke@435 47 return constants()->int_at(_initial_value_index);
duke@435 48 }
duke@435 49
duke@435 50 jlong fieldDescriptor::long_initial_value() const {
duke@435 51 return constants()->long_at(_initial_value_index);
duke@435 52 }
duke@435 53
duke@435 54 jfloat fieldDescriptor::float_initial_value() const {
duke@435 55 return constants()->float_at(_initial_value_index);
duke@435 56 }
duke@435 57
duke@435 58 jdouble fieldDescriptor::double_initial_value() const {
duke@435 59 return constants()->double_at(_initial_value_index);
duke@435 60 }
duke@435 61
duke@435 62 oop fieldDescriptor::string_initial_value(TRAPS) const {
duke@435 63 return constants()->string_at(_initial_value_index, CHECK_0);
duke@435 64 }
duke@435 65
duke@435 66 void fieldDescriptor::initialize(klassOop k, int index) {
duke@435 67 instanceKlass* ik = instanceKlass::cast(k);
duke@435 68 _cp = ik->constants();
duke@435 69 typeArrayOop fields = ik->fields();
duke@435 70
duke@435 71 assert(fields->length() % instanceKlass::next_offset == 0, "Illegal size of field array");
duke@435 72 assert(fields->length() >= index + instanceKlass::next_offset, "Illegal size of field array");
duke@435 73
duke@435 74 _access_flags.set_field_flags(fields->ushort_at(index + instanceKlass::access_flags_offset));
duke@435 75 _name_index = fields->ushort_at(index + instanceKlass::name_index_offset);
duke@435 76 _signature_index = fields->ushort_at(index + instanceKlass::signature_index_offset);
duke@435 77 _initial_value_index = fields->ushort_at(index + instanceKlass::initval_index_offset);
duke@435 78 guarantee(_name_index != 0 && _signature_index != 0, "bad constant pool index for fieldDescriptor");
duke@435 79 _offset = ik->offset_from_fields( index );
duke@435 80 _generic_signature_index = fields->ushort_at(index + instanceKlass::generic_signature_offset);
duke@435 81 _index = index;
duke@435 82 }
duke@435 83
duke@435 84 #ifndef PRODUCT
duke@435 85
duke@435 86 void fieldDescriptor::print_on(outputStream* st) const {
duke@435 87 _access_flags.print_on(st);
duke@435 88 constants()->symbol_at(_name_index)->print_value_on(st);
duke@435 89 st->print(" ");
duke@435 90 constants()->symbol_at(_signature_index)->print_value_on(st);
duke@435 91 st->print(" @%d ", offset());
duke@435 92 if (WizardMode && has_initial_value()) {
duke@435 93 st->print("(initval ");
duke@435 94 constantTag t = initial_value_tag();
duke@435 95 if (t.is_int()) {
duke@435 96 st->print("int %d)", int_initial_value());
duke@435 97 } else if (t.is_long()){
duke@435 98 st->print_jlong(long_initial_value());
duke@435 99 } else if (t.is_float()){
duke@435 100 st->print("float %f)", float_initial_value());
duke@435 101 } else if (t.is_double()){
duke@435 102 st->print("double %lf)", double_initial_value());
duke@435 103 }
duke@435 104 }
duke@435 105 }
duke@435 106
duke@435 107 void fieldDescriptor::print_on_for(outputStream* st, oop obj) {
duke@435 108 print_on(st);
duke@435 109 BasicType ft = field_type();
duke@435 110 jint as_int;
duke@435 111 switch (ft) {
duke@435 112 case T_BYTE:
duke@435 113 as_int = (jint)obj->byte_field(offset());
duke@435 114 st->print(" %d", obj->byte_field(offset()));
duke@435 115 break;
duke@435 116 case T_CHAR:
duke@435 117 {
duke@435 118 jchar c = obj->char_field(offset());
duke@435 119 as_int = c;
duke@435 120 st->print(" %c %d", isprint(c) ? c : ' ', c);
duke@435 121 }
duke@435 122 break;
duke@435 123 case T_DOUBLE:
duke@435 124 st->print(" %lf", obj->double_field(offset()));
duke@435 125 break;
duke@435 126 case T_FLOAT:
duke@435 127 as_int = obj->int_field(offset());
duke@435 128 st->print(" %f", obj->float_field(offset()));
duke@435 129 break;
duke@435 130 case T_INT:
duke@435 131 st->print(" %d", obj->int_field(offset()));
duke@435 132 break;
duke@435 133 case T_LONG:
duke@435 134 st->print(" ");
duke@435 135 st->print_jlong(obj->long_field(offset()));
duke@435 136 break;
duke@435 137 case T_SHORT:
duke@435 138 as_int = obj->short_field(offset());
duke@435 139 st->print(" %d", obj->short_field(offset()));
duke@435 140 break;
duke@435 141 case T_BOOLEAN:
duke@435 142 as_int = obj->bool_field(offset());
duke@435 143 st->print(" %s", obj->bool_field(offset()) ? "true" : "false");
duke@435 144 break;
duke@435 145 case T_ARRAY:
duke@435 146 st->print(" ");
duke@435 147 as_int = obj->int_field(offset());
duke@435 148 obj->obj_field(offset())->print_value_on(st);
duke@435 149 break;
duke@435 150 case T_OBJECT:
duke@435 151 st->print(" ");
duke@435 152 as_int = obj->int_field(offset());
duke@435 153 obj->obj_field(offset())->print_value_on(st);
duke@435 154 break;
duke@435 155 default:
duke@435 156 ShouldNotReachHere();
duke@435 157 break;
duke@435 158 }
duke@435 159 // Print a hint as to the underlying integer representation. This can be wrong for
duke@435 160 // pointers on an LP64 machine
duke@435 161 if (ft == T_LONG || ft == T_DOUBLE) {
duke@435 162 st->print(" (%x %x)", obj->int_field(offset()), obj->int_field(offset()+sizeof(jint)));
duke@435 163 } else {
duke@435 164 st->print(" (%x)", as_int);
duke@435 165 }
duke@435 166 }
duke@435 167
duke@435 168 #endif /* PRODUCT */

mercurial