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
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
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 void ciInstanceKlass::compute_shared_init_state() {
149 GUARDED_VM_ENTRY(
150 InstanceKlass* ik = get_instanceKlass();
151 _init_state = compute_init_state(ik);
152 )
153 }
154
155 InstanceKlass::ClassState ciInstanceKlass::compute_init_state(InstanceKlass* ik) {
156 ASSERT_IN_VM;
157 ciEnv* env = CURRENT_ENV;
158 if (env != nullptr && env->is_precompile()) {
159 return env->compute_init_state_for_precompiled(ik);
160 } else {
161 return ik->init_state();
162 }
163 }
164
165 // ------------------------------------------------------------------
166 // ciInstanceKlass::compute_shared_has_subklass
167 bool ciInstanceKlass::compute_shared_has_subklass() {
168 GUARDED_VM_ENTRY(
169 InstanceKlass* ik = get_instanceKlass();
170 _has_subklass = ik->subklass() != nullptr ? subklass_true : subklass_false;
171 return _has_subklass == subklass_true;
172 )
173 }
174
175 // ------------------------------------------------------------------
176 // ciInstanceKlass::loader
177 oop ciInstanceKlass::loader() {
178 ASSERT_IN_VM;
179 return JNIHandles::resolve(_loader);
180 }
181
182 // ------------------------------------------------------------------
183 // ciInstanceKlass::loader_handle
184 jobject ciInstanceKlass::loader_handle() {
320 if (name()->index_of_at(len+1, "/", 1) >= 0)
321 return false;
322
323 return true;
324 }
325
326 // ------------------------------------------------------------------
327 // ciInstanceKlass::print_impl
328 //
329 // Implementation of the print method.
330 void ciInstanceKlass::print_impl(outputStream* st) {
331 ciKlass::print_impl(st);
332 GUARDED_VM_ENTRY(st->print(" loader=" INTPTR_FORMAT, p2i(loader()));)
333 if (is_loaded()) {
334 st->print(" initialized=%s finalized=%s subklass=%s size=%d flags=",
335 bool_to_str(is_initialized()),
336 bool_to_str(has_finalizer()),
337 bool_to_str(has_subklass()),
338 layout_helper());
339
340 _flags.print_klass_flags(st);
341
342 if (_super) {
343 st->print(" super=");
344 _super->print_name_on(st);
345 }
346 if (_java_mirror) {
347 st->print(" mirror=PRESENT");
348 }
349 }
350 }
351
352 // ------------------------------------------------------------------
353 // ciInstanceKlass::super
354 //
355 // Get the superklass of this klass.
356 ciInstanceKlass* ciInstanceKlass::super() {
357 assert(is_loaded(), "must be loaded");
358 if (_super == nullptr && !is_java_lang_Object()) {
359 GUARDED_VM_ENTRY(
360 Klass* super_klass = get_instanceKlass()->super();
361 _super = CURRENT_ENV->get_instance_klass(super_klass);
362 )
363 }
364 return _super;
|