annotate src/share/vm/ci/ciField.hpp @ 196:d1605aabd0a1 jdk7-b30

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