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