ciField.hpp revision 1879:f95d63e2154a
11541Srgrimes/* 21541Srgrimes * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 31541Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 41541Srgrimes * 51541Srgrimes * This code is free software; you can redistribute it and/or modify it 61541Srgrimes * under the terms of the GNU General Public License version 2 only, as 71541Srgrimes * published by the Free Software Foundation. 81541Srgrimes * 91541Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT 101541Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 111541Srgrimes * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 121541Srgrimes * version 2 for more details (a copy is included in the LICENSE file that 131541Srgrimes * accompanied this code). 141541Srgrimes * 151541Srgrimes * You should have received a copy of the GNU General Public License version 161541Srgrimes * 2 along with this work; if not, write to the Free Software Foundation, 171541Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 181541Srgrimes * 191541Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 201541Srgrimes * or visit www.oracle.com if you need additional information or have any 211541Srgrimes * questions. 221541Srgrimes * 231541Srgrimes */ 241541Srgrimes 251541Srgrimes#ifndef SHARE_VM_CI_CIFIELD_HPP 261541Srgrimes#define SHARE_VM_CI_CIFIELD_HPP 271541Srgrimes 281541Srgrimes#include "ci/ciClassList.hpp" 291541Srgrimes#include "ci/ciConstant.hpp" 301541Srgrimes#include "ci/ciFlags.hpp" 311541Srgrimes#include "ci/ciInstance.hpp" 321541Srgrimes 331541Srgrimes// ciField 3444510Swollman// 351541Srgrimes// This class represents the result of a field lookup in the VM. 361541Srgrimes// The lookup may not succeed, in which case the information in 37116182Sobrien// the ciField will be incomplete. 38116182Sobrienclass ciField : public ResourceObj { 39116182Sobrien CI_PACKAGE_ACCESS 401541Srgrimes friend class ciEnv; 411541Srgrimes friend class ciInstanceKlass; 4233392Sphk friend class NonStaticFieldFiller; 43127969Scperciva 441541Srgrimesprivate: 45133229Srwatson ciFlags _flags; 4674914Sjhb ciInstanceKlass* _holder; 4768840Sjhb ciSymbol* _name; 48150188Sjhb ciSymbol* _signature; 49115810Sphk ciType* _type; 501541Srgrimes int _offset; 51115810Sphk bool _is_constant; 52115810Sphk ciInstanceKlass* _known_to_link_with; 53115810Sphk ciConstant _constant_value; 54115810Sphk 55115810Sphk // Used for will_link 56115810Sphk int _cp_index; 57141428Siedowse 58141428Siedowse ciType* compute_type(); 59141428Siedowse ciType* compute_type_impl(); 60115810Sphk 61115810Sphk ciField(ciInstanceKlass* klass, int index); 62115810Sphk ciField(fieldDescriptor* fd); 6333392Sphk 6433392Sphk // shared constructor code 6533392Sphk void initialize_from(fieldDescriptor* fd); 6633392Sphk 6733392Sphk // The implementation of the print method. 6833392Sphk void print_impl(outputStream* st); 6929680Sgibbs 7029680Sgibbspublic: 7129680Sgibbs ciFlags flags() { return _flags; } 7229680Sgibbs 7333392Sphk // Of which klass is this field a member? 74116606Sphk // 752112Swollman // Usage note: the declared holder of a field is the class 7629680Sgibbs // referenced by name in the bytecodes. The canonical holder 77128024Scperciva // is the most general class which holds the field. This 78139831Scperciva // method returns the canonical holder. The declared holder 79127969Scperciva // can be accessed via a method in ciBytecodeStream. 80127969Scperciva // 81155957Sjhb // Ex. 82155957Sjhb // class A { 83127969Scperciva // public int f = 7; 84141428Siedowse // } 85141428Siedowse // class B extends A { 86141428Siedowse // public void test() { 87141428Siedowse // System.out.println(f); 88155957Sjhb // } 89141428Siedowse // } 90155957Sjhb // 91155957Sjhb // A java compiler is permitted to compile the access to 92128024Scperciva // field f as: 93127969Scperciva // 94127969Scperciva // getfield B.f 95141428Siedowse // 96155957Sjhb // In that case the declared holder of f would be B and 97128024Scperciva // the canonical holder of f would be A. 981541Srgrimes ciInstanceKlass* holder() { return _holder; } 9982127Sdillon 10082127Sdillon // Name of this field? 10182127Sdillon ciSymbol* name() { return _name; } 10282127Sdillon 10382127Sdillon // Signature of this field? 10482127Sdillon ciSymbol* signature() { return _signature; } 10582127Sdillon 10682127Sdillon // Of what type is this field? 10782127Sdillon ciType* type() { return (_type == NULL) ? compute_type() : _type; } 10882127Sdillon 10982127Sdillon // How is this field actually stored in memory? 11082127Sdillon BasicType layout_type() { return type2field[(_type == NULL) ? T_OBJECT : _type->basic_type()]; } 11182127Sdillon 11282127Sdillon // How big is this field in memory? 11382127Sdillon int size_in_bytes() { return type2aelembytes(layout_type()); } 11482127Sdillon 11582127Sdillon // What is the offset of this field? 11682127Sdillon int offset() { 11782127Sdillon assert(_offset >= 1, "illegal call to offset()"); 11882127Sdillon return _offset; 11982127Sdillon } 12082127Sdillon 12182127Sdillon // Same question, explicit units. (Fields are aligned to the byte level.) 12282127Sdillon int offset_in_bytes() { 12382127Sdillon return offset(); 12482127Sdillon } 12582127Sdillon 12682127Sdillon // Is this field shared? 12782127Sdillon bool is_shared() { 12882127Sdillon // non-static fields of shared holders are cached 12982127Sdillon return _holder->is_shared() && !is_static(); 13082127Sdillon } 13182127Sdillon 13282127Sdillon // Is this field a constant? 13382127Sdillon // 13482127Sdillon // Clarification: A field is considered constant if: 13582127Sdillon // 1. The field is both static and final 13682127Sdillon // 2. The canonical holder of the field has undergone 13782127Sdillon // static initialization. 13882127Sdillon // 3. If the field is an object or array, then the oop 13982127Sdillon // in question is allocated in perm space. 14082127Sdillon // 4. The field is not one of the special static/final 14182127Sdillon // non-constant fields. These are java.lang.System.in 14282127Sdillon // and java.lang.System.out. Abomination. 14382127Sdillon // 14493818Sjhb // Note: the check for case 4 is not yet implemented. 14582127Sdillon bool is_constant() { return _is_constant; } 14682127Sdillon 14782127Sdillon // Get the constant value of this field. 14829680Sgibbs ciConstant constant_value() { 14929680Sgibbs assert(is_static() && is_constant(), "illegal call to constant_value()"); 15029680Sgibbs return _constant_value; 15129680Sgibbs } 152128630Shmp 15329680Sgibbs // Get the constant value of non-static final field in the given 15429680Sgibbs // object. 15529680Sgibbs ciConstant constant_value_of(ciObject* object) { 15629680Sgibbs assert(!is_static() && is_constant(), "only if field is non-static constant"); 15729680Sgibbs assert(object->is_instance(), "must be instance"); 15832388Sphk return object->as_instance()->field_value(this); 15929680Sgibbs } 1601541Srgrimes 1611541Srgrimes // Check for link time errors. Accessing a field from a 1621541Srgrimes // certain class via a certain bytecode may or may not be legal. 1631541Srgrimes // This call checks to see if an exception may be raised by 16467551Sjhb // an access of this field. 1651541Srgrimes // 166102936Sphk // Usage note: if the same field is accessed multiple times 167102936Sphk // in the same compilation, will_link will need to be checked 168102936Sphk // at each point of access. 169102936Sphk bool will_link(ciInstanceKlass* accessing_klass, 170115810Sphk Bytecodes::Code bc); 171115810Sphk 172141428Siedowse // Java access flags 173115810Sphk bool is_public () { return flags().is_public(); } 174122585Smckusick bool is_private () { return flags().is_private(); } 175122585Smckusick bool is_protected () { return flags().is_protected(); } 176122585Smckusick bool is_static () { return flags().is_static(); } 177122585Smckusick bool is_final () { return flags().is_final(); } 178123254Sphk bool is_volatile () { return flags().is_volatile(); } 179122585Smckusick bool is_transient () { return flags().is_transient(); } 1801541Srgrimes 18133392Sphk // Debugging output 18233392Sphk void print(); 18333392Sphk void print_name_on(outputStream* st); 18429680Sgibbs}; 185115810Sphk 186141428Siedowse#endif // SHARE_VM_CI_CIFIELD_HPP 187115810Sphk