src/share/vm/runtime/fieldDescriptor.cpp

Fri, 20 Mar 2009 23:19:36 -0700

author
jrose
date
Fri, 20 Mar 2009 23:19:36 -0700
changeset 1100
c89f86385056
parent 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6814659: separable cleanups and subroutines for 6655638
Summary: preparatory but separable changes for method handles
Reviewed-by: kvn, never

duke@435 1 /*
jrose@1100 2 * Copyright 1997-2009 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();
jrose@1100 110 jint as_int = 0;
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:
jrose@1100 117 as_int = (jint)obj->char_field(offset());
duke@435 118 {
duke@435 119 jchar c = obj->char_field(offset());
duke@435 120 as_int = c;
duke@435 121 st->print(" %c %d", isprint(c) ? c : ' ', c);
duke@435 122 }
duke@435 123 break;
duke@435 124 case T_DOUBLE:
duke@435 125 st->print(" %lf", obj->double_field(offset()));
duke@435 126 break;
duke@435 127 case T_FLOAT:
duke@435 128 as_int = obj->int_field(offset());
duke@435 129 st->print(" %f", obj->float_field(offset()));
duke@435 130 break;
duke@435 131 case T_INT:
jrose@1100 132 as_int = obj->int_field(offset());
duke@435 133 st->print(" %d", obj->int_field(offset()));
duke@435 134 break;
duke@435 135 case T_LONG:
duke@435 136 st->print(" ");
duke@435 137 st->print_jlong(obj->long_field(offset()));
duke@435 138 break;
duke@435 139 case T_SHORT:
duke@435 140 as_int = obj->short_field(offset());
duke@435 141 st->print(" %d", obj->short_field(offset()));
duke@435 142 break;
duke@435 143 case T_BOOLEAN:
duke@435 144 as_int = obj->bool_field(offset());
duke@435 145 st->print(" %s", obj->bool_field(offset()) ? "true" : "false");
duke@435 146 break;
duke@435 147 case T_ARRAY:
duke@435 148 st->print(" ");
jrose@1100 149 NOT_LP64(as_int = obj->int_field(offset()));
duke@435 150 obj->obj_field(offset())->print_value_on(st);
duke@435 151 break;
duke@435 152 case T_OBJECT:
duke@435 153 st->print(" ");
jrose@1100 154 NOT_LP64(as_int = obj->int_field(offset()));
duke@435 155 obj->obj_field(offset())->print_value_on(st);
duke@435 156 break;
duke@435 157 default:
duke@435 158 ShouldNotReachHere();
duke@435 159 break;
duke@435 160 }
duke@435 161 // Print a hint as to the underlying integer representation. This can be wrong for
duke@435 162 // pointers on an LP64 machine
jrose@1100 163 if (ft == T_LONG || ft == T_DOUBLE LP64_ONLY(|| !is_java_primitive(ft)) ) {
duke@435 164 st->print(" (%x %x)", obj->int_field(offset()), obj->int_field(offset()+sizeof(jint)));
jrose@1100 165 } else if (as_int < 0 || as_int > 9) {
duke@435 166 st->print(" (%x)", as_int);
duke@435 167 }
duke@435 168 }
duke@435 169
duke@435 170 #endif /* PRODUCT */

mercurial