< prev index next >

src/hotspot/share/ci/ciInstanceKlass.cpp

Print this page

 36 #include "oops/klass.inline.hpp"
 37 #include "oops/oop.inline.hpp"
 38 #include "runtime/fieldDescriptor.inline.hpp"
 39 #include "runtime/handles.inline.hpp"
 40 #include "runtime/jniHandles.inline.hpp"
 41 
 42 // ciInstanceKlass
 43 //
 44 // This class represents a Klass* in the HotSpot virtual machine
 45 // whose Klass part in an InstanceKlass.
 46 
 47 
 48 // ------------------------------------------------------------------
 49 // ciInstanceKlass::ciInstanceKlass
 50 //
 51 // Loaded instance klass.
 52 ciInstanceKlass::ciInstanceKlass(Klass* k) :
 53   ciKlass(k)
 54 {
 55   assert(get_Klass()->is_instance_klass(), "wrong type");
 56   assert(get_instanceKlass()->is_loaded(), "must be at least loaded");
 57   InstanceKlass* ik = get_instanceKlass();
 58 








 59   AccessFlags access_flags = ik->access_flags();
 60   _flags = ciFlags(access_flags);
 61   _has_finalizer = ik->has_finalizer();
 62   _has_subklass = flags().is_final() ? subklass_false : subklass_unknown;
 63   _init_state = ik->init_state();
 64   _has_nonstatic_fields = ik->has_nonstatic_fields();
 65   _has_nonstatic_concrete_methods = ik->has_nonstatic_concrete_methods();
 66   _is_hidden = ik->is_hidden();
 67   _is_record = ik->is_record();
 68   _trust_final_fields = ik->trust_final_fields();
 69   _nonstatic_fields = nullptr; // initialized lazily by compute_nonstatic_fields:
 70   _has_injected_fields = -1;
 71   _implementor = nullptr; // we will fill these lazily
 72   _transitive_interfaces = nullptr;
 73 
 74   // Ensure that the metadata wrapped by the ciMetadata is kept alive by GC.
 75   // This is primarily useful for metadata which is considered as weak roots
 76   // by the GC but need to be strong roots if reachable from a current compilation.
 77   // InstanceKlass are created for both weak and strong metadata.  Ensuring this metadata
 78   // alive covers the cases where there are weak roots without performance cost.
 79   oop holder = ik->klass_holder();
 80   if (ik->class_loader_data()->has_class_mirror_holder()) {
 81     // Though ciInstanceKlass records class loader oop, it's not enough to keep
 82     // non-strong hidden classes alive (loader == nullptr). Klass holder should
 83     // be used instead. It is enough to record a ciObject, since cached elements are never removed

120 {
121   assert(name->char_at(0) != JVM_SIGNATURE_ARRAY, "not an instance klass");
122   _init_state = (InstanceKlass::ClassState)0;
123   _has_nonstatic_fields = false;
124   _nonstatic_fields = nullptr;
125   _has_injected_fields = -1;
126   _is_hidden = false;
127   _is_record = false;
128   _loader = loader;
129   _is_shared = false;
130   _super = nullptr;
131   _java_mirror = nullptr;
132   _field_cache = nullptr;
133   _has_trusted_loader = compute_has_trusted_loader();
134 }
135 
136 
137 
138 // ------------------------------------------------------------------
139 // ciInstanceKlass::compute_shared_is_initialized
140 void ciInstanceKlass::compute_shared_init_state() {
141   GUARDED_VM_ENTRY(
142     InstanceKlass* ik = get_instanceKlass();
143     _init_state = ik->init_state();

144   )
145 }
146 










147 // ------------------------------------------------------------------
148 // ciInstanceKlass::compute_shared_has_subklass
149 bool ciInstanceKlass::compute_shared_has_subklass() {
150   GUARDED_VM_ENTRY(
151     InstanceKlass* ik = get_instanceKlass();
152     _has_subklass = ik->subklass() != nullptr ? subklass_true : subklass_false;
153     return _has_subklass == subklass_true;
154   )
155 }
156 
157 // ------------------------------------------------------------------
158 // ciInstanceKlass::loader
159 oop ciInstanceKlass::loader() {
160   ASSERT_IN_VM;
161   return JNIHandles::resolve(_loader);
162 }
163 
164 // ------------------------------------------------------------------
165 // ciInstanceKlass::loader_handle
166 jobject ciInstanceKlass::loader_handle() {

302   if (name()->index_of_at(len+1, "/", 1) >= 0)
303     return false;
304 
305   return true;
306 }
307 
308 // ------------------------------------------------------------------
309 // ciInstanceKlass::print_impl
310 //
311 // Implementation of the print method.
312 void ciInstanceKlass::print_impl(outputStream* st) {
313   ciKlass::print_impl(st);
314   GUARDED_VM_ENTRY(st->print(" loader=" INTPTR_FORMAT, p2i(loader()));)
315   if (is_loaded()) {
316     st->print(" initialized=%s finalized=%s subklass=%s size=%d flags=",
317               bool_to_str(is_initialized()),
318               bool_to_str(has_finalizer()),
319               bool_to_str(has_subklass()),
320               layout_helper());
321 
322     _flags.print_klass_flags();
323 
324     if (_super) {
325       st->print(" super=");
326       _super->print_name();
327     }
328     if (_java_mirror) {
329       st->print(" mirror=PRESENT");
330     }
331   }
332 }
333 
334 // ------------------------------------------------------------------
335 // ciInstanceKlass::super
336 //
337 // Get the superklass of this klass.
338 ciInstanceKlass* ciInstanceKlass::super() {
339   assert(is_loaded(), "must be loaded");
340   if (_super == nullptr && !is_java_lang_Object()) {
341     GUARDED_VM_ENTRY(
342       Klass* super_klass = get_instanceKlass()->super();
343       _super = CURRENT_ENV->get_instance_klass(super_klass);
344     )
345   }
346   return _super;

 36 #include "oops/klass.inline.hpp"
 37 #include "oops/oop.inline.hpp"
 38 #include "runtime/fieldDescriptor.inline.hpp"
 39 #include "runtime/handles.inline.hpp"
 40 #include "runtime/jniHandles.inline.hpp"
 41 
 42 // ciInstanceKlass
 43 //
 44 // This class represents a Klass* in the HotSpot virtual machine
 45 // whose Klass part in an InstanceKlass.
 46 
 47 
 48 // ------------------------------------------------------------------
 49 // ciInstanceKlass::ciInstanceKlass
 50 //
 51 // Loaded instance klass.
 52 ciInstanceKlass::ciInstanceKlass(Klass* k) :
 53   ciKlass(k)
 54 {
 55   assert(get_Klass()->is_instance_klass(), "wrong type");
 56 
 57   InstanceKlass* ik = get_instanceKlass();
 58 
 59 #ifdef ASSERT
 60   if (!ik->is_loaded()) {
 61     ResourceMark rm;
 62     ik->print_on(tty);
 63     assert(false, "must be at least loaded: %s", ik->name()->as_C_string());
 64   }
 65 #endif // ASSERT
 66 
 67   AccessFlags access_flags = ik->access_flags();
 68   _flags = ciFlags(access_flags);
 69   _has_finalizer = ik->has_finalizer();
 70   _has_subklass = flags().is_final() ? subklass_false : subklass_unknown;
 71   _init_state = compute_init_state(ik);
 72   _has_nonstatic_fields = ik->has_nonstatic_fields();
 73   _has_nonstatic_concrete_methods = ik->has_nonstatic_concrete_methods();
 74   _is_hidden = ik->is_hidden();
 75   _is_record = ik->is_record();
 76   _trust_final_fields = ik->trust_final_fields();
 77   _nonstatic_fields = nullptr; // initialized lazily by compute_nonstatic_fields:
 78   _has_injected_fields = -1;
 79   _implementor = nullptr; // we will fill these lazily
 80   _transitive_interfaces = nullptr;
 81 
 82   // Ensure that the metadata wrapped by the ciMetadata is kept alive by GC.
 83   // This is primarily useful for metadata which is considered as weak roots
 84   // by the GC but need to be strong roots if reachable from a current compilation.
 85   // InstanceKlass are created for both weak and strong metadata.  Ensuring this metadata
 86   // alive covers the cases where there are weak roots without performance cost.
 87   oop holder = ik->klass_holder();
 88   if (ik->class_loader_data()->has_class_mirror_holder()) {
 89     // Though ciInstanceKlass records class loader oop, it's not enough to keep
 90     // non-strong hidden classes alive (loader == nullptr). Klass holder should
 91     // be used instead. It is enough to record a ciObject, since cached elements are never removed

128 {
129   assert(name->char_at(0) != JVM_SIGNATURE_ARRAY, "not an instance klass");
130   _init_state = (InstanceKlass::ClassState)0;
131   _has_nonstatic_fields = false;
132   _nonstatic_fields = nullptr;
133   _has_injected_fields = -1;
134   _is_hidden = false;
135   _is_record = false;
136   _loader = loader;
137   _is_shared = false;
138   _super = nullptr;
139   _java_mirror = nullptr;
140   _field_cache = nullptr;
141   _has_trusted_loader = compute_has_trusted_loader();
142 }
143 
144 
145 
146 // ------------------------------------------------------------------
147 // ciInstanceKlass::compute_shared_is_initialized
148 InstanceKlass::ClassState ciInstanceKlass::compute_shared_init_state() {
149   GUARDED_VM_ENTRY(
150     InstanceKlass* ik = get_instanceKlass();
151     _init_state = compute_init_state(ik);
152     return _init_state;
153   )
154 }
155 
156 InstanceKlass::ClassState ciInstanceKlass::compute_init_state(InstanceKlass* ik) {
157   ASSERT_IN_VM;
158   ciEnv* env = CURRENT_ENV;
159   if (env != nullptr && env->is_aot_compile()) {
160     return env->compute_init_state_for_aot_compile(ik);
161   } else {
162     return ik->init_state();
163   }
164 }
165 
166 // ------------------------------------------------------------------
167 // ciInstanceKlass::compute_shared_has_subklass
168 bool ciInstanceKlass::compute_shared_has_subklass() {
169   GUARDED_VM_ENTRY(
170     InstanceKlass* ik = get_instanceKlass();
171     _has_subklass = ik->subklass() != nullptr ? subklass_true : subklass_false;
172     return _has_subklass == subklass_true;
173   )
174 }
175 
176 // ------------------------------------------------------------------
177 // ciInstanceKlass::loader
178 oop ciInstanceKlass::loader() {
179   ASSERT_IN_VM;
180   return JNIHandles::resolve(_loader);
181 }
182 
183 // ------------------------------------------------------------------
184 // ciInstanceKlass::loader_handle
185 jobject ciInstanceKlass::loader_handle() {

321   if (name()->index_of_at(len+1, "/", 1) >= 0)
322     return false;
323 
324   return true;
325 }
326 
327 // ------------------------------------------------------------------
328 // ciInstanceKlass::print_impl
329 //
330 // Implementation of the print method.
331 void ciInstanceKlass::print_impl(outputStream* st) {
332   ciKlass::print_impl(st);
333   GUARDED_VM_ENTRY(st->print(" loader=" INTPTR_FORMAT, p2i(loader()));)
334   if (is_loaded()) {
335     st->print(" initialized=%s finalized=%s subklass=%s size=%d flags=",
336               bool_to_str(is_initialized()),
337               bool_to_str(has_finalizer()),
338               bool_to_str(has_subklass()),
339               layout_helper());
340 
341     _flags.print_klass_flags(st);
342 
343     if (_super) {
344       st->print(" super=");
345       _super->print_name_on(st);
346     }
347     if (_java_mirror) {
348       st->print(" mirror=PRESENT");
349     }
350   }
351 }
352 
353 // ------------------------------------------------------------------
354 // ciInstanceKlass::super
355 //
356 // Get the superklass of this klass.
357 ciInstanceKlass* ciInstanceKlass::super() {
358   assert(is_loaded(), "must be loaded");
359   if (_super == nullptr && !is_java_lang_Object()) {
360     GUARDED_VM_ENTRY(
361       Klass* super_klass = get_instanceKlass()->super();
362       _super = CURRENT_ENV->get_instance_klass(super_klass);
363     )
364   }
365   return _super;
< prev index next >