2771N/A/*
2771N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2771N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2771N/A *
2771N/A * This code is free software; you can redistribute it and/or modify it
2771N/A * under the terms of the GNU General Public License version 2 only, as
2771N/A * published by the Free Software Foundation.
2771N/A *
2771N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2771N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2771N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2771N/A * version 2 for more details (a copy is included in the LICENSE file that
2771N/A * accompanied this code).
2771N/A *
2771N/A * You should have received a copy of the GNU General Public License version
2771N/A * 2 along with this work; if not, write to the Free Software Foundation,
2771N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2771N/A *
2771N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2771N/A * or visit www.oracle.com if you need additional information or have any
2771N/A * questions.
2771N/A *
2771N/A */
2771N/A
2771N/A#ifndef SHARE_VM_OOPS_FIELDINFO_HPP
2771N/A#define SHARE_VM_OOPS_FIELDINFO_HPP
2771N/A
2771N/A#include "oops/typeArrayOop.hpp"
2771N/A#include "classfile/vmSymbols.hpp"
2771N/A
2771N/A// This class represents the field information contained in the fields
2771N/A// array of an instanceKlass. Currently it's laid on top an array of
2771N/A// Java shorts but in the future it could simply be used as a real
2771N/A// array type. FieldInfo generally shouldn't be used directly.
2771N/A// Fields should be queried either through instanceKlass or through
2771N/A// the various FieldStreams.
2771N/Aclass FieldInfo VALUE_OBJ_CLASS_SPEC {
2771N/A friend class fieldDescriptor;
2771N/A friend class JavaFieldStream;
2771N/A friend class ClassFileParser;
2771N/A
2771N/A public:
2771N/A // fields
2771N/A // Field info extracted from the class file and stored
2771N/A // as an array of 7 shorts
2771N/A enum FieldOffset {
2771N/A access_flags_offset = 0,
2771N/A name_index_offset = 1,
2771N/A signature_index_offset = 2,
2771N/A initval_index_offset = 3,
2771N/A low_offset = 4,
2771N/A high_offset = 5,
3767N/A field_slots = 6
2771N/A };
2771N/A
2771N/A private:
2771N/A u2 _shorts[field_slots];
2771N/A
2771N/A void set_name_index(u2 val) { _shorts[name_index_offset] = val; }
2771N/A void set_signature_index(u2 val) { _shorts[signature_index_offset] = val; }
2771N/A void set_initval_index(u2 val) { _shorts[initval_index_offset] = val; }
2771N/A
2771N/A u2 name_index() const { return _shorts[name_index_offset]; }
2771N/A u2 signature_index() const { return _shorts[signature_index_offset]; }
2771N/A u2 initval_index() const { return _shorts[initval_index_offset]; }
2771N/A
2771N/A public:
2771N/A static FieldInfo* from_field_array(typeArrayOop fields, int index) {
2771N/A return ((FieldInfo*)fields->short_at_addr(index * field_slots));
2771N/A }
3767N/A static FieldInfo* from_field_array(u2* fields, int index) {
3767N/A return ((FieldInfo*)(fields + index * field_slots));
3767N/A }
2771N/A
2771N/A void initialize(u2 access_flags,
2771N/A u2 name_index,
2771N/A u2 signature_index,
2771N/A u2 initval_index,
2771N/A u4 offset) {
2771N/A _shorts[access_flags_offset] = access_flags;
2771N/A _shorts[name_index_offset] = name_index;
2771N/A _shorts[signature_index_offset] = signature_index;
2771N/A _shorts[initval_index_offset] = initval_index;
2771N/A set_offset(offset);
2771N/A }
2771N/A
2771N/A u2 access_flags() const { return _shorts[access_flags_offset]; }
2771N/A u4 offset() const { return build_int_from_shorts(_shorts[low_offset], _shorts[high_offset]); }
2771N/A
2771N/A Symbol* name(constantPoolHandle cp) const {
2771N/A int index = name_index();
2771N/A if (is_internal()) {
2771N/A return lookup_symbol(index);
2771N/A }
2771N/A return cp->symbol_at(index);
2771N/A }
2771N/A
2771N/A Symbol* signature(constantPoolHandle cp) const {
2771N/A int index = signature_index();
2771N/A if (is_internal()) {
2771N/A return lookup_symbol(index);
2771N/A }
2771N/A return cp->symbol_at(index);
2771N/A }
2771N/A
2771N/A void set_access_flags(u2 val) { _shorts[access_flags_offset] = val; }
2771N/A void set_offset(u4 val) {
2771N/A _shorts[low_offset] = extract_low_short_from_int(val);
2771N/A _shorts[high_offset] = extract_high_short_from_int(val);
2771N/A }
2771N/A
2771N/A bool is_internal() const {
2771N/A return (access_flags() & JVM_ACC_FIELD_INTERNAL) != 0;
2771N/A }
2771N/A
2771N/A Symbol* lookup_symbol(int symbol_index) const {
2771N/A assert(is_internal(), "only internal fields");
2771N/A return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);
2771N/A }
2771N/A};
2771N/A
2771N/A#endif // SHARE_VM_OOPS_FIELDINFO_HPP