< prev index next >

src/hotspot/share/code/dependencies.hpp

Print this page

 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, RC1, RM1) 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, RC1, RM1) is just {M1}, or
129     // perhaps a set of two {M1,M2}, and issue dependencies on this.
130 
131     // The set MM(CX, M1, RC1, RM1) 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 context class CX, the method M1,
136     // the resolved class RC1, and the resolved method RM1. M1 must be either inherited in CX

142     unique_implementor, // one unique implementor under CX
143 
144     // This dependency asserts that no instances of class or it's
145     // subclasses require finalization registration.
146     no_finalizable_subclasses,
147 
148     // This dependency asserts when the CallSite.target value changed.
149     call_site_target_value,
150 
151     TYPE_LIMIT
152   };
153   enum {
154     LG2_TYPE_LIMIT = 4,  // assert(TYPE_LIMIT <= (1<<LG2_TYPE_LIMIT))
155 
156     // handy categorizations of dependency types:
157     all_types           = ((1 << TYPE_LIMIT) - 1) & ((~0u) << FIRST_TYPE),
158 
159     non_klass_types     = (1 << call_site_target_value),
160     klass_types         = all_types & ~non_klass_types,
161 
162     non_ctxk_types      = (1 << evol_method) | (1 << call_site_target_value),
163     implicit_ctxk_types = 0,
164     explicit_ctxk_types = all_types & ~(non_ctxk_types | implicit_ctxk_types),
165 
166     max_arg_count = 4,   // current maximum number of arguments (incl. ctxk)
167 
168     // A "context type" is a class or interface that
169     // provides context for evaluating a dependency.
170     // When present, it is one of the arguments (dep_context_arg).
171     //
172     // If a dependency does not have a context type, there is a
173     // default context, depending on the type of the dependency.
174     // This bit signals that a default context has been compressed away.
175     default_context_type_bit = (1<<LG2_TYPE_LIMIT)


176   };
177 
178   static const char* dep_name(DepType dept);
179   static int         dep_args(DepType dept);
180 
181   static bool is_klass_type(           DepType dept) { return dept_in_mask(dept, klass_types        ); }
182 
183   static bool has_explicit_context_arg(DepType dept) { return dept_in_mask(dept, explicit_ctxk_types); }
184   static bool has_implicit_context_arg(DepType dept) { return dept_in_mask(dept, implicit_ctxk_types); }
185 


186   static int           dep_context_arg(DepType dept) { return has_explicit_context_arg(dept) ? 0 : -1; }
187   static int  dep_implicit_context_arg(DepType dept) { return has_implicit_context_arg(dept) ? 0 : -1; }
188 
189   static void check_valid_dependency_type(DepType dept);
190 
191  private:
192   // State for writing a new set of dependencies:
193   GrowableArray<int>*       _dep_seen;  // (seen[h->ident] & (1<<dept))
194   GrowableArray<ciBaseObject*>*  _deps[TYPE_LIMIT];
195 
196   static const char* _dep_name[TYPE_LIMIT];
197   static int         _dep_args[TYPE_LIMIT];
198 
199   static bool dept_in_mask(DepType dept, int mask) {
200     return (int)dept >= 0 && dept < TYPE_LIMIT && ((1<<dept) & mask) != 0;
201   }
202 
203   bool note_dep_seen(int dept, ciBaseObject* x) {
204     assert(dept < BitsPerInt, "oob");
205     int x_id = x->ident();

244     assert(is_concrete_klass(ctxk->as_instance_klass()), "must be concrete");
245   }
246   static void check_ctxk_abstract(ciKlass* ctxk) {
247     check_ctxk(ctxk);
248     assert(!is_concrete_klass(ctxk->as_instance_klass()), "must be abstract");
249   }
250   static void check_unique_method(ciKlass* ctxk, ciMethod* m) {
251     assert(!m->can_be_statically_bound(ctxk->as_instance_klass()) || ctxk->is_interface(), "redundant");
252   }
253   static void check_unique_implementor(ciInstanceKlass* ctxk, ciInstanceKlass* uniqk) {
254     assert(ctxk->implementor() == uniqk, "not a unique implementor");
255   }
256 
257   void assert_common_1(DepType dept, ciBaseObject* x);
258   void assert_common_2(DepType dept, ciBaseObject* x0, ciBaseObject* x1);
259   void assert_common_4(DepType dept, ciKlass* ctxk, ciBaseObject* x1, ciBaseObject* x2, ciBaseObject* x3);
260 
261  public:
262   // Adding assertions to a new dependency set at compile time:
263   void assert_evol_method(ciMethod* m);

