annotate src/share/vm/runtime/fieldDescriptor.cpp @ 3602:da91efe96a93

6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author coleenp
date Sat, 01 Sep 2012 13:25:18 -0400
parents 634b8615a6ba
children 18fb7da42534
rev   line source
duke@0 1 /*
coleenp@3602 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1879 25 #include "precompiled.hpp"
stefank@1879 26 #include "classfile/systemDictionary.hpp"
stefank@1879 27 #include "classfile/vmSymbols.hpp"
stefank@1879 28 #include "memory/resourceArea.hpp"
stefank@1879 29 #include "memory/universe.inline.hpp"
coleenp@3602 30 #include "oops/annotations.hpp"
stefank@1879 31 #include "oops/instanceKlass.hpp"
jiangli@3368 32 #include "oops/fieldStreams.hpp"
stefank@1879 33 #include "runtime/fieldDescriptor.hpp"
stefank@1879 34 #include "runtime/handles.inline.hpp"
stefank@1879 35 #include "runtime/signature.hpp"
duke@0 36
duke@0 37
duke@0 38 oop fieldDescriptor::loader() const {
coleenp@3602 39 return InstanceKlass::cast(_cp->pool_holder())->class_loader();
duke@0 40 }
duke@0 41
jiangli@3368 42 Symbol* fieldDescriptor::generic_signature() const {
jiangli@3444 43 if (!has_generic_signature()) {
jiangli@3444 44 return NULL;
jiangli@3444 45 }
jiangli@3444 46
jiangli@3368 47 int idx = 0;
coleenp@3602 48 InstanceKlass* ik = InstanceKlass::cast(field_holder());
jiangli@3368 49 for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
jiangli@3368 50 if (idx == _index) {
jiangli@3368 51 return fs.generic_signature();
jiangli@3368 52 } else {
jiangli@3368 53 idx ++;
jiangli@3368 54 }
jiangli@3368 55 }
jiangli@3368 56 assert(false, "should never happen");
jiangli@3368 57 return NULL;
jiangli@3368 58 }
jiangli@3368 59
coleenp@3602 60 AnnotationArray* fieldDescriptor::annotations() const {
coleenp@3602 61 InstanceKlass* ik = InstanceKlass::cast(field_holder());
coleenp@3602 62 Array<AnnotationArray*>* md = ik->fields_annotations();
duke@0 63 if (md == NULL)
duke@0 64 return NULL;
coleenp@3602 65 return md->at(index());
duke@0 66 }
duke@0 67
duke@0 68 constantTag fieldDescriptor::initial_value_tag() const {
never@2702 69 return constants()->tag_at(initial_value_index());
duke@0 70 }
duke@0 71
duke@0 72 jint fieldDescriptor::int_initial_value() const {
never@2702 73 return constants()->int_at(initial_value_index());
duke@0 74 }
duke@0 75
duke@0 76 jlong fieldDescriptor::long_initial_value() const {
never@2702 77 return constants()->long_at(initial_value_index());
duke@0 78 }
duke@0 79
duke@0 80 jfloat fieldDescriptor::float_initial_value() const {
never@2702 81 return constants()->float_at(initial_value_index());
duke@0 82 }
duke@0 83
duke@0 84 jdouble fieldDescriptor::double_initial_value() const {
never@2702 85 return constants()->double_at(initial_value_index());
duke@0 86 }
duke@0 87
duke@0 88 oop fieldDescriptor::string_initial_value(TRAPS) const {
coleenp@3602 89 return constants()->uncached_string_at(initial_value_index(), CHECK_0);
duke@0 90 }
duke@0 91
coleenp@3602 92 void fieldDescriptor::initialize(InstanceKlass* ik, int index) {
duke@0 93 _cp = ik->constants();
never@2702 94 FieldInfo* f = ik->field(index);
never@2702 95 assert(!f->is_internal(), "regular Java fields only");
duke@0 96
never@2702 97 _access_flags = accessFlags_from(f->access_flags());
never@2702 98 guarantee(f->name_index() != 0 && f->signature_index() != 0, "bad constant pool index for fieldDescriptor");
duke@0 99 _index = index;
duke@0 100 }
duke@0 101
duke@0 102 #ifndef PRODUCT
duke@0 103
duke@0 104 void fieldDescriptor::print_on(outputStream* st) const {
never@2702 105 access_flags().print_on(st);
never@2702 106 name()->print_value_on(st);
duke@0 107 st->print(" ");
never@2702 108 signature()->print_value_on(st);
duke@0 109 st->print(" @%d ", offset());
duke@0 110 if (WizardMode && has_initial_value()) {
duke@0 111 st->print("(initval ");
duke@0 112 constantTag t = initial_value_tag();
duke@0 113 if (t.is_int()) {
duke@0 114 st->print("int %d)", int_initial_value());
duke@0 115 } else if (t.is_long()){
duke@0 116 st->print_jlong(long_initial_value());
duke@0 117 } else if (t.is_float()){
duke@0 118 st->print("float %f)", float_initial_value());
duke@0 119 } else if (t.is_double()){
duke@0 120 st->print("double %lf)", double_initial_value());
duke@0 121 }
duke@0 122 }
duke@0 123 }
duke@0 124
duke@0 125 void fieldDescriptor::print_on_for(outputStream* st, oop obj) {
duke@0 126 print_on(st);
duke@0 127 BasicType ft = field_type();
jrose@665 128 jint as_int = 0;
duke@0 129 switch (ft) {
duke@0 130 case T_BYTE:
duke@0 131 as_int = (jint)obj->byte_field(offset());
duke@0 132 st->print(" %d", obj->byte_field(offset()));
duke@0 133 break;
duke@0 134 case T_CHAR:
jrose@665 135 as_int = (jint)obj->char_field(offset());
duke@0 136 {
duke@0 137 jchar c = obj->char_field(offset());
duke@0 138 as_int = c;
duke@0 139 st->print(" %c %d", isprint(c) ? c : ' ', c);
duke@0 140 }
duke@0 141 break;
duke@0 142 case T_DOUBLE:
duke@0 143 st->print(" %lf", obj->double_field(offset()));
duke@0 144 break;
duke@0 145 case T_FLOAT:
duke@0 146 as_int = obj->int_field(offset());
duke@0 147 st->print(" %f", obj->float_field(offset()));
duke@0 148 break;
duke@0 149 case T_INT:
jrose@665 150 as_int = obj->int_field(offset());
duke@0 151 st->print(" %d", obj->int_field(offset()));
duke@0 152 break;
duke@0 153 case T_LONG:
duke@0 154 st->print(" ");
duke@0 155 st->print_jlong(obj->long_field(offset()));
duke@0 156 break;
duke@0 157 case T_SHORT:
duke@0 158 as_int = obj->short_field(offset());
duke@0 159 st->print(" %d", obj->short_field(offset()));
duke@0 160 break;
duke@0 161 case T_BOOLEAN:
duke@0 162 as_int = obj->bool_field(offset());
duke@0 163 st->print(" %s", obj->bool_field(offset()) ? "true" : "false");
duke@0 164 break;
duke@0 165 case T_ARRAY:
duke@0 166 st->print(" ");
jrose@665 167 NOT_LP64(as_int = obj->int_field(offset()));
duke@0 168 obj->obj_field(offset())->print_value_on(st);
duke@0 169 break;
duke@0 170 case T_OBJECT:
duke@0 171 st->print(" ");
jrose@665 172 NOT_LP64(as_int = obj->int_field(offset()));
duke@0 173 obj->obj_field(offset())->print_value_on(st);
duke@0 174 break;
duke@0 175 default:
duke@0 176 ShouldNotReachHere();
duke@0 177 break;
duke@0 178 }
duke@0 179 // Print a hint as to the underlying integer representation. This can be wrong for
duke@0 180 // pointers on an LP64 machine
jrose@665 181 if (ft == T_LONG || ft == T_DOUBLE LP64_ONLY(|| !is_java_primitive(ft)) ) {
duke@0 182 st->print(" (%x %x)", obj->int_field(offset()), obj->int_field(offset()+sizeof(jint)));
jrose@665 183 } else if (as_int < 0 || as_int > 9) {
duke@0 184 st->print(" (%x)", as_int);
duke@0 185 }
duke@0 186 }
duke@0 187
duke@0 188 #endif /* PRODUCT */