src/share/vm/runtime/fieldDescriptor.cpp

Sat, 01 Sep 2012 13:25:18 -0400

author
coleenp
date
Sat, 01 Sep 2012 13:25:18 -0400
changeset 4037
da91efe96a93
parent 3879
634b8615a6ba
child 4251
18fb7da42534
permissions
-rw-r--r--

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>

duke@435 1 /*
coleenp@4037 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "classfile/systemDictionary.hpp"
stefank@2314 27 #include "classfile/vmSymbols.hpp"
stefank@2314 28 #include "memory/resourceArea.hpp"
stefank@2314 29 #include "memory/universe.inline.hpp"
coleenp@4037 30 #include "oops/annotations.hpp"
stefank@2314 31 #include "oops/instanceKlass.hpp"
jiangli@3803 32 #include "oops/fieldStreams.hpp"
stefank@2314 33 #include "runtime/fieldDescriptor.hpp"
stefank@2314 34 #include "runtime/handles.inline.hpp"
stefank@2314 35 #include "runtime/signature.hpp"
duke@435 36
duke@435 37
duke@435 38 oop fieldDescriptor::loader() const {
coleenp@4037 39 return InstanceKlass::cast(_cp->pool_holder())->class_loader();
duke@435 40 }
duke@435 41
jiangli@3803 42 Symbol* fieldDescriptor::generic_signature() const {
jiangli@3879 43 if (!has_generic_signature()) {
jiangli@3879 44 return NULL;
jiangli@3879 45 }
jiangli@3879 46
jiangli@3803 47 int idx = 0;
coleenp@4037 48 InstanceKlass* ik = InstanceKlass::cast(field_holder());
jiangli@3803 49 for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
jiangli@3803 50 if (idx == _index) {
jiangli@3803 51 return fs.generic_signature();
jiangli@3803 52 } else {
jiangli@3803 53 idx ++;
jiangli@3803 54 }
jiangli@3803 55 }
jiangli@3803 56 assert(false, "should never happen");
jiangli@3803 57 return NULL;
jiangli@3803 58 }
jiangli@3803 59
coleenp@4037 60 AnnotationArray* fieldDescriptor::annotations() const {
coleenp@4037 61 InstanceKlass* ik = InstanceKlass::cast(field_holder());
coleenp@4037 62 Array<AnnotationArray*>* md = ik->fields_annotations();
duke@435 63 if (md == NULL)
duke@435 64 return NULL;
coleenp@4037 65 return md->at(index());
duke@435 66 }
duke@435 67
duke@435 68 constantTag fieldDescriptor::initial_value_tag() const {
never@3137 69 return constants()->tag_at(initial_value_index());
duke@435 70 }
duke@435 71
duke@435 72 jint fieldDescriptor::int_initial_value() const {
never@3137 73 return constants()->int_at(initial_value_index());
duke@435 74 }
duke@435 75
duke@435 76 jlong fieldDescriptor::long_initial_value() const {
never@3137 77 return constants()->long_at(initial_value_index());
duke@435 78 }
duke@435 79
duke@435 80 jfloat fieldDescriptor::float_initial_value() const {
never@3137 81 return constants()->float_at(initial_value_index());
duke@435 82 }
duke@435 83
duke@435 84 jdouble fieldDescriptor::double_initial_value() const {
never@3137 85 return constants()->double_at(initial_value_index());
duke@435 86 }
duke@435 87
duke@435 88 oop fieldDescriptor::string_initial_value(TRAPS) const {
coleenp@4037 89 return constants()->uncached_string_at(initial_value_index(), CHECK_0);
duke@435 90 }
duke@435 91
coleenp@4037 92 void fieldDescriptor::initialize(InstanceKlass* ik, int index) {
duke@435 93 _cp = ik->constants();
never@3137 94 FieldInfo* f = ik->field(index);
never@3137 95 assert(!f->is_internal(), "regular Java fields only");
duke@435 96
never@3137 97 _access_flags = accessFlags_from(f->access_flags());
never@3137 98 guarantee(f->name_index() != 0 && f->signature_index() != 0, "bad constant pool index for fieldDescriptor");
duke@435 99 _index = index;
duke@435 100 }
duke@435 101
duke@435 102 #ifndef PRODUCT
duke@435 103
duke@435 104 void fieldDescriptor::print_on(outputStream* st) const {
never@3137 105 access_flags().print_on(st);
never@3137 106 name()->print_value_on(st);
duke@435 107 st->print(" ");
never@3137 108 signature()->print_value_on(st);
duke@435 109 st->print(" @%d ", offset());
duke@435 110 if (WizardMode && has_initial_value()) {
duke@435 111 st->print("(initval ");
duke@435 112 constantTag t = initial_value_tag();
duke@435 113 if (t.is_int()) {
duke@435 114 st->print("int %d)", int_initial_value());
duke@435 115 } else if (t.is_long()){
duke@435 116 st->print_jlong(long_initial_value());
duke@435 117 } else if (t.is_float()){
duke@435 118 st->print("float %f)", float_initial_value());
duke@435 119 } else if (t.is_double()){
duke@435 120 st->print("double %lf)", double_initial_value());
duke@435 121 }
duke@435 122 }
duke@435 123 }
duke@435 124
duke@435 125 void fieldDescriptor::print_on_for(outputStream* st, oop obj) {
duke@435 126 print_on(st);
duke@435 127 BasicType ft = field_type();
jrose@1100 128 jint as_int = 0;
duke@435 129 switch (ft) {
duke@435 130 case T_BYTE:
duke@435 131 as_int = (jint)obj->byte_field(offset());
duke@435 132 st->print(" %d", obj->byte_field(offset()));
duke@435 133 break;
duke@435 134 case T_CHAR:
jrose@1100 135 as_int = (jint)obj->char_field(offset());
duke@435 136 {
duke@435 137 jchar c = obj->char_field(offset());
duke@435 138 as_int = c;
duke@435 139 st->print(" %c %d", isprint(c) ? c : ' ', c);
duke@435 140 }
duke@435 141 break;
duke@435 142 case T_DOUBLE:
duke@435 143 st->print(" %lf", obj->double_field(offset()));
duke@435 144 break;
duke@435 145 case T_FLOAT:
duke@435 146 as_int = obj->int_field(offset());
duke@435 147 st->print(" %f", obj->float_field(offset()));
duke@435 148 break;
duke@435 149 case T_INT:
jrose@1100 150 as_int = obj->int_field(offset());
duke@435 151 st->print(" %d", obj->int_field(offset()));
duke@435 152 break;
duke@435 153 case T_LONG:
duke@435 154 st->print(" ");
duke@435 155 st->print_jlong(obj->long_field(offset()));
duke@435 156 break;
duke@435 157 case T_SHORT:
duke@435 158 as_int = obj->short_field(offset());
duke@435 159 st->print(" %d", obj->short_field(offset()));
duke@435 160 break;
duke@435 161 case T_BOOLEAN:
duke@435 162 as_int = obj->bool_field(offset());
duke@435 163 st->print(" %s", obj->bool_field(offset()) ? "true" : "false");
duke@435 164 break;
duke@435 165 case T_ARRAY:
duke@435 166 st->print(" ");
jrose@1100 167 NOT_LP64(as_int = obj->int_field(offset()));
duke@435 168 obj->obj_field(offset())->print_value_on(st);
duke@435 169 break;
duke@435 170 case T_OBJECT:
duke@435 171 st->print(" ");
jrose@1100 172 NOT_LP64(as_int = obj->int_field(offset()));
duke@435 173 obj->obj_field(offset())->print_value_on(st);
duke@435 174 break;
duke@435 175 default:
duke@435 176 ShouldNotReachHere();
duke@435 177 break;
duke@435 178 }
duke@435 179 // Print a hint as to the underlying integer representation. This can be wrong for
duke@435 180 // pointers on an LP64 machine
jrose@1100 181 if (ft == T_LONG || ft == T_DOUBLE LP64_ONLY(|| !is_java_primitive(ft)) ) {
duke@435 182 st->print(" (%x %x)", obj->int_field(offset()), obj->int_field(offset()+sizeof(jint)));
jrose@1100 183 } else if (as_int < 0 || as_int > 9) {
duke@435 184 st->print(" (%x)", as_int);
duke@435 185 }
duke@435 186 }
duke@435 187
duke@435 188 #endif /* PRODUCT */

mercurial