src/share/vm/runtime/fieldDescriptor.cpp

Tue, 05 Mar 2013 04:24:33 -0800

author
morris
date
Tue, 05 Mar 2013 04:24:33 -0800
changeset 4690
c40fbf634c90
parent 4572
927a311d00f9
child 5732
b2e698d2276c
permissions
-rw-r--r--

8008574: [parfait] Null pointer deference in hotspot/src/share/vm/runtime/frame.cpp
Summary: fix null pointer
Reviewed-by: kvn

duke@435 1 /*
coleenp@4572 2 * Copyright (c) 1997, 2013, 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@4251 39 return _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@4251 48 InstanceKlass* ik = 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@4251 61 InstanceKlass* ik = 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
stefank@4393 68 AnnotationArray* fieldDescriptor::type_annotations() const {
stefank@4393 69 InstanceKlass* ik = field_holder();
coleenp@4572 70 Array<AnnotationArray*>* type_annos = ik->fields_type_annotations();
stefank@4393 71 if (type_annos == NULL)
stefank@4393 72 return NULL;
coleenp@4572 73 return type_annos->at(index());
stefank@4393 74 }
stefank@4393 75
duke@435 76 constantTag fieldDescriptor::initial_value_tag() const {
never@3137 77 return constants()->tag_at(initial_value_index());
duke@435 78 }
duke@435 79
duke@435 80 jint fieldDescriptor::int_initial_value() const {
never@3137 81 return constants()->int_at(initial_value_index());
duke@435 82 }
duke@435 83
duke@435 84 jlong fieldDescriptor::long_initial_value() const {
never@3137 85 return constants()->long_at(initial_value_index());
duke@435 86 }
duke@435 87
duke@435 88 jfloat fieldDescriptor::float_initial_value() const {
never@3137 89 return constants()->float_at(initial_value_index());
duke@435 90 }
duke@435 91
duke@435 92 jdouble fieldDescriptor::double_initial_value() const {
never@3137 93 return constants()->double_at(initial_value_index());
duke@435 94 }
duke@435 95
duke@435 96 oop fieldDescriptor::string_initial_value(TRAPS) const {
coleenp@4037 97 return constants()->uncached_string_at(initial_value_index(), CHECK_0);
duke@435 98 }
duke@435 99
coleenp@4037 100 void fieldDescriptor::initialize(InstanceKlass* ik, int index) {
duke@435 101 _cp = ik->constants();
never@3137 102 FieldInfo* f = ik->field(index);
never@3137 103 assert(!f->is_internal(), "regular Java fields only");
duke@435 104
never@3137 105 _access_flags = accessFlags_from(f->access_flags());
never@3137 106 guarantee(f->name_index() != 0 && f->signature_index() != 0, "bad constant pool index for fieldDescriptor");
duke@435 107 _index = index;
duke@435 108 }
duke@435 109
duke@435 110 #ifndef PRODUCT
duke@435 111
duke@435 112 void fieldDescriptor::print_on(outputStream* st) const {
never@3137 113 access_flags().print_on(st);
never@3137 114 name()->print_value_on(st);
duke@435 115 st->print(" ");
never@3137 116 signature()->print_value_on(st);
duke@435 117 st->print(" @%d ", offset());
duke@435 118 if (WizardMode && has_initial_value()) {
duke@435 119 st->print("(initval ");
duke@435 120 constantTag t = initial_value_tag();
duke@435 121 if (t.is_int()) {
duke@435 122 st->print("int %d)", int_initial_value());
duke@435 123 } else if (t.is_long()){
duke@435 124 st->print_jlong(long_initial_value());
duke@435 125 } else if (t.is_float()){
duke@435 126 st->print("float %f)", float_initial_value());
duke@435 127 } else if (t.is_double()){
duke@435 128 st->print("double %lf)", double_initial_value());
duke@435 129 }
duke@435 130 }
duke@435 131 }
duke@435 132
duke@435 133 void fieldDescriptor::print_on_for(outputStream* st, oop obj) {
duke@435 134 print_on(st);
duke@435 135 BasicType ft = field_type();
jrose@1100 136 jint as_int = 0;
duke@435 137 switch (ft) {
duke@435 138 case T_BYTE:
duke@435 139 as_int = (jint)obj->byte_field(offset());
duke@435 140 st->print(" %d", obj->byte_field(offset()));
duke@435 141 break;
duke@435 142 case T_CHAR:
jrose@1100 143 as_int = (jint)obj->char_field(offset());
duke@435 144 {
duke@435 145 jchar c = obj->char_field(offset());
duke@435 146 as_int = c;
duke@435 147 st->print(" %c %d", isprint(c) ? c : ' ', c);
duke@435 148 }
duke@435 149 break;
duke@435 150 case T_DOUBLE:
duke@435 151 st->print(" %lf", obj->double_field(offset()));
duke@435 152 break;
duke@435 153 case T_FLOAT:
duke@435 154 as_int = obj->int_field(offset());
duke@435 155 st->print(" %f", obj->float_field(offset()));
duke@435 156 break;
duke@435 157 case T_INT:
jrose@1100 158 as_int = obj->int_field(offset());
duke@435 159 st->print(" %d", obj->int_field(offset()));
duke@435 160 break;
duke@435 161 case T_LONG:
duke@435 162 st->print(" ");
duke@435 163 st->print_jlong(obj->long_field(offset()));
duke@435 164 break;
duke@435 165 case T_SHORT:
duke@435 166 as_int = obj->short_field(offset());
duke@435 167 st->print(" %d", obj->short_field(offset()));
duke@435 168 break;
duke@435 169 case T_BOOLEAN:
duke@435 170 as_int = obj->bool_field(offset());
duke@435 171 st->print(" %s", obj->bool_field(offset()) ? "true" : "false");
duke@435 172 break;
duke@435 173 case T_ARRAY:
duke@435 174 st->print(" ");
jrose@1100 175 NOT_LP64(as_int = obj->int_field(offset()));
duke@435 176 obj->obj_field(offset())->print_value_on(st);
duke@435 177 break;
duke@435 178 case T_OBJECT:
duke@435 179 st->print(" ");
jrose@1100 180 NOT_LP64(as_int = obj->int_field(offset()));
duke@435 181 obj->obj_field(offset())->print_value_on(st);
duke@435 182 break;
duke@435 183 default:
duke@435 184 ShouldNotReachHere();
duke@435 185 break;
duke@435 186 }
duke@435 187 // Print a hint as to the underlying integer representation. This can be wrong for
duke@435 188 // pointers on an LP64 machine
jrose@1100 189 if (ft == T_LONG || ft == T_DOUBLE LP64_ONLY(|| !is_java_primitive(ft)) ) {
duke@435 190 st->print(" (%x %x)", obj->int_field(offset()), obj->int_field(offset()+sizeof(jint)));
jrose@1100 191 } else if (as_int < 0 || as_int > 9) {
duke@435 192 st->print(" (%x)", as_int);
duke@435 193 }
duke@435 194 }
duke@435 195
duke@435 196 #endif /* PRODUCT */

mercurial