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