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