0N/A/*
3418N/A * Copyright (c) 1999, 2012, 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
1879N/A#ifndef SHARE_VM_CI_CIFIELD_HPP
1879N/A#define SHARE_VM_CI_CIFIELD_HPP
1879N/A
1879N/A#include "ci/ciClassList.hpp"
1879N/A#include "ci/ciConstant.hpp"
1879N/A#include "ci/ciFlags.hpp"
1879N/A#include "ci/ciInstance.hpp"
1879N/A
0N/A// ciField
0N/A//
0N/A// This class represents the result of a field lookup in the VM.
0N/A// The lookup may not succeed, in which case the information in
0N/A// the ciField will be incomplete.
0N/Aclass ciField : public ResourceObj {
0N/A CI_PACKAGE_ACCESS
0N/A friend class ciEnv;
0N/A friend class ciInstanceKlass;
0N/A friend class NonStaticFieldFiller;
0N/A
0N/Aprivate:
0N/A ciFlags _flags;
0N/A ciInstanceKlass* _holder;
0N/A ciSymbol* _name;
0N/A ciSymbol* _signature;
0N/A ciType* _type;
0N/A int _offset;
0N/A bool _is_constant;
3418N/A ciInstanceKlass* _known_to_link_with_put;
3418N/A ciInstanceKlass* _known_to_link_with_get;
0N/A ciConstant _constant_value;
0N/A
0N/A // Used for will_link
0N/A int _cp_index;
0N/A
0N/A ciType* compute_type();
0N/A ciType* compute_type_impl();
0N/A
0N/A ciField(ciInstanceKlass* klass, int index);
0N/A ciField(fieldDescriptor* fd);
0N/A
0N/A // shared constructor code
0N/A void initialize_from(fieldDescriptor* fd);
0N/A
0N/Apublic:
0N/A ciFlags flags() { return _flags; }
0N/A
0N/A // Of which klass is this field a member?
0N/A //
0N/A // Usage note: the declared holder of a field is the class
0N/A // referenced by name in the bytecodes. The canonical holder
0N/A // is the most general class which holds the field. This
0N/A // method returns the canonical holder. The declared holder
0N/A // can be accessed via a method in ciBytecodeStream.
0N/A //
0N/A // Ex.
0N/A // class A {
0N/A // public int f = 7;
0N/A // }
0N/A // class B extends A {
0N/A // public void test() {
0N/A // System.out.println(f);
0N/A // }
0N/A // }
0N/A //
0N/A // A java compiler is permitted to compile the access to
0N/A // field f as:
0N/A //
0N/A // getfield B.f
0N/A //
0N/A // In that case the declared holder of f would be B and
0N/A // the canonical holder of f would be A.
0N/A ciInstanceKlass* holder() { return _holder; }
0N/A
0N/A // Name of this field?
0N/A ciSymbol* name() { return _name; }
0N/A
0N/A // Signature of this field?
0N/A ciSymbol* signature() { return _signature; }
0N/A
0N/A // Of what type is this field?
0N/A ciType* type() { return (_type == NULL) ? compute_type() : _type; }
0N/A
0N/A // How is this field actually stored in memory?
0N/A BasicType layout_type() { return type2field[(_type == NULL) ? T_OBJECT : _type->basic_type()]; }
0N/A
0N/A // How big is this field in memory?
29N/A int size_in_bytes() { return type2aelembytes(layout_type()); }
0N/A
0N/A // What is the offset of this field?
0N/A int offset() {
0N/A assert(_offset >= 1, "illegal call to offset()");
0N/A return _offset;
0N/A }
0N/A
0N/A // Same question, explicit units. (Fields are aligned to the byte level.)
0N/A int offset_in_bytes() {
0N/A return offset();
0N/A }
0N/A
0N/A // Is this field shared?
0N/A bool is_shared() {
0N/A // non-static fields of shared holders are cached
0N/A return _holder->is_shared() && !is_static();
0N/A }
0N/A
0N/A // Is this field a constant?
0N/A //
0N/A // Clarification: A field is considered constant if:
0N/A // 1. The field is both static and final
0N/A // 2. The canonical holder of the field has undergone
0N/A // static initialization.
0N/A // 3. If the field is an object or array, then the oop
0N/A // in question is allocated in perm space.
0N/A // 4. The field is not one of the special static/final
0N/A // non-constant fields. These are java.lang.System.in
0N/A // and java.lang.System.out. Abomination.
0N/A //
0N/A // Note: the check for case 4 is not yet implemented.
0N/A bool is_constant() { return _is_constant; }
0N/A
0N/A // Get the constant value of this field.
0N/A ciConstant constant_value() {
1138N/A assert(is_static() && is_constant(), "illegal call to constant_value()");
0N/A return _constant_value;
0N/A }
0N/A
1138N/A // Get the constant value of non-static final field in the given
1138N/A // object.
1138N/A ciConstant constant_value_of(ciObject* object) {
1138N/A assert(!is_static() && is_constant(), "only if field is non-static constant");
1138N/A assert(object->is_instance(), "must be instance");
1138N/A return object->as_instance()->field_value(this);
1138N/A }
1138N/A
0N/A // Check for link time errors. Accessing a field from a
0N/A // certain class via a certain bytecode may or may not be legal.
0N/A // This call checks to see if an exception may be raised by
0N/A // an access of this field.
0N/A //
0N/A // Usage note: if the same field is accessed multiple times
0N/A // in the same compilation, will_link will need to be checked
0N/A // at each point of access.
0N/A bool will_link(ciInstanceKlass* accessing_klass,
0N/A Bytecodes::Code bc);
0N/A
0N/A // Java access flags
0N/A bool is_public () { return flags().is_public(); }
0N/A bool is_private () { return flags().is_private(); }
0N/A bool is_protected () { return flags().is_protected(); }
0N/A bool is_static () { return flags().is_static(); }
0N/A bool is_final () { return flags().is_final(); }
0N/A bool is_volatile () { return flags().is_volatile(); }
0N/A bool is_transient () { return flags().is_transient(); }
0N/A
2735N/A bool is_call_site_target() {
2741N/A ciInstanceKlass* callsite_klass = CURRENT_ENV->CallSite_klass();
2741N/A if (callsite_klass == NULL)
2741N/A return false;
2741N/A return (holder()->is_subclass_of(callsite_klass) && (name() == ciSymbol::target_name()));
2735N/A }
2677N/A
0N/A // Debugging output
0N/A void print();
0N/A void print_name_on(outputStream* st);
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_CI_CIFIELD_HPP