Wed, 03 Jul 2019 20:42:37 +0800
Merge
aoqi@0 | 1 | /* |
zgu@7074 | 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/ciCallSite.hpp" |
aoqi@0 | 27 | #include "ci/ciInstance.hpp" |
aoqi@0 | 28 | #include "ci/ciInstanceKlass.hpp" |
aoqi@0 | 29 | #include "ci/ciMemberName.hpp" |
aoqi@0 | 30 | #include "ci/ciMethod.hpp" |
aoqi@0 | 31 | #include "ci/ciMethodData.hpp" |
aoqi@0 | 32 | #include "ci/ciMethodHandle.hpp" |
aoqi@0 | 33 | #include "ci/ciMethodType.hpp" |
aoqi@0 | 34 | #include "ci/ciNullObject.hpp" |
aoqi@0 | 35 | #include "ci/ciObjArray.hpp" |
aoqi@0 | 36 | #include "ci/ciObjArrayKlass.hpp" |
aoqi@0 | 37 | #include "ci/ciObject.hpp" |
aoqi@0 | 38 | #include "ci/ciObjectFactory.hpp" |
aoqi@0 | 39 | #include "ci/ciSymbol.hpp" |
aoqi@0 | 40 | #include "ci/ciTypeArray.hpp" |
aoqi@0 | 41 | #include "ci/ciTypeArrayKlass.hpp" |
aoqi@0 | 42 | #include "ci/ciUtilities.hpp" |
aoqi@0 | 43 | #include "classfile/systemDictionary.hpp" |
aoqi@0 | 44 | #include "gc_interface/collectedHeap.inline.hpp" |
aoqi@0 | 45 | #include "memory/allocation.inline.hpp" |
aoqi@0 | 46 | #include "oops/oop.inline.hpp" |
aoqi@0 | 47 | #include "oops/oop.inline2.hpp" |
aoqi@0 | 48 | #include "runtime/fieldType.hpp" |
stefank@6992 | 49 | #if INCLUDE_ALL_GCS |
stefank@6992 | 50 | # include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" |
stefank@6992 | 51 | #endif |
aoqi@0 | 52 | |
aoqi@0 | 53 | // ciObjectFactory |
aoqi@0 | 54 | // |
aoqi@0 | 55 | // This class handles requests for the creation of new instances |
aoqi@0 | 56 | // of ciObject and its subclasses. It contains a caching mechanism |
aoqi@0 | 57 | // which ensures that for each oop, at most one ciObject is created. |
aoqi@0 | 58 | // This invariant allows more efficient implementation of ciObject. |
aoqi@0 | 59 | // |
aoqi@0 | 60 | // Implementation note: the oop->ciObject mapping is represented as |
aoqi@0 | 61 | // a table stored in an array. Even though objects are moved |
aoqi@0 | 62 | // by the garbage collector, the compactor preserves their relative |
aoqi@0 | 63 | // order; address comparison of oops (in perm space) is safe so long |
aoqi@0 | 64 | // as we prohibit GC during our comparisons. We currently use binary |
aoqi@0 | 65 | // search to find the oop in the table, and inserting a new oop |
aoqi@0 | 66 | // into the table may be costly. If this cost ends up being |
aoqi@0 | 67 | // problematic the underlying data structure can be switched to some |
aoqi@0 | 68 | // sort of balanced binary tree. |
aoqi@0 | 69 | |
aoqi@0 | 70 | GrowableArray<ciMetadata*>* ciObjectFactory::_shared_ci_metadata = NULL; |
aoqi@0 | 71 | ciSymbol* ciObjectFactory::_shared_ci_symbols[vmSymbols::SID_LIMIT]; |
aoqi@0 | 72 | int ciObjectFactory::_shared_ident_limit = 0; |
aoqi@0 | 73 | volatile bool ciObjectFactory::_initialized = false; |
aoqi@0 | 74 | |
aoqi@0 | 75 | |
aoqi@0 | 76 | // ------------------------------------------------------------------ |
aoqi@0 | 77 | // ciObjectFactory::ciObjectFactory |
aoqi@0 | 78 | ciObjectFactory::ciObjectFactory(Arena* arena, |
aoqi@0 | 79 | int expected_size) { |
aoqi@0 | 80 | |
aoqi@0 | 81 | for (int i = 0; i < NON_PERM_BUCKETS; i++) { |
aoqi@0 | 82 | _non_perm_bucket[i] = NULL; |
aoqi@0 | 83 | } |
aoqi@0 | 84 | _non_perm_count = 0; |
aoqi@0 | 85 | |
aoqi@0 | 86 | _next_ident = _shared_ident_limit; |
aoqi@0 | 87 | _arena = arena; |
aoqi@0 | 88 | _ci_metadata = new (arena) GrowableArray<ciMetadata*>(arena, expected_size, 0, NULL); |
aoqi@0 | 89 | |
aoqi@0 | 90 | // If the shared ci objects exist append them to this factory's objects |
aoqi@0 | 91 | |
aoqi@0 | 92 | if (_shared_ci_metadata != NULL) { |
aoqi@0 | 93 | _ci_metadata->appendAll(_shared_ci_metadata); |
aoqi@0 | 94 | } |
aoqi@0 | 95 | |
aoqi@0 | 96 | _unloaded_methods = new (arena) GrowableArray<ciMethod*>(arena, 4, 0, NULL); |
aoqi@0 | 97 | _unloaded_klasses = new (arena) GrowableArray<ciKlass*>(arena, 8, 0, NULL); |
aoqi@0 | 98 | _unloaded_instances = new (arena) GrowableArray<ciInstance*>(arena, 4, 0, NULL); |
aoqi@0 | 99 | _return_addresses = |
aoqi@0 | 100 | new (arena) GrowableArray<ciReturnAddress*>(arena, 8, 0, NULL); |
aoqi@0 | 101 | |
aoqi@0 | 102 | _symbols = new (arena) GrowableArray<ciSymbol*>(arena, 100, 0, NULL); |
aoqi@0 | 103 | } |
aoqi@0 | 104 | |
aoqi@0 | 105 | // ------------------------------------------------------------------ |
aoqi@0 | 106 | // ciObjectFactory::ciObjectFactory |
aoqi@0 | 107 | void ciObjectFactory::initialize() { |
aoqi@0 | 108 | ASSERT_IN_VM; |
aoqi@0 | 109 | JavaThread* thread = JavaThread::current(); |
aoqi@0 | 110 | HandleMark handle_mark(thread); |
aoqi@0 | 111 | |
aoqi@0 | 112 | // This Arena is long lived and exists in the resource mark of the |
aoqi@0 | 113 | // compiler thread that initializes the initial ciObjectFactory which |
aoqi@0 | 114 | // creates the shared ciObjects that all later ciObjectFactories use. |
zgu@7074 | 115 | Arena* arena = new (mtCompiler) Arena(mtCompiler); |
aoqi@0 | 116 | ciEnv initial(arena); |
aoqi@0 | 117 | ciEnv* env = ciEnv::current(); |
aoqi@0 | 118 | env->_factory->init_shared_objects(); |
aoqi@0 | 119 | |
aoqi@0 | 120 | _initialized = true; |
aoqi@0 | 121 | |
aoqi@0 | 122 | } |
aoqi@0 | 123 | |
aoqi@0 | 124 | void ciObjectFactory::init_shared_objects() { |
aoqi@0 | 125 | |
aoqi@0 | 126 | _next_ident = 1; // start numbering CI objects at 1 |
aoqi@0 | 127 | |
aoqi@0 | 128 | { |
aoqi@0 | 129 | // Create the shared symbols, but not in _shared_ci_metadata. |
aoqi@0 | 130 | int i; |
aoqi@0 | 131 | for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) { |
aoqi@0 | 132 | Symbol* vmsym = vmSymbols::symbol_at((vmSymbols::SID) i); |
aoqi@0 | 133 | assert(vmSymbols::find_sid(vmsym) == i, "1-1 mapping"); |
aoqi@0 | 134 | ciSymbol* sym = new (_arena) ciSymbol(vmsym, (vmSymbols::SID) i); |
aoqi@0 | 135 | init_ident_of(sym); |
aoqi@0 | 136 | _shared_ci_symbols[i] = sym; |
aoqi@0 | 137 | } |
aoqi@0 | 138 | #ifdef ASSERT |
aoqi@0 | 139 | for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) { |
aoqi@0 | 140 | Symbol* vmsym = vmSymbols::symbol_at((vmSymbols::SID) i); |
aoqi@0 | 141 | ciSymbol* sym = vm_symbol_at((vmSymbols::SID) i); |
aoqi@0 | 142 | assert(sym->get_symbol() == vmsym, "oop must match"); |
aoqi@0 | 143 | } |
aoqi@0 | 144 | assert(ciSymbol::void_class_signature()->get_symbol() == vmSymbols::void_class_signature(), "spot check"); |
aoqi@0 | 145 | #endif |
aoqi@0 | 146 | } |
aoqi@0 | 147 | |
aoqi@0 | 148 | _ci_metadata = new (_arena) GrowableArray<ciMetadata*>(_arena, 64, 0, NULL); |
aoqi@0 | 149 | |
aoqi@0 | 150 | for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) { |
aoqi@0 | 151 | BasicType t = (BasicType)i; |
aoqi@0 | 152 | if (type2name(t) != NULL && t != T_OBJECT && t != T_ARRAY && t != T_NARROWOOP && t != T_NARROWKLASS) { |
aoqi@0 | 153 | ciType::_basic_types[t] = new (_arena) ciType(t); |
aoqi@0 | 154 | init_ident_of(ciType::_basic_types[t]); |
aoqi@0 | 155 | } |
aoqi@0 | 156 | } |
aoqi@0 | 157 | |
aoqi@0 | 158 | ciEnv::_null_object_instance = new (_arena) ciNullObject(); |
aoqi@0 | 159 | init_ident_of(ciEnv::_null_object_instance); |
aoqi@0 | 160 | |
aoqi@0 | 161 | #define WK_KLASS_DEFN(name, ignore_s, opt) \ |
aoqi@0 | 162 | if (SystemDictionary::name() != NULL) \ |
aoqi@0 | 163 | ciEnv::_##name = get_metadata(SystemDictionary::name())->as_instance_klass(); |
aoqi@0 | 164 | |
aoqi@0 | 165 | WK_KLASSES_DO(WK_KLASS_DEFN) |
aoqi@0 | 166 | #undef WK_KLASS_DEFN |
aoqi@0 | 167 | |
aoqi@0 | 168 | for (int len = -1; len != _ci_metadata->length(); ) { |
aoqi@0 | 169 | len = _ci_metadata->length(); |
aoqi@0 | 170 | for (int i2 = 0; i2 < len; i2++) { |
aoqi@0 | 171 | ciMetadata* obj = _ci_metadata->at(i2); |
aoqi@0 | 172 | assert (obj->is_metadata(), "what else would it be?"); |
aoqi@0 | 173 | if (obj->is_loaded() && obj->is_instance_klass()) { |
aoqi@0 | 174 | obj->as_instance_klass()->compute_nonstatic_fields(); |
aoqi@0 | 175 | } |
aoqi@0 | 176 | } |
aoqi@0 | 177 | } |
aoqi@0 | 178 | |
aoqi@0 | 179 | ciEnv::_unloaded_cisymbol = ciObjectFactory::get_symbol(vmSymbols::dummy_symbol()); |
aoqi@0 | 180 | // Create dummy InstanceKlass and ObjArrayKlass object and assign them idents |
aoqi@0 | 181 | ciEnv::_unloaded_ciinstance_klass = new (_arena) ciInstanceKlass(ciEnv::_unloaded_cisymbol, NULL, NULL); |
aoqi@0 | 182 | init_ident_of(ciEnv::_unloaded_ciinstance_klass); |
aoqi@0 | 183 | ciEnv::_unloaded_ciobjarrayklass = new (_arena) ciObjArrayKlass(ciEnv::_unloaded_cisymbol, ciEnv::_unloaded_ciinstance_klass, 1); |
aoqi@0 | 184 | init_ident_of(ciEnv::_unloaded_ciobjarrayklass); |
aoqi@0 | 185 | assert(ciEnv::_unloaded_ciobjarrayklass->is_obj_array_klass(), "just checking"); |
aoqi@0 | 186 | |
aoqi@0 | 187 | get_metadata(Universe::boolArrayKlassObj()); |
aoqi@0 | 188 | get_metadata(Universe::charArrayKlassObj()); |
aoqi@0 | 189 | get_metadata(Universe::singleArrayKlassObj()); |
aoqi@0 | 190 | get_metadata(Universe::doubleArrayKlassObj()); |
aoqi@0 | 191 | get_metadata(Universe::byteArrayKlassObj()); |
aoqi@0 | 192 | get_metadata(Universe::shortArrayKlassObj()); |
aoqi@0 | 193 | get_metadata(Universe::intArrayKlassObj()); |
aoqi@0 | 194 | get_metadata(Universe::longArrayKlassObj()); |
aoqi@0 | 195 | |
aoqi@0 | 196 | |
aoqi@0 | 197 | |
aoqi@0 | 198 | assert(_non_perm_count == 0, "no shared non-perm objects"); |
aoqi@0 | 199 | |
aoqi@0 | 200 | // The shared_ident_limit is the first ident number that will |
aoqi@0 | 201 | // be used for non-shared objects. That is, numbers less than |
aoqi@0 | 202 | // this limit are permanently assigned to shared CI objects, |
aoqi@0 | 203 | // while the higher numbers are recycled afresh by each new ciEnv. |
aoqi@0 | 204 | |
aoqi@0 | 205 | _shared_ident_limit = _next_ident; |
aoqi@0 | 206 | _shared_ci_metadata = _ci_metadata; |
aoqi@0 | 207 | } |
aoqi@0 | 208 | |
aoqi@0 | 209 | |
aoqi@0 | 210 | ciSymbol* ciObjectFactory::get_symbol(Symbol* key) { |
aoqi@0 | 211 | vmSymbols::SID sid = vmSymbols::find_sid(key); |
aoqi@0 | 212 | if (sid != vmSymbols::NO_SID) { |
aoqi@0 | 213 | // do not pollute the main cache with it |
aoqi@0 | 214 | return vm_symbol_at(sid); |
aoqi@0 | 215 | } |
aoqi@0 | 216 | |
aoqi@0 | 217 | assert(vmSymbols::find_sid(key) == vmSymbols::NO_SID, ""); |
aoqi@0 | 218 | ciSymbol* s = new (arena()) ciSymbol(key, vmSymbols::NO_SID); |
aoqi@0 | 219 | _symbols->push(s); |
aoqi@0 | 220 | return s; |
aoqi@0 | 221 | } |
aoqi@0 | 222 | |
aoqi@0 | 223 | // Decrement the refcount when done on symbols referenced by this compilation. |
aoqi@0 | 224 | void ciObjectFactory::remove_symbols() { |
aoqi@0 | 225 | for (int i = 0; i < _symbols->length(); i++) { |
aoqi@0 | 226 | ciSymbol* s = _symbols->at(i); |
aoqi@0 | 227 | s->get_symbol()->decrement_refcount(); |
aoqi@0 | 228 | } |
aoqi@0 | 229 | // Since _symbols is resource allocated we're not allowed to delete it |
aoqi@0 | 230 | // but it'll go away just the same. |
aoqi@0 | 231 | } |
aoqi@0 | 232 | |
aoqi@0 | 233 | // ------------------------------------------------------------------ |
aoqi@0 | 234 | // ciObjectFactory::get |
aoqi@0 | 235 | // |
aoqi@0 | 236 | // Get the ciObject corresponding to some oop. If the ciObject has |
aoqi@0 | 237 | // already been created, it is returned. Otherwise, a new ciObject |
aoqi@0 | 238 | // is created. |
aoqi@0 | 239 | ciObject* ciObjectFactory::get(oop key) { |
aoqi@0 | 240 | ASSERT_IN_VM; |
aoqi@0 | 241 | |
vlivanov@7384 | 242 | assert(Universe::heap()->is_in_reserved(key), "must be"); |
aoqi@0 | 243 | |
aoqi@0 | 244 | NonPermObject* &bucket = find_non_perm(key); |
aoqi@0 | 245 | if (bucket != NULL) { |
aoqi@0 | 246 | return bucket->object(); |
aoqi@0 | 247 | } |
aoqi@0 | 248 | |
aoqi@0 | 249 | // The ciObject does not yet exist. Create it and insert it |
aoqi@0 | 250 | // into the cache. |
aoqi@0 | 251 | Handle keyHandle(key); |
aoqi@0 | 252 | ciObject* new_object = create_new_object(keyHandle()); |
aoqi@0 | 253 | assert(keyHandle() == new_object->get_oop(), "must be properly recorded"); |
aoqi@0 | 254 | init_ident_of(new_object); |
aoqi@0 | 255 | assert(Universe::heap()->is_in_reserved(new_object->get_oop()), "must be"); |
aoqi@0 | 256 | |
aoqi@0 | 257 | // Not a perm-space object. |
aoqi@0 | 258 | insert_non_perm(bucket, keyHandle(), new_object); |
aoqi@0 | 259 | return new_object; |
aoqi@0 | 260 | } |
aoqi@0 | 261 | |
aoqi@0 | 262 | // ------------------------------------------------------------------ |
vlivanov@7384 | 263 | // ciObjectFactory::get_metadata |
aoqi@0 | 264 | // |
vlivanov@7384 | 265 | // Get the ciMetadata corresponding to some Metadata. If the ciMetadata has |
vlivanov@7384 | 266 | // already been created, it is returned. Otherwise, a new ciMetadata |
aoqi@0 | 267 | // is created. |
aoqi@0 | 268 | ciMetadata* ciObjectFactory::get_metadata(Metadata* key) { |
aoqi@0 | 269 | ASSERT_IN_VM; |
aoqi@0 | 270 | |
aoqi@0 | 271 | #ifdef ASSERT |
aoqi@0 | 272 | if (CIObjectFactoryVerify) { |
aoqi@0 | 273 | Metadata* last = NULL; |
aoqi@0 | 274 | for (int j = 0; j< _ci_metadata->length(); j++) { |
aoqi@0 | 275 | Metadata* o = _ci_metadata->at(j)->constant_encoding(); |
aoqi@0 | 276 | assert(last < o, "out of order"); |
aoqi@0 | 277 | last = o; |
aoqi@0 | 278 | } |
aoqi@0 | 279 | } |
aoqi@0 | 280 | #endif // ASSERT |
aoqi@0 | 281 | int len = _ci_metadata->length(); |
aoqi@0 | 282 | int index = find(key, _ci_metadata); |
aoqi@0 | 283 | #ifdef ASSERT |
aoqi@0 | 284 | if (CIObjectFactoryVerify) { |
aoqi@0 | 285 | for (int i=0; i<_ci_metadata->length(); i++) { |
aoqi@0 | 286 | if (_ci_metadata->at(i)->constant_encoding() == key) { |
aoqi@0 | 287 | assert(index == i, " bad lookup"); |
aoqi@0 | 288 | } |
aoqi@0 | 289 | } |
aoqi@0 | 290 | } |
aoqi@0 | 291 | #endif |
aoqi@0 | 292 | if (!is_found_at(index, key, _ci_metadata)) { |
vlivanov@7384 | 293 | // The ciMetadata does not yet exist. Create it and insert it |
aoqi@0 | 294 | // into the cache. |
vlivanov@7384 | 295 | ciMetadata* new_object = create_new_metadata(key); |
aoqi@0 | 296 | init_ident_of(new_object); |
aoqi@0 | 297 | assert(new_object->is_metadata(), "must be"); |
aoqi@0 | 298 | |
aoqi@0 | 299 | if (len != _ci_metadata->length()) { |
aoqi@0 | 300 | // creating the new object has recursively entered new objects |
aoqi@0 | 301 | // into the table. We need to recompute our index. |
aoqi@0 | 302 | index = find(key, _ci_metadata); |
aoqi@0 | 303 | } |
aoqi@0 | 304 | assert(!is_found_at(index, key, _ci_metadata), "no double insert"); |
aoqi@0 | 305 | insert(index, new_object, _ci_metadata); |
aoqi@0 | 306 | return new_object; |
aoqi@0 | 307 | } |
aoqi@0 | 308 | return _ci_metadata->at(index)->as_metadata(); |
aoqi@0 | 309 | } |
aoqi@0 | 310 | |
aoqi@0 | 311 | // ------------------------------------------------------------------ |
aoqi@0 | 312 | // ciObjectFactory::create_new_object |
aoqi@0 | 313 | // |
aoqi@0 | 314 | // Create a new ciObject from an oop. |
aoqi@0 | 315 | // |
aoqi@0 | 316 | // Implementation note: this functionality could be virtual behavior |
aoqi@0 | 317 | // of the oop itself. For now, we explicitly marshal the object. |
aoqi@0 | 318 | ciObject* ciObjectFactory::create_new_object(oop o) { |
aoqi@0 | 319 | EXCEPTION_CONTEXT; |
aoqi@0 | 320 | |
aoqi@0 | 321 | if (o->is_instance()) { |
aoqi@0 | 322 | instanceHandle h_i(THREAD, (instanceOop)o); |
aoqi@0 | 323 | if (java_lang_invoke_CallSite::is_instance(o)) |
aoqi@0 | 324 | return new (arena()) ciCallSite(h_i); |
aoqi@0 | 325 | else if (java_lang_invoke_MemberName::is_instance(o)) |
aoqi@0 | 326 | return new (arena()) ciMemberName(h_i); |
aoqi@0 | 327 | else if (java_lang_invoke_MethodHandle::is_instance(o)) |
aoqi@0 | 328 | return new (arena()) ciMethodHandle(h_i); |
aoqi@0 | 329 | else if (java_lang_invoke_MethodType::is_instance(o)) |
aoqi@0 | 330 | return new (arena()) ciMethodType(h_i); |
aoqi@0 | 331 | else |
aoqi@0 | 332 | return new (arena()) ciInstance(h_i); |
aoqi@0 | 333 | } else if (o->is_objArray()) { |
aoqi@0 | 334 | objArrayHandle h_oa(THREAD, (objArrayOop)o); |
aoqi@0 | 335 | return new (arena()) ciObjArray(h_oa); |
aoqi@0 | 336 | } else if (o->is_typeArray()) { |
aoqi@0 | 337 | typeArrayHandle h_ta(THREAD, (typeArrayOop)o); |
aoqi@0 | 338 | return new (arena()) ciTypeArray(h_ta); |
aoqi@0 | 339 | } |
aoqi@0 | 340 | |
aoqi@0 | 341 | // The oop is of some type not supported by the compiler interface. |
aoqi@0 | 342 | ShouldNotReachHere(); |
aoqi@0 | 343 | return NULL; |
aoqi@0 | 344 | } |
aoqi@0 | 345 | |
aoqi@0 | 346 | // ------------------------------------------------------------------ |
vlivanov@7384 | 347 | // ciObjectFactory::create_new_metadata |
aoqi@0 | 348 | // |
vlivanov@7384 | 349 | // Create a new ciMetadata from a Metadata*. |
aoqi@0 | 350 | // |
vlivanov@7384 | 351 | // Implementation note: in order to keep Metadata live, an auxiliary ciObject |
vlivanov@7384 | 352 | // is used, which points to it's holder. |
vlivanov@7384 | 353 | ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) { |
aoqi@0 | 354 | EXCEPTION_CONTEXT; |
aoqi@0 | 355 | |
vlivanov@7384 | 356 | // Hold metadata from unloading by keeping it's holder alive. |
vlivanov@7384 | 357 | if (_initialized && o->is_klass()) { |
vlivanov@7384 | 358 | Klass* holder = ((Klass*)o); |
vlivanov@7384 | 359 | if (holder->oop_is_instance() && InstanceKlass::cast(holder)->is_anonymous()) { |
vlivanov@7384 | 360 | // Though ciInstanceKlass records class loader oop, it's not enough to keep |
vlivanov@7384 | 361 | // VM anonymous classes alive (loader == NULL). Klass holder should be used instead. |
vlivanov@7384 | 362 | // It is enough to record a ciObject, since cached elements are never removed |
vlivanov@7384 | 363 | // during ciObjectFactory lifetime. ciObjectFactory itself is created for |
vlivanov@7384 | 364 | // every compilation and lives for the whole duration of the compilation. |
vlivanov@7384 | 365 | ciObject* h = get(holder->klass_holder()); |
vlivanov@7384 | 366 | } |
vlivanov@7384 | 367 | } |
vlivanov@7384 | 368 | |
aoqi@0 | 369 | if (o->is_klass()) { |
aoqi@0 | 370 | KlassHandle h_k(THREAD, (Klass*)o); |
aoqi@0 | 371 | Klass* k = (Klass*)o; |
aoqi@0 | 372 | if (k->oop_is_instance()) { |
aoqi@0 | 373 | return new (arena()) ciInstanceKlass(h_k); |
aoqi@0 | 374 | } else if (k->oop_is_objArray()) { |
aoqi@0 | 375 | return new (arena()) ciObjArrayKlass(h_k); |
aoqi@0 | 376 | } else if (k->oop_is_typeArray()) { |
aoqi@0 | 377 | return new (arena()) ciTypeArrayKlass(h_k); |
aoqi@0 | 378 | } |
aoqi@0 | 379 | } else if (o->is_method()) { |
aoqi@0 | 380 | methodHandle h_m(THREAD, (Method*)o); |
vlivanov@7384 | 381 | ciEnv *env = CURRENT_THREAD_ENV; |
vlivanov@7384 | 382 | ciInstanceKlass* holder = env->get_instance_klass(h_m()->method_holder()); |
vlivanov@7384 | 383 | return new (arena()) ciMethod(h_m, holder); |
aoqi@0 | 384 | } else if (o->is_methodData()) { |
aoqi@0 | 385 | // Hold methodHandle alive - might not be necessary ??? |
aoqi@0 | 386 | methodHandle h_m(THREAD, ((MethodData*)o)->method()); |
aoqi@0 | 387 | return new (arena()) ciMethodData((MethodData*)o); |
aoqi@0 | 388 | } |
aoqi@0 | 389 | |
vlivanov@7384 | 390 | // The Metadata* is of some type not supported by the compiler interface. |
aoqi@0 | 391 | ShouldNotReachHere(); |
aoqi@0 | 392 | return NULL; |
aoqi@0 | 393 | } |
aoqi@0 | 394 | |
stefank@6992 | 395 | // ------------------------------------------------------------------ |
stefank@6992 | 396 | // ciObjectFactory::ensure_metadata_alive |
stefank@6992 | 397 | // |
stefank@6992 | 398 | // Ensure that the metadata wrapped by the ciMetadata is kept alive by GC. |
stefank@6992 | 399 | // This is primarily useful for metadata which is considered as weak roots |
stefank@6992 | 400 | // by the GC but need to be strong roots if reachable from a current compilation. |
stefank@6992 | 401 | // |
stefank@6992 | 402 | void ciObjectFactory::ensure_metadata_alive(ciMetadata* m) { |
stefank@6992 | 403 | ASSERT_IN_VM; // We're handling raw oops here. |
stefank@6992 | 404 | |
stefank@6992 | 405 | #if INCLUDE_ALL_GCS |
stefank@6992 | 406 | if (!UseG1GC) { |
stefank@6992 | 407 | return; |
stefank@6992 | 408 | } |
stefank@6992 | 409 | Klass* metadata_owner_klass; |
stefank@6992 | 410 | if (m->is_klass()) { |
stefank@6992 | 411 | metadata_owner_klass = m->as_klass()->get_Klass(); |
stefank@6992 | 412 | } else if (m->is_method()) { |
stefank@6992 | 413 | metadata_owner_klass = m->as_method()->get_Method()->constants()->pool_holder(); |
stefank@6992 | 414 | } else { |
stefank@6992 | 415 | fatal("Not implemented for other types of metadata"); |
csahu@8316 | 416 | return; |
stefank@6992 | 417 | } |
stefank@6992 | 418 | |
stefank@6992 | 419 | oop metadata_holder = metadata_owner_klass->klass_holder(); |
stefank@6992 | 420 | if (metadata_holder != NULL) { |
stefank@6992 | 421 | G1SATBCardTableModRefBS::enqueue(metadata_holder); |
stefank@6992 | 422 | } |
stefank@6992 | 423 | |
stefank@6992 | 424 | #endif |
stefank@6992 | 425 | } |
stefank@6992 | 426 | |
aoqi@0 | 427 | //------------------------------------------------------------------ |
aoqi@0 | 428 | // ciObjectFactory::get_unloaded_method |
aoqi@0 | 429 | // |
aoqi@0 | 430 | // Get the ciMethod representing an unloaded/unfound method. |
aoqi@0 | 431 | // |
aoqi@0 | 432 | // Implementation note: unloaded methods are currently stored in |
aoqi@0 | 433 | // an unordered array, requiring a linear-time lookup for each |
aoqi@0 | 434 | // unloaded method. This may need to change. |
aoqi@0 | 435 | ciMethod* ciObjectFactory::get_unloaded_method(ciInstanceKlass* holder, |
aoqi@0 | 436 | ciSymbol* name, |
aoqi@0 | 437 | ciSymbol* signature, |
aoqi@0 | 438 | ciInstanceKlass* accessor) { |
aoqi@0 | 439 | ciSignature* that = NULL; |
aoqi@0 | 440 | for (int i = 0; i < _unloaded_methods->length(); i++) { |
aoqi@0 | 441 | ciMethod* entry = _unloaded_methods->at(i); |
aoqi@0 | 442 | if (entry->holder()->equals(holder) && |
aoqi@0 | 443 | entry->name()->equals(name) && |
aoqi@0 | 444 | entry->signature()->as_symbol()->equals(signature)) { |
aoqi@0 | 445 | // Short-circuit slow resolve. |
aoqi@0 | 446 | if (entry->signature()->accessing_klass() == accessor) { |
aoqi@0 | 447 | // We've found a match. |
aoqi@0 | 448 | return entry; |
aoqi@0 | 449 | } else { |
aoqi@0 | 450 | // Lazily create ciSignature |
aoqi@0 | 451 | if (that == NULL) that = new (arena()) ciSignature(accessor, constantPoolHandle(), signature); |
aoqi@0 | 452 | if (entry->signature()->equals(that)) { |
aoqi@0 | 453 | // We've found a match. |
aoqi@0 | 454 | return entry; |
aoqi@0 | 455 | } |
aoqi@0 | 456 | } |
aoqi@0 | 457 | } |
aoqi@0 | 458 | } |
aoqi@0 | 459 | |
aoqi@0 | 460 | // This is a new unloaded method. Create it and stick it in |
aoqi@0 | 461 | // the cache. |
aoqi@0 | 462 | ciMethod* new_method = new (arena()) ciMethod(holder, name, signature, accessor); |
aoqi@0 | 463 | |
aoqi@0 | 464 | init_ident_of(new_method); |
aoqi@0 | 465 | _unloaded_methods->append(new_method); |
aoqi@0 | 466 | |
aoqi@0 | 467 | return new_method; |
aoqi@0 | 468 | } |
aoqi@0 | 469 | |
aoqi@0 | 470 | //------------------------------------------------------------------ |
aoqi@0 | 471 | // ciObjectFactory::get_unloaded_klass |
aoqi@0 | 472 | // |
aoqi@0 | 473 | // Get a ciKlass representing an unloaded klass. |
aoqi@0 | 474 | // |
aoqi@0 | 475 | // Implementation note: unloaded klasses are currently stored in |
aoqi@0 | 476 | // an unordered array, requiring a linear-time lookup for each |
aoqi@0 | 477 | // unloaded klass. This may need to change. |
aoqi@0 | 478 | ciKlass* ciObjectFactory::get_unloaded_klass(ciKlass* accessing_klass, |
aoqi@0 | 479 | ciSymbol* name, |
aoqi@0 | 480 | bool create_if_not_found) { |
aoqi@0 | 481 | EXCEPTION_CONTEXT; |
aoqi@0 | 482 | oop loader = NULL; |
aoqi@0 | 483 | oop domain = NULL; |
aoqi@0 | 484 | if (accessing_klass != NULL) { |
aoqi@0 | 485 | loader = accessing_klass->loader(); |
aoqi@0 | 486 | domain = accessing_klass->protection_domain(); |
aoqi@0 | 487 | } |
aoqi@0 | 488 | for (int i=0; i<_unloaded_klasses->length(); i++) { |
aoqi@0 | 489 | ciKlass* entry = _unloaded_klasses->at(i); |
aoqi@0 | 490 | if (entry->name()->equals(name) && |
aoqi@0 | 491 | entry->loader() == loader && |
aoqi@0 | 492 | entry->protection_domain() == domain) { |
aoqi@0 | 493 | // We've found a match. |
aoqi@0 | 494 | return entry; |
aoqi@0 | 495 | } |
aoqi@0 | 496 | } |
aoqi@0 | 497 | |
aoqi@0 | 498 | if (!create_if_not_found) |
aoqi@0 | 499 | return NULL; |
aoqi@0 | 500 | |
aoqi@0 | 501 | // This is a new unloaded klass. Create it and stick it in |
aoqi@0 | 502 | // the cache. |
aoqi@0 | 503 | ciKlass* new_klass = NULL; |
aoqi@0 | 504 | |
aoqi@0 | 505 | // Two cases: this is an unloaded ObjArrayKlass or an |
aoqi@0 | 506 | // unloaded InstanceKlass. Deal with both. |
aoqi@0 | 507 | if (name->byte_at(0) == '[') { |
aoqi@0 | 508 | // Decompose the name.' |
aoqi@0 | 509 | FieldArrayInfo fd; |
aoqi@0 | 510 | BasicType element_type = FieldType::get_array_info(name->get_symbol(), |
aoqi@0 | 511 | fd, THREAD); |
aoqi@0 | 512 | if (HAS_PENDING_EXCEPTION) { |
aoqi@0 | 513 | CLEAR_PENDING_EXCEPTION; |
aoqi@0 | 514 | CURRENT_THREAD_ENV->record_out_of_memory_failure(); |
aoqi@0 | 515 | return ciEnv::_unloaded_ciobjarrayklass; |
aoqi@0 | 516 | } |
aoqi@0 | 517 | int dimension = fd.dimension(); |
aoqi@0 | 518 | assert(element_type != T_ARRAY, "unsuccessful decomposition"); |
aoqi@0 | 519 | ciKlass* element_klass = NULL; |
aoqi@0 | 520 | if (element_type == T_OBJECT) { |
aoqi@0 | 521 | ciEnv *env = CURRENT_THREAD_ENV; |
aoqi@0 | 522 | ciSymbol* ci_name = env->get_symbol(fd.object_key()); |
aoqi@0 | 523 | element_klass = |
aoqi@0 | 524 | env->get_klass_by_name(accessing_klass, ci_name, false)->as_instance_klass(); |
aoqi@0 | 525 | } else { |
aoqi@0 | 526 | assert(dimension > 1, "one dimensional type arrays are always loaded."); |
aoqi@0 | 527 | |
aoqi@0 | 528 | // The type array itself takes care of one of the dimensions. |
aoqi@0 | 529 | dimension--; |
aoqi@0 | 530 | |
aoqi@0 | 531 | // The element klass is a TypeArrayKlass. |
aoqi@0 | 532 | element_klass = ciTypeArrayKlass::make(element_type); |
aoqi@0 | 533 | } |
aoqi@0 | 534 | new_klass = new (arena()) ciObjArrayKlass(name, element_klass, dimension); |
aoqi@0 | 535 | } else { |
aoqi@0 | 536 | jobject loader_handle = NULL; |
aoqi@0 | 537 | jobject domain_handle = NULL; |
aoqi@0 | 538 | if (accessing_klass != NULL) { |
aoqi@0 | 539 | loader_handle = accessing_klass->loader_handle(); |
aoqi@0 | 540 | domain_handle = accessing_klass->protection_domain_handle(); |
aoqi@0 | 541 | } |
aoqi@0 | 542 | new_klass = new (arena()) ciInstanceKlass(name, loader_handle, domain_handle); |
aoqi@0 | 543 | } |
aoqi@0 | 544 | init_ident_of(new_klass); |
aoqi@0 | 545 | _unloaded_klasses->append(new_klass); |
aoqi@0 | 546 | |
aoqi@0 | 547 | return new_klass; |
aoqi@0 | 548 | } |
aoqi@0 | 549 | |
aoqi@0 | 550 | |
aoqi@0 | 551 | //------------------------------------------------------------------ |
aoqi@0 | 552 | // ciObjectFactory::get_unloaded_instance |
aoqi@0 | 553 | // |
aoqi@0 | 554 | // Get a ciInstance representing an as-yet undetermined instance of a given class. |
aoqi@0 | 555 | // |
aoqi@0 | 556 | ciInstance* ciObjectFactory::get_unloaded_instance(ciInstanceKlass* instance_klass) { |
aoqi@0 | 557 | for (int i=0; i<_unloaded_instances->length(); i++) { |
aoqi@0 | 558 | ciInstance* entry = _unloaded_instances->at(i); |
aoqi@0 | 559 | if (entry->klass()->equals(instance_klass)) { |
aoqi@0 | 560 | // We've found a match. |
aoqi@0 | 561 | return entry; |
aoqi@0 | 562 | } |
aoqi@0 | 563 | } |
aoqi@0 | 564 | |
aoqi@0 | 565 | // This is a new unloaded instance. Create it and stick it in |
aoqi@0 | 566 | // the cache. |
aoqi@0 | 567 | ciInstance* new_instance = new (arena()) ciInstance(instance_klass); |
aoqi@0 | 568 | |
aoqi@0 | 569 | init_ident_of(new_instance); |
aoqi@0 | 570 | _unloaded_instances->append(new_instance); |
aoqi@0 | 571 | |
aoqi@0 | 572 | // make sure it looks the way we want: |
aoqi@0 | 573 | assert(!new_instance->is_loaded(), ""); |
aoqi@0 | 574 | assert(new_instance->klass() == instance_klass, ""); |
aoqi@0 | 575 | |
aoqi@0 | 576 | return new_instance; |
aoqi@0 | 577 | } |
aoqi@0 | 578 | |
aoqi@0 | 579 | |
aoqi@0 | 580 | //------------------------------------------------------------------ |
aoqi@0 | 581 | // ciObjectFactory::get_unloaded_klass_mirror |
aoqi@0 | 582 | // |
aoqi@0 | 583 | // Get a ciInstance representing an unresolved klass mirror. |
aoqi@0 | 584 | // |
aoqi@0 | 585 | // Currently, this ignores the parameters and returns a unique unloaded instance. |
aoqi@0 | 586 | ciInstance* ciObjectFactory::get_unloaded_klass_mirror(ciKlass* type) { |
aoqi@0 | 587 | assert(ciEnv::_Class_klass != NULL, ""); |
aoqi@0 | 588 | return get_unloaded_instance(ciEnv::_Class_klass->as_instance_klass()); |
aoqi@0 | 589 | } |
aoqi@0 | 590 | |
aoqi@0 | 591 | //------------------------------------------------------------------ |
aoqi@0 | 592 | // ciObjectFactory::get_unloaded_method_handle_constant |
aoqi@0 | 593 | // |
aoqi@0 | 594 | // Get a ciInstance representing an unresolved method handle constant. |
aoqi@0 | 595 | // |
aoqi@0 | 596 | // Currently, this ignores the parameters and returns a unique unloaded instance. |
aoqi@0 | 597 | ciInstance* ciObjectFactory::get_unloaded_method_handle_constant(ciKlass* holder, |
aoqi@0 | 598 | ciSymbol* name, |
aoqi@0 | 599 | ciSymbol* signature, |
aoqi@0 | 600 | int ref_kind) { |
aoqi@0 | 601 | if (ciEnv::_MethodHandle_klass == NULL) return NULL; |
aoqi@0 | 602 | return get_unloaded_instance(ciEnv::_MethodHandle_klass->as_instance_klass()); |
aoqi@0 | 603 | } |
aoqi@0 | 604 | |
aoqi@0 | 605 | //------------------------------------------------------------------ |
aoqi@0 | 606 | // ciObjectFactory::get_unloaded_method_type_constant |
aoqi@0 | 607 | // |
aoqi@0 | 608 | // Get a ciInstance representing an unresolved method type constant. |
aoqi@0 | 609 | // |
aoqi@0 | 610 | // Currently, this ignores the parameters and returns a unique unloaded instance. |
aoqi@0 | 611 | ciInstance* ciObjectFactory::get_unloaded_method_type_constant(ciSymbol* signature) { |
aoqi@0 | 612 | if (ciEnv::_MethodType_klass == NULL) return NULL; |
aoqi@0 | 613 | return get_unloaded_instance(ciEnv::_MethodType_klass->as_instance_klass()); |
aoqi@0 | 614 | } |
aoqi@0 | 615 | |
aoqi@0 | 616 | ciInstance* ciObjectFactory::get_unloaded_object_constant() { |
aoqi@0 | 617 | if (ciEnv::_Object_klass == NULL) return NULL; |
aoqi@0 | 618 | return get_unloaded_instance(ciEnv::_Object_klass->as_instance_klass()); |
aoqi@0 | 619 | } |
aoqi@0 | 620 | |
aoqi@0 | 621 | //------------------------------------------------------------------ |
aoqi@0 | 622 | // ciObjectFactory::get_empty_methodData |
aoqi@0 | 623 | // |
aoqi@0 | 624 | // Get the ciMethodData representing the methodData for a method with |
aoqi@0 | 625 | // none. |
aoqi@0 | 626 | ciMethodData* ciObjectFactory::get_empty_methodData() { |
aoqi@0 | 627 | ciMethodData* new_methodData = new (arena()) ciMethodData(); |
aoqi@0 | 628 | init_ident_of(new_methodData); |
aoqi@0 | 629 | return new_methodData; |
aoqi@0 | 630 | } |
aoqi@0 | 631 | |
aoqi@0 | 632 | //------------------------------------------------------------------ |
aoqi@0 | 633 | // ciObjectFactory::get_return_address |
aoqi@0 | 634 | // |
aoqi@0 | 635 | // Get a ciReturnAddress for a specified bci. |
aoqi@0 | 636 | ciReturnAddress* ciObjectFactory::get_return_address(int bci) { |
aoqi@0 | 637 | for (int i=0; i<_return_addresses->length(); i++) { |
aoqi@0 | 638 | ciReturnAddress* entry = _return_addresses->at(i); |
aoqi@0 | 639 | if (entry->bci() == bci) { |
aoqi@0 | 640 | // We've found a match. |
aoqi@0 | 641 | return entry; |
aoqi@0 | 642 | } |
aoqi@0 | 643 | } |
aoqi@0 | 644 | |
aoqi@0 | 645 | ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci); |
aoqi@0 | 646 | init_ident_of(new_ret_addr); |
aoqi@0 | 647 | _return_addresses->append(new_ret_addr); |
aoqi@0 | 648 | return new_ret_addr; |
aoqi@0 | 649 | } |
aoqi@0 | 650 | |
aoqi@0 | 651 | // ------------------------------------------------------------------ |
aoqi@0 | 652 | // ciObjectFactory::init_ident_of |
aoqi@0 | 653 | void ciObjectFactory::init_ident_of(ciBaseObject* obj) { |
aoqi@0 | 654 | obj->set_ident(_next_ident++); |
aoqi@0 | 655 | } |
aoqi@0 | 656 | |
aoqi@0 | 657 | // ------------------------------------------------------------------ |
aoqi@0 | 658 | // ciObjectFactory::find |
aoqi@0 | 659 | // |
aoqi@0 | 660 | // Use binary search to find the position of this oop in the cache. |
aoqi@0 | 661 | // If there is no entry in the cache corresponding to this oop, return |
aoqi@0 | 662 | // the position at which the oop should be inserted. |
aoqi@0 | 663 | int ciObjectFactory::find(Metadata* key, GrowableArray<ciMetadata*>* objects) { |
aoqi@0 | 664 | int min = 0; |
aoqi@0 | 665 | int max = objects->length()-1; |
aoqi@0 | 666 | |
aoqi@0 | 667 | // print_contents(); |
aoqi@0 | 668 | |
aoqi@0 | 669 | while (max >= min) { |
aoqi@0 | 670 | int mid = (max + min) / 2; |
aoqi@0 | 671 | Metadata* value = objects->at(mid)->constant_encoding(); |
aoqi@0 | 672 | if (value < key) { |
aoqi@0 | 673 | min = mid + 1; |
aoqi@0 | 674 | } else if (value > key) { |
aoqi@0 | 675 | max = mid - 1; |
aoqi@0 | 676 | } else { |
aoqi@0 | 677 | return mid; |
aoqi@0 | 678 | } |
aoqi@0 | 679 | } |
aoqi@0 | 680 | return min; |
aoqi@0 | 681 | } |
aoqi@0 | 682 | |
aoqi@0 | 683 | // ------------------------------------------------------------------ |
aoqi@0 | 684 | // ciObjectFactory::is_found_at |
aoqi@0 | 685 | // |
aoqi@0 | 686 | // Verify that the binary seach found the given key. |
aoqi@0 | 687 | bool ciObjectFactory::is_found_at(int index, Metadata* key, GrowableArray<ciMetadata*>* objects) { |
aoqi@0 | 688 | return (index < objects->length() && |
aoqi@0 | 689 | objects->at(index)->constant_encoding() == key); |
aoqi@0 | 690 | } |
aoqi@0 | 691 | |
aoqi@0 | 692 | |
aoqi@0 | 693 | // ------------------------------------------------------------------ |
aoqi@0 | 694 | // ciObjectFactory::insert |
aoqi@0 | 695 | // |
aoqi@0 | 696 | // Insert a ciObject into the table at some index. |
aoqi@0 | 697 | void ciObjectFactory::insert(int index, ciMetadata* obj, GrowableArray<ciMetadata*>* objects) { |
aoqi@0 | 698 | int len = objects->length(); |
aoqi@0 | 699 | if (len == index) { |
aoqi@0 | 700 | objects->append(obj); |
aoqi@0 | 701 | } else { |
aoqi@0 | 702 | objects->append(objects->at(len-1)); |
aoqi@0 | 703 | int pos; |
aoqi@0 | 704 | for (pos = len-2; pos >= index; pos--) { |
aoqi@0 | 705 | objects->at_put(pos+1,objects->at(pos)); |
aoqi@0 | 706 | } |
aoqi@0 | 707 | objects->at_put(index, obj); |
aoqi@0 | 708 | } |
aoqi@0 | 709 | } |
aoqi@0 | 710 | |
aoqi@0 | 711 | static ciObjectFactory::NonPermObject* emptyBucket = NULL; |
aoqi@0 | 712 | |
aoqi@0 | 713 | // ------------------------------------------------------------------ |
aoqi@0 | 714 | // ciObjectFactory::find_non_perm |
aoqi@0 | 715 | // |
aoqi@0 | 716 | // Use a small hash table, hashed on the klass of the key. |
aoqi@0 | 717 | // If there is no entry in the cache corresponding to this oop, return |
aoqi@0 | 718 | // the null tail of the bucket into which the oop should be inserted. |
aoqi@0 | 719 | ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) { |
vlivanov@7384 | 720 | assert(Universe::heap()->is_in_reserved(key), "must be"); |
aoqi@0 | 721 | ciMetadata* klass = get_metadata(key->klass()); |
aoqi@0 | 722 | NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS]; |
aoqi@0 | 723 | for (NonPermObject* p; (p = (*bp)) != NULL; bp = &p->next()) { |
aoqi@0 | 724 | if (is_equal(p, key)) break; |
aoqi@0 | 725 | } |
aoqi@0 | 726 | return (*bp); |
aoqi@0 | 727 | } |
aoqi@0 | 728 | |
aoqi@0 | 729 | |
aoqi@0 | 730 | |
aoqi@0 | 731 | // ------------------------------------------------------------------ |
aoqi@0 | 732 | // Code for for NonPermObject |
aoqi@0 | 733 | // |
aoqi@0 | 734 | inline ciObjectFactory::NonPermObject::NonPermObject(ciObjectFactory::NonPermObject* &bucket, oop key, ciObject* object) { |
aoqi@0 | 735 | assert(ciObjectFactory::is_initialized(), ""); |
aoqi@0 | 736 | _object = object; |
aoqi@0 | 737 | _next = bucket; |
aoqi@0 | 738 | bucket = this; |
aoqi@0 | 739 | } |
aoqi@0 | 740 | |
aoqi@0 | 741 | |
aoqi@0 | 742 | |
aoqi@0 | 743 | // ------------------------------------------------------------------ |
aoqi@0 | 744 | // ciObjectFactory::insert_non_perm |
aoqi@0 | 745 | // |
aoqi@0 | 746 | // Insert a ciObject into the non-perm table. |
aoqi@0 | 747 | void ciObjectFactory::insert_non_perm(ciObjectFactory::NonPermObject* &where, oop key, ciObject* obj) { |
aoqi@0 | 748 | assert(Universe::heap()->is_in_reserved_or_null(key), "must be"); |
aoqi@0 | 749 | assert(&where != &emptyBucket, "must not try to fill empty bucket"); |
aoqi@0 | 750 | NonPermObject* p = new (arena()) NonPermObject(where, key, obj); |
aoqi@0 | 751 | assert(where == p && is_equal(p, key) && p->object() == obj, "entry must match"); |
aoqi@0 | 752 | assert(find_non_perm(key) == p, "must find the same spot"); |
aoqi@0 | 753 | ++_non_perm_count; |
aoqi@0 | 754 | } |
aoqi@0 | 755 | |
aoqi@0 | 756 | // ------------------------------------------------------------------ |
aoqi@0 | 757 | // ciObjectFactory::vm_symbol_at |
aoqi@0 | 758 | // Get the ciSymbol corresponding to some index in vmSymbols. |
aoqi@0 | 759 | ciSymbol* ciObjectFactory::vm_symbol_at(int index) { |
aoqi@0 | 760 | assert(index >= vmSymbols::FIRST_SID && index < vmSymbols::SID_LIMIT, "oob"); |
aoqi@0 | 761 | return _shared_ci_symbols[index]; |
aoqi@0 | 762 | } |
aoqi@0 | 763 | |
aoqi@0 | 764 | // ------------------------------------------------------------------ |
aoqi@0 | 765 | // ciObjectFactory::metadata_do |
aoqi@0 | 766 | void ciObjectFactory::metadata_do(void f(Metadata*)) { |
aoqi@0 | 767 | if (_ci_metadata == NULL) return; |
aoqi@0 | 768 | for (int j = 0; j< _ci_metadata->length(); j++) { |
aoqi@0 | 769 | Metadata* o = _ci_metadata->at(j)->constant_encoding(); |
aoqi@0 | 770 | f(o); |
aoqi@0 | 771 | } |
aoqi@0 | 772 | } |
aoqi@0 | 773 | |
aoqi@0 | 774 | // ------------------------------------------------------------------ |
aoqi@0 | 775 | // ciObjectFactory::print_contents_impl |
aoqi@0 | 776 | void ciObjectFactory::print_contents_impl() { |
aoqi@0 | 777 | int len = _ci_metadata->length(); |
aoqi@0 | 778 | tty->print_cr("ciObjectFactory (%d) meta data contents:", len); |
aoqi@0 | 779 | for (int i=0; i<len; i++) { |
aoqi@0 | 780 | _ci_metadata->at(i)->print(); |
aoqi@0 | 781 | tty->cr(); |
aoqi@0 | 782 | } |
aoqi@0 | 783 | } |
aoqi@0 | 784 | |
aoqi@0 | 785 | // ------------------------------------------------------------------ |
aoqi@0 | 786 | // ciObjectFactory::print_contents |
aoqi@0 | 787 | void ciObjectFactory::print_contents() { |
aoqi@0 | 788 | print(); |
aoqi@0 | 789 | tty->cr(); |
aoqi@0 | 790 | GUARDED_VM_ENTRY(print_contents_impl();) |
aoqi@0 | 791 | } |
aoqi@0 | 792 | |
aoqi@0 | 793 | // ------------------------------------------------------------------ |
aoqi@0 | 794 | // ciObjectFactory::print |
aoqi@0 | 795 | // |
aoqi@0 | 796 | // Print debugging information about the object factory |
aoqi@0 | 797 | void ciObjectFactory::print() { |
aoqi@0 | 798 | tty->print("<ciObjectFactory oops=%d metadata=%d unloaded_methods=%d unloaded_instances=%d unloaded_klasses=%d>", |
aoqi@0 | 799 | _non_perm_count, _ci_metadata->length(), _unloaded_methods->length(), |
aoqi@0 | 800 | _unloaded_instances->length(), |
aoqi@0 | 801 | _unloaded_klasses->length()); |
aoqi@0 | 802 | } |