duke@435: /* xdono@631: * Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: // ciField duke@435: // duke@435: // This class represents the result of a field lookup in the VM. duke@435: // The lookup may not succeed, in which case the information in duke@435: // the ciField will be incomplete. duke@435: class ciField : public ResourceObj { duke@435: CI_PACKAGE_ACCESS duke@435: friend class ciEnv; duke@435: friend class ciInstanceKlass; duke@435: friend class NonStaticFieldFiller; duke@435: duke@435: private: duke@435: ciFlags _flags; duke@435: ciInstanceKlass* _holder; duke@435: ciSymbol* _name; duke@435: ciSymbol* _signature; duke@435: ciType* _type; duke@435: int _offset; duke@435: bool _is_constant; duke@435: ciInstanceKlass* _known_to_link_with; duke@435: ciConstant _constant_value; duke@435: duke@435: // Used for will_link duke@435: int _cp_index; duke@435: duke@435: ciType* compute_type(); duke@435: ciType* compute_type_impl(); duke@435: duke@435: ciField(ciInstanceKlass* klass, int index); duke@435: ciField(fieldDescriptor* fd); duke@435: duke@435: // shared constructor code duke@435: void initialize_from(fieldDescriptor* fd); duke@435: duke@435: // The implementation of the print method. duke@435: void print_impl(outputStream* st); duke@435: duke@435: public: duke@435: ciFlags flags() { return _flags; } duke@435: duke@435: // Of which klass is this field a member? duke@435: // duke@435: // Usage note: the declared holder of a field is the class duke@435: // referenced by name in the bytecodes. The canonical holder duke@435: // is the most general class which holds the field. This duke@435: // method returns the canonical holder. The declared holder duke@435: // can be accessed via a method in ciBytecodeStream. duke@435: // duke@435: // Ex. duke@435: // class A { duke@435: // public int f = 7; duke@435: // } duke@435: // class B extends A { duke@435: // public void test() { duke@435: // System.out.println(f); duke@435: // } duke@435: // } duke@435: // duke@435: // A java compiler is permitted to compile the access to duke@435: // field f as: duke@435: // duke@435: // getfield B.f duke@435: // duke@435: // In that case the declared holder of f would be B and duke@435: // the canonical holder of f would be A. duke@435: ciInstanceKlass* holder() { return _holder; } duke@435: duke@435: // Name of this field? duke@435: ciSymbol* name() { return _name; } duke@435: duke@435: // Signature of this field? duke@435: ciSymbol* signature() { return _signature; } duke@435: duke@435: // Of what type is this field? duke@435: ciType* type() { return (_type == NULL) ? compute_type() : _type; } duke@435: duke@435: // How is this field actually stored in memory? duke@435: BasicType layout_type() { return type2field[(_type == NULL) ? T_OBJECT : _type->basic_type()]; } duke@435: duke@435: // How big is this field in memory? kvn@464: int size_in_bytes() { return type2aelembytes(layout_type()); } duke@435: duke@435: // What is the offset of this field? duke@435: int offset() { duke@435: assert(_offset >= 1, "illegal call to offset()"); duke@435: return _offset; duke@435: } duke@435: duke@435: // Same question, explicit units. (Fields are aligned to the byte level.) duke@435: int offset_in_bytes() { duke@435: return offset(); duke@435: } duke@435: duke@435: // Is this field shared? duke@435: bool is_shared() { duke@435: // non-static fields of shared holders are cached duke@435: return _holder->is_shared() && !is_static(); duke@435: } duke@435: duke@435: // Is this field a constant? duke@435: // duke@435: // Clarification: A field is considered constant if: duke@435: // 1. The field is both static and final duke@435: // 2. The canonical holder of the field has undergone duke@435: // static initialization. duke@435: // 3. If the field is an object or array, then the oop duke@435: // in question is allocated in perm space. duke@435: // 4. The field is not one of the special static/final duke@435: // non-constant fields. These are java.lang.System.in duke@435: // and java.lang.System.out. Abomination. duke@435: // duke@435: // Note: the check for case 4 is not yet implemented. duke@435: bool is_constant() { return _is_constant; } duke@435: duke@435: // Get the constant value of this field. duke@435: ciConstant constant_value() { twisti@1573: assert(is_static() && is_constant(), "illegal call to constant_value()"); duke@435: return _constant_value; duke@435: } duke@435: twisti@1573: // Get the constant value of non-static final field in the given twisti@1573: // object. twisti@1573: ciConstant constant_value_of(ciObject* object) { twisti@1573: assert(!is_static() && is_constant(), "only if field is non-static constant"); twisti@1573: assert(object->is_instance(), "must be instance"); twisti@1573: return object->as_instance()->field_value(this); twisti@1573: } twisti@1573: duke@435: // Check for link time errors. Accessing a field from a duke@435: // certain class via a certain bytecode may or may not be legal. duke@435: // This call checks to see if an exception may be raised by duke@435: // an access of this field. duke@435: // duke@435: // Usage note: if the same field is accessed multiple times duke@435: // in the same compilation, will_link will need to be checked duke@435: // at each point of access. duke@435: bool will_link(ciInstanceKlass* accessing_klass, duke@435: Bytecodes::Code bc); duke@435: duke@435: // Java access flags duke@435: bool is_public () { return flags().is_public(); } duke@435: bool is_private () { return flags().is_private(); } duke@435: bool is_protected () { return flags().is_protected(); } duke@435: bool is_static () { return flags().is_static(); } duke@435: bool is_final () { return flags().is_final(); } duke@435: bool is_volatile () { return flags().is_volatile(); } duke@435: bool is_transient () { return flags().is_transient(); } duke@435: duke@435: // Debugging output duke@435: void print(); duke@435: void print_name_on(outputStream* st); duke@435: };