264   void assert_leaf_type(ciKlass* ctxk);
265   void assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck);
266   void assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm, ciKlass* resolved_klass, ciMethod* resolved_method);
267   void assert_unique_implementor(ciInstanceKlass* ctxk, ciInstanceKlass* uniqk);
268   void assert_has_no_finalizable_subclasses(ciKlass* ctxk);
269   void assert_call_site_target_value(ciCallSite* call_site, ciMethodHandle* method_handle);
270 
271   // Define whether a given method or type is concrete.
272   // These methods define the term "concrete" as used in this module.
273   // For this module, an "abstract" class is one which is non-concrete.
274   //
275   // Future optimizations may allow some classes to remain
276   // non-concrete until their first instantiation, and allow some
277   // methods to remain non-concrete until their first invocation.
278   // In that case, there would be a middle ground between concrete
279   // and abstract (as defined by the Java language and VM).
280   static bool is_concrete_klass(Klass* k);    // k is instantiable
281   static bool is_concrete_method(Method* m, Klass* k);  // m is invocable
282   static Klass* find_finalizable_subclass(InstanceKlass* ik);
283 

288   // optimization opportunity.
289   //
290   // In order to prevent spurious assertions, query results must
291   // remain stable within any single ciEnv instance.  (I.e., they must
292   // not go back into the VM to get their value; they must cache the
293   // bit in the CI, either eagerly or lazily.)
294   static bool is_concrete_klass(ciInstanceKlass* k); // k appears instantiable
295   static bool has_finalizable_subclass(ciInstanceKlass* k);
296 
297   // As a general rule, it is OK to compile under the assumption that
298   // a given type or method is concrete, even if it at some future
299   // point becomes abstract.  So dependency checking is one-sided, in
300   // that it permits supposedly concrete classes or methods to turn up
301   // as really abstract.  (This shouldn't happen, except during class
302   // evolution, but that's the logic of the checking.)  However, if a
303   // supposedly abstract class or method suddenly becomes concrete, a
304   // dependency on it must fail.
305 
306   // Checking old assertions at run-time (in the VM only):
307   static Klass* check_evol_method(Method* m);

308   static Klass* check_leaf_type(InstanceKlass* ctxk);
309   static Klass* check_abstract_with_unique_concrete_subtype(InstanceKlass* ctxk, Klass* conck, NewKlassDepChange* changes = nullptr);
310   static Klass* check_unique_implementor(InstanceKlass* ctxk, Klass* uniqk, NewKlassDepChange* changes = nullptr);
311   static Klass* check_unique_concrete_method(InstanceKlass* ctxk, Method* uniqm, Klass* resolved_klass, Method* resolved_method, KlassDepChange* changes = nullptr);
312   static Klass* check_has_no_finalizable_subclasses(InstanceKlass* ctxk, NewKlassDepChange* changes = nullptr);
313   static Klass* check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes = nullptr);
314   // A returned Klass* is nullptr if the dependency assertion is still
315   // valid.  A non-nullptr Klass* is a 'witness' to the assertion
316   // failure, a point in the class hierarchy where the assertion has
317   // been proven false.  For example, if check_leaf_type returns
318   // non-nullptr, the value is a subtype of the supposed leaf type.  This
319   // witness value may be useful for logging the dependency failure.
320   // Note that, when a dependency fails, there may be several possible
321   // witnesses to the failure.  The value returned from the check_foo
322   // method is chosen arbitrarily.
323 
324   // The 'changes' value, if non-null, requests a limited spot-check
325   // near the indicated recent changes in the class hierarchy.
326   // It is used by DepStream::spot_check_dependency_at.
327 

 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, RC1, RM1) 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, RC1, RM1) is just {M1}, or
