duke@435: /* duke@435: * Copyright 1999-2005 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: #include "incls/_precompiled.incl" duke@435: #include "incls/_ciInstance.cpp.incl" duke@435: duke@435: // ciInstance duke@435: // duke@435: // This class represents an instanceOop in the HotSpot virtual duke@435: // machine. duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciObject::java_mirror_type duke@435: ciType* ciInstance::java_mirror_type() { duke@435: VM_ENTRY_MARK; duke@435: oop m = get_oop(); duke@435: // Return NULL if it is not java.lang.Class. never@1577: if (m == NULL || m->klass() != SystemDictionary::Class_klass()) { duke@435: return NULL; duke@435: } duke@435: // Return either a primitive type or a klass. duke@435: if (java_lang_Class::is_primitive(m)) { duke@435: return ciType::make(java_lang_Class::primitive_type(m)); duke@435: } else { duke@435: klassOop k = java_lang_Class::as_klassOop(m); duke@435: assert(k != NULL, ""); duke@435: return CURRENT_THREAD_ENV->get_object(k)->as_klass(); duke@435: } duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciInstance::field_value duke@435: // duke@435: // Constant value of a field. duke@435: ciConstant ciInstance::field_value(ciField* field) { duke@435: assert(is_loaded() && duke@435: field->holder()->is_loaded() && duke@435: klass()->is_subclass_of(field->holder()), duke@435: "invalid access"); duke@435: VM_ENTRY_MARK; duke@435: ciConstant result; duke@435: oop obj = get_oop(); duke@435: assert(obj != NULL, "bad oop"); duke@435: BasicType field_btype = field->type()->basic_type(); duke@435: int offset = field->offset(); duke@435: duke@435: switch(field_btype) { duke@435: case T_BYTE: duke@435: return ciConstant(field_btype, obj->byte_field(offset)); duke@435: break; duke@435: case T_CHAR: duke@435: return ciConstant(field_btype, obj->char_field(offset)); duke@435: break; duke@435: case T_SHORT: duke@435: return ciConstant(field_btype, obj->short_field(offset)); duke@435: break; duke@435: case T_BOOLEAN: duke@435: return ciConstant(field_btype, obj->bool_field(offset)); duke@435: break; duke@435: case T_INT: duke@435: return ciConstant(field_btype, obj->int_field(offset)); duke@435: break; duke@435: case T_FLOAT: duke@435: return ciConstant(obj->float_field(offset)); duke@435: break; duke@435: case T_DOUBLE: duke@435: return ciConstant(obj->double_field(offset)); duke@435: break; duke@435: case T_LONG: duke@435: return ciConstant(obj->long_field(offset)); duke@435: break; duke@435: case T_OBJECT: duke@435: case T_ARRAY: duke@435: { duke@435: oop o = obj->obj_field(offset); duke@435: duke@435: // A field will be "constant" if it is known always to be duke@435: // a non-null reference to an instance of a particular class, duke@435: // or to a particular array. This can happen even if the instance duke@435: // or array is not perm. In such a case, an "unloaded" ciArray duke@435: // or ciInstance is created. The compiler may be able to use duke@435: // information about the object's class (which is exact) or length. duke@435: duke@435: if (o == NULL) { duke@435: return ciConstant(field_btype, ciNullObject::make()); duke@435: } else { duke@435: return ciConstant(field_btype, CURRENT_ENV->get_object(o)); duke@435: } duke@435: } duke@435: } duke@435: ShouldNotReachHere(); duke@435: // to shut up the compiler duke@435: return ciConstant(); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciInstance::field_value_by_offset duke@435: // duke@435: // Constant value of a field at the specified offset. duke@435: ciConstant ciInstance::field_value_by_offset(int field_offset) { duke@435: ciInstanceKlass* ik = klass()->as_instance_klass(); duke@435: ciField* field = ik->get_field_by_offset(field_offset, false); duke@435: return field_value(field); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciInstance::print_impl duke@435: // duke@435: // Implementation of the print method. duke@435: void ciInstance::print_impl(outputStream* st) { duke@435: st->print(" type="); duke@435: klass()->print(st); duke@435: }