11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "ci/ciField.hpp"
26 #include "ci/ciInstanceKlass.hpp"
27 #include "ci/ciSymbols.hpp"
28 #include "ci/ciUtilities.inline.hpp"
29 #include "classfile/javaClasses.hpp"
30 #include "classfile/vmClasses.hpp"
31 #include "gc/shared/collectedHeap.inline.hpp"
32 #include "interpreter/linkResolver.hpp"
33 #include "oops/klass.inline.hpp"
34 #include "oops/oop.inline.hpp"
35 #include "runtime/fieldDescriptor.inline.hpp"
36 #include "runtime/handles.inline.hpp"
37 #include "runtime/reflection.hpp"
38
39 // ciField
40 //
41 // This class represents the result of a field lookup in the VM.
42 // The lookup may not succeed, in which case the information in
43 // the ciField will be incomplete.
44
45 // The ciObjectFactory cannot create circular data structures in one query.
46 // To avoid vicious circularities, we initialize ciField::_type to null
47 // for reference types and derive it lazily from the ciField::_signature.
48 // Primitive types are eagerly initialized, and basic layout queries
49 // can succeed without initialization, using only the BasicType of the field.
50
274 }
275 }
276 }
277
278 // ------------------------------------------------------------------
279 // ciField::constant_value
280 // Get the constant value of a this static field.
281 ciConstant ciField::constant_value() {
282 assert(is_static() && is_constant(), "illegal call to constant_value()");
283 if (!_holder->is_initialized()) {
284 return ciConstant(); // Not initialized yet
285 }
286 if (_constant_value.basic_type() == T_ILLEGAL) {
287 // Static fields are placed in mirror objects.
288 ciInstance* mirror = _holder->java_mirror();
289 _constant_value = mirror->field_value_impl(type()->basic_type(), offset_in_bytes());
290 }
291 if (FoldStableValues && is_stable() && _constant_value.is_null_or_zero()) {
292 return ciConstant();
293 }
294 return _constant_value;
295 }
296
297 // ------------------------------------------------------------------
298 // ciField::constant_value_of
299 // Get the constant value of non-static final field in the given object.
300 ciConstant ciField::constant_value_of(ciObject* object) {
301 assert(!is_static() && is_constant(), "only if field is non-static constant");
302 assert(object->is_instance(), "must be instance");
303 ciConstant field_value = object->as_instance()->field_value(this);
304 if (FoldStableValues && is_stable() && field_value.is_null_or_zero()) {
305 return ciConstant();
306 }
307 return field_value;
308 }
309
310 // ------------------------------------------------------------------
311 // ciField::compute_type
312 //
313 // Lazily compute the type, if it is an instance klass.
314 ciType* ciField::compute_type() {
315 GUARDED_VM_ENTRY(return compute_type_impl();)
316 }
317
318 ciType* ciField::compute_type_impl() {
319 ciKlass* type = CURRENT_ENV->get_klass_by_name_impl(_holder, constantPoolHandle(), _signature, false);
320 if (!type->is_primitive_type() && is_shared()) {
321 // We must not cache a pointer to an unshared type, in a shared field.
322 bool type_is_also_shared = false;
323 if (type->is_type_array_klass()) {
324 type_is_also_shared = true; // int[] etc. are explicitly bootstrapped
325 } else if (type->is_instance_klass()) {
326 type_is_also_shared = type->as_instance_klass()->is_shared();
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "ci/ciField.hpp"
26 #include "ci/ciInstanceKlass.hpp"
27 #include "ci/ciSymbols.hpp"
28 #include "ci/ciUtilities.inline.hpp"
29 #include "classfile/javaClasses.hpp"
30 #include "classfile/vmClasses.hpp"
31 #include "code/aotCodeCache.hpp"
32 #include "gc/shared/collectedHeap.inline.hpp"
33 #include "interpreter/linkResolver.hpp"
34 #include "oops/klass.inline.hpp"
35 #include "oops/oop.inline.hpp"
36 #include "runtime/fieldDescriptor.inline.hpp"
37 #include "runtime/handles.inline.hpp"
38 #include "runtime/reflection.hpp"
39
40 // ciField
41 //
42 // This class represents the result of a field lookup in the VM.
43 // The lookup may not succeed, in which case the information in
44 // the ciField will be incomplete.
45
46 // The ciObjectFactory cannot create circular data structures in one query.
47 // To avoid vicious circularities, we initialize ciField::_type to null
48 // for reference types and derive it lazily from the ciField::_signature.
49 // Primitive types are eagerly initialized, and basic layout queries
50 // can succeed without initialization, using only the BasicType of the field.
51
275 }
276 }
277 }
278
279 // ------------------------------------------------------------------
280 // ciField::constant_value
281 // Get the constant value of a this static field.
282 ciConstant ciField::constant_value() {
283 assert(is_static() && is_constant(), "illegal call to constant_value()");
284 if (!_holder->is_initialized()) {
285 return ciConstant(); // Not initialized yet
286 }
287 if (_constant_value.basic_type() == T_ILLEGAL) {
288 // Static fields are placed in mirror objects.
289 ciInstance* mirror = _holder->java_mirror();
290 _constant_value = mirror->field_value_impl(type()->basic_type(), offset_in_bytes());
291 }
292 if (FoldStableValues && is_stable() && _constant_value.is_null_or_zero()) {
293 return ciConstant();
294 }
295 if (!AOTCodeCache::allow_const_field(_constant_value)) {
296 return ciConstant();
297 }
298 return _constant_value;
299 }
300
301 // ------------------------------------------------------------------
302 // ciField::constant_value_of
303 // Get the constant value of non-static final field in the given object.
304 ciConstant ciField::constant_value_of(ciObject* object) {
305 assert(!is_static() && is_constant(), "only if field is non-static constant");
306 assert(object->is_instance(), "must be instance");
307 ciConstant field_value = object->as_instance()->field_value(this);
308 if (FoldStableValues && is_stable() && field_value.is_null_or_zero()) {
309 return ciConstant();
310 }
311 if (!AOTCodeCache::allow_const_field(field_value)) {
312 return ciConstant();
313 }
314 return field_value;
315 }
316
317 // ------------------------------------------------------------------
318 // ciField::compute_type
319 //
320 // Lazily compute the type, if it is an instance klass.
321 ciType* ciField::compute_type() {
322 GUARDED_VM_ENTRY(return compute_type_impl();)
323 }
324
325 ciType* ciField::compute_type_impl() {
326 ciKlass* type = CURRENT_ENV->get_klass_by_name_impl(_holder, constantPoolHandle(), _signature, false);
327 if (!type->is_primitive_type() && is_shared()) {
328 // We must not cache a pointer to an unshared type, in a shared field.
329 bool type_is_also_shared = false;
330 if (type->is_type_array_klass()) {
331 type_is_also_shared = true; // int[] etc. are explicitly bootstrapped
332 } else if (type->is_instance_klass()) {
333 type_is_also_shared = type->as_instance_klass()->is_shared();
|