Sat, 01 Dec 2007 00:00:00 +0000
Initial load
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 1999-2005 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | #include "incls/_precompiled.incl" |
duke@435 | 26 | #include "incls/_ciInstance.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | // ciInstance |
duke@435 | 29 | // |
duke@435 | 30 | // This class represents an instanceOop in the HotSpot virtual |
duke@435 | 31 | // machine. |
duke@435 | 32 | |
duke@435 | 33 | // ------------------------------------------------------------------ |
duke@435 | 34 | // ciObject::java_mirror_type |
duke@435 | 35 | ciType* ciInstance::java_mirror_type() { |
duke@435 | 36 | VM_ENTRY_MARK; |
duke@435 | 37 | oop m = get_oop(); |
duke@435 | 38 | // Return NULL if it is not java.lang.Class. |
duke@435 | 39 | if (m == NULL || m->klass() != SystemDictionary::class_klass()) { |
duke@435 | 40 | return NULL; |
duke@435 | 41 | } |
duke@435 | 42 | // Return either a primitive type or a klass. |
duke@435 | 43 | if (java_lang_Class::is_primitive(m)) { |
duke@435 | 44 | return ciType::make(java_lang_Class::primitive_type(m)); |
duke@435 | 45 | } else { |
duke@435 | 46 | klassOop k = java_lang_Class::as_klassOop(m); |
duke@435 | 47 | assert(k != NULL, ""); |
duke@435 | 48 | return CURRENT_THREAD_ENV->get_object(k)->as_klass(); |
duke@435 | 49 | } |
duke@435 | 50 | } |
duke@435 | 51 | |
duke@435 | 52 | // ------------------------------------------------------------------ |
duke@435 | 53 | // ciInstance::field_value |
duke@435 | 54 | // |
duke@435 | 55 | // Constant value of a field. |
duke@435 | 56 | ciConstant ciInstance::field_value(ciField* field) { |
duke@435 | 57 | assert(is_loaded() && |
duke@435 | 58 | field->holder()->is_loaded() && |
duke@435 | 59 | klass()->is_subclass_of(field->holder()), |
duke@435 | 60 | "invalid access"); |
duke@435 | 61 | VM_ENTRY_MARK; |
duke@435 | 62 | ciConstant result; |
duke@435 | 63 | oop obj = get_oop(); |
duke@435 | 64 | assert(obj != NULL, "bad oop"); |
duke@435 | 65 | BasicType field_btype = field->type()->basic_type(); |
duke@435 | 66 | int offset = field->offset(); |
duke@435 | 67 | |
duke@435 | 68 | switch(field_btype) { |
duke@435 | 69 | case T_BYTE: |
duke@435 | 70 | return ciConstant(field_btype, obj->byte_field(offset)); |
duke@435 | 71 | break; |
duke@435 | 72 | case T_CHAR: |
duke@435 | 73 | return ciConstant(field_btype, obj->char_field(offset)); |
duke@435 | 74 | break; |
duke@435 | 75 | case T_SHORT: |
duke@435 | 76 | return ciConstant(field_btype, obj->short_field(offset)); |
duke@435 | 77 | break; |
duke@435 | 78 | case T_BOOLEAN: |
duke@435 | 79 | return ciConstant(field_btype, obj->bool_field(offset)); |
duke@435 | 80 | break; |
duke@435 | 81 | case T_INT: |
duke@435 | 82 | return ciConstant(field_btype, obj->int_field(offset)); |
duke@435 | 83 | break; |
duke@435 | 84 | case T_FLOAT: |
duke@435 | 85 | return ciConstant(obj->float_field(offset)); |
duke@435 | 86 | break; |
duke@435 | 87 | case T_DOUBLE: |
duke@435 | 88 | return ciConstant(obj->double_field(offset)); |
duke@435 | 89 | break; |
duke@435 | 90 | case T_LONG: |
duke@435 | 91 | return ciConstant(obj->long_field(offset)); |
duke@435 | 92 | break; |
duke@435 | 93 | case T_OBJECT: |
duke@435 | 94 | case T_ARRAY: |
duke@435 | 95 | { |
duke@435 | 96 | oop o = obj->obj_field(offset); |
duke@435 | 97 | |
duke@435 | 98 | // A field will be "constant" if it is known always to be |
duke@435 | 99 | // a non-null reference to an instance of a particular class, |
duke@435 | 100 | // or to a particular array. This can happen even if the instance |
duke@435 | 101 | // or array is not perm. In such a case, an "unloaded" ciArray |
duke@435 | 102 | // or ciInstance is created. The compiler may be able to use |
duke@435 | 103 | // information about the object's class (which is exact) or length. |
duke@435 | 104 | |
duke@435 | 105 | if (o == NULL) { |
duke@435 | 106 | return ciConstant(field_btype, ciNullObject::make()); |
duke@435 | 107 | } else { |
duke@435 | 108 | return ciConstant(field_btype, CURRENT_ENV->get_object(o)); |
duke@435 | 109 | } |
duke@435 | 110 | } |
duke@435 | 111 | } |
duke@435 | 112 | ShouldNotReachHere(); |
duke@435 | 113 | // to shut up the compiler |
duke@435 | 114 | return ciConstant(); |
duke@435 | 115 | } |
duke@435 | 116 | |
duke@435 | 117 | // ------------------------------------------------------------------ |
duke@435 | 118 | // ciInstance::field_value_by_offset |
duke@435 | 119 | // |
duke@435 | 120 | // Constant value of a field at the specified offset. |
duke@435 | 121 | ciConstant ciInstance::field_value_by_offset(int field_offset) { |
duke@435 | 122 | ciInstanceKlass* ik = klass()->as_instance_klass(); |
duke@435 | 123 | ciField* field = ik->get_field_by_offset(field_offset, false); |
duke@435 | 124 | return field_value(field); |
duke@435 | 125 | } |
duke@435 | 126 | |
duke@435 | 127 | // ------------------------------------------------------------------ |
duke@435 | 128 | // ciInstance::print_impl |
duke@435 | 129 | // |
duke@435 | 130 | // Implementation of the print method. |
duke@435 | 131 | void ciInstance::print_impl(outputStream* st) { |
duke@435 | 132 | st->print(" type="); |
duke@435 | 133 | klass()->print(st); |
duke@435 | 134 | } |