Path: blob/master/src/hotspot/share/oops/fieldInfo.hpp
40951 views
/*1* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_OOPS_FIELDINFO_HPP25#define SHARE_OOPS_FIELDINFO_HPP2627#include "oops/constantPool.hpp"28#include "oops/symbol.hpp"29#include "oops/typeArrayOop.hpp"30#include "utilities/vmEnums.hpp"3132// This class represents the field information contained in the fields33// array of an InstanceKlass. Currently it's laid on top an array of34// Java shorts but in the future it could simply be used as a real35// array type. FieldInfo generally shouldn't be used directly.36// Fields should be queried either through InstanceKlass or through37// the various FieldStreams.38class FieldInfo {39friend class fieldDescriptor;40friend class JavaFieldStream;41friend class ClassFileParser;4243public:44// fields45// Field info extracted from the class file and stored46// as an array of 6 shorts.4748#define FIELDINFO_TAG_SIZE 249#define FIELDINFO_TAG_OFFSET 1 << 050#define FIELDINFO_TAG_CONTENDED 1 << 15152// Packed field has the tag, and can be either of:53// hi bits <--------------------------- lo bits54// |---------high---------|---------low---------|55// ..........................................CO56// ..........................................00 - non-contended field57// [--contention_group--]....................10 - contended field with contention group58// [------------------offset----------------]01 - real field offset5960// Bit O indicates if the packed field contains an offset (O=1) or not (O=0)61// Bit C indicates if the field is contended (C=1) or not (C=0)62// (if it is contended, the high packed field contains the contention group)6364enum FieldOffset {65access_flags_offset = 0,66name_index_offset = 1,67signature_index_offset = 2,68initval_index_offset = 3,69low_packed_offset = 4,70high_packed_offset = 5,71field_slots = 672};7374private:75u2 _shorts[field_slots];7677void set_name_index(u2 val) { _shorts[name_index_offset] = val; }78void set_signature_index(u2 val) { _shorts[signature_index_offset] = val; }79void set_initval_index(u2 val) { _shorts[initval_index_offset] = val; }8081u2 name_index() const { return _shorts[name_index_offset]; }82u2 signature_index() const { return _shorts[signature_index_offset]; }83u2 initval_index() const { return _shorts[initval_index_offset]; }8485public:86static FieldInfo* from_field_array(Array<u2>* fields, int index) {87return ((FieldInfo*)fields->adr_at(index * field_slots));88}89static FieldInfo* from_field_array(u2* fields, int index) {90return ((FieldInfo*)(fields + index * field_slots));91}9293void initialize(u2 access_flags,94u2 name_index,95u2 signature_index,96u2 initval_index) {97_shorts[access_flags_offset] = access_flags;98_shorts[name_index_offset] = name_index;99_shorts[signature_index_offset] = signature_index;100_shorts[initval_index_offset] = initval_index;101_shorts[low_packed_offset] = 0;102_shorts[high_packed_offset] = 0;103}104105u2 access_flags() const { return _shorts[access_flags_offset]; }106u4 offset() const {107assert((_shorts[low_packed_offset] & FIELDINFO_TAG_OFFSET) != 0, "Offset must have been set");108return build_int_from_shorts(_shorts[low_packed_offset], _shorts[high_packed_offset]) >> FIELDINFO_TAG_SIZE;109}110111bool is_contended() const {112return (_shorts[low_packed_offset] & FIELDINFO_TAG_CONTENDED) != 0;113}114115u2 contended_group() const {116assert((_shorts[low_packed_offset] & FIELDINFO_TAG_OFFSET) == 0, "Offset must not have been set");117assert((_shorts[low_packed_offset] & FIELDINFO_TAG_CONTENDED) != 0, "Field must be contended");118return _shorts[high_packed_offset];119}120121bool is_offset_set() const {122return (_shorts[low_packed_offset] & FIELDINFO_TAG_OFFSET)!= 0;123}124125Symbol* name(ConstantPool* cp) const {126int index = name_index();127if (is_internal()) {128return lookup_symbol(index);129}130return cp->symbol_at(index);131}132133Symbol* signature(ConstantPool* cp) const {134int index = signature_index();135if (is_internal()) {136return lookup_symbol(index);137}138return cp->symbol_at(index);139}140141void set_access_flags(u2 val) { _shorts[access_flags_offset] = val; }142void set_offset(u4 val) {143val = val << FIELDINFO_TAG_SIZE; // make room for tag144_shorts[low_packed_offset] = extract_low_short_from_int(val) | FIELDINFO_TAG_OFFSET;145_shorts[high_packed_offset] = extract_high_short_from_int(val);146}147148void set_contended_group(u2 val) {149assert((_shorts[low_packed_offset] & FIELDINFO_TAG_OFFSET) == 0, "Offset must not have been set");150assert((_shorts[low_packed_offset] & FIELDINFO_TAG_CONTENDED) == 0, "Overwritting contended group");151_shorts[low_packed_offset] |= FIELDINFO_TAG_CONTENDED;152_shorts[high_packed_offset] = val;153}154155bool is_internal() const {156return (access_flags() & JVM_ACC_FIELD_INTERNAL) != 0;157}158159bool is_stable() const {160return (access_flags() & JVM_ACC_FIELD_STABLE) != 0;161}162void set_stable(bool z) {163if (z) _shorts[access_flags_offset] |= JVM_ACC_FIELD_STABLE;164else _shorts[access_flags_offset] &= ~JVM_ACC_FIELD_STABLE;165}166167Symbol* lookup_symbol(int symbol_index) const {168assert(is_internal(), "only internal fields");169return Symbol::vm_symbol_at(static_cast<vmSymbolID>(symbol_index));170}171};172173#endif // SHARE_OOPS_FIELDINFO_HPP174175176