1
|
1 |
/*
|
|
2 |
* Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*
|
|
23 |
*/
|
|
24 |
|
|
25 |
# include "incls/_precompiled.incl"
|
|
26 |
#include "incls/_fieldDescriptor.cpp.incl"
|
|
27 |
|
|
28 |
|
|
29 |
oop fieldDescriptor::loader() const {
|
|
30 |
return instanceKlass::cast(_cp->pool_holder())->class_loader();
|
|
31 |
}
|
|
32 |
|
|
33 |
typeArrayOop fieldDescriptor::annotations() const {
|
|
34 |
instanceKlass* ik = instanceKlass::cast(field_holder());
|
|
35 |
objArrayOop md = ik->fields_annotations();
|
|
36 |
if (md == NULL)
|
|
37 |
return NULL;
|
|
38 |
assert((index() % instanceKlass::next_offset) == 0, "");
|
|
39 |
return typeArrayOop(md->obj_at(index() / instanceKlass::next_offset));
|
|
40 |
}
|
|
41 |
|
|
42 |
constantTag fieldDescriptor::initial_value_tag() const {
|
|
43 |
return constants()->tag_at(_initial_value_index);
|
|
44 |
}
|
|
45 |
|
|
46 |
jint fieldDescriptor::int_initial_value() const {
|
|
47 |
return constants()->int_at(_initial_value_index);
|
|
48 |
}
|
|
49 |
|
|
50 |
jlong fieldDescriptor::long_initial_value() const {
|
|
51 |
return constants()->long_at(_initial_value_index);
|
|
52 |
}
|
|
53 |
|
|
54 |
jfloat fieldDescriptor::float_initial_value() const {
|
|
55 |
return constants()->float_at(_initial_value_index);
|
|
56 |
}
|
|
57 |
|
|
58 |
jdouble fieldDescriptor::double_initial_value() const {
|
|
59 |
return constants()->double_at(_initial_value_index);
|
|
60 |
}
|
|
61 |
|
|
62 |
oop fieldDescriptor::string_initial_value(TRAPS) const {
|
|
63 |
return constants()->string_at(_initial_value_index, CHECK_0);
|
|
64 |
}
|
|
65 |
|
|
66 |
void fieldDescriptor::initialize(klassOop k, int index) {
|
|
67 |
instanceKlass* ik = instanceKlass::cast(k);
|
|
68 |
_cp = ik->constants();
|
|
69 |
typeArrayOop fields = ik->fields();
|
|
70 |
|
|
71 |
assert(fields->length() % instanceKlass::next_offset == 0, "Illegal size of field array");
|
|
72 |
assert(fields->length() >= index + instanceKlass::next_offset, "Illegal size of field array");
|
|
73 |
|
|
74 |
_access_flags.set_field_flags(fields->ushort_at(index + instanceKlass::access_flags_offset));
|
|
75 |
_name_index = fields->ushort_at(index + instanceKlass::name_index_offset);
|
|
76 |
_signature_index = fields->ushort_at(index + instanceKlass::signature_index_offset);
|
|
77 |
_initial_value_index = fields->ushort_at(index + instanceKlass::initval_index_offset);
|
|
78 |
guarantee(_name_index != 0 && _signature_index != 0, "bad constant pool index for fieldDescriptor");
|
|
79 |
_offset = ik->offset_from_fields( index );
|
|
80 |
_generic_signature_index = fields->ushort_at(index + instanceKlass::generic_signature_offset);
|
|
81 |
_index = index;
|
|
82 |
}
|
|
83 |
|
|
84 |
#ifndef PRODUCT
|
|
85 |
|
|
86 |
void fieldDescriptor::print_on(outputStream* st) const {
|
|
87 |
_access_flags.print_on(st);
|
|
88 |
constants()->symbol_at(_name_index)->print_value_on(st);
|
|
89 |
st->print(" ");
|
|
90 |
constants()->symbol_at(_signature_index)->print_value_on(st);
|
|
91 |
st->print(" @%d ", offset());
|
|
92 |
if (WizardMode && has_initial_value()) {
|
|
93 |
st->print("(initval ");
|
|
94 |
constantTag t = initial_value_tag();
|
|
95 |
if (t.is_int()) {
|
|
96 |
st->print("int %d)", int_initial_value());
|
|
97 |
} else if (t.is_long()){
|
|
98 |
st->print_jlong(long_initial_value());
|
|
99 |
} else if (t.is_float()){
|
|
100 |
st->print("float %f)", float_initial_value());
|
|
101 |
} else if (t.is_double()){
|
|
102 |
st->print("double %lf)", double_initial_value());
|
|
103 |
}
|
|
104 |
}
|
|
105 |
}
|
|
106 |
|
|
107 |
void fieldDescriptor::print_on_for(outputStream* st, oop obj) {
|
|
108 |
print_on(st);
|
|
109 |
BasicType ft = field_type();
|
|
110 |
jint as_int;
|
|
111 |
switch (ft) {
|
|
112 |
case T_BYTE:
|
|
113 |
as_int = (jint)obj->byte_field(offset());
|
|
114 |
st->print(" %d", obj->byte_field(offset()));
|
|
115 |
break;
|
|
116 |
case T_CHAR:
|
|
117 |
{
|
|
118 |
jchar c = obj->char_field(offset());
|
|
119 |
as_int = c;
|
|
120 |
st->print(" %c %d", isprint(c) ? c : ' ', c);
|
|
121 |
}
|
|
122 |
break;
|
|
123 |
case T_DOUBLE:
|
|
124 |
st->print(" %lf", obj->double_field(offset()));
|
|
125 |
break;
|
|
126 |
case T_FLOAT:
|
|
127 |
as_int = obj->int_field(offset());
|
|
128 |
st->print(" %f", obj->float_field(offset()));
|
|
129 |
break;
|
|
130 |
case T_INT:
|
|
131 |
st->print(" %d", obj->int_field(offset()));
|
|
132 |
break;
|
|
133 |
case T_LONG:
|
|
134 |
st->print(" ");
|
|
135 |
st->print_jlong(obj->long_field(offset()));
|
|
136 |
break;
|
|
137 |
case T_SHORT:
|
|
138 |
as_int = obj->short_field(offset());
|
|
139 |
st->print(" %d", obj->short_field(offset()));
|
|
140 |
break;
|
|
141 |
case T_BOOLEAN:
|
|
142 |
as_int = obj->bool_field(offset());
|
|
143 |
st->print(" %s", obj->bool_field(offset()) ? "true" : "false");
|
|
144 |
break;
|
|
145 |
case T_ARRAY:
|
|
146 |
st->print(" ");
|
|
147 |
as_int = obj->int_field(offset());
|
|
148 |
obj->obj_field(offset())->print_value_on(st);
|
|
149 |
break;
|
|
150 |
case T_OBJECT:
|
|
151 |
st->print(" ");
|
|
152 |
as_int = obj->int_field(offset());
|
|
153 |
obj->obj_field(offset())->print_value_on(st);
|
|
154 |
break;
|
|
155 |
default:
|
|
156 |
ShouldNotReachHere();
|
|
157 |
break;
|
|
158 |
}
|
|
159 |
// Print a hint as to the underlying integer representation. This can be wrong for
|
|
160 |
// pointers on an LP64 machine
|
|
161 |
if (ft == T_LONG || ft == T_DOUBLE) {
|
|
162 |
st->print(" (%x %x)", obj->int_field(offset()), obj->int_field(offset()+sizeof(jint)));
|
|
163 |
} else {
|
|
164 |
st->print(" (%x)", as_int);
|
|
165 |
}
|
|
166 |
}
|
|
167 |
|
|
168 |
#endif /* PRODUCT */
|