annotate src/share/vm/oops/fieldInfo.hpp @ 12823:b756e7a2ec33

Added tag jdk-9+181 for changeset 4a443796f6f5
author prr
date Thu, 03 Aug 2017 18:56:57 +0000
parents de6a9e811145
children
rev   line source
never@2702 1 /*
coleenp@9248 2 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
never@2702 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
never@2702 4 *
never@2702 5 * This code is free software; you can redistribute it and/or modify it
never@2702 6 * under the terms of the GNU General Public License version 2 only, as
never@2702 7 * published by the Free Software Foundation.
never@2702 8 *
never@2702 9 * This code is distributed in the hope that it will be useful, but WITHOUT
never@2702 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
never@2702 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
never@2702 12 * version 2 for more details (a copy is included in the LICENSE file that
never@2702 13 * accompanied this code).
never@2702 14 *
never@2702 15 * You should have received a copy of the GNU General Public License version
never@2702 16 * 2 along with this work; if not, write to the Free Software Foundation,
never@2702 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
never@2702 18 *
never@2702 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
never@2702 20 * or visit www.oracle.com if you need additional information or have any
never@2702 21 * questions.
never@2702 22 *
never@2702 23 */
never@2702 24
never@2702 25 #ifndef SHARE_VM_OOPS_FIELDINFO_HPP
never@2702 26 #define SHARE_VM_OOPS_FIELDINFO_HPP
never@2702 27
coleenp@3602 28 #include "oops/constantPool.hpp"
never@2702 29 #include "oops/typeArrayOop.hpp"
never@2702 30 #include "classfile/vmSymbols.hpp"
never@2702 31
never@2702 32 // This class represents the field information contained in the fields
coleenp@3602 33 // array of an InstanceKlass. Currently it's laid on top an array of
never@2702 34 // Java shorts but in the future it could simply be used as a real
never@2702 35 // array type. FieldInfo generally shouldn't be used directly.
coleenp@3602 36 // Fields should be queried either through InstanceKlass or through
never@2702 37 // the various FieldStreams.
never@2702 38 class FieldInfo VALUE_OBJ_CLASS_SPEC {
never@2702 39 friend class fieldDescriptor;
never@2702 40 friend class JavaFieldStream;
never@2702 41 friend class ClassFileParser;
never@2702 42
never@2702 43 public:
never@2702 44 // fields
never@2702 45 // Field info extracted from the class file and stored
jwilhelm@3995 46 // as an array of 6 shorts.
jwilhelm@3995 47
jwilhelm@3995 48 #define FIELDINFO_TAG_SIZE 2
jwilhelm@3995 49 #define FIELDINFO_TAG_BLANK 0
jwilhelm@3995 50 #define FIELDINFO_TAG_OFFSET 1
jwilhelm@3995 51 #define FIELDINFO_TAG_TYPE_PLAIN 2
jwilhelm@3995 52 #define FIELDINFO_TAG_TYPE_CONTENDED 3
jwilhelm@3995 53 #define FIELDINFO_TAG_MASK 3
jwilhelm@3995 54
jwilhelm@3995 55 // Packed field has the tag, and can be either of:
jwilhelm@3995 56 // hi bits <--------------------------- lo bits
jwilhelm@3995 57 // |---------high---------|---------low---------|
jwilhelm@3995 58 // ..........................................00 - blank
jwilhelm@3995 59 // [------------------offset----------------]01 - real field offset
jwilhelm@3995 60 // ......................[-------type-------]10 - plain field with type
jwilhelm@3995 61 // [--contention_group--][-------type-------]11 - contended field with type and contention group
never@2702 62 enum FieldOffset {
never@2702 63 access_flags_offset = 0,
never@2702 64 name_index_offset = 1,
never@2702 65 signature_index_offset = 2,
never@2702 66 initval_index_offset = 3,
jwilhelm@3995 67 low_packed_offset = 4,
jwilhelm@3995 68 high_packed_offset = 5,
jiangli@3368 69 field_slots = 6
never@2702 70 };
never@2702 71
never@2702 72 private:
never@2702 73 u2 _shorts[field_slots];
never@2702 74
never@2702 75 void set_name_index(u2 val) { _shorts[name_index_offset] = val; }
never@2702 76 void set_signature_index(u2 val) { _shorts[signature_index_offset] = val; }
never@2702 77 void set_initval_index(u2 val) { _shorts[initval_index_offset] = val; }
never@2702 78
never@2702 79 u2 name_index() const { return _shorts[name_index_offset]; }
never@2702 80 u2 signature_index() const { return _shorts[signature_index_offset]; }
never@2702 81 u2 initval_index() const { return _shorts[initval_index_offset]; }
never@2702 82
never@2702 83 public:
coleenp@3602 84 static FieldInfo* from_field_array(Array<u2>* fields, int index) {
coleenp@3602 85 return ((FieldInfo*)fields->adr_at(index * field_slots));
never@2702 86 }
jiangli@3368 87 static FieldInfo* from_field_array(u2* fields, int index) {
jiangli@3368 88 return ((FieldInfo*)(fields + index * field_slots));
jiangli@3368 89 }
never@2702 90
never@2702 91 void initialize(u2 access_flags,
never@2702 92 u2 name_index,
never@2702 93 u2 signature_index,
jwilhelm@3995 94 u2 initval_index) {
never@2702 95 _shorts[access_flags_offset] = access_flags;
never@2702 96 _shorts[name_index_offset] = name_index;
never@2702 97 _shorts[signature_index_offset] = signature_index;
never@2702 98 _shorts[initval_index_offset] = initval_index;
jwilhelm@3995 99 _shorts[low_packed_offset] = 0;
jwilhelm@3995 100 _shorts[high_packed_offset] = 0;
never@2702 101 }
never@2702 102
never@2702 103 u2 access_flags() const { return _shorts[access_flags_offset]; }
jwilhelm@3995 104 u4 offset() const {
jwilhelm@3995 105 u2 lo = _shorts[low_packed_offset];
jwilhelm@3995 106 switch(lo & FIELDINFO_TAG_MASK) {
jwilhelm@3995 107 case FIELDINFO_TAG_OFFSET:
jwilhelm@3995 108 return build_int_from_shorts(_shorts[low_packed_offset], _shorts[high_packed_offset]) >> FIELDINFO_TAG_SIZE;
jwilhelm@3995 109 #ifndef PRODUCT
jwilhelm@3995 110 case FIELDINFO_TAG_TYPE_PLAIN:
neliasso@4334 111 fatal("Asking offset for the plain type field");
jwilhelm@3995 112 case FIELDINFO_TAG_TYPE_CONTENDED:
neliasso@4334 113 fatal("Asking offset for the contended type field");
jwilhelm@3995 114 case FIELDINFO_TAG_BLANK:
neliasso@4334 115 fatal("Asking offset for the blank field");
jwilhelm@3995 116 #endif
jwilhelm@3995 117 }
jwilhelm@3995 118 ShouldNotReachHere();
jwilhelm@3995 119 return 0;
jwilhelm@3995 120 }
jwilhelm@3995 121
jwilhelm@3995 122 bool is_contended() const {
jwilhelm@3995 123 u2 lo = _shorts[low_packed_offset];
jwilhelm@3995 124 switch(lo & FIELDINFO_TAG_MASK) {
jwilhelm@3995 125 case FIELDINFO_TAG_TYPE_PLAIN:
jwilhelm@3995 126 return false;
jwilhelm@3995 127 case FIELDINFO_TAG_TYPE_CONTENDED:
jwilhelm@3995 128 return true;
jwilhelm@3995 129 #ifndef PRODUCT
jwilhelm@3995 130 case FIELDINFO_TAG_OFFSET:
neliasso@4334 131 fatal("Asking contended flag for the field with offset");
jwilhelm@3995 132 case FIELDINFO_TAG_BLANK:
neliasso@4334 133 fatal("Asking contended flag for the blank field");
jwilhelm@3995 134 #endif
jwilhelm@3995 135 }
jwilhelm@3995 136 ShouldNotReachHere();
jwilhelm@3995 137 return false;
jwilhelm@3995 138 }
jwilhelm@3995 139
jwilhelm@3995 140 u2 contended_group() const {
jwilhelm@3995 141 u2 lo = _shorts[low_packed_offset];
jwilhelm@3995 142 switch(lo & FIELDINFO_TAG_MASK) {
jwilhelm@3995 143 case FIELDINFO_TAG_TYPE_PLAIN:
jwilhelm@3995 144 return 0;
jwilhelm@3995 145 case FIELDINFO_TAG_TYPE_CONTENDED:
jwilhelm@3995 146 return _shorts[high_packed_offset];
jwilhelm@3995 147 #ifndef PRODUCT
jwilhelm@3995 148 case FIELDINFO_TAG_OFFSET:
neliasso@4334 149 fatal("Asking the contended group for the field with offset");
jwilhelm@3995 150 case FIELDINFO_TAG_BLANK:
neliasso@4334 151 fatal("Asking the contended group for the blank field");
jwilhelm@3995 152 #endif
jwilhelm@3995 153 }
jwilhelm@3995 154 ShouldNotReachHere();
jwilhelm@3995 155 return 0;
jwilhelm@3995 156 }
jwilhelm@3995 157
jwilhelm@3995 158 u2 allocation_type() const {
jwilhelm@3995 159 u2 lo = _shorts[low_packed_offset];
jwilhelm@3995 160 switch(lo & FIELDINFO_TAG_MASK) {
jwilhelm@3995 161 case FIELDINFO_TAG_TYPE_PLAIN:
jwilhelm@3995 162 case FIELDINFO_TAG_TYPE_CONTENDED:
jwilhelm@3995 163 return (lo >> FIELDINFO_TAG_SIZE);
jwilhelm@3995 164 #ifndef PRODUCT
jwilhelm@3995 165 case FIELDINFO_TAG_OFFSET:
neliasso@4334 166 fatal("Asking the field type for field with offset");
jwilhelm@3995 167 case FIELDINFO_TAG_BLANK:
neliasso@4334 168 fatal("Asking the field type for the blank field");
jwilhelm@3995 169 #endif
jwilhelm@3995 170 }
jwilhelm@3995 171 ShouldNotReachHere();
jwilhelm@3995 172 return 0;
jwilhelm@3995 173 }
jwilhelm@3995 174
jwilhelm@3995 175 bool is_offset_set() const {
jwilhelm@3995 176 return (_shorts[low_packed_offset] & FIELDINFO_TAG_MASK) == FIELDINFO_TAG_OFFSET;
jwilhelm@3995 177 }
never@2702 178
coleenp@9248 179 Symbol* name(const constantPoolHandle& cp) const {
never@2702 180 int index = name_index();
never@2702 181 if (is_internal()) {
never@2702 182 return lookup_symbol(index);
never@2702 183 }
never@2702 184 return cp->symbol_at(index);
never@2702 185 }
never@2702 186
coleenp@9248 187 Symbol* signature(const constantPoolHandle& cp) const {
never@2702 188 int index = signature_index();
never@2702 189 if (is_internal()) {
never@2702 190 return lookup_symbol(index);
never@2702 191 }
never@2702 192 return cp->symbol_at(index);
never@2702 193 }
never@2702 194
never@2702 195 void set_access_flags(u2 val) { _shorts[access_flags_offset] = val; }
never@2702 196 void set_offset(u4 val) {
jwilhelm@3995 197 val = val << FIELDINFO_TAG_SIZE; // make room for tag
jwilhelm@3995 198 _shorts[low_packed_offset] = extract_low_short_from_int(val) | FIELDINFO_TAG_OFFSET;
jwilhelm@3995 199 _shorts[high_packed_offset] = extract_high_short_from_int(val);
jwilhelm@3995 200 }
jwilhelm@3995 201
jwilhelm@3995 202 void set_allocation_type(int type) {
jwilhelm@3995 203 u2 lo = _shorts[low_packed_offset];
jwilhelm@3995 204 switch(lo & FIELDINFO_TAG_MASK) {
jwilhelm@3995 205 case FIELDINFO_TAG_BLANK:
jwilhelm@3995 206 _shorts[low_packed_offset] = ((type << FIELDINFO_TAG_SIZE)) & 0xFFFF;
jwilhelm@3995 207 _shorts[low_packed_offset] &= ~FIELDINFO_TAG_MASK;
jwilhelm@3995 208 _shorts[low_packed_offset] |= FIELDINFO_TAG_TYPE_PLAIN;
jwilhelm@3995 209 return;
jwilhelm@3995 210 #ifndef PRODUCT
jwilhelm@3995 211 case FIELDINFO_TAG_TYPE_PLAIN:
jwilhelm@3995 212 case FIELDINFO_TAG_TYPE_CONTENDED:
jwilhelm@3995 213 case FIELDINFO_TAG_OFFSET:
neliasso@4334 214 fatal("Setting the field type with overwriting");
jwilhelm@3995 215 #endif
jwilhelm@3995 216 }
jwilhelm@3995 217 ShouldNotReachHere();
jwilhelm@3995 218 }
jwilhelm@3995 219
jwilhelm@3995 220 void set_contended_group(u2 val) {
jwilhelm@3995 221 u2 lo = _shorts[low_packed_offset];
jwilhelm@3995 222 switch(lo & FIELDINFO_TAG_MASK) {
jwilhelm@3995 223 case FIELDINFO_TAG_TYPE_PLAIN:
jwilhelm@3995 224 _shorts[low_packed_offset] |= FIELDINFO_TAG_TYPE_CONTENDED;
jwilhelm@3995 225 _shorts[high_packed_offset] = val;
jwilhelm@3995 226 return;
jwilhelm@3995 227 #ifndef PRODUCT
jwilhelm@3995 228 case FIELDINFO_TAG_TYPE_CONTENDED:
neliasso@4334 229 fatal("Overwriting contended group");
jwilhelm@3995 230 case FIELDINFO_TAG_BLANK:
neliasso@4334 231 fatal("Setting contended group for the blank field");
jwilhelm@3995 232 case FIELDINFO_TAG_OFFSET:
neliasso@4334 233 fatal("Setting contended group for field with offset");
jwilhelm@3995 234 #endif
jwilhelm@3995 235 }
jwilhelm@3995 236 ShouldNotReachHere();
never@2702 237 }
never@2702 238
never@2702 239 bool is_internal() const {
never@2702 240 return (access_flags() & JVM_ACC_FIELD_INTERNAL) != 0;
never@2702 241 }
never@2702 242
vlivanov@5223 243 bool is_stable() const {
vlivanov@5223 244 return (access_flags() & JVM_ACC_FIELD_STABLE) != 0;
vlivanov@5223 245 }
vlivanov@5223 246 void set_stable(bool z) {
vlivanov@5223 247 if (z) _shorts[access_flags_offset] |= JVM_ACC_FIELD_STABLE;
vlivanov@5223 248 else _shorts[access_flags_offset] &= ~JVM_ACC_FIELD_STABLE;
vlivanov@5223 249 }
vlivanov@5223 250
never@2702 251 Symbol* lookup_symbol(int symbol_index) const {
never@2702 252 assert(is_internal(), "only internal fields");
never@2702 253 return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);
never@2702 254 }
never@2702 255 };
never@2702 256
never@2702 257 #endif // SHARE_VM_OOPS_FIELDINFO_HPP