annotate src/share/vm/ci/ciField.hpp @ 12190:edb5ab0f3fe5

8001107: @Stable annotation for constant folding of lazily evaluated variables Reviewed-by: rbackman, twisti, kvn Contributed-by: john.r.rose@oracle.com, vladimir.x.ivanov@oracle.com
author vlivanov
date Tue, 10 Sep 2013 14:51:48 -0700
parents e778c29768e6
children b2e698d2276c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6151
e778c29768e6 7152811: Issues in client compiler
never
parents: 3907
diff changeset
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. 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 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1138
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1138
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1138
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_CI_CIFIELD_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_CI_CIFIELD_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "ci/ciClassList.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "ci/ciConstant.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "ci/ciFlags.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "ci/ciInstance.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32
0
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // ciField
a61af66fc99e Initial load
duke
parents:
diff changeset
34 //
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // This class represents the result of a field lookup in the VM.
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // The lookup may not succeed, in which case the information in
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // the ciField will be incomplete.
a61af66fc99e Initial load
duke
parents:
diff changeset
38 class ciField : public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 CI_PACKAGE_ACCESS
a61af66fc99e Initial load
duke
parents:
diff changeset
40 friend class ciEnv;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 friend class ciInstanceKlass;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 friend class NonStaticFieldFiller;
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
45 ciFlags _flags;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 ciInstanceKlass* _holder;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 ciSymbol* _name;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 ciSymbol* _signature;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 ciType* _type;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 int _offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 bool _is_constant;
6151
e778c29768e6 7152811: Issues in client compiler
never
parents: 3907
diff changeset
52 ciInstanceKlass* _known_to_link_with_put;
e778c29768e6 7152811: Issues in client compiler
never
parents: 3907
diff changeset
53 ciInstanceKlass* _known_to_link_with_get;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
54 ciConstant _constant_value;
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // Used for will_link
a61af66fc99e Initial load
duke
parents:
diff changeset
57 int _cp_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 ciType* compute_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
60 ciType* compute_type_impl();
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 ciField(ciInstanceKlass* klass, int index);
a61af66fc99e Initial load
duke
parents:
diff changeset
63 ciField(fieldDescriptor* fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // shared constructor code
a61af66fc99e Initial load
duke
parents:
diff changeset
66 void initialize_from(fieldDescriptor* fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
69 ciFlags flags() { return _flags; }
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // Of which klass is this field a member?
a61af66fc99e Initial load
duke
parents:
diff changeset
72 //
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // Usage note: the declared holder of a field is the class
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // referenced by name in the bytecodes. The canonical holder
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // is the most general class which holds the field. This
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // method returns the canonical holder. The declared holder
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // can be accessed via a method in ciBytecodeStream.
a61af66fc99e Initial load
duke
parents:
diff changeset
78 //
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // Ex.
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // class A {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // public int f = 7;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // class B extends A {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // public void test() {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // System.out.println(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
88 //
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // A java compiler is permitted to compile the access to
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // field f as:
a61af66fc99e Initial load
duke
parents:
diff changeset
91 //
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // getfield B.f
a61af66fc99e Initial load
duke
parents:
diff changeset
93 //
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // In that case the declared holder of f would be B and
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // the canonical holder of f would be A.
a61af66fc99e Initial load
duke
parents:
diff changeset
96 ciInstanceKlass* holder() { return _holder; }
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // Name of this field?
a61af66fc99e Initial load
duke
parents:
diff changeset
99 ciSymbol* name() { return _name; }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // Signature of this field?
a61af66fc99e Initial load
duke
parents:
diff changeset
102 ciSymbol* signature() { return _signature; }
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // Of what type is this field?
a61af66fc99e Initial load
duke
parents:
diff changeset
105 ciType* type() { return (_type == NULL) ? compute_type() : _type; }
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // How is this field actually stored in memory?
a61af66fc99e Initial load
duke
parents:
diff changeset
108 BasicType layout_type() { return type2field[(_type == NULL) ? T_OBJECT : _type->basic_type()]; }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // 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
111 int size_in_bytes() { return type2aelembytes(layout_type()); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // What is the offset of this field?
a61af66fc99e Initial load
duke
parents:
diff changeset
114 int offset() {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 assert(_offset >= 1, "illegal call to offset()");
a61af66fc99e Initial load
duke
parents:
diff changeset
116 return _offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // Same question, explicit units. (Fields are aligned to the byte level.)
a61af66fc99e Initial load
duke
parents:
diff changeset
120 int offset_in_bytes() {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return offset();
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 shared?
a61af66fc99e Initial load
duke
parents:
diff changeset
125 bool is_shared() {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // non-static fields of shared holders are cached
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return _holder->is_shared() && !is_static();
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // Is this field a constant?
a61af66fc99e Initial load
duke
parents:
diff changeset
131 //
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // Clarification: A field is considered constant if:
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // 1. The field is both static and final
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // 2. The canonical holder of the field has undergone
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // static initialization.
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // 3. If the field is an object or array, then the oop
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // in question is allocated in perm space.
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // 4. The field is not one of the special static/final
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // non-constant fields. These are java.lang.System.in
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // and java.lang.System.out. Abomination.
a61af66fc99e Initial load
duke
parents:
diff changeset
141 //
12190
edb5ab0f3fe5 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 6151
diff changeset
142 // A field is also considered constant if it is marked @Stable
edb5ab0f3fe5 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 6151
diff changeset
143 // and is non-null (or non-zero, if a primitive).
edb5ab0f3fe5 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 6151
diff changeset
144 // For non-static fields, the null/zero check must be
edb5ab0f3fe5 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 6151
diff changeset
145 // arranged by the user, as constant_value().is_null_or_zero().
0
a61af66fc99e Initial load
duke
parents:
diff changeset
146 bool is_constant() { return _is_constant; }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // Get the constant value of this field.
a61af66fc99e Initial load
duke
parents:
diff changeset
149 ciConstant constant_value() {
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 196
diff changeset
150 assert(is_static() && is_constant(), "illegal call to constant_value()");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
151 return _constant_value;
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 196
diff changeset
154 // Get the constant value of non-static final field in the given
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 196
diff changeset
155 // object.
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 196
diff changeset
156 ciConstant constant_value_of(ciObject* object) {
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 196
diff changeset
157 assert(!is_static() && is_constant(), "only if field is non-static constant");
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 196
diff changeset
158 assert(object->is_instance(), "must be instance");
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 196
diff changeset
159 return object->as_instance()->field_value(this);
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 196
diff changeset
160 }
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 196
diff changeset
161
0
a61af66fc99e Initial load
duke
parents:
diff changeset
162 // Check for link time errors. Accessing a field from a
a61af66fc99e Initial load
duke
parents:
diff changeset
163 // certain class via a certain bytecode may or may not be legal.
a61af66fc99e Initial load
duke
parents:
diff changeset
164 // This call checks to see if an exception may be raised by
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // an access of this field.
a61af66fc99e Initial load
duke
parents:
diff changeset
166 //
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // Usage note: if the same field is accessed multiple times
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // in the same compilation, will_link will need to be checked
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // at each point of access.
a61af66fc99e Initial load
duke
parents:
diff changeset
170 bool will_link(ciInstanceKlass* accessing_klass,
a61af66fc99e Initial load
duke
parents:
diff changeset
171 Bytecodes::Code bc);
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // Java access flags
a61af66fc99e Initial load
duke
parents:
diff changeset
174 bool is_public () { return flags().is_public(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
175 bool is_private () { return flags().is_private(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
176 bool is_protected () { return flags().is_protected(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
177 bool is_static () { return flags().is_static(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
178 bool is_final () { return flags().is_final(); }
12190
edb5ab0f3fe5 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 6151
diff changeset
179 bool is_stable () { return flags().is_stable(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
180 bool is_volatile () { return flags().is_volatile(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 bool is_transient () { return flags().is_transient(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
182
3901
aa67216400d3 7085404: JSR 292: VolatileCallSites should have push notification too
twisti
parents: 3899
diff changeset
183 bool is_call_site_target() {
3907
7b5c767f229c 7086560: 7085404 changes broke VM with -XX:-EnableInvokeDynamic
kvn
parents: 3901
diff changeset
184 ciInstanceKlass* callsite_klass = CURRENT_ENV->CallSite_klass();
7b5c767f229c 7086560: 7085404 changes broke VM with -XX:-EnableInvokeDynamic
kvn
parents: 3901
diff changeset
185 if (callsite_klass == NULL)
7b5c767f229c 7086560: 7085404 changes broke VM with -XX:-EnableInvokeDynamic
kvn
parents: 3901
diff changeset
186 return false;
7b5c767f229c 7086560: 7085404 changes broke VM with -XX:-EnableInvokeDynamic
kvn
parents: 3901
diff changeset
187 return (holder()->is_subclass_of(callsite_klass) && (name() == ciSymbol::target_name()));
3901
aa67216400d3 7085404: JSR 292: VolatileCallSites should have push notification too
twisti
parents: 3899
diff changeset
188 }
3852
fdb992d83a87 7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents: 1972
diff changeset
189
0
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // Debugging output
a61af66fc99e Initial load
duke
parents:
diff changeset
191 void print();
a61af66fc99e Initial load
duke
parents:
diff changeset
192 void print_name_on(outputStream* st);
a61af66fc99e Initial load
duke
parents:
diff changeset
193 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
194
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
195 #endif // SHARE_VM_CI_CIFIELD_HPP