ciField.hpp revision 0:a61af66fc99e
150472Speter/* 21664Sphk * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved. 33023Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 43023Srgrimes * 53023Srgrimes * This code is free software; you can redistribute it and/or modify it 61664Sphk * under the terms of the GNU General Public License version 2 only, as 73023Srgrimes * published by the Free Software Foundation. 83023Srgrimes * 91664Sphk * This code is distributed in the hope that it will be useful, but WITHOUT 101664Sphk * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 111664Sphk * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1258648Skris * version 2 for more details (a copy is included in the LICENSE file that 1358648Skris * accompanied this code). 1458648Skris * 1558648Skris * You should have received a copy of the GNU General Public License version 1658648Skris * 2 along with this work; if not, write to the Free Software Foundation, 1758648Skris * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1858648Skris * 191664Sphk * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2029281Sjkh * CA 95054 USA or visit www.sun.com if you need additional information or 211664Sphk * have any questions. 2259006Sobrien * 2359006Sobrien */ 2459006Sobrien 2559006Sobrien// ciField 261664Sphk// 2759006Sobrien// This class represents the result of a field lookup in the VM. 2859006Sobrien// The lookup may not succeed, in which case the information in 2962136Sobrien// the ciField will be incomplete. 3062136Sobrienclass ciField : public ResourceObj { 3162136Sobrien CI_PACKAGE_ACCESS 3262136Sobrien friend class ciEnv; 3362136Sobrien friend class ciInstanceKlass; 3462136Sobrien friend class NonStaticFieldFiller; 3562136Sobrien 3662136Sobrienprivate: 3762136Sobrien ciFlags _flags; 3865380Sobrien ciInstanceKlass* _holder; 3965380Sobrien ciSymbol* _name; 4065380Sobrien ciSymbol* _signature; 4165380Sobrien ciType* _type; 4265380Sobrien int _offset; 4342325Sobrien bool _is_constant; 4435222Sache ciInstanceKlass* _known_to_link_with; 4535222Sache ciConstant _constant_value; 4665884Sache 4765884Sache // Used for will_link 4865884Sache int _cp_index; 4964576Simp 5064576Simp ciType* compute_type(); 5134651Sjkh ciType* compute_type_impl(); 5250883Smarkm 5350883Smarkm ciField(ciInstanceKlass* klass, int index); 5450883Smarkm ciField(fieldDescriptor* fd); 5564803Sbrian 5664803Sbrian // shared constructor code 5764803Sbrian void initialize_from(fieldDescriptor* fd); 5851299Speter 5957542Skris // The implementation of the print method. 6059124Sasmodai void print_impl(outputStream* st); 6157542Skris 6261139Shoekpublic: 6358859Ssheldonh ciFlags flags() { return _flags; } 6459884Schuckr 6557764Skris // Of which klass is this field a member? 6657542Skris // 6757542Skris // Usage note: the declared holder of a field is the class 6857542Skris // referenced by name in the bytecodes. The canonical holder 6958418Sobrien // is the most general class which holds the field. This 7059338Sobrien // method returns the canonical holder. The declared holder 7158280Skris // can be accessed via a method in ciBytecodeStream. 7257553Skris // 7357603Skris // Ex. 7457542Skris // class A { 7557542Skris // public int f = 7; 7657542Skris // } 7765381Sobrien // class B extends A { 7865381Sobrien // public void test() { 7957553Skris // System.out.println(f); 8057542Skris // } 8158390Sdan // } 8235206Sphk // 8361744Sobrien // A java compiler is permitted to compile the access to 8461744Sobrien // field f as: 8561744Sobrien // 8657458Smarkm // getfield B.f 8762482Speter // 8862482Speter // In that case the declared holder of f would be B and 8962482Speter // the canonical holder of f would be A. 9062482Speter ciInstanceKlass* holder() { return _holder; } 9162482Speter 9262482Speter // Name of this field? 9362482Speter ciSymbol* name() { return _name; } 9462482Speter 9562482Speter // Signature of this field? 9663123Speter ciSymbol* signature() { return _signature; } 9762482Speter 9857071Srwatson // Of what type is this field? 9957071Srwatson ciType* type() { return (_type == NULL) ? compute_type() : _type; } 10057071Srwatson 1011684Scsgr // How is this field actually stored in memory? 1021684Scsgr BasicType layout_type() { return type2field[(_type == NULL) ? T_OBJECT : _type->basic_type()]; } 1031684Scsgr 1049509Srgrimes // How big is this field in memory? 1051697Sache int size_in_bytes() { return type2aelembytes[layout_type()]; } 1061697Sache 10720847Speter // What is the offset of this field? 10820847Speter int offset() { 10920847Speter assert(_offset >= 1, "illegal call to offset()"); 11020847Speter return _offset; 11120847Speter } 11220847Speter 11347318Sobrien // Same question, explicit units. (Fields are aligned to the byte level.) 11447430Sobrien int offset_in_bytes() { 11520847Speter return offset(); 11620847Speter } 11714403Sasami 11814403Sasami // Is this field shared? 11914403Sasami bool is_shared() { 12014403Sasami // non-static fields of shared holders are cached 12114403Sasami return _holder->is_shared() && !is_static(); 12214403Sasami } 1231697Sache 1241697Sache // Is this field a constant? 1251697Sache // 12625424Sandreas // Clarification: A field is considered constant if: 1271733Sadam // 1. The field is both static and final 1281733Sadam // 2. The canonical holder of the field has undergone 12914102Sadam // static initialization. 13014102Sadam // 3. If the field is an object or array, then the oop 13114102Sadam // in question is allocated in perm space. 13214102Sadam // 4. The field is not one of the special static/final 1331733Sadam // non-constant fields. These are java.lang.System.in 1341740Sadam // and java.lang.System.out. Abomination. 1353023Srgrimes // 1361733Sadam // Note: the check for case 4 is not yet implemented. 13718927Spst bool is_constant() { return _is_constant; } 13826522Sbde 13926522Sbde // Get the constant value of this field. 1401733Sadam ciConstant constant_value() { 14118927Spst assert(is_constant(), "illegal call to constant_value()"); 14249190Snik return _constant_value; 14318927Spst } 14449190Snik 14549190Snik // Check for link time errors. Accessing a field from a 14618928Spst // certain class via a certain bytecode may or may not be legal. 14718927Spst // This call checks to see if an exception may be raised by 14826522Sbde // an access of this field. 14926522Sbde // 15018927Spst // Usage note: if the same field is accessed multiple times 15126522Sbde // in the same compilation, will_link will need to be checked 15218927Spst // at each point of access. 15318927Spst bool will_link(ciInstanceKlass* accessing_klass, 1544224Sphk Bytecodes::Code bc); 15515334Sasami 15615334Sasami // Java access flags 1573023Srgrimes bool is_public () { return flags().is_public(); } 1584224Sphk bool is_private () { return flags().is_private(); } 1593023Srgrimes bool is_protected () { return flags().is_protected(); } 1603023Srgrimes bool is_static () { return flags().is_static(); } 16115212Sasami bool is_final () { return flags().is_final(); } 16215212Sasami bool is_volatile () { return flags().is_volatile(); } 16315212Sasami bool is_transient () { return flags().is_transient(); } 16435221Sache 16515212Sasami // Debugging output 16615334Sasami void print(); 16715334Sasami void print_name_on(outputStream* st); 16815334Sasami}; 16915212Sasami