never@3137: /* mikael@6198: * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. never@3137: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. never@3137: * never@3137: * This code is free software; you can redistribute it and/or modify it never@3137: * under the terms of the GNU General Public License version 2 only, as never@3137: * published by the Free Software Foundation. never@3137: * never@3137: * This code is distributed in the hope that it will be useful, but WITHOUT never@3137: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or never@3137: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License never@3137: * version 2 for more details (a copy is included in the LICENSE file that never@3137: * accompanied this code). never@3137: * never@3137: * You should have received a copy of the GNU General Public License version never@3137: * 2 along with this work; if not, write to the Free Software Foundation, never@3137: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. never@3137: * never@3137: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA never@3137: * or visit www.oracle.com if you need additional information or have any never@3137: * questions. never@3137: * never@3137: */ never@3137: never@3137: #ifndef SHARE_VM_OOPS_FIELDINFO_HPP never@3137: #define SHARE_VM_OOPS_FIELDINFO_HPP never@3137: coleenp@4037: #include "oops/constantPool.hpp" never@3137: #include "oops/typeArrayOop.hpp" never@3137: #include "classfile/vmSymbols.hpp" never@3137: never@3137: // This class represents the field information contained in the fields coleenp@4037: // array of an InstanceKlass. Currently it's laid on top an array of never@3137: // Java shorts but in the future it could simply be used as a real never@3137: // array type. FieldInfo generally shouldn't be used directly. coleenp@4037: // Fields should be queried either through InstanceKlass or through never@3137: // the various FieldStreams. never@3137: class FieldInfo VALUE_OBJ_CLASS_SPEC { never@3137: friend class fieldDescriptor; never@3137: friend class JavaFieldStream; never@3137: friend class ClassFileParser; never@3137: never@3137: public: never@3137: // fields never@3137: // Field info extracted from the class file and stored jwilhelm@4430: // as an array of 6 shorts. jwilhelm@4430: jwilhelm@4430: #define FIELDINFO_TAG_SIZE 2 jwilhelm@4430: #define FIELDINFO_TAG_BLANK 0 jwilhelm@4430: #define FIELDINFO_TAG_OFFSET 1 jwilhelm@4430: #define FIELDINFO_TAG_TYPE_PLAIN 2 jwilhelm@4430: #define FIELDINFO_TAG_TYPE_CONTENDED 3 jwilhelm@4430: #define FIELDINFO_TAG_MASK 3 jwilhelm@4430: jwilhelm@4430: // Packed field has the tag, and can be either of: jwilhelm@4430: // hi bits <--------------------------- lo bits jwilhelm@4430: // |---------high---------|---------low---------| jwilhelm@4430: // ..........................................00 - blank jwilhelm@4430: // [------------------offset----------------]01 - real field offset jwilhelm@4430: // ......................[-------type-------]10 - plain field with type jwilhelm@4430: // [--contention_group--][-------type-------]11 - contended field with type and contention group never@3137: enum FieldOffset { never@3137: access_flags_offset = 0, never@3137: name_index_offset = 1, never@3137: signature_index_offset = 2, never@3137: initval_index_offset = 3, jwilhelm@4430: low_packed_offset = 4, jwilhelm@4430: high_packed_offset = 5, jiangli@3803: field_slots = 6 never@3137: }; never@3137: never@3137: private: never@3137: u2 _shorts[field_slots]; never@3137: never@3137: void set_name_index(u2 val) { _shorts[name_index_offset] = val; } never@3137: void set_signature_index(u2 val) { _shorts[signature_index_offset] = val; } never@3137: void set_initval_index(u2 val) { _shorts[initval_index_offset] = val; } never@3137: never@3137: u2 name_index() const { return _shorts[name_index_offset]; } never@3137: u2 signature_index() const { return _shorts[signature_index_offset]; } never@3137: u2 initval_index() const { return _shorts[initval_index_offset]; } never@3137: never@3137: public: coleenp@4037: static FieldInfo* from_field_array(Array* fields, int index) { coleenp@4037: return ((FieldInfo*)fields->adr_at(index * field_slots)); never@3137: } jiangli@3803: static FieldInfo* from_field_array(u2* fields, int index) { jiangli@3803: return ((FieldInfo*)(fields + index * field_slots)); jiangli@3803: } never@3137: never@3137: void initialize(u2 access_flags, never@3137: u2 name_index, never@3137: u2 signature_index, jwilhelm@4430: u2 initval_index) { never@3137: _shorts[access_flags_offset] = access_flags; never@3137: _shorts[name_index_offset] = name_index; never@3137: _shorts[signature_index_offset] = signature_index; never@3137: _shorts[initval_index_offset] = initval_index; jwilhelm@4430: _shorts[low_packed_offset] = 0; jwilhelm@4430: _shorts[high_packed_offset] = 0; never@3137: } never@3137: never@3137: u2 access_flags() const { return _shorts[access_flags_offset]; } jwilhelm@4430: u4 offset() const { jwilhelm@4430: u2 lo = _shorts[low_packed_offset]; jwilhelm@4430: switch(lo & FIELDINFO_TAG_MASK) { jwilhelm@4430: case FIELDINFO_TAG_OFFSET: jwilhelm@4430: return build_int_from_shorts(_shorts[low_packed_offset], _shorts[high_packed_offset]) >> FIELDINFO_TAG_SIZE; jwilhelm@4430: #ifndef PRODUCT jwilhelm@4430: case FIELDINFO_TAG_TYPE_PLAIN: neliasso@4769: fatal("Asking offset for the plain type field"); jwilhelm@4430: case FIELDINFO_TAG_TYPE_CONTENDED: neliasso@4769: fatal("Asking offset for the contended type field"); jwilhelm@4430: case FIELDINFO_TAG_BLANK: neliasso@4769: fatal("Asking offset for the blank field"); jwilhelm@4430: #endif jwilhelm@4430: } jwilhelm@4430: ShouldNotReachHere(); jwilhelm@4430: return 0; jwilhelm@4430: } jwilhelm@4430: jwilhelm@4430: bool is_contended() const { jwilhelm@4430: u2 lo = _shorts[low_packed_offset]; jwilhelm@4430: switch(lo & FIELDINFO_TAG_MASK) { jwilhelm@4430: case FIELDINFO_TAG_TYPE_PLAIN: jwilhelm@4430: return false; jwilhelm@4430: case FIELDINFO_TAG_TYPE_CONTENDED: jwilhelm@4430: return true; jwilhelm@4430: #ifndef PRODUCT jwilhelm@4430: case FIELDINFO_TAG_OFFSET: neliasso@4769: fatal("Asking contended flag for the field with offset"); jwilhelm@4430: case FIELDINFO_TAG_BLANK: neliasso@4769: fatal("Asking contended flag for the blank field"); jwilhelm@4430: #endif jwilhelm@4430: } jwilhelm@4430: ShouldNotReachHere(); jwilhelm@4430: return false; jwilhelm@4430: } jwilhelm@4430: jwilhelm@4430: u2 contended_group() const { jwilhelm@4430: u2 lo = _shorts[low_packed_offset]; jwilhelm@4430: switch(lo & FIELDINFO_TAG_MASK) { jwilhelm@4430: case FIELDINFO_TAG_TYPE_PLAIN: jwilhelm@4430: return 0; jwilhelm@4430: case FIELDINFO_TAG_TYPE_CONTENDED: jwilhelm@4430: return _shorts[high_packed_offset]; jwilhelm@4430: #ifndef PRODUCT jwilhelm@4430: case FIELDINFO_TAG_OFFSET: neliasso@4769: fatal("Asking the contended group for the field with offset"); jwilhelm@4430: case FIELDINFO_TAG_BLANK: neliasso@4769: fatal("Asking the contended group for the blank field"); jwilhelm@4430: #endif jwilhelm@4430: } jwilhelm@4430: ShouldNotReachHere(); jwilhelm@4430: return 0; jwilhelm@4430: } jwilhelm@4430: jwilhelm@4430: u2 allocation_type() const { jwilhelm@4430: u2 lo = _shorts[low_packed_offset]; jwilhelm@4430: switch(lo & FIELDINFO_TAG_MASK) { jwilhelm@4430: case FIELDINFO_TAG_TYPE_PLAIN: jwilhelm@4430: case FIELDINFO_TAG_TYPE_CONTENDED: jwilhelm@4430: return (lo >> FIELDINFO_TAG_SIZE); jwilhelm@4430: #ifndef PRODUCT jwilhelm@4430: case FIELDINFO_TAG_OFFSET: neliasso@4769: fatal("Asking the field type for field with offset"); jwilhelm@4430: case FIELDINFO_TAG_BLANK: neliasso@4769: fatal("Asking the field type for the blank field"); jwilhelm@4430: #endif jwilhelm@4430: } jwilhelm@4430: ShouldNotReachHere(); jwilhelm@4430: return 0; jwilhelm@4430: } jwilhelm@4430: jwilhelm@4430: bool is_offset_set() const { jwilhelm@4430: return (_shorts[low_packed_offset] & FIELDINFO_TAG_MASK) == FIELDINFO_TAG_OFFSET; jwilhelm@4430: } never@3137: never@3137: Symbol* name(constantPoolHandle cp) const { never@3137: int index = name_index(); never@3137: if (is_internal()) { never@3137: return lookup_symbol(index); never@3137: } never@3137: return cp->symbol_at(index); never@3137: } never@3137: never@3137: Symbol* signature(constantPoolHandle cp) const { never@3137: int index = signature_index(); never@3137: if (is_internal()) { never@3137: return lookup_symbol(index); never@3137: } never@3137: return cp->symbol_at(index); never@3137: } never@3137: never@3137: void set_access_flags(u2 val) { _shorts[access_flags_offset] = val; } never@3137: void set_offset(u4 val) { jwilhelm@4430: val = val << FIELDINFO_TAG_SIZE; // make room for tag jwilhelm@4430: _shorts[low_packed_offset] = extract_low_short_from_int(val) | FIELDINFO_TAG_OFFSET; jwilhelm@4430: _shorts[high_packed_offset] = extract_high_short_from_int(val); jwilhelm@4430: } jwilhelm@4430: jwilhelm@4430: void set_allocation_type(int type) { jwilhelm@4430: u2 lo = _shorts[low_packed_offset]; jwilhelm@4430: switch(lo & FIELDINFO_TAG_MASK) { jwilhelm@4430: case FIELDINFO_TAG_BLANK: jwilhelm@4430: _shorts[low_packed_offset] = ((type << FIELDINFO_TAG_SIZE)) & 0xFFFF; jwilhelm@4430: _shorts[low_packed_offset] &= ~FIELDINFO_TAG_MASK; jwilhelm@4430: _shorts[low_packed_offset] |= FIELDINFO_TAG_TYPE_PLAIN; jwilhelm@4430: return; jwilhelm@4430: #ifndef PRODUCT jwilhelm@4430: case FIELDINFO_TAG_TYPE_PLAIN: jwilhelm@4430: case FIELDINFO_TAG_TYPE_CONTENDED: jwilhelm@4430: case FIELDINFO_TAG_OFFSET: neliasso@4769: fatal("Setting the field type with overwriting"); jwilhelm@4430: #endif jwilhelm@4430: } jwilhelm@4430: ShouldNotReachHere(); jwilhelm@4430: } jwilhelm@4430: jwilhelm@4430: void set_contended_group(u2 val) { jwilhelm@4430: u2 lo = _shorts[low_packed_offset]; jwilhelm@4430: switch(lo & FIELDINFO_TAG_MASK) { jwilhelm@4430: case FIELDINFO_TAG_TYPE_PLAIN: jwilhelm@4430: _shorts[low_packed_offset] |= FIELDINFO_TAG_TYPE_CONTENDED; jwilhelm@4430: _shorts[high_packed_offset] = val; jwilhelm@4430: return; jwilhelm@4430: #ifndef PRODUCT jwilhelm@4430: case FIELDINFO_TAG_TYPE_CONTENDED: neliasso@4769: fatal("Overwriting contended group"); jwilhelm@4430: case FIELDINFO_TAG_BLANK: neliasso@4769: fatal("Setting contended group for the blank field"); jwilhelm@4430: case FIELDINFO_TAG_OFFSET: neliasso@4769: fatal("Setting contended group for field with offset"); jwilhelm@4430: #endif jwilhelm@4430: } jwilhelm@4430: ShouldNotReachHere(); never@3137: } never@3137: never@3137: bool is_internal() const { never@3137: return (access_flags() & JVM_ACC_FIELD_INTERNAL) != 0; never@3137: } never@3137: vlivanov@5658: bool is_stable() const { vlivanov@5658: return (access_flags() & JVM_ACC_FIELD_STABLE) != 0; vlivanov@5658: } vlivanov@5658: void set_stable(bool z) { vlivanov@5658: if (z) _shorts[access_flags_offset] |= JVM_ACC_FIELD_STABLE; vlivanov@5658: else _shorts[access_flags_offset] &= ~JVM_ACC_FIELD_STABLE; vlivanov@5658: } vlivanov@5658: never@3137: Symbol* lookup_symbol(int symbol_index) const { never@3137: assert(is_internal(), "only internal fields"); never@3137: return vmSymbols::symbol_at((vmSymbols::SID)symbol_index); never@3137: } never@3137: }; never@3137: never@3137: #endif // SHARE_VM_OOPS_FIELDINFO_HPP