Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/oops/fieldInfo.hpp
32285 views
/*1* Copyright (c) 2011, 2013, 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_VM_OOPS_FIELDINFO_HPP25#define SHARE_VM_OOPS_FIELDINFO_HPP2627#include "oops/constantPool.hpp"28#include "oops/typeArrayOop.hpp"29#include "classfile/vmSymbols.hpp"3031// This class represents the field information contained in the fields32// array of an InstanceKlass. Currently it's laid on top an array of33// Java shorts but in the future it could simply be used as a real34// array type. FieldInfo generally shouldn't be used directly.35// Fields should be queried either through InstanceKlass or through36// the various FieldStreams.37class FieldInfo VALUE_OBJ_CLASS_SPEC {38friend class fieldDescriptor;39friend class JavaFieldStream;40friend class ClassFileParser;4142public:43// fields44// Field info extracted from the class file and stored45// as an array of 6 shorts.4647#define FIELDINFO_TAG_SIZE 248#define FIELDINFO_TAG_BLANK 049#define FIELDINFO_TAG_OFFSET 150#define FIELDINFO_TAG_TYPE_PLAIN 251#define FIELDINFO_TAG_TYPE_CONTENDED 352#define FIELDINFO_TAG_MASK 35354// Packed field has the tag, and can be either of:55// hi bits <--------------------------- lo bits56// |---------high---------|---------low---------|57// ..........................................00 - blank58// [------------------offset----------------]01 - real field offset59// ......................[-------type-------]10 - plain field with type60// [--contention_group--][-------type-------]11 - contended field with type and contention group61enum FieldOffset {62access_flags_offset = 0,63name_index_offset = 1,64signature_index_offset = 2,65initval_index_offset = 3,66low_packed_offset = 4,67high_packed_offset = 5,68field_slots = 669};7071private:72u2 _shorts[field_slots];7374void set_name_index(u2 val) { _shorts[name_index_offset] = val; }75void set_signature_index(u2 val) { _shorts[signature_index_offset] = val; }76void set_initval_index(u2 val) { _shorts[initval_index_offset] = val; }7778u2 name_index() const { return _shorts[name_index_offset]; }79u2 signature_index() const { return _shorts[signature_index_offset]; }80u2 initval_index() const { return _shorts[initval_index_offset]; }8182public:83static FieldInfo* from_field_array(Array<u2>* fields, int index) {84return ((FieldInfo*)fields->adr_at(index * field_slots));85}86static FieldInfo* from_field_array(u2* fields, int index) {87return ((FieldInfo*)(fields + index * field_slots));88}8990void initialize(u2 access_flags,91u2 name_index,92u2 signature_index,93u2 initval_index) {94_shorts[access_flags_offset] = access_flags;95_shorts[name_index_offset] = name_index;96_shorts[signature_index_offset] = signature_index;97_shorts[initval_index_offset] = initval_index;98_shorts[low_packed_offset] = 0;99_shorts[high_packed_offset] = 0;100}101102u2 access_flags() const { return _shorts[access_flags_offset]; }103u4 offset() const {104u2 lo = _shorts[low_packed_offset];105switch(lo & FIELDINFO_TAG_MASK) {106case FIELDINFO_TAG_OFFSET:107return build_int_from_shorts(_shorts[low_packed_offset], _shorts[high_packed_offset]) >> FIELDINFO_TAG_SIZE;108#ifndef PRODUCT109case FIELDINFO_TAG_TYPE_PLAIN:110fatal("Asking offset for the plain type field");111case FIELDINFO_TAG_TYPE_CONTENDED:112fatal("Asking offset for the contended type field");113case FIELDINFO_TAG_BLANK:114fatal("Asking offset for the blank field");115#endif116}117ShouldNotReachHere();118return 0;119}120121bool is_contended() const {122u2 lo = _shorts[low_packed_offset];123switch(lo & FIELDINFO_TAG_MASK) {124case FIELDINFO_TAG_TYPE_PLAIN:125return false;126case FIELDINFO_TAG_TYPE_CONTENDED:127return true;128#ifndef PRODUCT129case FIELDINFO_TAG_OFFSET:130fatal("Asking contended flag for the field with offset");131case FIELDINFO_TAG_BLANK:132fatal("Asking contended flag for the blank field");133#endif134}135ShouldNotReachHere();136return false;137}138139u2 contended_group() const {140u2 lo = _shorts[low_packed_offset];141switch(lo & FIELDINFO_TAG_MASK) {142case FIELDINFO_TAG_TYPE_PLAIN:143return 0;144case FIELDINFO_TAG_TYPE_CONTENDED:145return _shorts[high_packed_offset];146#ifndef PRODUCT147case FIELDINFO_TAG_OFFSET:148fatal("Asking the contended group for the field with offset");149case FIELDINFO_TAG_BLANK:150fatal("Asking the contended group for the blank field");151#endif152}153ShouldNotReachHere();154return 0;155}156157u2 allocation_type() const {158u2 lo = _shorts[low_packed_offset];159switch(lo & FIELDINFO_TAG_MASK) {160case FIELDINFO_TAG_TYPE_PLAIN:161case FIELDINFO_TAG_TYPE_CONTENDED:162return (lo >> FIELDINFO_TAG_SIZE);163#ifndef PRODUCT164case FIELDINFO_TAG_OFFSET:165fatal("Asking the field type for field with offset");166case FIELDINFO_TAG_BLANK:167fatal("Asking the field type for the blank field");168#endif169}170ShouldNotReachHere();171return 0;172}173174bool is_offset_set() const {175return (_shorts[low_packed_offset] & FIELDINFO_TAG_MASK) == FIELDINFO_TAG_OFFSET;176}177178Symbol* name(constantPoolHandle cp) const {179int index = name_index();180if (is_internal()) {181return lookup_symbol(index);182}183return cp->symbol_at(index);184}185186Symbol* signature(constantPoolHandle cp) const {187int index = signature_index();188if (is_internal()) {189return lookup_symbol(index);190}191return cp->symbol_at(index);192}193194void set_access_flags(u2 val) { _shorts[access_flags_offset] = val; }195void set_offset(u4 val) {196val = val << FIELDINFO_TAG_SIZE; // make room for tag197_shorts[low_packed_offset] = extract_low_short_from_int(val) | FIELDINFO_TAG_OFFSET;198_shorts[high_packed_offset] = extract_high_short_from_int(val);199}200201void set_allocation_type(int type) {202u2 lo = _shorts[low_packed_offset];203switch(lo & FIELDINFO_TAG_MASK) {204case FIELDINFO_TAG_BLANK:205_shorts[low_packed_offset] = ((type << FIELDINFO_TAG_SIZE)) & 0xFFFF;206_shorts[low_packed_offset] &= ~FIELDINFO_TAG_MASK;207_shorts[low_packed_offset] |= FIELDINFO_TAG_TYPE_PLAIN;208return;209#ifndef PRODUCT210case FIELDINFO_TAG_TYPE_PLAIN:211case FIELDINFO_TAG_TYPE_CONTENDED:212case FIELDINFO_TAG_OFFSET:213fatal("Setting the field type with overwriting");214#endif215}216ShouldNotReachHere();217}218219void set_contended_group(u2 val) {220u2 lo = _shorts[low_packed_offset];221switch(lo & FIELDINFO_TAG_MASK) {222case FIELDINFO_TAG_TYPE_PLAIN:223_shorts[low_packed_offset] |= FIELDINFO_TAG_TYPE_CONTENDED;224_shorts[high_packed_offset] = val;225return;226#ifndef PRODUCT227case FIELDINFO_TAG_TYPE_CONTENDED:228fatal("Overwriting contended group");229case FIELDINFO_TAG_BLANK:230fatal("Setting contended group for the blank field");231case FIELDINFO_TAG_OFFSET:232fatal("Setting contended group for field with offset");233#endif234}235ShouldNotReachHere();236}237238bool is_internal() const {239return (access_flags() & JVM_ACC_FIELD_INTERNAL) != 0;240}241242bool is_stable() const {243return (access_flags() & JVM_ACC_FIELD_STABLE) != 0;244}245void set_stable(bool z) {246if (z) _shorts[access_flags_offset] |= JVM_ACC_FIELD_STABLE;247else _shorts[access_flags_offset] &= ~JVM_ACC_FIELD_STABLE;248}249250Symbol* lookup_symbol(int symbol_index) const {251assert(is_internal(), "only internal fields");252return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);253}254};255256#endif // SHARE_VM_OOPS_FIELDINFO_HPP257258259