1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/ci/ciField.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,168 @@ 1.4 +/* 1.5 + * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// ciField 1.29 +// 1.30 +// This class represents the result of a field lookup in the VM. 1.31 +// The lookup may not succeed, in which case the information in 1.32 +// the ciField will be incomplete. 1.33 +class ciField : public ResourceObj { 1.34 + CI_PACKAGE_ACCESS 1.35 + friend class ciEnv; 1.36 + friend class ciInstanceKlass; 1.37 + friend class NonStaticFieldFiller; 1.38 + 1.39 +private: 1.40 + ciFlags _flags; 1.41 + ciInstanceKlass* _holder; 1.42 + ciSymbol* _name; 1.43 + ciSymbol* _signature; 1.44 + ciType* _type; 1.45 + int _offset; 1.46 + bool _is_constant; 1.47 + ciInstanceKlass* _known_to_link_with; 1.48 + ciConstant _constant_value; 1.49 + 1.50 + // Used for will_link 1.51 + int _cp_index; 1.52 + 1.53 + ciType* compute_type(); 1.54 + ciType* compute_type_impl(); 1.55 + 1.56 + ciField(ciInstanceKlass* klass, int index); 1.57 + ciField(fieldDescriptor* fd); 1.58 + 1.59 + // shared constructor code 1.60 + void initialize_from(fieldDescriptor* fd); 1.61 + 1.62 + // The implementation of the print method. 1.63 + void print_impl(outputStream* st); 1.64 + 1.65 +public: 1.66 + ciFlags flags() { return _flags; } 1.67 + 1.68 + // Of which klass is this field a member? 1.69 + // 1.70 + // Usage note: the declared holder of a field is the class 1.71 + // referenced by name in the bytecodes. The canonical holder 1.72 + // is the most general class which holds the field. This 1.73 + // method returns the canonical holder. The declared holder 1.74 + // can be accessed via a method in ciBytecodeStream. 1.75 + // 1.76 + // Ex. 1.77 + // class A { 1.78 + // public int f = 7; 1.79 + // } 1.80 + // class B extends A { 1.81 + // public void test() { 1.82 + // System.out.println(f); 1.83 + // } 1.84 + // } 1.85 + // 1.86 + // A java compiler is permitted to compile the access to 1.87 + // field f as: 1.88 + // 1.89 + // getfield B.f 1.90 + // 1.91 + // In that case the declared holder of f would be B and 1.92 + // the canonical holder of f would be A. 1.93 + ciInstanceKlass* holder() { return _holder; } 1.94 + 1.95 + // Name of this field? 1.96 + ciSymbol* name() { return _name; } 1.97 + 1.98 + // Signature of this field? 1.99 + ciSymbol* signature() { return _signature; } 1.100 + 1.101 + // Of what type is this field? 1.102 + ciType* type() { return (_type == NULL) ? compute_type() : _type; } 1.103 + 1.104 + // How is this field actually stored in memory? 1.105 + BasicType layout_type() { return type2field[(_type == NULL) ? T_OBJECT : _type->basic_type()]; } 1.106 + 1.107 + // How big is this field in memory? 1.108 + int size_in_bytes() { return type2aelembytes[layout_type()]; } 1.109 + 1.110 + // What is the offset of this field? 1.111 + int offset() { 1.112 + assert(_offset >= 1, "illegal call to offset()"); 1.113 + return _offset; 1.114 + } 1.115 + 1.116 + // Same question, explicit units. (Fields are aligned to the byte level.) 1.117 + int offset_in_bytes() { 1.118 + return offset(); 1.119 + } 1.120 + 1.121 + // Is this field shared? 1.122 + bool is_shared() { 1.123 + // non-static fields of shared holders are cached 1.124 + return _holder->is_shared() && !is_static(); 1.125 + } 1.126 + 1.127 + // Is this field a constant? 1.128 + // 1.129 + // Clarification: A field is considered constant if: 1.130 + // 1. The field is both static and final 1.131 + // 2. The canonical holder of the field has undergone 1.132 + // static initialization. 1.133 + // 3. If the field is an object or array, then the oop 1.134 + // in question is allocated in perm space. 1.135 + // 4. The field is not one of the special static/final 1.136 + // non-constant fields. These are java.lang.System.in 1.137 + // and java.lang.System.out. Abomination. 1.138 + // 1.139 + // Note: the check for case 4 is not yet implemented. 1.140 + bool is_constant() { return _is_constant; } 1.141 + 1.142 + // Get the constant value of this field. 1.143 + ciConstant constant_value() { 1.144 + assert(is_constant(), "illegal call to constant_value()"); 1.145 + return _constant_value; 1.146 + } 1.147 + 1.148 + // Check for link time errors. Accessing a field from a 1.149 + // certain class via a certain bytecode may or may not be legal. 1.150 + // This call checks to see if an exception may be raised by 1.151 + // an access of this field. 1.152 + // 1.153 + // Usage note: if the same field is accessed multiple times 1.154 + // in the same compilation, will_link will need to be checked 1.155 + // at each point of access. 1.156 + bool will_link(ciInstanceKlass* accessing_klass, 1.157 + Bytecodes::Code bc); 1.158 + 1.159 + // Java access flags 1.160 + bool is_public () { return flags().is_public(); } 1.161 + bool is_private () { return flags().is_private(); } 1.162 + bool is_protected () { return flags().is_protected(); } 1.163 + bool is_static () { return flags().is_static(); } 1.164 + bool is_final () { return flags().is_final(); } 1.165 + bool is_volatile () { return flags().is_volatile(); } 1.166 + bool is_transient () { return flags().is_transient(); } 1.167 + 1.168 + // Debugging output 1.169 + void print(); 1.170 + void print_name_on(outputStream* st); 1.171 +};