src/share/vm/oops/fieldInfo.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2011, 2013, 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 #ifndef SHARE_VM_OOPS_FIELDINFO_HPP
aoqi@0 26 #define SHARE_VM_OOPS_FIELDINFO_HPP
aoqi@0 27
aoqi@0 28 #include "oops/constantPool.hpp"
aoqi@0 29 #include "oops/typeArrayOop.hpp"
aoqi@0 30 #include "classfile/vmSymbols.hpp"
aoqi@0 31
aoqi@0 32 // This class represents the field information contained in the fields
aoqi@0 33 // array of an InstanceKlass. Currently it's laid on top an array of
aoqi@0 34 // Java shorts but in the future it could simply be used as a real
aoqi@0 35 // array type. FieldInfo generally shouldn't be used directly.
aoqi@0 36 // Fields should be queried either through InstanceKlass or through
aoqi@0 37 // the various FieldStreams.
aoqi@0 38 class FieldInfo VALUE_OBJ_CLASS_SPEC {
aoqi@0 39 friend class fieldDescriptor;
aoqi@0 40 friend class JavaFieldStream;
aoqi@0 41 friend class ClassFileParser;
aoqi@0 42
aoqi@0 43 public:
aoqi@0 44 // fields
aoqi@0 45 // Field info extracted from the class file and stored
aoqi@0 46 // as an array of 6 shorts.
aoqi@0 47
aoqi@0 48 #define FIELDINFO_TAG_SIZE 2
aoqi@0 49 #define FIELDINFO_TAG_BLANK 0
aoqi@0 50 #define FIELDINFO_TAG_OFFSET 1
aoqi@0 51 #define FIELDINFO_TAG_TYPE_PLAIN 2
aoqi@0 52 #define FIELDINFO_TAG_TYPE_CONTENDED 3
aoqi@0 53 #define FIELDINFO_TAG_MASK 3
aoqi@0 54
aoqi@0 55 // Packed field has the tag, and can be either of:
aoqi@0 56 // hi bits <--------------------------- lo bits
aoqi@0 57 // |---------high---------|---------low---------|
aoqi@0 58 // ..........................................00 - blank
aoqi@0 59 // [------------------offset----------------]01 - real field offset
aoqi@0 60 // ......................[-------type-------]10 - plain field with type
aoqi@0 61 // [--contention_group--][-------type-------]11 - contended field with type and contention group
aoqi@0 62 enum FieldOffset {
aoqi@0 63 access_flags_offset = 0,
aoqi@0 64 name_index_offset = 1,
aoqi@0 65 signature_index_offset = 2,
aoqi@0 66 initval_index_offset = 3,
aoqi@0 67 low_packed_offset = 4,
aoqi@0 68 high_packed_offset = 5,
aoqi@0 69 field_slots = 6
aoqi@0 70 };
aoqi@0 71
aoqi@0 72 private:
aoqi@0 73 u2 _shorts[field_slots];
aoqi@0 74
aoqi@0 75 void set_name_index(u2 val) { _shorts[name_index_offset] = val; }
aoqi@0 76 void set_signature_index(u2 val) { _shorts[signature_index_offset] = val; }
aoqi@0 77 void set_initval_index(u2 val) { _shorts[initval_index_offset] = val; }
aoqi@0 78
aoqi@0 79 u2 name_index() const { return _shorts[name_index_offset]; }
aoqi@0 80 u2 signature_index() const { return _shorts[signature_index_offset]; }
aoqi@0 81 u2 initval_index() const { return _shorts[initval_index_offset]; }
aoqi@0 82
aoqi@0 83 public:
aoqi@0 84 static FieldInfo* from_field_array(Array<u2>* fields, int index) {
aoqi@0 85 return ((FieldInfo*)fields->adr_at(index * field_slots));
aoqi@0 86 }
aoqi@0 87 static FieldInfo* from_field_array(u2* fields, int index) {
aoqi@0 88 return ((FieldInfo*)(fields + index * field_slots));
aoqi@0 89 }
aoqi@0 90
aoqi@0 91 void initialize(u2 access_flags,
aoqi@0 92 u2 name_index,
aoqi@0 93 u2 signature_index,
aoqi@0 94 u2 initval_index) {
aoqi@0 95 _shorts[access_flags_offset] = access_flags;
aoqi@0 96 _shorts[name_index_offset] = name_index;
aoqi@0 97 _shorts[signature_index_offset] = signature_index;
aoqi@0 98 _shorts[initval_index_offset] = initval_index;
aoqi@0 99 _shorts[low_packed_offset] = 0;
aoqi@0 100 _shorts[high_packed_offset] = 0;
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 u2 access_flags() const { return _shorts[access_flags_offset]; }
aoqi@0 104 u4 offset() const {
aoqi@0 105 u2 lo = _shorts[low_packed_offset];
aoqi@0 106 switch(lo & FIELDINFO_TAG_MASK) {
aoqi@0 107 case FIELDINFO_TAG_OFFSET:
aoqi@0 108 return build_int_from_shorts(_shorts[low_packed_offset], _shorts[high_packed_offset]) >> FIELDINFO_TAG_SIZE;
aoqi@0 109 #ifndef PRODUCT
aoqi@0 110 case FIELDINFO_TAG_TYPE_PLAIN:
aoqi@0 111 fatal("Asking offset for the plain type field");
aoqi@0 112 case FIELDINFO_TAG_TYPE_CONTENDED:
aoqi@0 113 fatal("Asking offset for the contended type field");
aoqi@0 114 case FIELDINFO_TAG_BLANK:
aoqi@0 115 fatal("Asking offset for the blank field");
aoqi@0 116 #endif
aoqi@0 117 }
aoqi@0 118 ShouldNotReachHere();
aoqi@0 119 return 0;
aoqi@0 120 }
aoqi@0 121
aoqi@0 122 bool is_contended() const {
aoqi@0 123 u2 lo = _shorts[low_packed_offset];
aoqi@0 124 switch(lo & FIELDINFO_TAG_MASK) {
aoqi@0 125 case FIELDINFO_TAG_TYPE_PLAIN:
aoqi@0 126 return false;
aoqi@0 127 case FIELDINFO_TAG_TYPE_CONTENDED:
aoqi@0 128 return true;
aoqi@0 129 #ifndef PRODUCT
aoqi@0 130 case FIELDINFO_TAG_OFFSET:
aoqi@0 131 fatal("Asking contended flag for the field with offset");
aoqi@0 132 case FIELDINFO_TAG_BLANK:
aoqi@0 133 fatal("Asking contended flag for the blank field");
aoqi@0 134 #endif
aoqi@0 135 }
aoqi@0 136 ShouldNotReachHere();
aoqi@0 137 return false;
aoqi@0 138 }
aoqi@0 139
aoqi@0 140 u2 contended_group() const {
aoqi@0 141 u2 lo = _shorts[low_packed_offset];
aoqi@0 142 switch(lo & FIELDINFO_TAG_MASK) {
aoqi@0 143 case FIELDINFO_TAG_TYPE_PLAIN:
aoqi@0 144 return 0;
aoqi@0 145 case FIELDINFO_TAG_TYPE_CONTENDED:
aoqi@0 146 return _shorts[high_packed_offset];
aoqi@0 147 #ifndef PRODUCT
aoqi@0 148 case FIELDINFO_TAG_OFFSET:
aoqi@0 149 fatal("Asking the contended group for the field with offset");
aoqi@0 150 case FIELDINFO_TAG_BLANK:
aoqi@0 151 fatal("Asking the contended group for the blank field");
aoqi@0 152 #endif
aoqi@0 153 }
aoqi@0 154 ShouldNotReachHere();
aoqi@0 155 return 0;
aoqi@0 156 }
aoqi@0 157
aoqi@0 158 u2 allocation_type() const {
aoqi@0 159 u2 lo = _shorts[low_packed_offset];
aoqi@0 160 switch(lo & FIELDINFO_TAG_MASK) {
aoqi@0 161 case FIELDINFO_TAG_TYPE_PLAIN:
aoqi@0 162 case FIELDINFO_TAG_TYPE_CONTENDED:
aoqi@0 163 return (lo >> FIELDINFO_TAG_SIZE);
aoqi@0 164 #ifndef PRODUCT
aoqi@0 165 case FIELDINFO_TAG_OFFSET:
aoqi@0 166 fatal("Asking the field type for field with offset");
aoqi@0 167 case FIELDINFO_TAG_BLANK:
aoqi@0 168 fatal("Asking the field type for the blank field");
aoqi@0 169 #endif
aoqi@0 170 }
aoqi@0 171 ShouldNotReachHere();
aoqi@0 172 return 0;
aoqi@0 173 }
aoqi@0 174
aoqi@0 175 bool is_offset_set() const {
aoqi@0 176 return (_shorts[low_packed_offset] & FIELDINFO_TAG_MASK) == FIELDINFO_TAG_OFFSET;
aoqi@0 177 }
aoqi@0 178
aoqi@0 179 Symbol* name(constantPoolHandle cp) const {
aoqi@0 180 int index = name_index();
aoqi@0 181 if (is_internal()) {
aoqi@0 182 return lookup_symbol(index);
aoqi@0 183 }
aoqi@0 184 return cp->symbol_at(index);
aoqi@0 185 }
aoqi@0 186
aoqi@0 187 Symbol* signature(constantPoolHandle cp) const {
aoqi@0 188 int index = signature_index();
aoqi@0 189 if (is_internal()) {
aoqi@0 190 return lookup_symbol(index);
aoqi@0 191 }
aoqi@0 192 return cp->symbol_at(index);
aoqi@0 193 }
aoqi@0 194
aoqi@0 195 void set_access_flags(u2 val) { _shorts[access_flags_offset] = val; }
aoqi@0 196 void set_offset(u4 val) {
aoqi@0 197 val = val << FIELDINFO_TAG_SIZE; // make room for tag
aoqi@0 198 _shorts[low_packed_offset] = extract_low_short_from_int(val) | FIELDINFO_TAG_OFFSET;
aoqi@0 199 _shorts[high_packed_offset] = extract_high_short_from_int(val);
aoqi@0 200 }
aoqi@0 201
aoqi@0 202 void set_allocation_type(int type) {
aoqi@0 203 u2 lo = _shorts[low_packed_offset];
aoqi@0 204 switch(lo & FIELDINFO_TAG_MASK) {
aoqi@0 205 case FIELDINFO_TAG_BLANK:
aoqi@0 206 _shorts[low_packed_offset] = ((type << FIELDINFO_TAG_SIZE)) & 0xFFFF;
aoqi@0 207 _shorts[low_packed_offset] &= ~FIELDINFO_TAG_MASK;
aoqi@0 208 _shorts[low_packed_offset] |= FIELDINFO_TAG_TYPE_PLAIN;
aoqi@0 209 return;
aoqi@0 210 #ifndef PRODUCT
aoqi@0 211 case FIELDINFO_TAG_TYPE_PLAIN:
aoqi@0 212 case FIELDINFO_TAG_TYPE_CONTENDED:
aoqi@0 213 case FIELDINFO_TAG_OFFSET:
aoqi@0 214 fatal("Setting the field type with overwriting");
aoqi@0 215 #endif
aoqi@0 216 }
aoqi@0 217 ShouldNotReachHere();
aoqi@0 218 }
aoqi@0 219
aoqi@0 220 void set_contended_group(u2 val) {
aoqi@0 221 u2 lo = _shorts[low_packed_offset];
aoqi@0 222 switch(lo & FIELDINFO_TAG_MASK) {
aoqi@0 223 case FIELDINFO_TAG_TYPE_PLAIN:
aoqi@0 224 _shorts[low_packed_offset] |= FIELDINFO_TAG_TYPE_CONTENDED;
aoqi@0 225 _shorts[high_packed_offset] = val;
aoqi@0 226 return;
aoqi@0 227 #ifndef PRODUCT
aoqi@0 228 case FIELDINFO_TAG_TYPE_CONTENDED:
aoqi@0 229 fatal("Overwriting contended group");
aoqi@0 230 case FIELDINFO_TAG_BLANK:
aoqi@0 231 fatal("Setting contended group for the blank field");
aoqi@0 232 case FIELDINFO_TAG_OFFSET:
aoqi@0 233 fatal("Setting contended group for field with offset");
aoqi@0 234 #endif
aoqi@0 235 }
aoqi@0 236 ShouldNotReachHere();
aoqi@0 237 }
aoqi@0 238
aoqi@0 239 bool is_internal() const {
aoqi@0 240 return (access_flags() & JVM_ACC_FIELD_INTERNAL) != 0;
aoqi@0 241 }
aoqi@0 242
aoqi@0 243 bool is_stable() const {
aoqi@0 244 return (access_flags() & JVM_ACC_FIELD_STABLE) != 0;
aoqi@0 245 }
aoqi@0 246 void set_stable(bool z) {
aoqi@0 247 if (z) _shorts[access_flags_offset] |= JVM_ACC_FIELD_STABLE;
aoqi@0 248 else _shorts[access_flags_offset] &= ~JVM_ACC_FIELD_STABLE;
aoqi@0 249 }
aoqi@0 250
aoqi@0 251 Symbol* lookup_symbol(int symbol_index) const {
aoqi@0 252 assert(is_internal(), "only internal fields");
aoqi@0 253 return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);
aoqi@0 254 }
aoqi@0 255 };
aoqi@0 256
aoqi@0 257 #endif // SHARE_VM_OOPS_FIELDINFO_HPP

mercurial