17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "ci/ciField.hpp" 27 #include "ci/ciInstance.hpp" 28 #include "ci/ciInstanceKlass.hpp" 29 #include "ci/ciUtilities.hpp" 30 #include "classfile/systemDictionary.hpp" 31 #include "memory/allocation.hpp" 32 #include "memory/allocation.inline.hpp" 33 #include "memory/resourceArea.hpp" 34 #include "oops/oop.inline.hpp" 35 #include "oops/fieldStreams.hpp" 36 #include "runtime/fieldDescriptor.hpp" 37 38 // ciInstanceKlass 39 // 40 // This class represents a Klass* in the HotSpot virtual machine 41 // whose Klass part in an InstanceKlass. 42 43 // ------------------------------------------------------------------ 44 // ciInstanceKlass::ciInstanceKlass 45 // 46 // Loaded instance klass. 47 ciInstanceKlass::ciInstanceKlass(Klass* k) : 48 ciKlass(k) 49 { 50 assert(get_Klass()->is_instance_klass(), "wrong type"); 51 assert(get_instanceKlass()->is_loaded(), "must be at least loaded"); 52 InstanceKlass* ik = get_instanceKlass(); 53 54 AccessFlags access_flags = ik->access_flags(); 55 _flags = ciFlags(access_flags); 56 _has_finalizer = access_flags.has_finalizer(); 57 _has_subklass = ik->subklass() != NULL; 58 _init_state = ik->init_state(); 59 _nonstatic_field_size = ik->nonstatic_field_size(); 60 _has_nonstatic_fields = ik->has_nonstatic_fields(); 61 _has_nonstatic_concrete_methods = ik->has_nonstatic_concrete_methods(); 62 _is_anonymous = ik->is_anonymous(); 63 _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields: 64 _has_injected_fields = -1; 65 _implementor = NULL; // we will fill these lazily 66 67 Thread *thread = Thread::current(); 68 if (ciObjectFactory::is_initialized()) { 69 _loader = JNIHandles::make_local(thread, ik->class_loader()); 70 _protection_domain = JNIHandles::make_local(thread, 71 ik->protection_domain()); 72 _is_shared = false; 73 } else { 74 Handle h_loader(thread, ik->class_loader()); 75 Handle h_protection_domain(thread, ik->protection_domain()); 76 _loader = JNIHandles::make_global(h_loader); 77 _protection_domain = JNIHandles::make_global(h_protection_domain); 78 _is_shared = true; 79 } 80 81 // Lazy fields get filled in only upon request. 82 _super = NULL; 83 _java_mirror = NULL; 84 85 if (is_shared()) { | 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "ci/ciField.hpp" 27 #include "ci/ciInstance.hpp" 28 #include "ci/ciInstanceKlass.hpp" 29 #include "ci/ciUtilities.hpp" 30 #include "classfile/systemDictionary.hpp" 31 #include "memory/allocation.hpp" 32 #include "memory/allocation.inline.hpp" 33 #include "memory/resourceArea.hpp" 34 #include "oops/oop.inline.hpp" 35 #include "oops/fieldStreams.hpp" 36 #include "runtime/fieldDescriptor.hpp" 37 #if INCLUDE_ALL_GCS 38 # include "gc/g1/g1SATBCardTableModRefBS.hpp" 39 #endif 40 41 // ciInstanceKlass 42 // 43 // This class represents a Klass* in the HotSpot virtual machine 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 66 67 // ------------------------------------------------------------------ 68 // ciInstanceKlass::ciInstanceKlass 69 // 70 // Loaded instance klass. 71 ciInstanceKlass::ciInstanceKlass(Klass* k) : 72 ciKlass(k) 73 { 74 assert(get_Klass()->is_instance_klass(), "wrong type"); 75 assert(get_instanceKlass()->is_loaded(), "must be at least loaded"); 76 InstanceKlass* ik = get_instanceKlass(); 77 78 AccessFlags access_flags = ik->access_flags(); 79 _flags = ciFlags(access_flags); 80 _has_finalizer = access_flags.has_finalizer(); 81 _has_subklass = ik->subklass() != NULL; 82 _init_state = ik->init_state(); 83 _nonstatic_field_size = ik->nonstatic_field_size(); 84 _has_nonstatic_fields = ik->has_nonstatic_fields(); 85 _has_nonstatic_concrete_methods = ik->has_nonstatic_concrete_methods(); 86 _is_anonymous = ik->is_anonymous(); 87 _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields: 88 _has_injected_fields = -1; 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 ciObject* h = CURRENT_ENV->get_object(holder); 100 } 101 102 Thread *thread = Thread::current(); 103 if (ciObjectFactory::is_initialized()) { 104 _loader = JNIHandles::make_local(thread, ik->class_loader()); 105 _protection_domain = JNIHandles::make_local(thread, 106 ik->protection_domain()); 107 _is_shared = false; 108 } else { 109 Handle h_loader(thread, ik->class_loader()); 110 Handle h_protection_domain(thread, ik->protection_domain()); 111 _loader = JNIHandles::make_global(h_loader); 112 _protection_domain = JNIHandles::make_global(h_protection_domain); 113 _is_shared = true; 114 } 115 116 // Lazy fields get filled in only upon request. 117 _super = NULL; 118 _java_mirror = NULL; 119 120 if (is_shared()) { |