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