137     // perhaps a set of two {M1,M2}, and issue dependencies on this.
138 
139     // The set MM(CX, M1, RC1, RM1) 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 context class CX, the method M1,
144     // the resolved class RC1, and the resolved method RM1. M1 must be either inherited in CX

150     unique_implementor, // one unique implementor under CX
151 
152     // This dependency asserts that no instances of class or it's
153     // subclasses require finalization registration.
154     no_finalizable_subclasses,
155 
156     // This dependency asserts when the CallSite.target value changed.
157     call_site_target_value,
158 
159     TYPE_LIMIT
160   };
161   enum {
162     LG2_TYPE_LIMIT = 4,  // assert(TYPE_LIMIT <= (1<<LG2_TYPE_LIMIT))
163 
164     // handy categorizations of dependency types:
165     all_types           = ((1 << TYPE_LIMIT) - 1) & ((~0u) << FIRST_TYPE),
166 
167     non_klass_types     = (1 << call_site_target_value),
168     klass_types         = all_types & ~non_klass_types,
169 
170     non_ctxk_types      = (1 << evol_method) | (1 << mismatch_calling_convention) | (1 << call_site_target_value),
171     implicit_ctxk_types = 0,
172     explicit_ctxk_types = all_types & ~(non_ctxk_types | implicit_ctxk_types),
173 
174     max_arg_count = 4,   // current maximum number of arguments (incl. ctxk)
175 
176     // A "context type" is a class or interface that
177     // provides context for evaluating a dependency.
178     // When present, it is one of the arguments (dep_context_arg).
179     //
180     // If a dependency does not have a context type, there is a
181     // default context, depending on the type of the dependency.
182     // This bit signals that a default context has been compressed away.
183     default_context_type_bit = (1<<LG2_TYPE_LIMIT),
184 
185     method_types = (1 << evol_method) | (1 << mismatch_calling_convention),
186   };
187 
188   static const char* dep_name(DepType dept);
189   static int         dep_args(DepType dept);
190 
191   static bool is_klass_type(           DepType dept) { return dept_in_mask(dept, klass_types        ); }
192 
193   static bool has_explicit_context_arg(DepType dept) { return dept_in_mask(dept, explicit_ctxk_types); }
194   static bool has_implicit_context_arg(DepType dept) { return dept_in_mask(dept, implicit_ctxk_types); }
195 
196   static bool has_method_dep(DepType dept) { return dept_in_mask(dept, method_types); }
197 
198   static int           dep_context_arg(DepType dept) { return has_explicit_context_arg(dept) ? 0 : -1; }
199   static int  dep_implicit_context_arg(DepType dept) { return has_implicit_context_arg(dept) ? 0 : -1; }
200 
201   static void check_valid_dependency_type(DepType dept);
202 
203  private:
204   // State for writing a new set of dependencies:
205   GrowableArray<int>*       _dep_seen;  // (seen[h->ident] & (1<<dept))
206   GrowableArray<ciBaseObject*>*  _deps[TYPE_LIMIT];
207 
208   static const char* _dep_name[TYPE_LIMIT];
209   static int         _dep_args[TYPE_LIMIT];
210 
211   static bool dept_in_mask(DepType dept, int mask) {
212     return (int)dept >= 0 && dept < TYPE_LIMIT && ((1<<dept) & mask) != 0;
213   }
214 
215   bool note_dep_seen(int dept, ciBaseObject* x) {
216     assert(dept < BitsPerInt, "oob");
217     int x_id = x->ident();

256     assert(is_concrete_klass(ctxk->as_instance_klass()), "must be concrete");
257   }
258   static void check_ctxk_abstract(ciKlass* ctxk) {
259     check_ctxk(ctxk);
260     assert(!is_concrete_klass(ctxk->as_instance_klass()), "must be abstract");
261   }
262   static void check_unique_method(ciKlass* ctxk, ciMethod* m) {
263     assert(!m->can_be_statically_bound(ctxk->as_instance_klass()) || ctxk->is_interface(), "redundant");
264   }
265   static void check_unique_implementor(ciInstanceKlass* ctxk, ciInstanceKlass* uniqk) {
266     assert(ctxk->implementor() == uniqk, "not a unique implementor");
267   }
268 
269   void assert_common_1(DepType dept, ciBaseObject* x);
270   void assert_common_2(DepType dept, ciBaseObject* x0, ciBaseObject* x1);
271   void assert_common_4(DepType dept, ciKlass* ctxk, ciBaseObject* x1, ciBaseObject* x2, ciBaseObject* x3);
272 
273  public:
274   // Adding assertions to a new dependency set at compile time:
275   void assert_evol_method(ciMethod* m);
276   void assert_mismatch_calling_convention(ciMethod* m);
277   void assert_leaf_type(ciKlass* ctxk);
278   void assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck);
279   void assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm, ciKlass* resolved_klass, ciMethod* resolved_method);
280   void assert_unique_implementor(ciInstanceKlass* ctxk, ciInstanceKlass* uniqk);
281   void assert_has_no_finalizable_subclasses(ciKlass* ctxk);
282   void assert_call_site_target_value(ciCallSite* call_site, ciMethodHandle* method_handle);
283 
284   // Define whether a given method or type is concrete.
285   // These methods define the term "concrete" as used in this module.
286   // For this module, an "abstract" class is one which is non-concrete.
287   //
288   // Future optimizations may allow some classes to remain
289   // non-concrete until their first instantiation, and allow some
290   // methods to remain non-concrete until their first invocation.
291   // In that case, there would be a middle ground between concrete
292   // and abstract (as defined by the Java language and VM).
293   static bool is_concrete_klass(Klass* k);    // k is instantiable
294   static bool is_concrete_method(Method* m, Klass* k);  // m is invocable
295   static Klass* find_finalizable_subclass(InstanceKlass* ik);
296 

