97 // be converted to an assertion about its element type.
98 //
99 // Most dependencies are evaluated over a "context type" CX, which
100 // stands for the set Subtypes(CX) of every Java type that is a subtype*
101 // of CX. When the system loads a new class or interface N, it is
102 // responsible for re-evaluating changed dependencies whose context
103 // type now includes N, that is, all super types of N.
104 //
105 enum DepType {
106 // _type is initially set to -1, to prevent "already at end" assert
107 undefined_dependency = -1,
108
109 end_marker = 0,
110
111 // An 'evol' dependency simply notes that the contents of the
112 // method were used. If it evolves (is replaced), the nmethod
113 // must be recompiled. No other dependencies are implied.
114 evol_method,
115 FIRST_TYPE = evol_method,
116
117 // A context type CX is a leaf it if has no proper subtype.
118 leaf_type,
119
120 // An abstract class CX has exactly one concrete subtype CC.
121 abstract_with_unique_concrete_subtype,
122
123 // Given a method M1 and a context class CX, the set MM(CX, M1) of
124 // "concrete matching methods" in CX of M1 is the set of every
125 // concrete M2 for which it is possible to create an invokevirtual
126 // or invokeinterface call site that can reach either M1 or M2.
127 // That is, M1 and M2 share a name, signature, and vtable index.
128 // We wish to notice when the set MM(CX, M1) is just {M1}, or
129 // perhaps a set of two {M1,M2}, and issue dependencies on this.
130
131 // The set MM(CX, M1) can be computed by starting with any matching
132 // concrete M2 that is inherited into CX, and then walking the
133 // subtypes* of CX looking for concrete definitions.
134
135 // The parameters to this dependency are the method M1 and the
136 // context class CX. M1 must be either inherited in CX or defined
149 unique_implementor, // one unique implementor under CX
150
151 // This dependency asserts that no instances of class or it's
152 // subclasses require finalization registration.
153 no_finalizable_subclasses,
154
155 // This dependency asserts when the CallSite.target value changed.
156 call_site_target_value,
157
158 TYPE_LIMIT
159 };
160 enum {
161 LG2_TYPE_LIMIT = 4, // assert(TYPE_LIMIT <= (1<<LG2_TYPE_LIMIT))
162
163 // handy categorizations of dependency types:
164 all_types = ((1 << TYPE_LIMIT) - 1) & ((~0u) << FIRST_TYPE),
165
166 non_klass_types = (1 << call_site_target_value),
167 klass_types = all_types & ~non_klass_types,
168
169 non_ctxk_types = (1 << evol_method) | (1 << call_site_target_value),
170 implicit_ctxk_types = 0,
171 explicit_ctxk_types = all_types & ~(non_ctxk_types | implicit_ctxk_types),
172
173 max_arg_count = 4, // current maximum number of arguments (incl. ctxk)
174
175 // A "context type" is a class or interface that
176 // provides context for evaluating a dependency.
177 // When present, it is one of the arguments (dep_context_arg).
178 //
179 // If a dependency does not have a context type, there is a
180 // default context, depending on the type of the dependency.
181 // This bit signals that a default context has been compressed away.
182 default_context_type_bit = (1<<LG2_TYPE_LIMIT)
183 };
184
185 static const char* dep_name(DepType dept);
186 static int dep_args(DepType dept);
187
188 static bool is_klass_type( DepType dept) { return dept_in_mask(dept, klass_types ); }
189
190 static bool has_explicit_context_arg(DepType dept) { return dept_in_mask(dept, explicit_ctxk_types); }
191 static bool has_implicit_context_arg(DepType dept) { return dept_in_mask(dept, implicit_ctxk_types); }
192
193 static int dep_context_arg(DepType dept) { return has_explicit_context_arg(dept) ? 0 : -1; }
194 static int dep_implicit_context_arg(DepType dept) { return has_implicit_context_arg(dept) ? 0 : -1; }
195
196 static void check_valid_dependency_type(DepType dept);
197
198 #if INCLUDE_JVMCI
199 // A Metadata* or object value recorded in an OopRecorder
200 class DepValue {
201 private:
202 // Unique identifier of the value within the associated OopRecorder that
203 // encodes both the category of the value (0: invalid, positive: metadata, negative: object)
204 // and the index within a category specific array (metadata: index + 1, object: -(index + 1))
205 int _id;
206
207 public:
208 DepValue() : _id(0) {}
209 DepValue(OopRecorder* rec, Metadata* metadata, DepValue* candidate = nullptr) {
210 assert(candidate == nullptr || candidate->is_metadata(), "oops");
211 if (candidate != nullptr && candidate->as_metadata(rec) == metadata) {
212 _id = candidate->_id;
330 assert(is_concrete_klass(ctxk->as_instance_klass()), "must be concrete");
331 }
332 static void check_ctxk_abstract(ciKlass* ctxk) {
333 check_ctxk(ctxk);
334 assert(!is_concrete_klass(ctxk->as_instance_klass()), "must be abstract");
335 }
336 static void check_unique_method(ciKlass* ctxk, ciMethod* m) {
337 assert(!m->can_be_statically_bound(ctxk->as_instance_klass()) || ctxk->is_interface(), "redundant");
338 }
339 static void check_unique_implementor(ciInstanceKlass* ctxk, ciInstanceKlass* uniqk) {
340 assert(ctxk->implementor() == uniqk, "not a unique implementor");
341 }
342
343 void assert_common_1(DepType dept, ciBaseObject* x);
344 void assert_common_2(DepType dept, ciBaseObject* x0, ciBaseObject* x1);
345 void assert_common_4(DepType dept, ciKlass* ctxk, ciBaseObject* x1, ciBaseObject* x2, ciBaseObject* x3);
346
347 public:
348 // Adding assertions to a new dependency set at compile time:
349 void assert_evol_method(ciMethod* m);
350 void assert_leaf_type(ciKlass* ctxk);
351 void assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck);
352 void assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm);
353 void assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm, ciKlass* resolved_klass, ciMethod* resolved_method);
354 void assert_unique_implementor(ciInstanceKlass* ctxk, ciInstanceKlass* uniqk);
355 void assert_has_no_finalizable_subclasses(ciKlass* ctxk);
356 void assert_call_site_target_value(ciCallSite* call_site, ciMethodHandle* method_handle);
357 #if INCLUDE_JVMCI
358 private:
359 static void check_ctxk(Klass* ctxk) {
360 assert(ctxk->is_instance_klass(), "java types only");
361 }
362 static void check_ctxk_abstract(Klass* ctxk) {
363 check_ctxk(ctxk);
364 assert(ctxk->is_abstract(), "must be abstract");
365 }
366 static void check_unique_method(Klass* ctxk, Method* m) {
367 assert(!m->can_be_statically_bound(InstanceKlass::cast(ctxk)), "redundant");
368 }
369
403 // optimization opportunity.
404 //
405 // In order to prevent spurious assertions, query results must
406 // remain stable within any single ciEnv instance. (I.e., they must
407 // not go back into the VM to get their value; they must cache the
408 // bit in the CI, either eagerly or lazily.)
409 static bool is_concrete_klass(ciInstanceKlass* k); // k appears instantiable
410 static bool has_finalizable_subclass(ciInstanceKlass* k);
411
412 // As a general rule, it is OK to compile under the assumption that
413 // a given type or method is concrete, even if it at some future
414 // point becomes abstract. So dependency checking is one-sided, in
415 // that it permits supposedly concrete classes or methods to turn up
416 // as really abstract. (This shouldn't happen, except during class
417 // evolution, but that's the logic of the checking.) However, if a
418 // supposedly abstract class or method suddenly becomes concrete, a
419 // dependency on it must fail.
420
421 // Checking old assertions at run-time (in the VM only):
422 static Klass* check_evol_method(Method* m);
423 static Klass* check_leaf_type(InstanceKlass* ctxk);
424 static Klass* check_abstract_with_unique_concrete_subtype(InstanceKlass* ctxk, Klass* conck, NewKlassDepChange* changes = nullptr);
425 static Klass* check_unique_implementor(InstanceKlass* ctxk, Klass* uniqk, NewKlassDepChange* changes = nullptr);
426 static Klass* check_unique_concrete_method(InstanceKlass* ctxk, Method* uniqm, NewKlassDepChange* changes = nullptr);
427 static Klass* check_unique_concrete_method(InstanceKlass* ctxk, Method* uniqm, Klass* resolved_klass, Method* resolved_method, KlassDepChange* changes = nullptr);
428 static Klass* check_has_no_finalizable_subclasses(InstanceKlass* ctxk, NewKlassDepChange* changes = nullptr);
429 static Klass* check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes = nullptr);
430 // A returned Klass* is nullptr if the dependency assertion is still
431 // valid. A non-nullptr Klass* is a 'witness' to the assertion
432 // failure, a point in the class hierarchy where the assertion has
433 // been proven false. For example, if check_leaf_type returns
434 // non-nullptr, the value is a subtype of the supposed leaf type. This
435 // witness value may be useful for logging the dependency failure.
436 // Note that, when a dependency fails, there may be several possible
437 // witnesses to the failure. The value returned from the check_foo
438 // method is chosen arbitrarily.
439
440 // The 'changes' value, if non-null, requests a limited spot-check
441 // near the indicated recent changes in the class hierarchy.
442 // It is used by DepStream::spot_check_dependency_at.
|
97 // be converted to an assertion about its element type.
98 //
99 // Most dependencies are evaluated over a "context type" CX, which
100 // stands for the set Subtypes(CX) of every Java type that is a subtype*
101 // of CX. When the system loads a new class or interface N, it is
102 // responsible for re-evaluating changed dependencies whose context
103 // type now includes N, that is, all super types of N.
104 //
105 enum DepType {
106 // _type is initially set to -1, to prevent "already at end" assert
107 undefined_dependency = -1,
108
109 end_marker = 0,
110
111 // An 'evol' dependency simply notes that the contents of the
112 // method were used. If it evolves (is replaced), the nmethod
113 // must be recompiled. No other dependencies are implied.
114 evol_method,
115 FIRST_TYPE = evol_method,
116
117 // This dependency means that some argument of this method was
118 // assumed to be always passed in scalarized form. In case of
119 // a mismatch with two super methods (one assuming scalarized
120 // and one assuming non-scalarized), all callers of this method
121 // (via virtual calls) now need to be recompiled.
122 // See CompiledEntrySignature::compute_calling_conventions
123 mismatch_calling_convention,
124
125 // A context type CX is a leaf it if has no proper subtype.
126 leaf_type,
127
128 // An abstract class CX has exactly one concrete subtype CC.
129 abstract_with_unique_concrete_subtype,
130
131 // Given a method M1 and a context class CX, the set MM(CX, M1) of
132 // "concrete matching methods" in CX of M1 is the set of every
133 // concrete M2 for which it is possible to create an invokevirtual
134 // or invokeinterface call site that can reach either M1 or M2.
135 // That is, M1 and M2 share a name, signature, and vtable index.
136 // We wish to notice when the set MM(CX, M1) is just {M1}, or
137 // perhaps a set of two {M1,M2}, and issue dependencies on this.
138
139 // The set MM(CX, M1) can be computed by starting with any matching
140 // concrete M2 that is inherited into CX, and then walking the
141 // subtypes* of CX looking for concrete definitions.
142
143 // The parameters to this dependency are the method M1 and the
144 // context class CX. M1 must be either inherited in CX or defined
157 unique_implementor, // one unique implementor under CX
158
159 // This dependency asserts that no instances of class or it's
160 // subclasses require finalization registration.
161 no_finalizable_subclasses,
162
163 // This dependency asserts when the CallSite.target value changed.
164 call_site_target_value,
165
166 TYPE_LIMIT
167 };
168 enum {
169 LG2_TYPE_LIMIT = 4, // assert(TYPE_LIMIT <= (1<<LG2_TYPE_LIMIT))
170
171 // handy categorizations of dependency types:
172 all_types = ((1 << TYPE_LIMIT) - 1) & ((~0u) << FIRST_TYPE),
173
174 non_klass_types = (1 << call_site_target_value),
175 klass_types = all_types & ~non_klass_types,
176
177 non_ctxk_types = (1 << evol_method) | (1 << mismatch_calling_convention) | (1 << call_site_target_value),
178 implicit_ctxk_types = 0,
179 explicit_ctxk_types = all_types & ~(non_ctxk_types | implicit_ctxk_types),
180
181 max_arg_count = 4, // current maximum number of arguments (incl. ctxk)
182
183 // A "context type" is a class or interface that
184 // provides context for evaluating a dependency.
185 // When present, it is one of the arguments (dep_context_arg).
186 //
187 // If a dependency does not have a context type, there is a
188 // default context, depending on the type of the dependency.
189 // This bit signals that a default context has been compressed away.
190 default_context_type_bit = (1<<LG2_TYPE_LIMIT),
191
192 method_types = (1 << evol_method) | (1 << mismatch_calling_convention),
193 };
194
195 static const char* dep_name(DepType dept);
196 static int dep_args(DepType dept);
197
198 static bool is_klass_type( DepType dept) { return dept_in_mask(dept, klass_types ); }
199
200 static bool has_explicit_context_arg(DepType dept) { return dept_in_mask(dept, explicit_ctxk_types); }
201 static bool has_implicit_context_arg(DepType dept) { return dept_in_mask(dept, implicit_ctxk_types); }
202
203 static bool has_method_dep(DepType dept) { return dept_in_mask(dept, method_types); }
204
205 static int dep_context_arg(DepType dept) { return has_explicit_context_arg(dept) ? 0 : -1; }
206 static int dep_implicit_context_arg(DepType dept) { return has_implicit_context_arg(dept) ? 0 : -1; }
207
208 static void check_valid_dependency_type(DepType dept);
209
210 #if INCLUDE_JVMCI
211 // A Metadata* or object value recorded in an OopRecorder
212 class DepValue {
213 private:
214 // Unique identifier of the value within the associated OopRecorder that
215 // encodes both the category of the value (0: invalid, positive: metadata, negative: object)
216 // and the index within a category specific array (metadata: index + 1, object: -(index + 1))
217 int _id;
218
219 public:
220 DepValue() : _id(0) {}
221 DepValue(OopRecorder* rec, Metadata* metadata, DepValue* candidate = nullptr) {
222 assert(candidate == nullptr || candidate->is_metadata(), "oops");
223 if (candidate != nullptr && candidate->as_metadata(rec) == metadata) {
224 _id = candidate->_id;
342 assert(is_concrete_klass(ctxk->as_instance_klass()), "must be concrete");
343 }
344 static void check_ctxk_abstract(ciKlass* ctxk) {
345 check_ctxk(ctxk);
346 assert(!is_concrete_klass(ctxk->as_instance_klass()), "must be abstract");
347 }
348 static void check_unique_method(ciKlass* ctxk, ciMethod* m) {
349 assert(!m->can_be_statically_bound(ctxk->as_instance_klass()) || ctxk->is_interface(), "redundant");
350 }
351 static void check_unique_implementor(ciInstanceKlass* ctxk, ciInstanceKlass* uniqk) {
352 assert(ctxk->implementor() == uniqk, "not a unique implementor");
353 }
354
355 void assert_common_1(DepType dept, ciBaseObject* x);
356 void assert_common_2(DepType dept, ciBaseObject* x0, ciBaseObject* x1);
357 void assert_common_4(DepType dept, ciKlass* ctxk, ciBaseObject* x1, ciBaseObject* x2, ciBaseObject* x3);
358
359 public:
360 // Adding assertions to a new dependency set at compile time:
361 void assert_evol_method(ciMethod* m);
362 void assert_mismatch_calling_convention(ciMethod* m);
363 void assert_leaf_type(ciKlass* ctxk);
364 void assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck);
365 void assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm);
366 void assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm, ciKlass* resolved_klass, ciMethod* resolved_method);
367 void assert_unique_implementor(ciInstanceKlass* ctxk, ciInstanceKlass* uniqk);
368 void assert_has_no_finalizable_subclasses(ciKlass* ctxk);
369 void assert_call_site_target_value(ciCallSite* call_site, ciMethodHandle* method_handle);
370 #if INCLUDE_JVMCI
371 private:
372 static void check_ctxk(Klass* ctxk) {
373 assert(ctxk->is_instance_klass(), "java types only");
374 }
375 static void check_ctxk_abstract(Klass* ctxk) {
376 check_ctxk(ctxk);
377 assert(ctxk->is_abstract(), "must be abstract");
378 }
379 static void check_unique_method(Klass* ctxk, Method* m) {
380 assert(!m->can_be_statically_bound(InstanceKlass::cast(ctxk)), "redundant");
381 }
382
416 // optimization opportunity.
417 //
418 // In order to prevent spurious assertions, query results must
419 // remain stable within any single ciEnv instance. (I.e., they must
420 // not go back into the VM to get their value; they must cache the
421 // bit in the CI, either eagerly or lazily.)
422 static bool is_concrete_klass(ciInstanceKlass* k); // k appears instantiable
423 static bool has_finalizable_subclass(ciInstanceKlass* k);
424
425 // As a general rule, it is OK to compile under the assumption that
426 // a given type or method is concrete, even if it at some future
427 // point becomes abstract. So dependency checking is one-sided, in
428 // that it permits supposedly concrete classes or methods to turn up
429 // as really abstract. (This shouldn't happen, except during class
430 // evolution, but that's the logic of the checking.) However, if a
431 // supposedly abstract class or method suddenly becomes concrete, a
432 // dependency on it must fail.
433
434 // Checking old assertions at run-time (in the VM only):
435 static Klass* check_evol_method(Method* m);
436 static Klass* check_mismatch_calling_convention(Method* m);
437 static Klass* check_leaf_type(InstanceKlass* ctxk);
438 static Klass* check_abstract_with_unique_concrete_subtype(InstanceKlass* ctxk, Klass* conck, NewKlassDepChange* changes = nullptr);
439 static Klass* check_unique_implementor(InstanceKlass* ctxk, Klass* uniqk, NewKlassDepChange* changes = nullptr);
440 static Klass* check_unique_concrete_method(InstanceKlass* ctxk, Method* uniqm, NewKlassDepChange* changes = nullptr);
441 static Klass* check_unique_concrete_method(InstanceKlass* ctxk, Method* uniqm, Klass* resolved_klass, Method* resolved_method, KlassDepChange* changes = nullptr);
442 static Klass* check_has_no_finalizable_subclasses(InstanceKlass* ctxk, NewKlassDepChange* changes = nullptr);
443 static Klass* check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes = nullptr);
444 // A returned Klass* is nullptr if the dependency assertion is still
445 // valid. A non-nullptr Klass* is a 'witness' to the assertion
446 // failure, a point in the class hierarchy where the assertion has
447 // been proven false. For example, if check_leaf_type returns
448 // non-nullptr, the value is a subtype of the supposed leaf type. This
449 // witness value may be useful for logging the dependency failure.
450 // Note that, when a dependency fails, there may be several possible
451 // witnesses to the failure. The value returned from the check_foo
452 // method is chosen arbitrarily.
453
454 // The 'changes' value, if non-null, requests a limited spot-check
455 // near the indicated recent changes in the class hierarchy.
456 // It is used by DepStream::spot_check_dependency_at.
|