src/hotspot/share/ci/ciInstanceKlass.cpp
changeset 47887 e20d8f168bb6
parent 47551 4d034d861e13
child 48614 c39ae979ca35
equal deleted inserted replaced
47882:a93ce8f7bddb 47887:e20d8f168bb6
    32 #include "memory/allocation.inline.hpp"
    32 #include "memory/allocation.inline.hpp"
    33 #include "memory/resourceArea.hpp"
    33 #include "memory/resourceArea.hpp"
    34 #include "oops/oop.inline.hpp"
    34 #include "oops/oop.inline.hpp"
    35 #include "oops/fieldStreams.hpp"
    35 #include "oops/fieldStreams.hpp"
    36 #include "runtime/fieldDescriptor.hpp"
    36 #include "runtime/fieldDescriptor.hpp"
       
    37 #if INCLUDE_ALL_GCS
       
    38 # include "gc/g1/g1SATBCardTableModRefBS.hpp"
       
    39 #endif
    37 
    40 
    38 // ciInstanceKlass
    41 // ciInstanceKlass
    39 //
    42 //
    40 // This class represents a Klass* in the HotSpot virtual machine
    43 // This class represents a Klass* in the HotSpot virtual machine
    41 // whose Klass part in an InstanceKlass.
    44 // whose Klass part in an InstanceKlass.
       
    45 
       
    46 // ------------------------------------------------------------------
       
    47 // ensure_metadata_alive
       
    48 //
       
    49 // Ensure that the metadata wrapped by the ciMetadata is kept alive by GC.
       
    50 // This is primarily useful for metadata which is considered as weak roots
       
    51 // by the GC but need to be strong roots if reachable from a current compilation.
       
    52 // InstanceKlass are created for both weak and strong metadata.  Ensuring this metadata
       
    53 // alive covers the cases where there are weak roots without performance cost.
       
    54 //
       
    55 static void ensure_metadata_alive(oop metadata_holder) {
       
    56 #if INCLUDE_ALL_GCS
       
    57   if (!UseG1GC) {
       
    58     return;
       
    59   }
       
    60   if (metadata_holder != NULL) {
       
    61     G1SATBCardTableModRefBS::enqueue(metadata_holder);
       
    62   }
       
    63 #endif
       
    64 }
       
    65 
    42 
    66 
    43 // ------------------------------------------------------------------
    67 // ------------------------------------------------------------------
    44 // ciInstanceKlass::ciInstanceKlass
    68 // ciInstanceKlass::ciInstanceKlass
    45 //
    69 //
    46 // Loaded instance klass.
    70 // Loaded instance klass.
    61   _has_nonstatic_concrete_methods = ik->has_nonstatic_concrete_methods();
    85   _has_nonstatic_concrete_methods = ik->has_nonstatic_concrete_methods();
    62   _is_anonymous = ik->is_anonymous();
    86   _is_anonymous = ik->is_anonymous();
    63   _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields:
    87   _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields:
    64   _has_injected_fields = -1;
    88   _has_injected_fields = -1;
    65   _implementor = NULL; // we will fill these lazily
    89   _implementor = NULL; // we will fill these lazily
       
    90 
       
    91   oop holder = ik->klass_holder();
       
    92   ensure_metadata_alive(holder);
       
    93   if (ik->is_anonymous()) {
       
    94     // Though ciInstanceKlass records class loader oop, it's not enough to keep
       
    95     // VM anonymous classes alive (loader == NULL). Klass holder should be used instead.
       
    96     // It is enough to record a ciObject, since cached elements are never removed
       
    97     // during ciObjectFactory lifetime. ciObjectFactory itself is created for
       
    98     // every compilation and lives for the whole duration of the compilation.
       
    99     assert(holder != NULL, "holder of anonymous class is the mirror which is never null");
       
   100     (void)CURRENT_ENV->get_object(holder);
       
   101   }
    66 
   102 
    67   Thread *thread = Thread::current();
   103   Thread *thread = Thread::current();
    68   if (ciObjectFactory::is_initialized()) {
   104   if (ciObjectFactory::is_initialized()) {
    69     _loader = JNIHandles::make_local(thread, ik->class_loader());
   105     _loader = JNIHandles::make_local(thread, ik->class_loader());
    70     _protection_domain = JNIHandles::make_local(thread,
   106     _protection_domain = JNIHandles::make_local(thread,