< prev index next >

src/hotspot/share/runtime/fieldDescriptor.cpp

Print this page

 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "classfile/vmSymbols.hpp"
 27 #include "memory/resourceArea.hpp"
 28 #include "oops/annotations.hpp"
 29 #include "oops/constantPool.hpp"
 30 #include "oops/instanceKlass.hpp"
 31 #include "oops/klass.inline.hpp"
 32 #include "oops/oop.inline.hpp"
 33 #include "oops/fieldStreams.inline.hpp"

 34 #include "runtime/fieldDescriptor.inline.hpp"
 35 #include "runtime/handles.inline.hpp"
 36 #include "runtime/signature.hpp"
 37 
 38 Symbol* fieldDescriptor::generic_signature() const {
 39   if (!has_generic_signature()) {
 40     return NULL;
 41   }
 42 
 43   int idx = 0;
 44   InstanceKlass* ik = field_holder();
 45   for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
 46     if (idx == _index) {
 47       return fs.generic_signature();
 48     } else {
 49       idx ++;
 50     }
 51   }
 52   assert(false, "should never happen");
 53   return vmSymbols::void_signature(); // return a default value (for code analyzers)
 54 }
 55 
 56 bool fieldDescriptor::is_trusted_final() const {
 57   InstanceKlass* ik = field_holder();
 58   return is_final() && (is_static() || ik->is_hidden() || ik->is_record());
 59 }
 60 
 61 AnnotationArray* fieldDescriptor::annotations() const {
 62   InstanceKlass* ik = field_holder();
 63   Array<AnnotationArray*>* md = ik->fields_annotations();
 64   if (md == NULL)
 65     return NULL;
 66   return md->at(index());
 67 }
 68 
 69 AnnotationArray* fieldDescriptor::type_annotations() const {
 70   InstanceKlass* ik = field_holder();
 71   Array<AnnotationArray*>* type_annos = ik->fields_type_annotations();
 72   if (type_annos == NULL)
 73     return NULL;
 74   return type_annos->at(index());
 75 }
 76 
 77 constantTag fieldDescriptor::initial_value_tag() const {
 78   return constants()->tag_at(initial_value_index());

135   signature()->print_value_on(st);
136   st->print(" @%d ", offset());
137   if (WizardMode && has_initial_value()) {
138     st->print("(initval ");
139     constantTag t = initial_value_tag();
140     if (t.is_int()) {
141       st->print("int %d)", int_initial_value());
142     } else if (t.is_long()){
143       st->print_jlong(long_initial_value());
144     } else if (t.is_float()){
145       st->print("float %f)", float_initial_value());
146     } else if (t.is_double()){
147       st->print("double %lf)", double_initial_value());
148     }
149   }
150 }
151 
152 void fieldDescriptor::print() const { print_on(tty); }
153 
154 void fieldDescriptor::print_on_for(outputStream* st, oop obj) {
155   print_on(st);
156   st->print(" ");
157 
158   BasicType ft = field_type();





159   switch (ft) {
160     case T_BYTE:
161       st->print("%d", obj->byte_field(offset()));
162       break;
163     case T_CHAR:
164       {
165         jchar c = obj->char_field(offset());
166         st->print("%c %d", isprint(c) ? c : ' ', c);
167       }
168       break;
169     case T_DOUBLE:
170       st->print("%lf", obj->double_field(offset()));
171       break;
172     case T_FLOAT:
173       st->print("%f", obj->float_field(offset()));
174       break;
175     case T_INT:
176       st->print("%d", obj->int_field(offset()));
177       break;
178     case T_LONG:
179       st->print_jlong(obj->long_field(offset()));
180       break;
181     case T_SHORT:
182       st->print("%d", obj->short_field(offset()));
183       break;
184     case T_BOOLEAN:
185       st->print("%s", obj->bool_field(offset()) ? "true" : "false");
186       break;
187     case T_ARRAY:
188       if (obj->obj_field(offset()) != NULL) {
189         obj->obj_field(offset())->print_value_on(st);
190       } else {
191         st->print("NULL");





192       }
193       break;

194     case T_OBJECT:
195       if (obj->obj_field(offset()) != NULL) {
196         obj->obj_field(offset())->print_value_on(st);
197       } else {
198         st->print("NULL");
199       }
200       break;
201     default:
202       ShouldNotReachHere();
203       break;
204   }
205 
206   // Print a hint as to the underlying integer representation.
207   if (is_reference_type(ft)) {
208 #ifdef _LP64
209     if (UseCompressedOops) {
210       st->print(" (" INT32_FORMAT_X_0 ")", obj->int_field(offset()));
211     } else {
212       st->print(" (" INT64_FORMAT_X_0 ")", (int64_t)obj->long_field(offset()));
213     }
214 #else
215     st->print(" (" INT32_FORMAT_X_0 ")", obj->int_field(offset()));
216 #endif
217   } else { // Primitives
218     switch (ft) {
219       case T_LONG:    st->print(" (" INT64_FORMAT_X_0 ")", (int64_t)obj->long_field(offset())); break;
220       case T_DOUBLE:  st->print(" (" INT64_FORMAT_X_0 ")", (int64_t)obj->long_field(offset())); break;
221       case T_BYTE:    st->print(" (" INT8_FORMAT_X_0  ")", obj->byte_field(offset()));          break;
222       case T_CHAR:    st->print(" (" INT16_FORMAT_X_0 ")", obj->char_field(offset()));          break;
223       case T_FLOAT:   st->print(" (" INT32_FORMAT_X_0 ")", obj->int_field(offset()));           break;
224       case T_INT:     st->print(" (" INT32_FORMAT_X_0 ")", obj->int_field(offset()));           break;
225       case T_SHORT:   st->print(" (" INT16_FORMAT_X_0 ")", obj->short_field(offset()));         break;
226       case T_BOOLEAN: st->print(" (" INT8_FORMAT_X_0  ")", obj->bool_field(offset()));          break;
227     default:
228       ShouldNotReachHere();
229       break;
230     }
231   }

232 }

 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "classfile/vmSymbols.hpp"
 27 #include "memory/resourceArea.hpp"
 28 #include "oops/annotations.hpp"
 29 #include "oops/constantPool.hpp"
 30 #include "oops/instanceKlass.hpp"
 31 #include "oops/klass.inline.hpp"
 32 #include "oops/oop.inline.hpp"
 33 #include "oops/fieldStreams.inline.hpp"
 34 #include "oops/inlineKlass.inline.hpp"
 35 #include "runtime/fieldDescriptor.inline.hpp"
 36 #include "runtime/handles.inline.hpp"
 37 #include "runtime/signature.hpp"
 38 
 39 Symbol* fieldDescriptor::generic_signature() const {
 40   if (!has_generic_signature()) {
 41     return NULL;
 42   }
 43 
 44   int idx = 0;
 45   InstanceKlass* ik = field_holder();
 46   for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
 47     if (idx == _index) {
 48       return fs.generic_signature();
 49     } else {
 50       idx ++;
 51     }
 52   }
 53   assert(false, "should never happen");
 54   return vmSymbols::void_signature(); // return a default value (for code analyzers)
 55 }
 56 
 57 bool fieldDescriptor::is_trusted_final() const {
 58   InstanceKlass* ik = field_holder();
 59   return is_final() && (is_static() || ik->is_hidden() || ik->is_record() || ik->is_inline_klass());
 60 }
 61 
 62 AnnotationArray* fieldDescriptor::annotations() const {
 63   InstanceKlass* ik = field_holder();
 64   Array<AnnotationArray*>* md = ik->fields_annotations();
 65   if (md == NULL)
 66     return NULL;
 67   return md->at(index());
 68 }
 69 
 70 AnnotationArray* fieldDescriptor::type_annotations() const {
 71   InstanceKlass* ik = field_holder();
 72   Array<AnnotationArray*>* type_annos = ik->fields_type_annotations();
 73   if (type_annos == NULL)
 74     return NULL;
 75   return type_annos->at(index());
 76 }
 77 
 78 constantTag fieldDescriptor::initial_value_tag() const {
 79   return constants()->tag_at(initial_value_index());

136   signature()->print_value_on(st);
137   st->print(" @%d ", offset());
138   if (WizardMode && has_initial_value()) {
139     st->print("(initval ");
140     constantTag t = initial_value_tag();
141     if (t.is_int()) {
142       st->print("int %d)", int_initial_value());
143     } else if (t.is_long()){
144       st->print_jlong(long_initial_value());
145     } else if (t.is_float()){
146       st->print("float %f)", float_initial_value());
147     } else if (t.is_double()){
148       st->print("double %lf)", double_initial_value());
149     }
150   }
151 }
152 
153 void fieldDescriptor::print() const { print_on(tty); }
154 
155 void fieldDescriptor::print_on_for(outputStream* st, oop obj) {



156   BasicType ft = field_type();
157   if (ft != T_PRIMITIVE_OBJECT) {
158     print_on(st);
159     st->print(" ");
160   }
161   jint as_int = 0;
162   switch (ft) {
163     case T_BYTE:
164       st->print("%d", obj->byte_field(offset()));
165       break;
166     case T_CHAR:
167       {
168         jchar c = obj->char_field(offset());
169         st->print("%c %d", isprint(c) ? c : ' ', c);
170       }
171       break;
172     case T_DOUBLE:
173       st->print("%lf", obj->double_field(offset()));
174       break;
175     case T_FLOAT:
176       st->print("%f", obj->float_field(offset()));
177       break;
178     case T_INT:
179       st->print("%d", obj->int_field(offset()));
180       break;
181     case T_LONG:
182       st->print_jlong(obj->long_field(offset()));
183       break;
184     case T_SHORT:
185       st->print("%d", obj->short_field(offset()));
186       break;
187     case T_BOOLEAN:
188       st->print("%s", obj->bool_field(offset()) ? "true" : "false");
189       break;
190     case T_PRIMITIVE_OBJECT:
191       if (is_inlined()) {
192         // Print fields of inlined fields (recursively)
193         InlineKlass* vk = InlineKlass::cast(field_holder()->get_inline_type_field_klass(index()));
194         int field_offset = offset() - vk->first_field_offset();
195         obj = cast_to_oop(cast_from_oop<address>(obj) + field_offset);
196         st->print_cr("Inline type field inlined '%s':", vk->name()->as_C_string());
197         FieldPrinter print_field(st, obj);
198         vk->do_nonstatic_fields(&print_field);
199         return; // Do not print underlying representation
200       }
201       // inline type field not inlined, fall through
202     case T_ARRAY:
203     case T_OBJECT:
204       if (obj->obj_field(offset()) != NULL) {
205         obj->obj_field(offset())->print_value_on(st);
206       } else {
207         st->print("NULL");
208       }
209       break;
210     default:
211       ShouldNotReachHere();
212       break;
213   }
214 
215   // Print a hint as to the underlying integer representation.
216   if (is_reference_type(ft)) {
217 #ifdef _LP64
218     if (UseCompressedOops) {
219       st->print(" (" INT32_FORMAT_X_0 ")", obj->int_field(offset()));
220     } else {
221       st->print(" (" INT64_FORMAT_X_0 ")", (int64_t)obj->long_field(offset()));
222     }
223 #else
224     st->print(" (" INT32_FORMAT_X_0 ")", obj->int_field(offset()));
225 #endif
226   } else { // Primitives
227     switch (ft) {
228       case T_LONG:    st->print(" (" INT64_FORMAT_X_0 ")", (int64_t)obj->long_field(offset())); break;
229       case T_DOUBLE:  st->print(" (" INT64_FORMAT_X_0 ")", (int64_t)obj->long_field(offset())); break;
230       case T_BYTE:    st->print(" (" INT8_FORMAT_X_0  ")", obj->byte_field(offset()));          break;
231       case T_CHAR:    st->print(" (" INT16_FORMAT_X_0 ")", obj->char_field(offset()));          break;
232       case T_FLOAT:   st->print(" (" INT32_FORMAT_X_0 ")", obj->int_field(offset()));           break;
233       case T_INT:     st->print(" (" INT32_FORMAT_X_0 ")", obj->int_field(offset()));           break;
234       case T_SHORT:   st->print(" (" INT16_FORMAT_X_0 ")", obj->short_field(offset()));         break;
235       case T_BOOLEAN: st->print(" (" INT8_FORMAT_X_0  ")", obj->bool_field(offset()));          break;
236     default:
237       ShouldNotReachHere();
238       break;
239     }
240   }
241   st->cr();
242 }
< prev index next >