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