Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/ci/ciInstance.cpp
32285 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "ci/ciConstant.hpp"26#include "ci/ciField.hpp"27#include "ci/ciInstance.hpp"28#include "ci/ciInstanceKlass.hpp"29#include "ci/ciUtilities.hpp"30#include "classfile/systemDictionary.hpp"31#include "oops/oop.inline.hpp"3233// ciInstance34//35// This class represents an instanceOop in the HotSpot virtual36// machine.3738// ------------------------------------------------------------------39// ciObject::java_mirror_type40ciType* ciInstance::java_mirror_type() {41VM_ENTRY_MARK;42oop m = get_oop();43// Return NULL if it is not java.lang.Class.44if (m == NULL || m->klass() != SystemDictionary::Class_klass()) {45return NULL;46}47// Return either a primitive type or a klass.48if (java_lang_Class::is_primitive(m)) {49return ciType::make(java_lang_Class::primitive_type(m));50} else {51Klass* k = java_lang_Class::as_Klass(m);52assert(k != NULL, "");53return CURRENT_THREAD_ENV->get_klass(k);54}55}5657// ------------------------------------------------------------------58// ciInstance::field_value59//60// Constant value of a field.61ciConstant ciInstance::field_value(ciField* field) {62assert(is_loaded(), "invalid access - must be loaded");63assert(field->holder()->is_loaded(), "invalid access - holder must be loaded");64assert(klass()->is_subclass_of(field->holder()), "invalid access - must be subclass");6566VM_ENTRY_MARK;67ciConstant result;68Handle obj = get_oop();69assert(!obj.is_null(), "bad oop");70BasicType field_btype = field->type()->basic_type();71int offset = field->offset();7273switch(field_btype) {74case T_BYTE:75return ciConstant(field_btype, obj->byte_field(offset));76break;77case T_CHAR:78return ciConstant(field_btype, obj->char_field(offset));79break;80case T_SHORT:81return ciConstant(field_btype, obj->short_field(offset));82break;83case T_BOOLEAN:84return ciConstant(field_btype, obj->bool_field(offset));85break;86case T_INT:87return ciConstant(field_btype, obj->int_field(offset));88break;89case T_FLOAT:90return ciConstant(obj->float_field(offset));91break;92case T_DOUBLE:93return ciConstant(obj->double_field(offset));94break;95case T_LONG:96return ciConstant(obj->long_field(offset));97break;98case T_OBJECT:99case T_ARRAY:100{101oop o = obj->obj_field(offset);102103// A field will be "constant" if it is known always to be104// a non-null reference to an instance of a particular class,105// or to a particular array. This can happen even if the instance106// or array is not perm. In such a case, an "unloaded" ciArray107// or ciInstance is created. The compiler may be able to use108// information about the object's class (which is exact) or length.109110if (o == NULL) {111return ciConstant(field_btype, ciNullObject::make());112} else {113return ciConstant(field_btype, CURRENT_ENV->get_object(o));114}115}116}117ShouldNotReachHere();118// to shut up the compiler119return ciConstant();120}121122// ------------------------------------------------------------------123// ciInstance::field_value_by_offset124//125// Constant value of a field at the specified offset.126ciConstant ciInstance::field_value_by_offset(int field_offset) {127ciInstanceKlass* ik = klass()->as_instance_klass();128ciField* field = ik->get_field_by_offset(field_offset, false);129if (field == NULL)130return ciConstant(); // T_ILLEGAL131return field_value(field);132}133134// ------------------------------------------------------------------135// ciInstance::print_impl136//137// Implementation of the print method.138void ciInstance::print_impl(outputStream* st) {139st->print(" type=");140klass()->print(st);141}142143144ciKlass* ciInstance::java_lang_Class_klass() {145VM_ENTRY_MARK;146return CURRENT_ENV->get_metadata(java_lang_Class::as_Klass(get_oop()))->as_klass();147}148149150