annotate src/share/vm/ci/ciField.cpp @ 1930:2d26b0046e0d

Merge.
author Thomas Wuerthinger <wuerthinger@ssw.jku.at>
date Tue, 30 Nov 2010 14:53:30 +0100
parents 944071972cd9 e5dfb3ccb88b
children 06f017f7daa7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1173
diff changeset
2 * Copyright (c) 1999, 2009, 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: 1173
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1173
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: 1173
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
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_ciField.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // ciField
a61af66fc99e Initial load
duke
parents:
diff changeset
29 //
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // This class represents the result of a field lookup in the VM.
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // The lookup may not succeed, in which case the information in
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // the ciField will be incomplete.
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // The ciObjectFactory cannot create circular data structures in one query.
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // To avoid vicious circularities, we initialize ciField::_type to NULL
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // for reference types and derive it lazily from the ciField::_signature.
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // Primitive types are eagerly initialized, and basic layout queries
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // can succeed without initialization, using only the BasicType of the field.
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // Notes on bootstrapping and shared CI objects: A field is shared if and
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // only if it is (a) non-static and (b) declared by a shared instance klass.
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // This allows non-static field lists to be cached on shared types.
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // Because the _type field is lazily initialized, however, there is a
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // special restriction that a shared field cannot cache an unshared type.
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // This puts a small performance penalty on shared fields with unshared
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // types, such as StackTraceElement[] Throwable.stackTrace.
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // (Throwable is shared because ClassCastException is shared, but
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // StackTraceElement is not presently shared.)
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // It is not a vicious circularity for a ciField to recursively create
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // the ciSymbols necessary to represent its name and signature.
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // Therefore, these items are created eagerly, and the name and signature
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // of a shared field are themselves shared symbols. This somewhat
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // pollutes the set of shared CI objects: It grows from 50 to 93 items,
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // with all of the additional 43 being uninteresting shared ciSymbols.
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // This adds at most one step to the binary search, an amount which
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // decreases for complex compilation tasks.
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // ciField::ciField
a61af66fc99e Initial load
duke
parents:
diff changeset
61 ciField::ciField(ciInstanceKlass* klass, int index): _known_to_link_with(NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 ASSERT_IN_VM;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 CompilerThread *thread = CompilerThread::current();
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 assert(ciObjectFactory::is_initialized(), "not a shared field");
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 assert(klass->get_instanceKlass()->is_linked(), "must be linked before using its constan-pool");
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 _cp_index = index;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 constantPoolHandle cpool(thread, klass->get_instanceKlass()->constants());
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // Get the field's name, signature, and type.
a61af66fc99e Initial load
duke
parents:
diff changeset
73 symbolHandle name (thread, cpool->name_ref_at(index));
a61af66fc99e Initial load
duke
parents:
diff changeset
74 _name = ciEnv::current(thread)->get_object(name())->as_symbol();
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 int nt_index = cpool->name_and_type_ref_index_at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
77 int sig_index = cpool->signature_ref_index_at(nt_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 symbolHandle signature (thread, cpool->symbol_at(sig_index));
a61af66fc99e Initial load
duke
parents:
diff changeset
79 _signature = ciEnv::current(thread)->get_object(signature())->as_symbol();
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 BasicType field_type = FieldType::basic_type(signature());
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // If the field is a pointer type, get the klass of the
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // field.
a61af66fc99e Initial load
duke
parents:
diff changeset
85 if (field_type == T_OBJECT || field_type == T_ARRAY) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 bool ignore;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // This is not really a class reference; the index always refers to the
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // field's type signature, as a symbol. Linkage checks do not apply.
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
89 _type = ciEnv::current(thread)->get_klass_by_index(cpool, sig_index, ignore, klass);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
90 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 _type = ciType::make(field_type);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 _name = (ciSymbol*)ciEnv::current(thread)->get_object(name());
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // Get the field's declared holder.
a61af66fc99e Initial load
duke
parents:
diff changeset
97 //
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // Note: we actually create a ciInstanceKlass for this klass,
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // even though we may not need to.
a61af66fc99e Initial load
duke
parents:
diff changeset
100 int holder_index = cpool->klass_ref_index_at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 bool holder_is_accessible;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 ciInstanceKlass* declared_holder =
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
103 ciEnv::current(thread)->get_klass_by_index(cpool, holder_index,
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
104 holder_is_accessible,
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
105 klass)->as_instance_klass();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // The declared holder of this field may not have been loaded.
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // Bail out with partial field information.
a61af66fc99e Initial load
duke
parents:
diff changeset
109 if (!holder_is_accessible) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // _cp_index and _type have already been set.
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // The default values for _flags and _constant_value will suffice.
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // We need values for _holder, _offset, and _is_constant,
a61af66fc99e Initial load
duke
parents:
diff changeset
113 _holder = declared_holder;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 _offset = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 _is_constant = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 instanceKlass* loaded_decl_holder = declared_holder->get_instanceKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // Perform the field lookup.
a61af66fc99e Initial load
duke
parents:
diff changeset
122 fieldDescriptor field_desc;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 klassOop canonical_holder =
a61af66fc99e Initial load
duke
parents:
diff changeset
124 loaded_decl_holder->find_field(name(), signature(), &field_desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
125 if (canonical_holder == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // Field lookup failed. Will be detected by will_link.
a61af66fc99e Initial load
duke
parents:
diff changeset
127 _holder = declared_holder;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 _offset = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 _is_constant = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 assert(canonical_holder == field_desc.field_holder(), "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
134 initialize_from(&field_desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 ciField::ciField(fieldDescriptor *fd): _known_to_link_with(NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 ASSERT_IN_VM;
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 _cp_index = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // Get the field's name, signature, and type.
a61af66fc99e Initial load
duke
parents:
diff changeset
143 ciEnv* env = CURRENT_ENV;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 _name = env->get_object(fd->name())->as_symbol();
a61af66fc99e Initial load
duke
parents:
diff changeset
145 _signature = env->get_object(fd->signature())->as_symbol();
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 BasicType field_type = fd->field_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // If the field is a pointer type, get the klass of the
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // field.
a61af66fc99e Initial load
duke
parents:
diff changeset
151 if (field_type == T_OBJECT || field_type == T_ARRAY) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 _type = NULL; // must call compute_type on first access
a61af66fc99e Initial load
duke
parents:
diff changeset
153 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 _type = ciType::make(field_type);
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 initialize_from(fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // Either (a) it is marked shared, or else (b) we are done bootstrapping.
a61af66fc99e Initial load
duke
parents:
diff changeset
160 assert(is_shared() || ciObjectFactory::is_initialized(),
a61af66fc99e Initial load
duke
parents:
diff changeset
161 "bootstrap classes must not create & cache unshared fields");
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163
1173
73b22f919c34 6912065: final fields in objects need to support inlining optimizations for JSR 292
jrose
parents: 1142
diff changeset
164 static bool trust_final_non_static_fields(ciInstanceKlass* holder) {
73b22f919c34 6912065: final fields in objects need to support inlining optimizations for JSR 292
jrose
parents: 1142
diff changeset
165 if (holder == NULL)
73b22f919c34 6912065: final fields in objects need to support inlining optimizations for JSR 292
jrose
parents: 1142
diff changeset
166 return false;
73b22f919c34 6912065: final fields in objects need to support inlining optimizations for JSR 292
jrose
parents: 1142
diff changeset
167 if (holder->name() == ciSymbol::java_lang_System())
73b22f919c34 6912065: final fields in objects need to support inlining optimizations for JSR 292
jrose
parents: 1142
diff changeset
168 // Never trust strangely unstable finals: System.out, etc.
73b22f919c34 6912065: final fields in objects need to support inlining optimizations for JSR 292
jrose
parents: 1142
diff changeset
169 return false;
73b22f919c34 6912065: final fields in objects need to support inlining optimizations for JSR 292
jrose
parents: 1142
diff changeset
170 // Even if general trusting is disabled, trust system-built closures in these packages.
73b22f919c34 6912065: final fields in objects need to support inlining optimizations for JSR 292
jrose
parents: 1142
diff changeset
171 if (holder->is_in_package("java/dyn") || holder->is_in_package("sun/dyn"))
73b22f919c34 6912065: final fields in objects need to support inlining optimizations for JSR 292
jrose
parents: 1142
diff changeset
172 return true;
73b22f919c34 6912065: final fields in objects need to support inlining optimizations for JSR 292
jrose
parents: 1142
diff changeset
173 return TrustFinalNonStaticFields;
73b22f919c34 6912065: final fields in objects need to support inlining optimizations for JSR 292
jrose
parents: 1142
diff changeset
174 }
73b22f919c34 6912065: final fields in objects need to support inlining optimizations for JSR 292
jrose
parents: 1142
diff changeset
175
0
a61af66fc99e Initial load
duke
parents:
diff changeset
176 void ciField::initialize_from(fieldDescriptor* fd) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // Get the flags, offset, and canonical holder of the field.
a61af66fc99e Initial load
duke
parents:
diff changeset
178 _flags = ciFlags(fd->access_flags());
a61af66fc99e Initial load
duke
parents:
diff changeset
179 _offset = fd->offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
180 _holder = CURRENT_ENV->get_object(fd->field_holder())->as_instance_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 // Check to see if the field is constant.
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
183 if (_holder->is_initialized() && this->is_final()) {
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
184 if (!this->is_static()) {
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
185 // A field can be constant if it's a final static field or if it's
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
186 // a final non-static field of a trusted class ({java,sun}.dyn).
1173
73b22f919c34 6912065: final fields in objects need to support inlining optimizations for JSR 292
jrose
parents: 1142
diff changeset
187 if (trust_final_non_static_fields(_holder)) {
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
188 _is_constant = true;
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
189 return;
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
190 }
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
191 _is_constant = false;
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
192 return;
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
193 }
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
194
0
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // This field just may be constant. The only cases where it will
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // not be constant are:
a61af66fc99e Initial load
duke
parents:
diff changeset
197 //
a61af66fc99e Initial load
duke
parents:
diff changeset
198 // 1. The field holds a non-perm-space oop. The field is, strictly
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // speaking, constant but we cannot embed non-perm-space oops into
a61af66fc99e Initial load
duke
parents:
diff changeset
200 // generated code. For the time being we need to consider the
a61af66fc99e Initial load
duke
parents:
diff changeset
201 // field to be not constant.
a61af66fc99e Initial load
duke
parents:
diff changeset
202 // 2. The field is a *special* static&final field whose value
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // may change. The three examples are java.lang.System.in,
a61af66fc99e Initial load
duke
parents:
diff changeset
204 // java.lang.System.out, and java.lang.System.err.
a61af66fc99e Initial load
duke
parents:
diff changeset
205
a61af66fc99e Initial load
duke
parents:
diff changeset
206 klassOop k = _holder->get_klassOop();
1142
4ce7240d622c 6914300: ciEnv should export all well known classes
never
parents: 1138
diff changeset
207 assert( SystemDictionary::System_klass() != NULL, "Check once per vm");
4ce7240d622c 6914300: ciEnv should export all well known classes
never
parents: 1138
diff changeset
208 if( k == SystemDictionary::System_klass() ) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
209 // Check offsets for case 2: System.in, System.out, or System.err
a61af66fc99e Initial load
duke
parents:
diff changeset
210 if( _offset == java_lang_System::in_offset_in_bytes() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
211 _offset == java_lang_System::out_offset_in_bytes() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
212 _offset == java_lang_System::err_offset_in_bytes() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 _is_constant = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
214 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 _is_constant = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
219 switch(type()->basic_type()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 case T_BYTE:
a61af66fc99e Initial load
duke
parents:
diff changeset
221 _constant_value = ciConstant(type()->basic_type(), k->byte_field(_offset));
a61af66fc99e Initial load
duke
parents:
diff changeset
222 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
223 case T_CHAR:
a61af66fc99e Initial load
duke
parents:
diff changeset
224 _constant_value = ciConstant(type()->basic_type(), k->char_field(_offset));
a61af66fc99e Initial load
duke
parents:
diff changeset
225 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
226 case T_SHORT:
a61af66fc99e Initial load
duke
parents:
diff changeset
227 _constant_value = ciConstant(type()->basic_type(), k->short_field(_offset));
a61af66fc99e Initial load
duke
parents:
diff changeset
228 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
229 case T_BOOLEAN:
a61af66fc99e Initial load
duke
parents:
diff changeset
230 _constant_value = ciConstant(type()->basic_type(), k->bool_field(_offset));
a61af66fc99e Initial load
duke
parents:
diff changeset
231 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
232 case T_INT:
a61af66fc99e Initial load
duke
parents:
diff changeset
233 _constant_value = ciConstant(type()->basic_type(), k->int_field(_offset));
a61af66fc99e Initial load
duke
parents:
diff changeset
234 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 case T_FLOAT:
a61af66fc99e Initial load
duke
parents:
diff changeset
236 _constant_value = ciConstant(k->float_field(_offset));
a61af66fc99e Initial load
duke
parents:
diff changeset
237 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
238 case T_DOUBLE:
a61af66fc99e Initial load
duke
parents:
diff changeset
239 _constant_value = ciConstant(k->double_field(_offset));
a61af66fc99e Initial load
duke
parents:
diff changeset
240 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
241 case T_LONG:
a61af66fc99e Initial load
duke
parents:
diff changeset
242 _constant_value = ciConstant(k->long_field(_offset));
a61af66fc99e Initial load
duke
parents:
diff changeset
243 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
244 case T_OBJECT:
a61af66fc99e Initial load
duke
parents:
diff changeset
245 case T_ARRAY:
a61af66fc99e Initial load
duke
parents:
diff changeset
246 {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 oop o = k->obj_field(_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
248
a61af66fc99e Initial load
duke
parents:
diff changeset
249 // A field will be "constant" if it is known always to be
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // a non-null reference to an instance of a particular class,
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // or to a particular array. This can happen even if the instance
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // or array is not perm. In such a case, an "unloaded" ciArray
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // or ciInstance is created. The compiler may be able to use
a61af66fc99e Initial load
duke
parents:
diff changeset
254 // information about the object's class (which is exact) or length.
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 if (o == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 _constant_value = ciConstant(type()->basic_type(), ciNullObject::make());
a61af66fc99e Initial load
duke
parents:
diff changeset
258 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 _constant_value = ciConstant(type()->basic_type(), CURRENT_ENV->get_object(o));
a61af66fc99e Initial load
duke
parents:
diff changeset
260 assert(_constant_value.as_object() == CURRENT_ENV->get_object(o), "check interning");
a61af66fc99e Initial load
duke
parents:
diff changeset
261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
264 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
265 _is_constant = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268
a61af66fc99e Initial load
duke
parents:
diff changeset
269 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
270 // ciField::compute_type
a61af66fc99e Initial load
duke
parents:
diff changeset
271 //
a61af66fc99e Initial load
duke
parents:
diff changeset
272 // Lazily compute the type, if it is an instance klass.
a61af66fc99e Initial load
duke
parents:
diff changeset
273 ciType* ciField::compute_type() {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 GUARDED_VM_ENTRY(return compute_type_impl();)
a61af66fc99e Initial load
duke
parents:
diff changeset
275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277 ciType* ciField::compute_type_impl() {
a61af66fc99e Initial load
duke
parents:
diff changeset
278 ciKlass* type = CURRENT_ENV->get_klass_by_name_impl(_holder, _signature, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
279 if (!type->is_primitive_type() && is_shared()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
280 // We must not cache a pointer to an unshared type, in a shared field.
a61af66fc99e Initial load
duke
parents:
diff changeset
281 bool type_is_also_shared = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
282 if (type->is_type_array_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
283 type_is_also_shared = true; // int[] etc. are explicitly bootstrapped
a61af66fc99e Initial load
duke
parents:
diff changeset
284 } else if (type->is_instance_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
285 type_is_also_shared = type->as_instance_klass()->is_shared();
a61af66fc99e Initial load
duke
parents:
diff changeset
286 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 // Currently there is no 'shared' query for array types.
a61af66fc99e Initial load
duke
parents:
diff changeset
288 type_is_also_shared = !ciObjectFactory::is_initialized();
a61af66fc99e Initial load
duke
parents:
diff changeset
289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
290 if (!type_is_also_shared)
a61af66fc99e Initial load
duke
parents:
diff changeset
291 return type; // Bummer.
a61af66fc99e Initial load
duke
parents:
diff changeset
292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
293 _type = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
294 return type;
a61af66fc99e Initial load
duke
parents:
diff changeset
295 }
a61af66fc99e Initial load
duke
parents:
diff changeset
296
1459
a8f9f091c219 Don't mess with VMToNative transitions..
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents: 1173
diff changeset
297 bool ciField::will_link(ciInstanceKlass* accessing_klass,
a8f9f091c219 Don't mess with VMToNative transitions..
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents: 1173
diff changeset
298 Bytecodes::Code bc) {
a8f9f091c219 Don't mess with VMToNative transitions..
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents: 1173
diff changeset
299 VM_ENTRY_MARK;
a8f9f091c219 Don't mess with VMToNative transitions..
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents: 1173
diff changeset
300 will_link_from_vm(accessing_klass, bc);
a8f9f091c219 Don't mess with VMToNative transitions..
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents: 1173
diff changeset
301 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
304 // ciField::will_link
a61af66fc99e Initial load
duke
parents:
diff changeset
305 //
a61af66fc99e Initial load
duke
parents:
diff changeset
306 // Can a specific access to this field be made without causing
a61af66fc99e Initial load
duke
parents:
diff changeset
307 // link errors?
1459
a8f9f091c219 Don't mess with VMToNative transitions..
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents: 1173
diff changeset
308 bool ciField::will_link_from_vm(ciInstanceKlass* accessing_klass,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
309 Bytecodes::Code bc) {
1461
944071972cd9 Small fix.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents: 1459
diff changeset
310 Thread* THREAD = Thread::current();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
311 if (_offset == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
312 // at creation we couldn't link to our holder so we need to
a61af66fc99e Initial load
duke
parents:
diff changeset
313 // maintain that stance, otherwise there's no safe way to use this
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // ciField.
a61af66fc99e Initial load
duke
parents:
diff changeset
315 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 if (_known_to_link_with == accessing_klass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
319 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
321
a61af66fc99e Initial load
duke
parents:
diff changeset
322 FieldAccessInfo result;
a61af66fc99e Initial load
duke
parents:
diff changeset
323 constantPoolHandle c_pool(THREAD,
a61af66fc99e Initial load
duke
parents:
diff changeset
324 accessing_klass->get_instanceKlass()->constants());
a61af66fc99e Initial load
duke
parents:
diff changeset
325 LinkResolver::resolve_field(result, c_pool, _cp_index,
a61af66fc99e Initial load
duke
parents:
diff changeset
326 Bytecodes::java_code(bc),
a61af66fc99e Initial load
duke
parents:
diff changeset
327 true, false, KILL_COMPILE_ON_FATAL_(false));
a61af66fc99e Initial load
duke
parents:
diff changeset
328
a61af66fc99e Initial load
duke
parents:
diff changeset
329 // update the hit-cache, unless there is a problem with memory scoping:
a61af66fc99e Initial load
duke
parents:
diff changeset
330 if (accessing_klass->is_shared() || !is_shared())
a61af66fc99e Initial load
duke
parents:
diff changeset
331 _known_to_link_with = accessing_klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
332
a61af66fc99e Initial load
duke
parents:
diff changeset
333 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
335
a61af66fc99e Initial load
duke
parents:
diff changeset
336 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
337 // ciField::print
a61af66fc99e Initial load
duke
parents:
diff changeset
338 void ciField::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
339 tty->print("<ciField ");
a61af66fc99e Initial load
duke
parents:
diff changeset
340 _holder->print_name();
a61af66fc99e Initial load
duke
parents:
diff changeset
341 tty->print(".");
a61af66fc99e Initial load
duke
parents:
diff changeset
342 _name->print_symbol();
a61af66fc99e Initial load
duke
parents:
diff changeset
343 tty->print(" offset=%d type=", _offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
344 if (_type != NULL) _type->print_name();
a61af66fc99e Initial load
duke
parents:
diff changeset
345 else tty->print("(reference)");
a61af66fc99e Initial load
duke
parents:
diff changeset
346 tty->print(" is_constant=%s", bool_to_str(_is_constant));
1682
e5dfb3ccb88b 6969569: assert(is_static() && is_constant()) failed: illegal call to constant_value()
kvn
parents: 1552
diff changeset
347 if (_is_constant && is_static()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
348 tty->print(" constant_value=");
a61af66fc99e Initial load
duke
parents:
diff changeset
349 _constant_value.print();
a61af66fc99e Initial load
duke
parents:
diff changeset
350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
351 tty->print(">");
a61af66fc99e Initial load
duke
parents:
diff changeset
352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
353
a61af66fc99e Initial load
duke
parents:
diff changeset
354 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
355 // ciField::print_name_on
a61af66fc99e Initial load
duke
parents:
diff changeset
356 //
a61af66fc99e Initial load
duke
parents:
diff changeset
357 // Print the name of this field
a61af66fc99e Initial load
duke
parents:
diff changeset
358 void ciField::print_name_on(outputStream* st) {
a61af66fc99e Initial load
duke
parents:
diff changeset
359 name()->print_symbol_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 }