duke@435: /* coleenp@4572: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "classfile/systemDictionary.hpp" stefank@2314: #include "classfile/vmSymbols.hpp" stefank@2314: #include "memory/resourceArea.hpp" stefank@2314: #include "memory/universe.inline.hpp" coleenp@4037: #include "oops/annotations.hpp" stefank@2314: #include "oops/instanceKlass.hpp" jiangli@3803: #include "oops/fieldStreams.hpp" stefank@2314: #include "runtime/fieldDescriptor.hpp" stefank@2314: #include "runtime/handles.inline.hpp" stefank@2314: #include "runtime/signature.hpp" duke@435: duke@435: duke@435: oop fieldDescriptor::loader() const { coleenp@4251: return _cp->pool_holder()->class_loader(); duke@435: } duke@435: jiangli@3803: Symbol* fieldDescriptor::generic_signature() const { jiangli@3879: if (!has_generic_signature()) { jiangli@3879: return NULL; jiangli@3879: } jiangli@3879: jiangli@3803: int idx = 0; coleenp@4251: InstanceKlass* ik = field_holder(); jiangli@3803: for (AllFieldStream fs(ik); !fs.done(); fs.next()) { jiangli@3803: if (idx == _index) { jiangli@3803: return fs.generic_signature(); jiangli@3803: } else { jiangli@3803: idx ++; jiangli@3803: } jiangli@3803: } jiangli@3803: assert(false, "should never happen"); jiangli@3803: return NULL; jiangli@3803: } jiangli@3803: coleenp@4037: AnnotationArray* fieldDescriptor::annotations() const { coleenp@4251: InstanceKlass* ik = field_holder(); coleenp@4037: Array* md = ik->fields_annotations(); duke@435: if (md == NULL) duke@435: return NULL; coleenp@4037: return md->at(index()); duke@435: } duke@435: stefank@4393: AnnotationArray* fieldDescriptor::type_annotations() const { stefank@4393: InstanceKlass* ik = field_holder(); coleenp@4572: Array* type_annos = ik->fields_type_annotations(); stefank@4393: if (type_annos == NULL) stefank@4393: return NULL; coleenp@4572: return type_annos->at(index()); stefank@4393: } stefank@4393: duke@435: constantTag fieldDescriptor::initial_value_tag() const { never@3137: return constants()->tag_at(initial_value_index()); duke@435: } duke@435: duke@435: jint fieldDescriptor::int_initial_value() const { never@3137: return constants()->int_at(initial_value_index()); duke@435: } duke@435: duke@435: jlong fieldDescriptor::long_initial_value() const { never@3137: return constants()->long_at(initial_value_index()); duke@435: } duke@435: duke@435: jfloat fieldDescriptor::float_initial_value() const { never@3137: return constants()->float_at(initial_value_index()); duke@435: } duke@435: duke@435: jdouble fieldDescriptor::double_initial_value() const { never@3137: return constants()->double_at(initial_value_index()); duke@435: } duke@435: duke@435: oop fieldDescriptor::string_initial_value(TRAPS) const { coleenp@4037: return constants()->uncached_string_at(initial_value_index(), CHECK_0); duke@435: } duke@435: coleenp@4037: void fieldDescriptor::initialize(InstanceKlass* ik, int index) { duke@435: _cp = ik->constants(); never@3137: FieldInfo* f = ik->field(index); never@3137: assert(!f->is_internal(), "regular Java fields only"); duke@435: never@3137: _access_flags = accessFlags_from(f->access_flags()); never@3137: guarantee(f->name_index() != 0 && f->signature_index() != 0, "bad constant pool index for fieldDescriptor"); duke@435: _index = index; duke@435: } duke@435: duke@435: #ifndef PRODUCT duke@435: duke@435: void fieldDescriptor::print_on(outputStream* st) const { never@3137: access_flags().print_on(st); never@3137: name()->print_value_on(st); duke@435: st->print(" "); never@3137: signature()->print_value_on(st); duke@435: st->print(" @%d ", offset()); duke@435: if (WizardMode && has_initial_value()) { duke@435: st->print("(initval "); duke@435: constantTag t = initial_value_tag(); duke@435: if (t.is_int()) { duke@435: st->print("int %d)", int_initial_value()); duke@435: } else if (t.is_long()){ duke@435: st->print_jlong(long_initial_value()); duke@435: } else if (t.is_float()){ duke@435: st->print("float %f)", float_initial_value()); duke@435: } else if (t.is_double()){ duke@435: st->print("double %lf)", double_initial_value()); duke@435: } duke@435: } duke@435: } duke@435: duke@435: void fieldDescriptor::print_on_for(outputStream* st, oop obj) { duke@435: print_on(st); duke@435: BasicType ft = field_type(); jrose@1100: jint as_int = 0; duke@435: switch (ft) { duke@435: case T_BYTE: duke@435: as_int = (jint)obj->byte_field(offset()); duke@435: st->print(" %d", obj->byte_field(offset())); duke@435: break; duke@435: case T_CHAR: jrose@1100: as_int = (jint)obj->char_field(offset()); duke@435: { duke@435: jchar c = obj->char_field(offset()); duke@435: as_int = c; duke@435: st->print(" %c %d", isprint(c) ? c : ' ', c); duke@435: } duke@435: break; duke@435: case T_DOUBLE: duke@435: st->print(" %lf", obj->double_field(offset())); duke@435: break; duke@435: case T_FLOAT: duke@435: as_int = obj->int_field(offset()); duke@435: st->print(" %f", obj->float_field(offset())); duke@435: break; duke@435: case T_INT: jrose@1100: as_int = obj->int_field(offset()); duke@435: st->print(" %d", obj->int_field(offset())); duke@435: break; duke@435: case T_LONG: duke@435: st->print(" "); duke@435: st->print_jlong(obj->long_field(offset())); duke@435: break; duke@435: case T_SHORT: duke@435: as_int = obj->short_field(offset()); duke@435: st->print(" %d", obj->short_field(offset())); duke@435: break; duke@435: case T_BOOLEAN: duke@435: as_int = obj->bool_field(offset()); duke@435: st->print(" %s", obj->bool_field(offset()) ? "true" : "false"); duke@435: break; duke@435: case T_ARRAY: duke@435: st->print(" "); jrose@1100: NOT_LP64(as_int = obj->int_field(offset())); duke@435: obj->obj_field(offset())->print_value_on(st); duke@435: break; duke@435: case T_OBJECT: duke@435: st->print(" "); jrose@1100: NOT_LP64(as_int = obj->int_field(offset())); duke@435: obj->obj_field(offset())->print_value_on(st); duke@435: break; duke@435: default: duke@435: ShouldNotReachHere(); duke@435: break; duke@435: } duke@435: // Print a hint as to the underlying integer representation. This can be wrong for duke@435: // pointers on an LP64 machine jrose@1100: if (ft == T_LONG || ft == T_DOUBLE LP64_ONLY(|| !is_java_primitive(ft)) ) { duke@435: st->print(" (%x %x)", obj->int_field(offset()), obj->int_field(offset()+sizeof(jint))); jrose@1100: } else if (as_int < 0 || as_int > 9) { duke@435: st->print(" (%x)", as_int); duke@435: } duke@435: } duke@435: duke@435: #endif /* PRODUCT */