src/share/vm/ci/ciObject.cpp

Tue, 18 Jun 2013 12:31:07 -0700

author
johnc
date
Tue, 18 Jun 2013 12:31:07 -0700
changeset 5277
01522ca68fc7
parent 4037
da91efe96a93
child 6680
78bbf4d43a14
permissions
-rw-r--r--

8015237: Parallelize string table scanning during strong root processing
Summary: Parallelize the scanning of the intern string table by having each GC worker claim a given number of buckets. Changes were also reviewed by Per Liden <per.liden@oracle.com>.
Reviewed-by: tschatzl, stefank, twisti

duke@435 1 /*
coleenp@4037 2 * Copyright (c) 1999, 2012, 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 --
coleenp@4037 46 // the distinction between `Klass*' 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;
jrose@1424 60 init_flags_from(o);
duke@435 61 }
duke@435 62
duke@435 63 // ------------------------------------------------------------------
duke@435 64 // ciObject::ciObject
duke@435 65 //
duke@435 66 ciObject::ciObject(Handle h) {
duke@435 67 ASSERT_IN_VM;
duke@435 68 if (ciObjectFactory::is_initialized()) {
duke@435 69 _handle = JNIHandles::make_local(h());
duke@435 70 } else {
duke@435 71 _handle = JNIHandles::make_global(h);
duke@435 72 }
duke@435 73 _klass = NULL;
jrose@1424 74 init_flags_from(h());
duke@435 75 }
duke@435 76
duke@435 77 // ------------------------------------------------------------------
duke@435 78 // ciObject::ciObject
duke@435 79 //
duke@435 80 // Unloaded klass/method variant. `klass' is the klass of the unloaded
duke@435 81 // klass/method, if that makes sense.
duke@435 82 ciObject::ciObject(ciKlass* klass) {
duke@435 83 ASSERT_IN_VM;
duke@435 84 assert(klass != NULL, "must supply klass");
duke@435 85 _handle = NULL;
duke@435 86 _klass = klass;
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 }
duke@435 98
duke@435 99 // ------------------------------------------------------------------
duke@435 100 // ciObject::klass
duke@435 101 //
duke@435 102 // Get the ciKlass of this ciObject.
duke@435 103 ciKlass* ciObject::klass() {
duke@435 104 if (_klass == NULL) {
duke@435 105 if (_handle == NULL) {
duke@435 106 // When both _klass and _handle are NULL, we are dealing
duke@435 107 // with the distinguished instance of ciNullObject.
duke@435 108 // No one should ask it for its klass.
duke@435 109 assert(is_null_object(), "must be null object");
duke@435 110 ShouldNotReachHere();
duke@435 111 return NULL;
duke@435 112 }
duke@435 113
duke@435 114 GUARDED_VM_ENTRY(
duke@435 115 oop o = get_oop();
coleenp@4037 116 _klass = CURRENT_ENV->get_klass(o->klass());
duke@435 117 );
duke@435 118 }
duke@435 119 return _klass;
duke@435 120 }
duke@435 121
duke@435 122 // ------------------------------------------------------------------
duke@435 123 // ciObject::equals
duke@435 124 //
duke@435 125 // Are two ciObjects equal?
duke@435 126 bool ciObject::equals(ciObject* obj) {
duke@435 127 return (this == obj);
duke@435 128 }
duke@435 129
duke@435 130 // ------------------------------------------------------------------
duke@435 131 // ciObject::hash
duke@435 132 //
duke@435 133 // A hash value for the convenience of compilers.
duke@435 134 //
duke@435 135 // Implementation note: we use the address of the ciObject as the
duke@435 136 // basis for the hash. Use the _ident field, which is well-behaved.
duke@435 137 int ciObject::hash() {
duke@435 138 return ident() * 31;
duke@435 139 }
duke@435 140
duke@435 141 // ------------------------------------------------------------------
jrose@1424 142 // ciObject::constant_encoding
duke@435 143 //
duke@435 144 // The address which the compiler should embed into the
duke@435 145 // generated code to represent this oop. This address
duke@435 146 // is not the true address of the oop -- it will get patched
duke@435 147 // during nmethod creation.
duke@435 148 //
duke@435 149 //
duke@435 150 //
duke@435 151 // Implementation note: we use the handle as the encoding. The
duke@435 152 // nmethod constructor resolves the handle and patches in the oop.
duke@435 153 //
duke@435 154 // This method should be changed to return an generified address
duke@435 155 // to discourage use of the JNI handle.
jrose@1424 156 jobject ciObject::constant_encoding() {
duke@435 157 assert(is_null_object() || handle() != NULL, "cannot embed null pointer");
jrose@1424 158 assert(can_be_constant(), "oop must be NULL or perm");
duke@435 159 return handle();
duke@435 160 }
duke@435 161
duke@435 162 // ------------------------------------------------------------------
jrose@1424 163 // ciObject::can_be_constant
jrose@1424 164 bool ciObject::can_be_constant() {
jrose@1424 165 if (ScavengeRootsInCode >= 1) return true; // now everybody can encode as a constant
coleenp@4037 166 return handle() == NULL;
jrose@1424 167 }
jrose@1424 168
jrose@1424 169 // ------------------------------------------------------------------
jrose@1424 170 // ciObject::should_be_constant()
jrose@1424 171 bool ciObject::should_be_constant() {
jrose@1424 172 if (ScavengeRootsInCode >= 2) return true; // force everybody to be a constant
never@3105 173 if (is_null_object()) return true;
never@3105 174
never@3105 175 ciEnv* env = CURRENT_ENV;
coleenp@4037 176
never@2815 177 // We want Strings and Classes to be embeddable by default since
never@2815 178 // they used to be in the perm world. Not all Strings used to be
never@2815 179 // embeddable but there's no easy way to distinguish the interned
never@2815 180 // from the regulars ones so just treat them all that way.
never@2815 181 if (klass() == env->String_klass() || klass() == env->Class_klass()) {
never@2815 182 return true;
never@2815 183 }
never@3105 184 if (EnableInvokeDynamic &&
never@3105 185 (klass()->is_subclass_of(env->MethodHandle_klass()) ||
never@3105 186 klass()->is_subclass_of(env->CallSite_klass()))) {
never@3105 187 assert(ScavengeRootsInCode >= 1, "must be");
never@3105 188 // We want to treat these aggressively.
never@3105 189 return true;
never@3105 190 }
never@3105 191
coleenp@4037 192 return handle() == NULL;
duke@435 193 }
duke@435 194
coleenp@4037 195 // ------------------------------------------------------------------
coleenp@4037 196 // ciObject::should_be_constant()
coleenp@4037 197 void ciObject::init_flags_from(oop x) {
coleenp@4037 198 int flags = 0;
coleenp@4037 199 if (x != NULL) {
coleenp@4037 200 assert(Universe::heap()->is_in_reserved(x), "must be");
coleenp@4037 201 if (x->is_scavengable())
coleenp@4037 202 flags |= SCAVENGABLE_FLAG;
coleenp@4037 203 }
coleenp@4037 204 _ident |= flags;
coleenp@4037 205 }
duke@435 206
duke@435 207 // ------------------------------------------------------------------
duke@435 208 // ciObject::print
duke@435 209 //
duke@435 210 // Print debugging output about this ciObject.
duke@435 211 //
duke@435 212 // Implementation note: dispatch to the virtual print_impl behavior
duke@435 213 // for this ciObject.
duke@435 214 void ciObject::print(outputStream* st) {
duke@435 215 st->print("<%s", type_string());
duke@435 216 GUARDED_VM_ENTRY(print_impl(st);)
coleenp@4037 217 st->print(" ident=%d %s address=0x%x>", ident(),
jrose@1424 218 is_scavengable() ? "SCAVENGABLE" : "",
duke@435 219 (address)this);
duke@435 220 }
duke@435 221
duke@435 222 // ------------------------------------------------------------------
duke@435 223 // ciObject::print_oop
duke@435 224 //
duke@435 225 // Print debugging output about the oop this ciObject represents.
duke@435 226 void ciObject::print_oop(outputStream* st) {
duke@435 227 if (is_null_object()) {
duke@435 228 st->print_cr("NULL");
duke@435 229 } else if (!is_loaded()) {
duke@435 230 st->print_cr("UNLOADED");
duke@435 231 } else {
duke@435 232 GUARDED_VM_ENTRY(get_oop()->print_on(st);)
duke@435 233 }
duke@435 234 }

mercurial