Path: blob/master/src/hotspot/share/ci/ciInstance.cpp
40930 views
/*1* Copyright (c) 1999, 2021, 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 "classfile/javaClasses.inline.hpp"26#include "ci/ciConstant.hpp"27#include "ci/ciField.hpp"28#include "ci/ciInstance.hpp"29#include "ci/ciInstanceKlass.hpp"30#include "ci/ciUtilities.inline.hpp"31#include "classfile/vmClasses.hpp"32#include "oops/oop.inline.hpp"3334// ciInstance35//36// This class represents an instanceOop in the HotSpot virtual37// machine.3839// ------------------------------------------------------------------40// ciObject::java_mirror_type41ciType* ciInstance::java_mirror_type() {42VM_ENTRY_MARK;43oop m = get_oop();44// Return NULL if it is not java.lang.Class.45if (m == NULL || m->klass() != vmClasses::Class_klass()) {46return NULL;47}48// Return either a primitive type or a klass.49if (java_lang_Class::is_primitive(m)) {50return ciType::make(java_lang_Class::primitive_type(m));51} else {52Klass* k = java_lang_Class::as_Klass(m);53assert(k != NULL, "");54return CURRENT_THREAD_ENV->get_klass(k);55}56}5758// ------------------------------------------------------------------59// ciInstance::field_value_impl60ciConstant ciInstance::field_value_impl(BasicType field_btype, int offset) {61oop obj = get_oop();62assert(obj != NULL, "bad oop");63switch(field_btype) {64case T_BYTE: return ciConstant(field_btype, obj->byte_field(offset));65case T_CHAR: return ciConstant(field_btype, obj->char_field(offset));66case T_SHORT: return ciConstant(field_btype, obj->short_field(offset));67case T_BOOLEAN: return ciConstant(field_btype, obj->bool_field(offset));68case T_INT: return ciConstant(field_btype, obj->int_field(offset));69case T_FLOAT: return ciConstant(obj->float_field(offset));70case T_DOUBLE: return ciConstant(obj->double_field(offset));71case T_LONG: return ciConstant(obj->long_field(offset));72case T_OBJECT: // fall through73case T_ARRAY: {74oop o = obj->obj_field(offset);7576// A field will be "constant" if it is known always to be77// a non-null reference to an instance of a particular class,78// or to a particular array. This can happen even if the instance79// or array is not perm. In such a case, an "unloaded" ciArray80// or ciInstance is created. The compiler may be able to use81// information about the object's class (which is exact) or length.8283if (o == NULL) {84return ciConstant(field_btype, ciNullObject::make());85} else {86return ciConstant(field_btype, CURRENT_ENV->get_object(o));87}88}89default:90fatal("no field value: %s", type2name(field_btype));91return ciConstant();92}93}9495// ------------------------------------------------------------------96// ciInstance::field_value97//98// Constant value of a field.99ciConstant ciInstance::field_value(ciField* field) {100assert(is_loaded(), "invalid access - must be loaded");101assert(field->holder()->is_loaded(), "invalid access - holder must be loaded");102assert(field->is_static() || klass()->is_subclass_of(field->holder()), "invalid access - must be subclass");103104GUARDED_VM_ENTRY(return field_value_impl(field->type()->basic_type(), field->offset());)105}106107// ------------------------------------------------------------------108// ciInstance::field_value_by_offset109//110// Constant value of a field at the specified offset.111ciConstant ciInstance::field_value_by_offset(int field_offset) {112ciInstanceKlass* ik = klass()->as_instance_klass();113ciField* field = ik->get_field_by_offset(field_offset, false);114if (field == NULL)115return ciConstant(); // T_ILLEGAL116return field_value(field);117}118119// ------------------------------------------------------------------120// ciInstance::print_impl121//122// Implementation of the print method.123void ciInstance::print_impl(outputStream* st) {124st->print(" type=");125klass()->print(st);126}127128129ciKlass* ciInstance::java_lang_Class_klass() {130VM_ENTRY_MARK;131return CURRENT_ENV->get_metadata(java_lang_Class::as_Klass(get_oop()))->as_klass();132}133134135