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