src/share/vm/runtime/fieldDescriptor.cpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 9572
624a0741915c
permissions
-rw-r--r--

Merge

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

mercurial