src/share/vm/ci/ciObject.cpp

Thu, 28 Apr 2011 14:00:13 -0700

author
never
date
Thu, 28 Apr 2011 14:00:13 -0700
changeset 2815
01fd6090fdd8
parent 2314
f95d63e2154a
child 2933
28a9fe9534ea
permissions
-rw-r--r--

7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
Reviewed-by: kvn

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

mercurial