Wed, 06 Jan 2010 14:22:39 -0800
6914300: ciEnv should export all well known classes
Reviewed-by: kvn, twisti
duke@435 | 1 | /* |
xdono@631 | 2 | * Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | // ciField |
duke@435 | 26 | // |
duke@435 | 27 | // This class represents the result of a field lookup in the VM. |
duke@435 | 28 | // The lookup may not succeed, in which case the information in |
duke@435 | 29 | // the ciField will be incomplete. |
duke@435 | 30 | class ciField : public ResourceObj { |
duke@435 | 31 | CI_PACKAGE_ACCESS |
duke@435 | 32 | friend class ciEnv; |
duke@435 | 33 | friend class ciInstanceKlass; |
duke@435 | 34 | friend class NonStaticFieldFiller; |
duke@435 | 35 | |
duke@435 | 36 | private: |
duke@435 | 37 | ciFlags _flags; |
duke@435 | 38 | ciInstanceKlass* _holder; |
duke@435 | 39 | ciSymbol* _name; |
duke@435 | 40 | ciSymbol* _signature; |
duke@435 | 41 | ciType* _type; |
duke@435 | 42 | int _offset; |
duke@435 | 43 | bool _is_constant; |
duke@435 | 44 | ciInstanceKlass* _known_to_link_with; |
duke@435 | 45 | ciConstant _constant_value; |
duke@435 | 46 | |
duke@435 | 47 | // Used for will_link |
duke@435 | 48 | int _cp_index; |
duke@435 | 49 | |
duke@435 | 50 | ciType* compute_type(); |
duke@435 | 51 | ciType* compute_type_impl(); |
duke@435 | 52 | |
duke@435 | 53 | ciField(ciInstanceKlass* klass, int index); |
duke@435 | 54 | ciField(fieldDescriptor* fd); |
duke@435 | 55 | |
duke@435 | 56 | // shared constructor code |
duke@435 | 57 | void initialize_from(fieldDescriptor* fd); |
duke@435 | 58 | |
duke@435 | 59 | // The implementation of the print method. |
duke@435 | 60 | void print_impl(outputStream* st); |
duke@435 | 61 | |
duke@435 | 62 | public: |
duke@435 | 63 | ciFlags flags() { return _flags; } |
duke@435 | 64 | |
duke@435 | 65 | // Of which klass is this field a member? |
duke@435 | 66 | // |
duke@435 | 67 | // Usage note: the declared holder of a field is the class |
duke@435 | 68 | // referenced by name in the bytecodes. The canonical holder |
duke@435 | 69 | // is the most general class which holds the field. This |
duke@435 | 70 | // method returns the canonical holder. The declared holder |
duke@435 | 71 | // can be accessed via a method in ciBytecodeStream. |
duke@435 | 72 | // |
duke@435 | 73 | // Ex. |
duke@435 | 74 | // class A { |
duke@435 | 75 | // public int f = 7; |
duke@435 | 76 | // } |
duke@435 | 77 | // class B extends A { |
duke@435 | 78 | // public void test() { |
duke@435 | 79 | // System.out.println(f); |
duke@435 | 80 | // } |
duke@435 | 81 | // } |
duke@435 | 82 | // |
duke@435 | 83 | // A java compiler is permitted to compile the access to |
duke@435 | 84 | // field f as: |
duke@435 | 85 | // |
duke@435 | 86 | // getfield B.f |
duke@435 | 87 | // |
duke@435 | 88 | // In that case the declared holder of f would be B and |
duke@435 | 89 | // the canonical holder of f would be A. |
duke@435 | 90 | ciInstanceKlass* holder() { return _holder; } |
duke@435 | 91 | |
duke@435 | 92 | // Name of this field? |
duke@435 | 93 | ciSymbol* name() { return _name; } |
duke@435 | 94 | |
duke@435 | 95 | // Signature of this field? |
duke@435 | 96 | ciSymbol* signature() { return _signature; } |
duke@435 | 97 | |
duke@435 | 98 | // Of what type is this field? |
duke@435 | 99 | ciType* type() { return (_type == NULL) ? compute_type() : _type; } |
duke@435 | 100 | |
duke@435 | 101 | // How is this field actually stored in memory? |
duke@435 | 102 | BasicType layout_type() { return type2field[(_type == NULL) ? T_OBJECT : _type->basic_type()]; } |
duke@435 | 103 | |
duke@435 | 104 | // How big is this field in memory? |
kvn@464 | 105 | int size_in_bytes() { return type2aelembytes(layout_type()); } |
duke@435 | 106 | |
duke@435 | 107 | // What is the offset of this field? |
duke@435 | 108 | int offset() { |
duke@435 | 109 | assert(_offset >= 1, "illegal call to offset()"); |
duke@435 | 110 | return _offset; |
duke@435 | 111 | } |
duke@435 | 112 | |
duke@435 | 113 | // Same question, explicit units. (Fields are aligned to the byte level.) |
duke@435 | 114 | int offset_in_bytes() { |
duke@435 | 115 | return offset(); |
duke@435 | 116 | } |
duke@435 | 117 | |
duke@435 | 118 | // Is this field shared? |
duke@435 | 119 | bool is_shared() { |
duke@435 | 120 | // non-static fields of shared holders are cached |
duke@435 | 121 | return _holder->is_shared() && !is_static(); |
duke@435 | 122 | } |
duke@435 | 123 | |
duke@435 | 124 | // Is this field a constant? |
duke@435 | 125 | // |
duke@435 | 126 | // Clarification: A field is considered constant if: |
duke@435 | 127 | // 1. The field is both static and final |
duke@435 | 128 | // 2. The canonical holder of the field has undergone |
duke@435 | 129 | // static initialization. |
duke@435 | 130 | // 3. If the field is an object or array, then the oop |
duke@435 | 131 | // in question is allocated in perm space. |
duke@435 | 132 | // 4. The field is not one of the special static/final |
duke@435 | 133 | // non-constant fields. These are java.lang.System.in |
duke@435 | 134 | // and java.lang.System.out. Abomination. |
duke@435 | 135 | // |
duke@435 | 136 | // Note: the check for case 4 is not yet implemented. |
duke@435 | 137 | bool is_constant() { return _is_constant; } |
duke@435 | 138 | |
duke@435 | 139 | // Get the constant value of this field. |
duke@435 | 140 | ciConstant constant_value() { |
twisti@1573 | 141 | assert(is_static() && is_constant(), "illegal call to constant_value()"); |
duke@435 | 142 | return _constant_value; |
duke@435 | 143 | } |
duke@435 | 144 | |
twisti@1573 | 145 | // Get the constant value of non-static final field in the given |
twisti@1573 | 146 | // object. |
twisti@1573 | 147 | ciConstant constant_value_of(ciObject* object) { |
twisti@1573 | 148 | assert(!is_static() && is_constant(), "only if field is non-static constant"); |
twisti@1573 | 149 | assert(object->is_instance(), "must be instance"); |
twisti@1573 | 150 | return object->as_instance()->field_value(this); |
twisti@1573 | 151 | } |
twisti@1573 | 152 | |
duke@435 | 153 | // Check for link time errors. Accessing a field from a |
duke@435 | 154 | // certain class via a certain bytecode may or may not be legal. |
duke@435 | 155 | // This call checks to see if an exception may be raised by |
duke@435 | 156 | // an access of this field. |
duke@435 | 157 | // |
duke@435 | 158 | // Usage note: if the same field is accessed multiple times |
duke@435 | 159 | // in the same compilation, will_link will need to be checked |
duke@435 | 160 | // at each point of access. |
duke@435 | 161 | bool will_link(ciInstanceKlass* accessing_klass, |
duke@435 | 162 | Bytecodes::Code bc); |
duke@435 | 163 | |
duke@435 | 164 | // Java access flags |
duke@435 | 165 | bool is_public () { return flags().is_public(); } |
duke@435 | 166 | bool is_private () { return flags().is_private(); } |
duke@435 | 167 | bool is_protected () { return flags().is_protected(); } |
duke@435 | 168 | bool is_static () { return flags().is_static(); } |
duke@435 | 169 | bool is_final () { return flags().is_final(); } |
duke@435 | 170 | bool is_volatile () { return flags().is_volatile(); } |
duke@435 | 171 | bool is_transient () { return flags().is_transient(); } |
duke@435 | 172 | |
duke@435 | 173 | // Debugging output |
duke@435 | 174 | void print(); |
duke@435 | 175 | void print_name_on(outputStream* st); |
duke@435 | 176 | }; |