annotate hotspot/src/share/vm/ci/ciField.hpp @ 12982:7d7a3e02610e

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