< prev index next >

src/share/vm/ci/ciObjectFactory.cpp

Print this page
rev 12906 : [mq]: gc_interface


  30 #include "ci/ciMethod.hpp"
  31 #include "ci/ciMethodData.hpp"
  32 #include "ci/ciMethodHandle.hpp"
  33 #include "ci/ciMethodType.hpp"
  34 #include "ci/ciNullObject.hpp"
  35 #include "ci/ciObjArray.hpp"
  36 #include "ci/ciObjArrayKlass.hpp"
  37 #include "ci/ciObject.hpp"
  38 #include "ci/ciObjectFactory.hpp"
  39 #include "ci/ciSymbol.hpp"
  40 #include "ci/ciTypeArray.hpp"
  41 #include "ci/ciTypeArrayKlass.hpp"
  42 #include "ci/ciUtilities.hpp"
  43 #include "classfile/javaClasses.inline.hpp"
  44 #include "classfile/systemDictionary.hpp"
  45 #include "gc/shared/collectedHeap.inline.hpp"
  46 #include "memory/allocation.inline.hpp"
  47 #include "oops/oop.inline.hpp"
  48 #include "runtime/fieldType.hpp"
  49 #include "utilities/macros.hpp"
  50 #if INCLUDE_ALL_GCS
  51 # include "gc/g1/g1SATBCardTableModRefBS.hpp"
  52 #endif
  53 
  54 // ciObjectFactory
  55 //
  56 // This class handles requests for the creation of new instances
  57 // of ciObject and its subclasses.  It contains a caching mechanism
  58 // which ensures that for each oop, at most one ciObject is created.
  59 // This invariant allows more efficient implementation of ciObject.
  60 //
  61 // Implementation note: the oop->ciObject mapping is represented as
  62 // a table stored in an array.  Even though objects are moved
  63 // by the garbage collector, the compactor preserves their relative
  64 // order; address comparison of oops (in perm space) is safe so long
  65 // as we prohibit GC during our comparisons.  We currently use binary
  66 // search to find the oop in the table, and inserting a new oop
  67 // into the table may be costly.  If this cost ends up being
  68 // problematic the underlying data structure can be switched to some
  69 // sort of balanced binary tree.
  70 
  71 GrowableArray<ciMetadata*>* ciObjectFactory::_shared_ci_metadata = NULL;
  72 ciSymbol*                 ciObjectFactory::_shared_ci_symbols[vmSymbols::SID_LIMIT];


 162 #define WK_KLASS_DEFN(name, ignore_s, opt)                              \
 163   if (SystemDictionary::name() != NULL) \
 164     ciEnv::_##name = get_metadata(SystemDictionary::name())->as_instance_klass();
 165 
 166   WK_KLASSES_DO(WK_KLASS_DEFN)
 167 #undef WK_KLASS_DEFN
 168 
 169   for (int len = -1; len != _ci_metadata->length(); ) {
 170     len = _ci_metadata->length();
 171     for (int i2 = 0; i2 < len; i2++) {
 172       ciMetadata* obj = _ci_metadata->at(i2);
 173       assert (obj->is_metadata(), "what else would it be?");
 174       if (obj->is_loaded() && obj->is_instance_klass()) {
 175         obj->as_instance_klass()->compute_nonstatic_fields();
 176       }
 177     }
 178   }
 179 
 180   ciEnv::_unloaded_cisymbol = ciObjectFactory::get_symbol(vmSymbols::dummy_symbol());
 181   // Create dummy InstanceKlass and ObjArrayKlass object and assign them idents
 182   ciEnv::_unloaded_ciinstance_klass = new (_arena) ciInstanceKlass(ciEnv::_unloaded_cisymbol, NULL, NULL);
 183   init_ident_of(ciEnv::_unloaded_ciinstance_klass);
 184   ciEnv::_unloaded_ciobjarrayklass = new (_arena) ciObjArrayKlass(ciEnv::_unloaded_cisymbol, ciEnv::_unloaded_ciinstance_klass, 1);
 185   init_ident_of(ciEnv::_unloaded_ciobjarrayklass);
 186   assert(ciEnv::_unloaded_ciobjarrayklass->is_obj_array_klass(), "just checking");
 187 
 188   get_metadata(Universe::boolArrayKlassObj());
 189   get_metadata(Universe::charArrayKlassObj());
 190   get_metadata(Universe::singleArrayKlassObj());
 191   get_metadata(Universe::doubleArrayKlassObj());
 192   get_metadata(Universe::byteArrayKlassObj());
 193   get_metadata(Universe::shortArrayKlassObj());
 194   get_metadata(Universe::intArrayKlassObj());
 195   get_metadata(Universe::longArrayKlassObj());
 196 
 197 
 198 
 199   assert(_non_perm_count == 0, "no shared non-perm objects");
 200 
 201   // The shared_ident_limit is the first ident number that will
 202   // be used for non-shared objects.  That is, numbers less than


 346   } else if (o->is_typeArray()) {
 347     typeArrayHandle h_ta(THREAD, (typeArrayOop)o);
 348     return new (arena()) ciTypeArray(h_ta);
 349   }
 350 
 351   // The oop is of some type not supported by the compiler interface.
 352   ShouldNotReachHere();
 353   return NULL;
 354 }
 355 
 356 // ------------------------------------------------------------------
 357 // ciObjectFactory::create_new_metadata
 358 //
 359 // Create a new ciMetadata from a Metadata*.
 360 //
 361 // Implementation note: in order to keep Metadata live, an auxiliary ciObject
 362 // is used, which points to it's holder.
 363 ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) {
 364   EXCEPTION_CONTEXT;
 365 
 366   // Hold metadata from unloading by keeping it's holder alive.
 367   if (_initialized && o->is_klass()) {
 368     Klass* holder = ((Klass*)o);
 369     if (holder->is_instance_klass() && InstanceKlass::cast(holder)->is_anonymous()) {
 370       // Though ciInstanceKlass records class loader oop, it's not enough to keep
 371       // VM anonymous classes alive (loader == NULL). Klass holder should be used instead.
 372       // It is enough to record a ciObject, since cached elements are never removed
 373       // during ciObjectFactory lifetime. ciObjectFactory itself is created for
 374       // every compilation and lives for the whole duration of the compilation.
 375       ciObject* h = get(holder->klass_holder());
 376     }
 377   }
 378 
 379   if (o->is_klass()) {
 380     Klass* k = (Klass*)o;
 381     if (k->is_instance_klass()) {
 382       return new (arena()) ciInstanceKlass(k);
 383     } else if (k->is_objArray_klass()) {
 384       return new (arena()) ciObjArrayKlass(k);
 385     } else if (k->is_typeArray_klass()) {
 386       return new (arena()) ciTypeArrayKlass(k);
 387     }
 388   } else if (o->is_method()) {
 389     methodHandle h_m(THREAD, (Method*)o);
 390     ciEnv *env = CURRENT_THREAD_ENV;
 391     ciInstanceKlass* holder = env->get_instance_klass(h_m()->method_holder());
 392     return new (arena()) ciMethod(h_m, holder);
 393   } else if (o->is_methodData()) {
 394     // Hold methodHandle alive - might not be necessary ???
 395     methodHandle h_m(THREAD, ((MethodData*)o)->method());
 396     return new (arena()) ciMethodData((MethodData*)o);
 397   }
 398 
 399   // The Metadata* is of some type not supported by the compiler interface.
 400   ShouldNotReachHere();
 401   return NULL;
 402 }
 403 
 404 // ------------------------------------------------------------------
 405 // ciObjectFactory::ensure_metadata_alive
 406 //
 407 // Ensure that the metadata wrapped by the ciMetadata is kept alive by GC.
 408 // This is primarily useful for metadata which is considered as weak roots
 409 // by the GC but need to be strong roots if reachable from a current compilation.
 410 //
 411 void ciObjectFactory::ensure_metadata_alive(ciMetadata* m) {
 412   ASSERT_IN_VM; // We're handling raw oops here.
 413 
 414 #if INCLUDE_ALL_GCS
 415   if (!UseG1GC) {
 416     return;
 417   }
 418   Klass* metadata_owner_klass;
 419   if (m->is_klass()) {
 420     metadata_owner_klass = m->as_klass()->get_Klass();
 421   } else if (m->is_method()) {
 422     metadata_owner_klass = m->as_method()->get_Method()->constants()->pool_holder();
 423   } else {
 424     fatal("Not implemented for other types of metadata");
 425     return;
 426   }
 427 
 428   oop metadata_holder = metadata_owner_klass->klass_holder();
 429   if (metadata_holder != NULL) {
 430     G1SATBCardTableModRefBS::enqueue(metadata_holder);
 431   }
 432 
 433 #endif
 434 }
 435 
 436 //------------------------------------------------------------------
 437 // ciObjectFactory::get_unloaded_method
 438 //
 439 // Get the ciMethod representing an unloaded/unfound method.
 440 //
 441 // Implementation note: unloaded methods are currently stored in
 442 // an unordered array, requiring a linear-time lookup for each
 443 // unloaded method.  This may need to change.
 444 ciMethod* ciObjectFactory::get_unloaded_method(ciInstanceKlass* holder,
 445                                                ciSymbol*        name,
 446                                                ciSymbol*        signature,
 447                                                ciInstanceKlass* accessor) {
 448   ciSignature* that = NULL;
 449   for (int i = 0; i < _unloaded_methods->length(); i++) {
 450     ciMethod* entry = _unloaded_methods->at(i);
 451     if (entry->holder()->equals(holder) &&
 452         entry->name()->equals(name) &&
 453         entry->signature()->as_symbol()->equals(signature)) {
 454       // Short-circuit slow resolve.


 525     }
 526     int dimension = fd.dimension();
 527     assert(element_type != T_ARRAY, "unsuccessful decomposition");
 528     ciKlass* element_klass = NULL;
 529     if (element_type == T_OBJECT) {
 530       ciEnv *env = CURRENT_THREAD_ENV;
 531       ciSymbol* ci_name = env->get_symbol(fd.object_key());
 532       element_klass =
 533         env->get_klass_by_name(accessing_klass, ci_name, false)->as_instance_klass();
 534     } else {
 535       assert(dimension > 1, "one dimensional type arrays are always loaded.");
 536 
 537       // The type array itself takes care of one of the dimensions.
 538       dimension--;
 539 
 540       // The element klass is a TypeArrayKlass.
 541       element_klass = ciTypeArrayKlass::make(element_type);
 542     }
 543     new_klass = new (arena()) ciObjArrayKlass(name, element_klass, dimension);
 544   } else {

 545     jobject loader_handle = NULL;
 546     jobject domain_handle = NULL;
 547     if (accessing_klass != NULL) {

 548       loader_handle = accessing_klass->loader_handle();
 549       domain_handle = accessing_klass->protection_domain_handle();
 550     }
 551     new_klass = new (arena()) ciInstanceKlass(name, loader_handle, domain_handle);
 552   }
 553   init_ident_of(new_klass);
 554   _unloaded_klasses->append(new_klass);
 555 
 556   return new_klass;
 557 }
 558 
 559 
 560 //------------------------------------------------------------------
 561 // ciObjectFactory::get_unloaded_instance
 562 //
 563 // Get a ciInstance representing an as-yet undetermined instance of a given class.
 564 //
 565 ciInstance* ciObjectFactory::get_unloaded_instance(ciInstanceKlass* instance_klass) {
 566   for (int i=0; i<_unloaded_instances->length(); i++) {
 567     ciInstance* entry = _unloaded_instances->at(i);
 568     if (entry->klass()->equals(instance_klass)) {
 569       // We've found a match.
 570       return entry;
 571     }




  30 #include "ci/ciMethod.hpp"
  31 #include "ci/ciMethodData.hpp"
  32 #include "ci/ciMethodHandle.hpp"
  33 #include "ci/ciMethodType.hpp"
  34 #include "ci/ciNullObject.hpp"
  35 #include "ci/ciObjArray.hpp"
  36 #include "ci/ciObjArrayKlass.hpp"
  37 #include "ci/ciObject.hpp"
  38 #include "ci/ciObjectFactory.hpp"
  39 #include "ci/ciSymbol.hpp"
  40 #include "ci/ciTypeArray.hpp"
  41 #include "ci/ciTypeArrayKlass.hpp"
  42 #include "ci/ciUtilities.hpp"
  43 #include "classfile/javaClasses.inline.hpp"
  44 #include "classfile/systemDictionary.hpp"
  45 #include "gc/shared/collectedHeap.inline.hpp"
  46 #include "memory/allocation.inline.hpp"
  47 #include "oops/oop.inline.hpp"
  48 #include "runtime/fieldType.hpp"
  49 #include "utilities/macros.hpp"



  50 
  51 // ciObjectFactory
  52 //
  53 // This class handles requests for the creation of new instances
  54 // of ciObject and its subclasses.  It contains a caching mechanism
  55 // which ensures that for each oop, at most one ciObject is created.
  56 // This invariant allows more efficient implementation of ciObject.
  57 //
  58 // Implementation note: the oop->ciObject mapping is represented as
  59 // a table stored in an array.  Even though objects are moved
  60 // by the garbage collector, the compactor preserves their relative
  61 // order; address comparison of oops (in perm space) is safe so long
  62 // as we prohibit GC during our comparisons.  We currently use binary
  63 // search to find the oop in the table, and inserting a new oop
  64 // into the table may be costly.  If this cost ends up being
  65 // problematic the underlying data structure can be switched to some
  66 // sort of balanced binary tree.
  67 
  68 GrowableArray<ciMetadata*>* ciObjectFactory::_shared_ci_metadata = NULL;
  69 ciSymbol*                 ciObjectFactory::_shared_ci_symbols[vmSymbols::SID_LIMIT];


 159 #define WK_KLASS_DEFN(name, ignore_s, opt)                              \
 160   if (SystemDictionary::name() != NULL) \
 161     ciEnv::_##name = get_metadata(SystemDictionary::name())->as_instance_klass();
 162 
 163   WK_KLASSES_DO(WK_KLASS_DEFN)
 164 #undef WK_KLASS_DEFN
 165 
 166   for (int len = -1; len != _ci_metadata->length(); ) {
 167     len = _ci_metadata->length();
 168     for (int i2 = 0; i2 < len; i2++) {
 169       ciMetadata* obj = _ci_metadata->at(i2);
 170       assert (obj->is_metadata(), "what else would it be?");
 171       if (obj->is_loaded() && obj->is_instance_klass()) {
 172         obj->as_instance_klass()->compute_nonstatic_fields();
 173       }
 174     }
 175   }
 176 
 177   ciEnv::_unloaded_cisymbol = ciObjectFactory::get_symbol(vmSymbols::dummy_symbol());
 178   // Create dummy InstanceKlass and ObjArrayKlass object and assign them idents
 179   ciEnv::_unloaded_ciinstance_klass = new (_arena) ciInstanceKlass(ciEnv::_unloaded_cisymbol, NULL, NULL, NULL);
 180   init_ident_of(ciEnv::_unloaded_ciinstance_klass);
 181   ciEnv::_unloaded_ciobjarrayklass = new (_arena) ciObjArrayKlass(ciEnv::_unloaded_cisymbol, ciEnv::_unloaded_ciinstance_klass, 1);
 182   init_ident_of(ciEnv::_unloaded_ciobjarrayklass);
 183   assert(ciEnv::_unloaded_ciobjarrayklass->is_obj_array_klass(), "just checking");
 184 
 185   get_metadata(Universe::boolArrayKlassObj());
 186   get_metadata(Universe::charArrayKlassObj());
 187   get_metadata(Universe::singleArrayKlassObj());
 188   get_metadata(Universe::doubleArrayKlassObj());
 189   get_metadata(Universe::byteArrayKlassObj());
 190   get_metadata(Universe::shortArrayKlassObj());
 191   get_metadata(Universe::intArrayKlassObj());
 192   get_metadata(Universe::longArrayKlassObj());
 193 
 194 
 195 
 196   assert(_non_perm_count == 0, "no shared non-perm objects");
 197 
 198   // The shared_ident_limit is the first ident number that will
 199   // be used for non-shared objects.  That is, numbers less than


 343   } else if (o->is_typeArray()) {
 344     typeArrayHandle h_ta(THREAD, (typeArrayOop)o);
 345     return new (arena()) ciTypeArray(h_ta);
 346   }
 347 
 348   // The oop is of some type not supported by the compiler interface.
 349   ShouldNotReachHere();
 350   return NULL;
 351 }
 352 
 353 // ------------------------------------------------------------------
 354 // ciObjectFactory::create_new_metadata
 355 //
 356 // Create a new ciMetadata from a Metadata*.
 357 //
 358 // Implementation note: in order to keep Metadata live, an auxiliary ciObject
 359 // is used, which points to it's holder.
 360 ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) {
 361   EXCEPTION_CONTEXT;
 362 













 363   if (o->is_klass()) {
 364     Klass* k = (Klass*)o;
 365     if (k->is_instance_klass()) {
 366       return new (arena()) ciInstanceKlass(k);
 367     } else if (k->is_objArray_klass()) {
 368       return new (arena()) ciObjArrayKlass(k);
 369     } else if (k->is_typeArray_klass()) {
 370       return new (arena()) ciTypeArrayKlass(k);
 371     }
 372   } else if (o->is_method()) {
 373     methodHandle h_m(THREAD, (Method*)o);
 374     ciEnv *env = CURRENT_THREAD_ENV;
 375     ciInstanceKlass* holder = env->get_instance_klass(h_m()->method_holder());
 376     return new (arena()) ciMethod(h_m, holder);
 377   } else if (o->is_methodData()) {
 378     // Hold methodHandle alive - might not be necessary ???
 379     methodHandle h_m(THREAD, ((MethodData*)o)->method());
 380     return new (arena()) ciMethodData((MethodData*)o);
 381   }
 382 
 383   // The Metadata* is of some type not supported by the compiler interface.
 384   ShouldNotReachHere();
 385   return NULL;
 386 }
 387 































 388 
 389 //------------------------------------------------------------------
 390 // ciObjectFactory::get_unloaded_method
 391 //
 392 // Get the ciMethod representing an unloaded/unfound method.
 393 //
 394 // Implementation note: unloaded methods are currently stored in
 395 // an unordered array, requiring a linear-time lookup for each
 396 // unloaded method.  This may need to change.
 397 ciMethod* ciObjectFactory::get_unloaded_method(ciInstanceKlass* holder,
 398                                                ciSymbol*        name,
 399                                                ciSymbol*        signature,
 400                                                ciInstanceKlass* accessor) {
 401   ciSignature* that = NULL;
 402   for (int i = 0; i < _unloaded_methods->length(); i++) {
 403     ciMethod* entry = _unloaded_methods->at(i);
 404     if (entry->holder()->equals(holder) &&
 405         entry->name()->equals(name) &&
 406         entry->signature()->as_symbol()->equals(signature)) {
 407       // Short-circuit slow resolve.


 478     }
 479     int dimension = fd.dimension();
 480     assert(element_type != T_ARRAY, "unsuccessful decomposition");
 481     ciKlass* element_klass = NULL;
 482     if (element_type == T_OBJECT) {
 483       ciEnv *env = CURRENT_THREAD_ENV;
 484       ciSymbol* ci_name = env->get_symbol(fd.object_key());
 485       element_klass =
 486         env->get_klass_by_name(accessing_klass, ci_name, false)->as_instance_klass();
 487     } else {
 488       assert(dimension > 1, "one dimensional type arrays are always loaded.");
 489 
 490       // The type array itself takes care of one of the dimensions.
 491       dimension--;
 492 
 493       // The element klass is a TypeArrayKlass.
 494       element_klass = ciTypeArrayKlass::make(element_type);
 495     }
 496     new_klass = new (arena()) ciObjArrayKlass(name, element_klass, dimension);
 497   } else {
 498     jobject holder_handle = NULL;
 499     jobject loader_handle = NULL;
 500     jobject domain_handle = NULL;
 501     if (accessing_klass != NULL) {
 502       holder_handle = accessing_klass->holder_handle();
 503       loader_handle = accessing_klass->loader_handle();
 504       domain_handle = accessing_klass->protection_domain_handle();
 505     }
 506     new_klass = new (arena()) ciInstanceKlass(name, holder_handle, loader_handle, domain_handle);
 507   }
 508   init_ident_of(new_klass);
 509   _unloaded_klasses->append(new_klass);
 510 
 511   return new_klass;
 512 }
 513 
 514 
 515 //------------------------------------------------------------------
 516 // ciObjectFactory::get_unloaded_instance
 517 //
 518 // Get a ciInstance representing an as-yet undetermined instance of a given class.
 519 //
 520 ciInstance* ciObjectFactory::get_unloaded_instance(ciInstanceKlass* instance_klass) {
 521   for (int i=0; i<_unloaded_instances->length(); i++) {
 522     ciInstance* entry = _unloaded_instances->at(i);
 523     if (entry->klass()->equals(instance_klass)) {
 524       // We've found a match.
 525       return entry;
 526     }


< prev index next >