301   // optimization opportunity.
302   //
303   // In order to prevent spurious assertions, query results must
304   // remain stable within any single ciEnv instance.  (I.e., they must
305   // not go back into the VM to get their value; they must cache the
306   // bit in the CI, either eagerly or lazily.)
307   static bool is_concrete_klass(ciInstanceKlass* k); // k appears instantiable
308   static bool has_finalizable_subclass(ciInstanceKlass* k);
309 
310   // As a general rule, it is OK to compile under the assumption that
311   // a given type or method is concrete, even if it at some future
312   // point becomes abstract.  So dependency checking is one-sided, in
313   // that it permits supposedly concrete classes or methods to turn up
314   // as really abstract.  (This shouldn't happen, except during class
315   // evolution, but that's the logic of the checking.)  However, if a
316   // supposedly abstract class or method suddenly becomes concrete, a
317   // dependency on it must fail.
318 
319   // Checking old assertions at run-time (in the VM only):
320   static Klass* check_evol_method(Method* m);
321   static Klass* check_mismatch_calling_convention(Method* m);
322   static Klass* check_leaf_type(InstanceKlass* ctxk);
323   static Klass* check_abstract_with_unique_concrete_subtype(InstanceKlass* ctxk, Klass* conck, NewKlassDepChange* changes = nullptr);
324   static Klass* check_unique_implementor(InstanceKlass* ctxk, Klass* uniqk, NewKlassDepChange* changes = nullptr);
325   static Klass* check_unique_concrete_method(InstanceKlass* ctxk, Method* uniqm, Klass* resolved_klass, Method* resolved_method, KlassDepChange* changes = nullptr);
326   static Klass* check_has_no_finalizable_subclasses(InstanceKlass* ctxk, NewKlassDepChange* changes = nullptr);
327   static Klass* check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes = nullptr);
328   // A returned Klass* is nullptr if the dependency assertion is still
329   // valid.  A non-nullptr Klass* is a 'witness' to the assertion
330   // failure, a point in the class hierarchy where the assertion has
331   // been proven false.  For example, if check_leaf_type returns
332   // non-nullptr, the value is a subtype of the supposed leaf type.  This
333   // witness value may be useful for logging the dependency failure.
334   // Note that, when a dependency fails, there may be several possible
335   // witnesses to the failure.  The value returned from the check_foo
336   // method is chosen arbitrarily.
337 
338   // The 'changes' value, if non-null, requests a limited spot-check
339   // near the indicated recent changes in the class hierarchy.
340   // It is used by DepStream::spot_check_dependency_at.
341 
< prev index next >