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   ciEnv::_StringBuffer =
 172     get(SystemDictionary::stringBuffer_klass())
 173       ->as_instance_klass();
 174   ciEnv::_StringBuilder =
 175     get(SystemDictionary::StringBuilder_klass())
 176       ->as_instance_klass();
 177   ciEnv::_Integer =
 178     get(SystemDictionary::int_klass())
 179       ->as_instance_klass();
 180 
 181   for (int len = -1; len != _ci_objects->length(); ) {
 182     len = _ci_objects->length();
 183     for (int i2 = 0; i2 < len; i2++) {
 184       ciObject* obj = _ci_objects->at(i2);
 185       if (obj->is_loaded() && obj->is_instance_klass()) {
 186         obj->as_instance_klass()->compute_nonstatic_fields();
 187       }
 188     }
 189   }
 190 
 191   ciEnv::_unloaded_cisymbol = (ciSymbol*) ciObjectFactory::get(vmSymbols::dummy_symbol_oop());
 192   // Create dummy instanceKlass and objArrayKlass object and assign them idents
 193   ciEnv::_unloaded_ciinstance_klass = new (_arena) ciInstanceKlass(ciEnv::_unloaded_cisymbol, NULL, NULL);
 194   init_ident_of(ciEnv::_unloaded_ciinstance_klass);
 195   ciEnv::_unloaded_ciobjarrayklass = new (_arena) ciObjArrayKlass(ciEnv::_unloaded_cisymbol, ciEnv::_unloaded_ciinstance_klass, 1);
 196   init_ident_of(ciEnv::_unloaded_ciobjarrayklass);
 197   assert(ciEnv::_unloaded_ciobjarrayklass->is_obj_array_klass(), "just checking");
 198 
 199   get(Universe::boolArrayKlassObj());
 200   get(Universe::charArrayKlassObj());
 201   get(Universe::singleArrayKlassObj());
 202   get(Universe::doubleArrayKlassObj());
 203   get(Universe::byteArrayKlassObj());
 204   get(Universe::shortArrayKlassObj());
 205   get(Universe::intArrayKlassObj());
 206   get(Universe::longArrayKlassObj());
 207 
 208 
 209 
 210   assert(_non_perm_count == 0, "no shared non-perm objects");
 211 
 212   // The shared_ident_limit is the first ident number that will
 213   // be used for non-shared objects.  That is, numbers less than
 214   // this limit are permanently assigned to shared CI objects,
 215   // while the higher numbers are recycled afresh by each new ciEnv.
 216 
 217   _shared_ident_limit = _next_ident;
 218   _shared_ci_objects = _ci_objects;
 219 }
 220 
 221 // ------------------------------------------------------------------
 222 // ciObjectFactory::get
 223 //
 224 // Get the ciObject corresponding to some oop.  If the ciObject has
 225 // already been created, it is returned.  Otherwise, a new ciObject
 226 // is created.
 227 ciObject* ciObjectFactory::get(oop key) {
 228   ASSERT_IN_VM;
 229 
 230 #ifdef ASSERT
 231   if (CIObjectFactoryVerify) {
 232     oop last = NULL;
 233     for (int j = 0; j< _ci_objects->length(); j++) {
 234       oop o = _ci_objects->at(j)->get_oop();
 235       assert(last < o, "out of order");
 236       last = o;
 237     }
 238   }
 239 #endif // ASSERT
 240   int len = _ci_objects->length();
 241   int index = find(key, _ci_objects);
 242 #ifdef ASSERT
 243   if (CIObjectFactoryVerify) {
 244     for (int i=0; i<_ci_objects->length(); i++) {
 245       if (_ci_objects->at(i)->get_oop() == key) {
 246         assert(index == i, " bad lookup");
 247       }
 248     }
 249   }
 250 #endif
 251   if (!is_found_at(index, key, _ci_objects)) {
 252     // Check in the non-perm area before putting it in the list.
 253     NonPermObject* &bucket = find_non_perm(key);
 254     if (bucket != NULL) {
 255       return bucket->object();
 256     }
 257 
 258     // Check in the shared symbol area before putting it in the list.
 259     if (key->is_symbol()) {
 260       vmSymbols::SID sid = vmSymbols::find_sid((symbolOop)key);
 261       if (sid != vmSymbols::NO_SID) {
 262         // do not pollute the main cache with it
 263         return vm_symbol_at(sid);
 264       }
 265     }
 266 
 267     // The ciObject does not yet exist.  Create it and insert it
 268     // into the cache.
 269     Handle keyHandle(key);
 270     ciObject* new_object = create_new_object(keyHandle());
 271     assert(keyHandle() == new_object->get_oop(), "must be properly recorded");
 272     init_ident_of(new_object);
 273     if (!new_object->is_perm()) {
 274       // Not a perm-space object.
 275       insert_non_perm(bucket, keyHandle(), new_object);
 276       return new_object;
 277     }
 278     if (len != _ci_objects->length()) {
 279       // creating the new object has recursively entered new objects
 280       // into the table.  We need to recompute our index.
 281       index = find(keyHandle(), _ci_objects);
 282     }
 283     assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert");
 284     insert(index, new_object, _ci_objects);
 285     return new_object;
 286   }
 287   return _ci_objects->at(index);
 288 }
 289 
 290 // ------------------------------------------------------------------
 291 // ciObjectFactory::create_new_object
 292 //
 293 // Create a new ciObject from an oop.
 294 //
 295 // Implementation note: this functionality could be virtual behavior
 296 // of the oop itself.  For now, we explicitly marshal the object.
 297 ciObject* ciObjectFactory::create_new_object(oop o) {
 298   EXCEPTION_CONTEXT;
 299 
 300   if (o->is_symbol()) {
 301     symbolHandle h_o(THREAD, (symbolOop)o);
 302     return new (arena()) ciSymbol(h_o);
 303   } else if (o->is_klass()) {
 304     KlassHandle h_k(THREAD, (klassOop)o);
 305     Klass* k = ((klassOop)o)->klass_part();
 306     if (k->oop_is_instance()) {
 307       return new (arena()) ciInstanceKlass(h_k);
 308     } else if (k->oop_is_objArray()) {
 309       return new (arena()) ciObjArrayKlass(h_k);
 310     } else if (k->oop_is_typeArray()) {
 311       return new (arena()) ciTypeArrayKlass(h_k);
 312     } else if (k->oop_is_method()) {
 313       return new (arena()) ciMethodKlass(h_k);
 314     } else if (k->oop_is_symbol()) {
 315       return new (arena()) ciSymbolKlass(h_k);
 316     } else if (k->oop_is_klass()) {
 317       if (k->oop_is_objArrayKlass()) {
 318         return new (arena()) ciObjArrayKlassKlass(h_k);
 319       } else if (k->oop_is_typeArrayKlass()) {
 320         return new (arena()) ciTypeArrayKlassKlass(h_k);
 321       } else if (k->oop_is_instanceKlass()) {
 322         return new (arena()) ciInstanceKlassKlass(h_k);
 323       } else {
 324         assert(o == Universe::klassKlassObj(), "bad klassKlass");
 325         return new (arena()) ciKlassKlass(h_k);
 326       }
 327     }
 328   } else if (o->is_method()) {
 329     methodHandle h_m(THREAD, (methodOop)o);
 330     return new (arena()) ciMethod(h_m);
 331   } else if (o->is_methodData()) {
 332     methodDataHandle h_md(THREAD, (methodDataOop)o);
 333     return new (arena()) ciMethodData(h_md);
 334   } else if (o->is_instance()) {
 335     instanceHandle h_i(THREAD, (instanceOop)o);
 336     return new (arena()) ciInstance(h_i);
 337   } else if (o->is_objArray()) {
 338     objArrayHandle h_oa(THREAD, (objArrayOop)o);
 339     return new (arena()) ciObjArray(h_oa);
 340   } else if (o->is_typeArray()) {
 341     typeArrayHandle h_ta(THREAD, (typeArrayOop)o);
 342     return new (arena()) ciTypeArray(h_ta);
 343   }
 344 
 345   // The oop is of some type not supported by the compiler interface.
 346   ShouldNotReachHere();
 347   return NULL;
 348 }
 349 
 350 //------------------------------------------------------------------
 351 // ciObjectFactory::get_unloaded_method
 352 //
 353 // Get the ciMethod representing an unloaded/unfound method.
 354 //
 355 // Implementation note: unloaded methods are currently stored in
 356 // an unordered array, requiring a linear-time lookup for each
 357 // unloaded method.  This may need to change.
 358 ciMethod* ciObjectFactory::get_unloaded_method(ciInstanceKlass* holder,
 359                                                ciSymbol*        name,
 360                                                ciSymbol*        signature) {
 361   for (int i=0; i<_unloaded_methods->length(); i++) {
 362     ciMethod* entry = _unloaded_methods->at(i);
 363     if (entry->holder()->equals(holder) &&
 364         entry->name()->equals(name) &&
 365         entry->signature()->as_symbol()->equals(signature)) {
 366       // We've found a match.
 367       return entry;
 368     }
 369   }
 370 
 371   // This is a new unloaded method.  Create it and stick it in
 372   // the cache.
 373   ciMethod* new_method = new (arena()) ciMethod(holder, name, signature);
 374 
 375   init_ident_of(new_method);
 376   _unloaded_methods->append(new_method);
 377 
 378   return new_method;
 379 }
 380 
 381 //------------------------------------------------------------------
 382 // ciObjectFactory::get_unloaded_klass
 383 //
 384 // Get a ciKlass representing an unloaded klass.
 385 //
 386 // Implementation note: unloaded klasses are currently stored in
 387 // an unordered array, requiring a linear-time lookup for each
 388 // unloaded klass.  This may need to change.
 389 ciKlass* ciObjectFactory::get_unloaded_klass(ciKlass* accessing_klass,
 390                                              ciSymbol* name,
 391                                              bool create_if_not_found) {
 392   EXCEPTION_CONTEXT;
 393   oop loader = NULL;
 394   oop domain = NULL;
 395   if (accessing_klass != NULL) {
 396     loader = accessing_klass->loader();
 397     domain = accessing_klass->protection_domain();
 398   }
 399   for (int i=0; i<_unloaded_klasses->length(); i++) {
 400     ciKlass* entry = _unloaded_klasses->at(i);
 401     if (entry->name()->equals(name) &&
 402         entry->loader() == loader &&
 403         entry->protection_domain() == domain) {
 404       // We've found a match.
 405       return entry;
 406     }
 407   }
 408 
 409   if (!create_if_not_found)
 410     return NULL;
 411 
 412   // This is a new unloaded klass.  Create it and stick it in
 413   // the cache.
 414   ciKlass* new_klass = NULL;
 415 
 416   // Two cases: this is an unloaded objArrayKlass or an
 417   // unloaded instanceKlass.  Deal with both.
 418   if (name->byte_at(0) == '[') {
 419     // Decompose the name.'
 420     jint dimension = 0;
 421     symbolOop element_name = NULL;
 422     BasicType element_type= FieldType::get_array_info(name->get_symbolOop(),
 423                                                       &dimension,
 424                                                       &element_name,
 425                                                       THREAD);
 426     if (HAS_PENDING_EXCEPTION) {
 427       CLEAR_PENDING_EXCEPTION;
 428       CURRENT_THREAD_ENV->record_out_of_memory_failure();
 429       return ciEnv::_unloaded_ciobjarrayklass;
 430     }
 431     assert(element_type != T_ARRAY, "unsuccessful decomposition");
 432     ciKlass* element_klass = NULL;
 433     if (element_type == T_OBJECT) {
 434       ciEnv *env = CURRENT_THREAD_ENV;
 435       ciSymbol* ci_name = env->get_object(element_name)->as_symbol();
 436       element_klass =
 437         env->get_klass_by_name(accessing_klass, ci_name, false)->as_instance_klass();
 438     } else {
 439       assert(dimension > 1, "one dimensional type arrays are always loaded.");
 440 
 441       // The type array itself takes care of one of the dimensions.
 442       dimension--;
 443 
 444       // The element klass is a typeArrayKlass.
 445       element_klass = ciTypeArrayKlass::make(element_type);
 446     }
 447     new_klass = new (arena()) ciObjArrayKlass(name, element_klass, dimension);
 448   } else {
 449     jobject loader_handle = NULL;
 450     jobject domain_handle = NULL;
 451     if (accessing_klass != NULL) {
 452       loader_handle = accessing_klass->loader_handle();
 453       domain_handle = accessing_klass->protection_domain_handle();
 454     }
 455     new_klass = new (arena()) ciInstanceKlass(name, loader_handle, domain_handle);
 456   }
 457   init_ident_of(new_klass);
 458   _unloaded_klasses->append(new_klass);
 459 
 460   return new_klass;
 461 }
 462 
 463 //------------------------------------------------------------------
 464 // ciObjectFactory::get_empty_methodData
 465 //
 466 // Get the ciMethodData representing the methodData for a method with
 467 // none.
 468 ciMethodData* ciObjectFactory::get_empty_methodData() {
 469   ciMethodData* new_methodData = new (arena()) ciMethodData();
 470   init_ident_of(new_methodData);
 471   return new_methodData;
 472 }
 473 
 474 //------------------------------------------------------------------
 475 // ciObjectFactory::get_return_address
 476 //
 477 // Get a ciReturnAddress for a specified bci.
 478 ciReturnAddress* ciObjectFactory::get_return_address(int bci) {
 479   for (int i=0; i<_return_addresses->length(); i++) {
 480     ciReturnAddress* entry = _return_addresses->at(i);
 481     if (entry->bci() == bci) {
 482       // We've found a match.
 483       return entry;
 484     }
 485   }
 486 
 487   ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci);
 488   init_ident_of(new_ret_addr);
 489   _return_addresses->append(new_ret_addr);
 490   return new_ret_addr;
 491 }
 492 
 493 // ------------------------------------------------------------------
 494 // ciObjectFactory::init_ident_of
 495 void ciObjectFactory::init_ident_of(ciObject* obj) {
 496   obj->set_ident(_next_ident++);
 497 }
 498 
 499 
 500 // ------------------------------------------------------------------
 501 // ciObjectFactory::find
 502 //
 503 // Use binary search to find the position of this oop in the cache.
 504 // If there is no entry in the cache corresponding to this oop, return
 505 // the position at which the oop should be inserted.
 506 int ciObjectFactory::find(oop key, GrowableArray<ciObject*>* objects) {
 507   int min = 0;
 508   int max = objects->length()-1;
 509 
 510   // print_contents();
 511 
 512   while (max >= min) {
 513     int mid = (max + min) / 2;
 514     oop value = objects->at(mid)->get_oop();
 515     if (value < key) {
 516       min = mid + 1;
 517     } else if (value > key) {
 518       max = mid - 1;
 519     } else {
 520       return mid;
 521     }
 522   }
 523   return min;
 524 }
 525 
 526 // ------------------------------------------------------------------
 527 // ciObjectFactory::is_found_at
 528 //
 529 // Verify that the binary seach found the given key.
 530 bool ciObjectFactory::is_found_at(int index, oop key, GrowableArray<ciObject*>* objects) {
 531   return (index < objects->length() &&
 532           objects->at(index)->get_oop() == key);
 533 }
 534 
 535 
 536 // ------------------------------------------------------------------
 537 // ciObjectFactory::insert
 538 //
 539 // Insert a ciObject into the table at some index.
 540 void ciObjectFactory::insert(int index, ciObject* obj, GrowableArray<ciObject*>* objects) {
 541   int len = objects->length();
 542   if (len == index) {
 543     objects->append(obj);
 544   } else {
 545     objects->append(objects->at(len-1));
 546     int pos;
 547     for (pos = len-2; pos >= index; pos--) {
 548       objects->at_put(pos+1,objects->at(pos));
 549     }
 550     objects->at_put(index, obj);
 551   }
 552 #ifdef ASSERT
 553   if (CIObjectFactoryVerify) {
 554     oop last = NULL;
 555     for (int j = 0; j< objects->length(); j++) {
 556       oop o = objects->at(j)->get_oop();
 557       assert(last < o, "out of order");
 558       last = o;
 559     }
 560   }
 561 #endif // ASSERT
 562 }
 563 
 564 static ciObjectFactory::NonPermObject* emptyBucket = NULL;
 565 
 566 // ------------------------------------------------------------------
 567 // ciObjectFactory::find_non_perm
 568 //
 569 // Use a small hash table, hashed on the klass of the key.
 570 // If there is no entry in the cache corresponding to this oop, return
 571 // the null tail of the bucket into which the oop should be inserted.
 572 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) {
 573   // Be careful:  is_perm might change from false to true.
 574   // Thus, there might be a matching perm object in the table.
 575   // If there is, this probe must find it.
 576   if (key->is_perm() && _non_perm_count == 0) {
 577     return emptyBucket;
 578   } else if (key->is_instance()) {
 579     if (key->klass() == SystemDictionary::class_klass()) {
 580       // class mirror instances are always perm
 581       return emptyBucket;
 582     }
 583     // fall through to probe
 584   } else if (key->is_array()) {
 585     // fall through to probe
 586   } else {
 587     // not an array or instance
 588     return emptyBucket;
 589   }
 590 
 591   ciObject* klass = get(key->klass());
 592   NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS];
 593   for (NonPermObject* p; (p = (*bp)) != NULL; bp = &p->next()) {
 594     if (is_equal(p, key))  break;
 595   }
 596   return (*bp);
 597 }
 598 
 599 
 600 
 601 // ------------------------------------------------------------------
 602 // Code for for NonPermObject
 603 //
 604 inline ciObjectFactory::NonPermObject::NonPermObject(ciObjectFactory::NonPermObject* &bucket, oop key, ciObject* object) {
 605   assert(ciObjectFactory::is_initialized(), "");
 606   _object = object;
 607   _next = bucket;
 608   bucket = this;
 609 }
 610 
 611 
 612 
 613 // ------------------------------------------------------------------
 614 // ciObjectFactory::insert_non_perm
 615 //
 616 // Insert a ciObject into the non-perm table.
 617 void ciObjectFactory::insert_non_perm(ciObjectFactory::NonPermObject* &where, oop key, ciObject* obj) {
 618   assert(&where != &emptyBucket, "must not try to fill empty bucket");
 619   NonPermObject* p = new (arena()) NonPermObject(where, key, obj);
 620   assert(where == p && is_equal(p, key) && p->object() == obj, "entry must match");
 621   assert(find_non_perm(key) == p, "must find the same spot");
 622   ++_non_perm_count;
 623 }
 624 
 625 // ------------------------------------------------------------------
 626 // ciObjectFactory::vm_symbol_at
 627 // Get the ciSymbol corresponding to some index in vmSymbols.
 628 ciSymbol* ciObjectFactory::vm_symbol_at(int index) {
 629   assert(index >= vmSymbols::FIRST_SID && index < vmSymbols::SID_LIMIT, "oob");
 630   return _shared_ci_symbols[index];
 631 }
 632 
 633 // ------------------------------------------------------------------
 634 // ciObjectFactory::print_contents_impl
 635 void ciObjectFactory::print_contents_impl() {
 636   int len = _ci_objects->length();
 637   tty->print_cr("ciObjectFactory (%d) oop contents:", len);
 638   for (int i=0; i<len; i++) {
 639     _ci_objects->at(i)->print();
 640     tty->cr();
 641   }
 642 }
 643 
 644 // ------------------------------------------------------------------
 645 // ciObjectFactory::print_contents
 646 void ciObjectFactory::print_contents() {
 647   print();
 648   tty->cr();
 649   GUARDED_VM_ENTRY(print_contents_impl();)
 650 }
 651 
 652 // ------------------------------------------------------------------
 653 // ciObjectFactory::print
 654 //
 655 // Print debugging information about the object factory
 656 void ciObjectFactory::print() {
 657   tty->print("<ciObjectFactory oops=%d unloaded_methods=%d unloaded_klasses=%d>",
 658              _ci_objects->length(), _unloaded_methods->length(),
 659              _unloaded_klasses->length());
 660 }