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
297 }
298 }
299 }
300
301 // ------------------------------------------------------------------
302 // ciField::constant_value
303 // Get the constant value of a this static field.
304 ciConstant ciField::constant_value() {
305 assert(is_static() && is_constant(), "illegal call to constant_value()");
306 if (!_holder->is_initialized()) {
307 return ciConstant(); // Not initialized yet
308 }
309 if (_constant_value.basic_type() == T_ILLEGAL) {
310 // Static fields are placed in mirror objects.
311 ciInstance* mirror = _holder->java_mirror();
312 _constant_value = mirror->field_value_impl(type()->basic_type(), offset_in_bytes());
313 }
314 if (FoldStableValues && is_stable() && _constant_value.is_null_or_zero()) {
315 return ciConstant();
316 }
317 return _constant_value;
318 }
319
320 // ------------------------------------------------------------------
321 // ciField::constant_value_of
322 // Get the constant value of non-static final field in the given object.
323 ciConstant ciField::constant_value_of(ciObject* object) {
324 assert(!is_static() && is_constant(), "only if field is non-static constant");
325 assert(object->is_instance(), "must be instance");
326 ciConstant field_value = object->as_instance()->field_value(this);
327 if (FoldStableValues && is_stable() && field_value.is_null_or_zero()) {
328 return ciConstant();
329 }
330 return field_value;
331 }
332
333 // ------------------------------------------------------------------
334 // ciField::compute_type
335 //
336 // Lazily compute the type, if it is an instance klass.
337 ciType* ciField::compute_type() {
338 GUARDED_VM_ENTRY(return compute_type_impl();)
339 }
340
341 ciType* ciField::compute_type_impl() {
342 ciKlass* type = CURRENT_ENV->get_klass_by_name_impl(_holder, constantPoolHandle(), _signature, false);
343 if (!type->is_primitive_type() && is_shared()) {
344 // We must not cache a pointer to an unshared type, in a shared field.
345 bool type_is_also_shared = false;
346 if (type->is_type_array_klass()) {
347 type_is_also_shared = true; // int[] etc. are explicitly bootstrapped
348 } else if (type->is_instance_klass()) {
349 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/SCCache.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
298 }
299 }
300 }
301
302 // ------------------------------------------------------------------
303 // ciField::constant_value
304 // Get the constant value of a this static field.
305 ciConstant ciField::constant_value() {
306 assert(is_static() && is_constant(), "illegal call to constant_value()");
307 if (!_holder->is_initialized()) {
308 return ciConstant(); // Not initialized yet
309 }
310 if (_constant_value.basic_type() == T_ILLEGAL) {
311 // Static fields are placed in mirror objects.
312 ciInstance* mirror = _holder->java_mirror();
313 _constant_value = mirror->field_value_impl(type()->basic_type(), offset_in_bytes());
314 }
315 if (FoldStableValues && is_stable() && _constant_value.is_null_or_zero()) {
316 return ciConstant();
317 }
318 if (!SCCache::allow_const_field(_constant_value)) {
319 return ciConstant();
320 }
321 return _constant_value;
322 }
323
324 // ------------------------------------------------------------------
325 // ciField::constant_value_of
326 // Get the constant value of non-static final field in the given object.
327 ciConstant ciField::constant_value_of(ciObject* object) {
328 assert(!is_static() && is_constant(), "only if field is non-static constant");
329 assert(object->is_instance(), "must be instance");
330 ciConstant field_value = object->as_instance()->field_value(this);
331 if (FoldStableValues && is_stable() && field_value.is_null_or_zero()) {
332 return ciConstant();
333 }
334 if (!SCCache::allow_const_field(field_value)) {
335 return ciConstant();
336 }
337 return field_value;
338 }
339
340 // ------------------------------------------------------------------
341 // ciField::compute_type
342 //
343 // Lazily compute the type, if it is an instance klass.
344 ciType* ciField::compute_type() {
345 GUARDED_VM_ENTRY(return compute_type_impl();)
346 }
347
348 ciType* ciField::compute_type_impl() {
349 ciKlass* type = CURRENT_ENV->get_klass_by_name_impl(_holder, constantPoolHandle(), _signature, false);
350 if (!type->is_primitive_type() && is_shared()) {
351 // We must not cache a pointer to an unshared type, in a shared field.
352 bool type_is_also_shared = false;
353 if (type->is_type_array_klass()) {
354 type_is_also_shared = true; // int[] etc. are explicitly bootstrapped
355 } else if (type->is_instance_klass()) {
356 type_is_also_shared = type->as_instance_klass()->is_shared();
|