Wed, 03 Jul 2019 20:42:37 +0800
Merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1999, 2014, 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/ciObject.hpp" |
aoqi@0 | 27 | #include "ci/ciUtilities.hpp" |
aoqi@0 | 28 | #include "gc_interface/collectedHeap.inline.hpp" |
aoqi@0 | 29 | #include "oops/oop.inline2.hpp" |
aoqi@0 | 30 | |
aoqi@0 | 31 | // ciObject |
aoqi@0 | 32 | // |
aoqi@0 | 33 | // This class represents an oop in the HotSpot virtual machine. |
aoqi@0 | 34 | // Its subclasses are structured in a hierarchy which mirrors |
aoqi@0 | 35 | // an aggregate of the VM's oop and klass hierarchies (see |
aoqi@0 | 36 | // oopHierarchy.hpp). Each instance of ciObject holds a handle |
aoqi@0 | 37 | // to a corresponding oop on the VM side and provides routines |
aoqi@0 | 38 | // for accessing the information in its oop. By using the ciObject |
aoqi@0 | 39 | // hierarchy for accessing oops in the VM, the compiler ensures |
aoqi@0 | 40 | // that it is safe with respect to garbage collection; that is, |
aoqi@0 | 41 | // GC and compilation can proceed independently without |
aoqi@0 | 42 | // interference. |
aoqi@0 | 43 | // |
aoqi@0 | 44 | // Within the VM, the oop and klass hierarchies are separate. |
aoqi@0 | 45 | // The compiler interface does not preserve this separation -- |
aoqi@0 | 46 | // the distinction between `Klass*' and `Klass' are not |
aoqi@0 | 47 | // reflected in the interface and instead the Klass hierarchy |
aoqi@0 | 48 | // is directly modeled as the subclasses of ciKlass. |
aoqi@0 | 49 | |
aoqi@0 | 50 | // ------------------------------------------------------------------ |
aoqi@0 | 51 | // ciObject::ciObject |
aoqi@0 | 52 | ciObject::ciObject(oop o) { |
aoqi@0 | 53 | ASSERT_IN_VM; |
aoqi@0 | 54 | if (ciObjectFactory::is_initialized()) { |
aoqi@0 | 55 | _handle = JNIHandles::make_local(o); |
aoqi@0 | 56 | } else { |
aoqi@0 | 57 | _handle = JNIHandles::make_global(o); |
aoqi@0 | 58 | } |
aoqi@0 | 59 | _klass = NULL; |
aoqi@0 | 60 | init_flags_from(o); |
aoqi@0 | 61 | } |
aoqi@0 | 62 | |
aoqi@0 | 63 | // ------------------------------------------------------------------ |
aoqi@0 | 64 | // ciObject::ciObject |
aoqi@0 | 65 | // |
aoqi@0 | 66 | ciObject::ciObject(Handle h) { |
aoqi@0 | 67 | ASSERT_IN_VM; |
aoqi@0 | 68 | if (ciObjectFactory::is_initialized()) { |
aoqi@0 | 69 | _handle = JNIHandles::make_local(h()); |
aoqi@0 | 70 | } else { |
aoqi@0 | 71 | _handle = JNIHandles::make_global(h); |
aoqi@0 | 72 | } |
aoqi@0 | 73 | _klass = NULL; |
aoqi@0 | 74 | init_flags_from(h()); |
aoqi@0 | 75 | } |
aoqi@0 | 76 | |
aoqi@0 | 77 | // ------------------------------------------------------------------ |
aoqi@0 | 78 | // ciObject::ciObject |
aoqi@0 | 79 | // |
aoqi@0 | 80 | // Unloaded klass/method variant. `klass' is the klass of the unloaded |
aoqi@0 | 81 | // klass/method, if that makes sense. |
aoqi@0 | 82 | ciObject::ciObject(ciKlass* klass) { |
aoqi@0 | 83 | ASSERT_IN_VM; |
aoqi@0 | 84 | assert(klass != NULL, "must supply klass"); |
aoqi@0 | 85 | _handle = NULL; |
aoqi@0 | 86 | _klass = klass; |
aoqi@0 | 87 | } |
aoqi@0 | 88 | |
aoqi@0 | 89 | // ------------------------------------------------------------------ |
aoqi@0 | 90 | // ciObject::ciObject |
aoqi@0 | 91 | // |
aoqi@0 | 92 | // NULL variant. Used only by ciNullObject. |
aoqi@0 | 93 | ciObject::ciObject() { |
aoqi@0 | 94 | ASSERT_IN_VM; |
aoqi@0 | 95 | _handle = NULL; |
aoqi@0 | 96 | _klass = NULL; |
aoqi@0 | 97 | } |
aoqi@0 | 98 | |
aoqi@0 | 99 | // ------------------------------------------------------------------ |
aoqi@0 | 100 | // ciObject::klass |
aoqi@0 | 101 | // |
aoqi@0 | 102 | // Get the ciKlass of this ciObject. |
aoqi@0 | 103 | ciKlass* ciObject::klass() { |
aoqi@0 | 104 | if (_klass == NULL) { |
aoqi@0 | 105 | if (_handle == NULL) { |
aoqi@0 | 106 | // When both _klass and _handle are NULL, we are dealing |
aoqi@0 | 107 | // with the distinguished instance of ciNullObject. |
aoqi@0 | 108 | // No one should ask it for its klass. |
aoqi@0 | 109 | assert(is_null_object(), "must be null object"); |
aoqi@0 | 110 | ShouldNotReachHere(); |
aoqi@0 | 111 | return NULL; |
aoqi@0 | 112 | } |
aoqi@0 | 113 | |
aoqi@0 | 114 | GUARDED_VM_ENTRY( |
aoqi@0 | 115 | oop o = get_oop(); |
aoqi@0 | 116 | _klass = CURRENT_ENV->get_klass(o->klass()); |
aoqi@0 | 117 | ); |
aoqi@0 | 118 | } |
aoqi@0 | 119 | return _klass; |
aoqi@0 | 120 | } |
aoqi@0 | 121 | |
aoqi@0 | 122 | // ------------------------------------------------------------------ |
aoqi@0 | 123 | // ciObject::equals |
aoqi@0 | 124 | // |
aoqi@0 | 125 | // Are two ciObjects equal? |
aoqi@0 | 126 | bool ciObject::equals(ciObject* obj) { |
aoqi@0 | 127 | return (this == obj); |
aoqi@0 | 128 | } |
aoqi@0 | 129 | |
aoqi@0 | 130 | // ------------------------------------------------------------------ |
aoqi@0 | 131 | // ciObject::hash |
aoqi@0 | 132 | // |
aoqi@0 | 133 | // A hash value for the convenience of compilers. |
aoqi@0 | 134 | // |
aoqi@0 | 135 | // Implementation note: we use the address of the ciObject as the |
aoqi@0 | 136 | // basis for the hash. Use the _ident field, which is well-behaved. |
aoqi@0 | 137 | int ciObject::hash() { |
aoqi@0 | 138 | return ident() * 31; |
aoqi@0 | 139 | } |
aoqi@0 | 140 | |
aoqi@0 | 141 | // ------------------------------------------------------------------ |
aoqi@0 | 142 | // ciObject::constant_encoding |
aoqi@0 | 143 | // |
aoqi@0 | 144 | // The address which the compiler should embed into the |
aoqi@0 | 145 | // generated code to represent this oop. This address |
aoqi@0 | 146 | // is not the true address of the oop -- it will get patched |
aoqi@0 | 147 | // during nmethod creation. |
aoqi@0 | 148 | // |
aoqi@0 | 149 | // |
aoqi@0 | 150 | // |
aoqi@0 | 151 | // Implementation note: we use the handle as the encoding. The |
aoqi@0 | 152 | // nmethod constructor resolves the handle and patches in the oop. |
aoqi@0 | 153 | // |
aoqi@0 | 154 | // This method should be changed to return an generified address |
aoqi@0 | 155 | // to discourage use of the JNI handle. |
aoqi@0 | 156 | jobject ciObject::constant_encoding() { |
aoqi@0 | 157 | assert(is_null_object() || handle() != NULL, "cannot embed null pointer"); |
aoqi@0 | 158 | assert(can_be_constant(), "oop must be NULL or perm"); |
aoqi@0 | 159 | return handle(); |
aoqi@0 | 160 | } |
aoqi@0 | 161 | |
aoqi@0 | 162 | // ------------------------------------------------------------------ |
aoqi@0 | 163 | // ciObject::can_be_constant |
aoqi@0 | 164 | bool ciObject::can_be_constant() { |
aoqi@0 | 165 | if (ScavengeRootsInCode >= 1) return true; // now everybody can encode as a constant |
aoqi@0 | 166 | return handle() == NULL; |
aoqi@0 | 167 | } |
aoqi@0 | 168 | |
aoqi@0 | 169 | // ------------------------------------------------------------------ |
aoqi@0 | 170 | // ciObject::should_be_constant() |
aoqi@0 | 171 | bool ciObject::should_be_constant() { |
aoqi@0 | 172 | if (ScavengeRootsInCode >= 2) return true; // force everybody to be a constant |
aoqi@0 | 173 | if (is_null_object()) return true; |
aoqi@0 | 174 | |
aoqi@0 | 175 | ciEnv* env = CURRENT_ENV; |
aoqi@0 | 176 | |
aoqi@0 | 177 | // We want Strings and Classes to be embeddable by default since |
aoqi@0 | 178 | // they used to be in the perm world. Not all Strings used to be |
aoqi@0 | 179 | // embeddable but there's no easy way to distinguish the interned |
aoqi@0 | 180 | // from the regulars ones so just treat them all that way. |
aoqi@0 | 181 | if (klass() == env->String_klass() || klass() == env->Class_klass()) { |
aoqi@0 | 182 | return true; |
aoqi@0 | 183 | } |
aoqi@0 | 184 | if (EnableInvokeDynamic && |
aoqi@0 | 185 | (klass()->is_subclass_of(env->MethodHandle_klass()) || |
aoqi@0 | 186 | klass()->is_subclass_of(env->CallSite_klass()))) { |
aoqi@0 | 187 | assert(ScavengeRootsInCode >= 1, "must be"); |
aoqi@0 | 188 | // We want to treat these aggressively. |
aoqi@0 | 189 | return true; |
aoqi@0 | 190 | } |
aoqi@0 | 191 | |
aoqi@0 | 192 | return handle() == NULL; |
aoqi@0 | 193 | } |
aoqi@0 | 194 | |
aoqi@0 | 195 | // ------------------------------------------------------------------ |
aoqi@0 | 196 | // ciObject::should_be_constant() |
aoqi@0 | 197 | void ciObject::init_flags_from(oop x) { |
aoqi@0 | 198 | int flags = 0; |
aoqi@0 | 199 | if (x != NULL) { |
aoqi@0 | 200 | assert(Universe::heap()->is_in_reserved(x), "must be"); |
aoqi@0 | 201 | if (x->is_scavengable()) |
aoqi@0 | 202 | flags |= SCAVENGABLE_FLAG; |
aoqi@0 | 203 | } |
aoqi@0 | 204 | _ident |= flags; |
aoqi@0 | 205 | } |
aoqi@0 | 206 | |
aoqi@0 | 207 | // ------------------------------------------------------------------ |
aoqi@0 | 208 | // ciObject::print |
aoqi@0 | 209 | // |
aoqi@0 | 210 | // Print debugging output about this ciObject. |
aoqi@0 | 211 | // |
aoqi@0 | 212 | // Implementation note: dispatch to the virtual print_impl behavior |
aoqi@0 | 213 | // for this ciObject. |
aoqi@0 | 214 | void ciObject::print(outputStream* st) { |
aoqi@0 | 215 | st->print("<%s", type_string()); |
aoqi@0 | 216 | GUARDED_VM_ENTRY(print_impl(st);) |
aoqi@0 | 217 | st->print(" ident=%d %s address=" INTPTR_FORMAT ">", ident(), |
aoqi@0 | 218 | is_scavengable() ? "SCAVENGABLE" : "", |
aoqi@0 | 219 | p2i((address)this)); |
aoqi@0 | 220 | } |
aoqi@0 | 221 | |
aoqi@0 | 222 | // ------------------------------------------------------------------ |
aoqi@0 | 223 | // ciObject::print_oop |
aoqi@0 | 224 | // |
aoqi@0 | 225 | // Print debugging output about the oop this ciObject represents. |
aoqi@0 | 226 | void ciObject::print_oop(outputStream* st) { |
aoqi@0 | 227 | if (is_null_object()) { |
aoqi@0 | 228 | st->print_cr("NULL"); |
aoqi@0 | 229 | } else if (!is_loaded()) { |
aoqi@0 | 230 | st->print_cr("UNLOADED"); |
aoqi@0 | 231 | } else { |
aoqi@0 | 232 | GUARDED_VM_ENTRY(get_oop()->print_on(st);) |
aoqi@0 | 233 | } |
aoqi@0 | 234 | } |