src/share/vm/ci/ciObject.cpp

Tue, 15 Sep 2009 21:53:47 -0700

author
jrose
date
Tue, 15 Sep 2009 21:53:47 -0700
changeset 1424
148e5441d916
parent 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6863023: need non-perm oops in code cache for JSR 292
Summary: Make a special root-list for those few nmethods which might contain non-perm oops.
Reviewed-by: twisti, kvn, never, jmasa, ysr

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

mercurial