185 //
186 // If a dependency does not have a context type, there is a
187 // default context, depending on the type of the dependency.
188 // This bit signals that a default context has been compressed away.
189 default_context_type_bit = (1<<LG2_TYPE_LIMIT)
190 };
191
192 static const char* dep_name(DepType dept);
193 static int dep_args(DepType dept);
194
195 static bool is_klass_type( DepType dept) { return dept_in_mask(dept, klass_types ); }
196
197 static bool has_explicit_context_arg(DepType dept) { return dept_in_mask(dept, explicit_ctxk_types); }
198 static bool has_implicit_context_arg(DepType dept) { return dept_in_mask(dept, implicit_ctxk_types); }
199
200 static int dep_context_arg(DepType dept) { return has_explicit_context_arg(dept) ? 0 : -1; }
201 static int dep_implicit_context_arg(DepType dept) { return has_implicit_context_arg(dept) ? 0 : -1; }
202
203 static void check_valid_dependency_type(DepType dept);
204
205 private:
206 // State for writing a new set of dependencies:
207 GrowableArray<int>* _dep_seen; // (seen[h->ident] & (1<<dept))
208 GrowableArray<ciBaseObject*>* _deps[TYPE_LIMIT];
209
210 static const char* _dep_name[TYPE_LIMIT];
211 static int _dep_args[TYPE_LIMIT];
212
213 static bool dept_in_mask(DepType dept, int mask) {
214 return (int)dept >= 0 && dept < TYPE_LIMIT && ((1<<dept) & mask) != 0;
215 }
216
217 bool note_dep_seen(int dept, ciBaseObject* x) {
218 assert(dept < BitsPerInt, "oob");
219 int x_id = x->ident();
220 assert(_dep_seen != NULL, "deps must be writable");
221 int seen = _dep_seen->at_grow(x_id, 0);
222 _dep_seen->at_put(x_id, seen | (1<<dept));
223 // return true if we've already seen dept/x
224 return (seen & (1<<dept)) != 0;
225 }
226
227 bool maybe_merge_ctxk(GrowableArray<ciBaseObject*>* deps,
228 int ctxk_i, ciKlass* ctxk);
229
230 void sort_all_deps();
231 size_t estimate_size_in_bytes();
232
233 // Initialize _deps, etc.
234 void initialize(ciEnv* env);
235
236 // State for making a new set of dependencies:
237 OopRecorder* _oop_recorder;
238
239 // Logging support
240 CompileLog* _log;
241
242 address _content_bytes; // everything but the oop references, encoded
243 size_t _size_in_bytes;
244
245 public:
246 // Make a new empty dependencies set.
247 Dependencies(ciEnv* env) {
248 initialize(env);
249 }
250
251 private:
252 // Check for a valid context type.
253 // Enforce the restriction against array types.
254 static void check_ctxk(ciKlass* ctxk) {
255 assert(ctxk->is_instance_klass(), "java types only");
256 }
257 static void check_ctxk_concrete(ciKlass* ctxk) {
258 assert(is_concrete_klass(ctxk->as_instance_klass()), "must be concrete");
259 }
260 static void check_ctxk_abstract(ciKlass* ctxk) {
261 check_ctxk(ctxk);
262 assert(!is_concrete_klass(ctxk->as_instance_klass()), "must be abstract");
263 }
264
265 void assert_common_1(DepType dept, ciBaseObject* x);
266 void assert_common_2(DepType dept, ciBaseObject* x0, ciBaseObject* x1);
267 void assert_common_3(DepType dept, ciKlass* ctxk, ciBaseObject* x1, ciBaseObject* x2);
268
269 public:
270 // Adding assertions to a new dependency set at compile time:
271 void assert_evol_method(ciMethod* m);
272 void assert_leaf_type(ciKlass* ctxk);
273 void assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck);
274 void assert_abstract_with_no_concrete_subtype(ciKlass* ctxk);
275 void assert_concrete_with_no_concrete_subtype(ciKlass* ctxk);
276 void assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm);
277 void assert_abstract_with_exclusive_concrete_subtypes(ciKlass* ctxk, ciKlass* k1, ciKlass* k2);
278 void assert_exclusive_concrete_methods(ciKlass* ctxk, ciMethod* m1, ciMethod* m2);
279 void assert_has_no_finalizable_subclasses(ciKlass* ctxk);
280 void assert_call_site_target_value(ciCallSite* call_site, ciMethodHandle* method_handle);
281
282 // Define whether a given method or type is concrete.
283 // These methods define the term "concrete" as used in this module.
284 // For this module, an "abstract" class is one which is non-concrete.
285 //
286 // Future optimizations may allow some classes to remain
287 // non-concrete until their first instantiation, and allow some
288 // methods to remain non-concrete until their first invocation.
289 // In that case, there would be a middle ground between concrete
290 // and abstract (as defined by the Java language and VM).
291 static bool is_concrete_klass(Klass* k); // k is instantiable
292 static bool is_concrete_method(Method* m, Klass* k); // m is invocable
293 static Klass* find_finalizable_subclass(Klass* k);
294
295 // These versions of the concreteness queries work through the CI.
296 // The CI versions are allowed to skew sometimes from the VM
297 // (oop-based) versions. The cost of such a difference is a
298 // (safely) aborted compilation, or a deoptimization, or a missed
299 // optimization opportunity.
300 //
301 // In order to prevent spurious assertions, query results must
405 bool _is_oop;
406 bool _valid;
407 void* _value;
408 public:
409 DepArgument() : _is_oop(false), _value(NULL), _valid(false) {}
410 DepArgument(oop v): _is_oop(true), _value(v), _valid(true) {}
411 DepArgument(Metadata* v): _is_oop(false), _value(v), _valid(true) {}
412
413 bool is_null() const { return _value == NULL; }
414 bool is_oop() const { return _is_oop; }
415 bool is_metadata() const { return !_is_oop; }
416 bool is_klass() const { return is_metadata() && metadata_value()->is_klass(); }
417 bool is_method() const { return is_metadata() && metadata_value()->is_method(); }
418
419 oop oop_value() const { assert(_is_oop && _valid, "must be"); return (oop) _value; }
420 Metadata* metadata_value() const { assert(!_is_oop && _valid, "must be"); return (Metadata*) _value; }
421 };
422
423 static void print_dependency(DepType dept,
424 GrowableArray<DepArgument>* args,
425 Klass* witness = NULL);
426
427 private:
428 // helper for encoding common context types as zero:
429 static ciKlass* ctxk_encoded_as_null(DepType dept, ciBaseObject* x);
430
431 static Klass* ctxk_encoded_as_null(DepType dept, Metadata* x);
432
433 static void write_dependency_to(CompileLog* log,
434 DepType dept,
435 GrowableArray<ciBaseObject*>* args,
436 Klass* witness = NULL);
437 static void write_dependency_to(CompileLog* log,
438 DepType dept,
439 GrowableArray<DepArgument>* args,
440 Klass* witness = NULL);
441 static void write_dependency_to(xmlStream* xtty,
442 DepType dept,
443 GrowableArray<DepArgument>* args,
444 Klass* witness = NULL);
445 public:
517 Metadata* x = argument(i);
518 assert(x->is_klass(), "type");
519 return (Klass*) x;
520 }
521
522 // The point of the whole exercise: Is this dep still OK?
523 Klass* check_dependency() {
524 Klass* result = check_klass_dependency(NULL);
525 if (result != NULL) return result;
526 return check_call_site_dependency(NULL);
527 }
528
529 // A lighter version: Checks only around recent changes in a class
530 // hierarchy. (See Universe::flush_dependents_on.)
531 Klass* spot_check_dependency_at(DepChange& changes);
532
533 // Log the current dependency to xtty or compilation log.
534 void log_dependency(Klass* witness = NULL);
535
536 // Print the current dependency to tty.
537 void print_dependency(Klass* witness = NULL, bool verbose = false);
538 };
539 friend class Dependencies::DepStream;
540
541 static void print_statistics() PRODUCT_RETURN;
542 };
543
544
545 class DependencySignature : public ResourceObj {
546 private:
547 int _args_count;
548 uintptr_t _argument_hash[Dependencies::max_arg_count];
549 Dependencies::DepType _type;
550
551 public:
552 DependencySignature(Dependencies::DepStream& dep) {
553 _args_count = dep.argument_count();
554 _type = dep.type();
555 for (int i = 0; i < _args_count; i++) {
556 _argument_hash[i] = dep.get_identifier(i);
557 }
|
185 //
186 // If a dependency does not have a context type, there is a
187 // default context, depending on the type of the dependency.
188 // This bit signals that a default context has been compressed away.
189 default_context_type_bit = (1<<LG2_TYPE_LIMIT)
190 };
191
192 static const char* dep_name(DepType dept);
193 static int dep_args(DepType dept);
194
195 static bool is_klass_type( DepType dept) { return dept_in_mask(dept, klass_types ); }
196
197 static bool has_explicit_context_arg(DepType dept) { return dept_in_mask(dept, explicit_ctxk_types); }
198 static bool has_implicit_context_arg(DepType dept) { return dept_in_mask(dept, implicit_ctxk_types); }
199
200 static int dep_context_arg(DepType dept) { return has_explicit_context_arg(dept) ? 0 : -1; }
201 static int dep_implicit_context_arg(DepType dept) { return has_implicit_context_arg(dept) ? 0 : -1; }
202
203 static void check_valid_dependency_type(DepType dept);
204
205 #if INCLUDE_JVMCI
206 // A Metadata* or object value recorded in an OopRecorder
207 class DepValue VALUE_OBJ_CLASS_SPEC {
208 private:
209 // Unique identifier of the value within the associated OopRecorder that
210 // encodes both the category of the value (0: invalid, positive: metadata, negative: object)
211 // and the index within a category specific array (metadata: index + 1, object: -(index + 1))
212 int _id;
213
214 public:
215 DepValue() : _id(0) {}
216 DepValue(OopRecorder* rec, Metadata* metadata, DepValue* candidate = NULL) {
217 assert(candidate == NULL || candidate->is_metadata(), "oops");
218 if (candidate != NULL && candidate->as_metadata(rec) == metadata) {
219 _id = candidate->_id;
220 } else {
221 _id = rec->find_index(metadata) + 1;
222 }
223 }
224 DepValue(OopRecorder* rec, jobject obj, DepValue* candidate = NULL) {
225 assert(candidate == NULL || candidate->is_object(), "oops");
226 if (candidate != NULL && candidate->as_object(rec) == obj) {
227 _id = candidate->_id;
228 } else {
229 _id = -(rec->find_index(obj) + 1);
230 }
231 }
232
233 // Used to sort values in ascending order of index() with metadata values preceding object values
234 int sort_key() const { return -_id; }
235
236 bool operator == (const DepValue& other) const { return other._id == _id; }
237
238 bool is_valid() const { return _id != 0; }
239 int index() const { assert(is_valid(), "oops"); return _id < 0 ? -(_id + 1) : _id - 1; }
240 bool is_metadata() const { assert(is_valid(), "oops"); return _id > 0; }
241 bool is_object() const { assert(is_valid(), "oops"); return _id < 0; }
242
243 Metadata* as_metadata(OopRecorder* rec) const { assert(is_metadata(), "oops"); return rec->metadata_at(index()); }
244 Klass* as_klass(OopRecorder* rec) const { assert(as_metadata(rec)->is_klass(), "oops"); return (Klass*) as_metadata(rec); }
245 Method* as_method(OopRecorder* rec) const { assert(as_metadata(rec)->is_method(), "oops"); return (Method*) as_metadata(rec); }
246 jobject as_object(OopRecorder* rec) const { assert(is_object(), "oops"); return rec->oop_at(index()); }
247 };
248 #endif // INCLUDE_JVMCI
249
250 private:
251 // State for writing a new set of dependencies:
252 GrowableArray<int>* _dep_seen; // (seen[h->ident] & (1<<dept))
253 GrowableArray<ciBaseObject*>* _deps[TYPE_LIMIT];
254 #if INCLUDE_JVMCI
255 bool _using_dep_values;
256 GrowableArray<DepValue>* _dep_values[TYPE_LIMIT];
257 #endif
258
259 static const char* _dep_name[TYPE_LIMIT];
260 static int _dep_args[TYPE_LIMIT];
261
262 static bool dept_in_mask(DepType dept, int mask) {
263 return (int)dept >= 0 && dept < TYPE_LIMIT && ((1<<dept) & mask) != 0;
264 }
265
266 bool note_dep_seen(int dept, ciBaseObject* x) {
267 assert(dept < BitsPerInt, "oob");
268 int x_id = x->ident();
269 assert(_dep_seen != NULL, "deps must be writable");
270 int seen = _dep_seen->at_grow(x_id, 0);
271 _dep_seen->at_put(x_id, seen | (1<<dept));
272 // return true if we've already seen dept/x
273 return (seen & (1<<dept)) != 0;
274 }
275
276 #if INCLUDE_JVMCI
277 bool note_dep_seen(int dept, DepValue x) {
278 assert(dept < BitsPerInt, "oops");
279 // place metadata deps at even indexes, object deps at odd indexes
280 int x_id = x.is_metadata() ? x.index() * 2 : (x.index() * 2) + 1;
281 assert(_dep_seen != NULL, "deps must be writable");
282 int seen = _dep_seen->at_grow(x_id, 0);
283 _dep_seen->at_put(x_id, seen | (1<<dept));
284 // return true if we've already seen dept/x
285 return (seen & (1<<dept)) != 0;
286 }
287 #endif
288
289 bool maybe_merge_ctxk(GrowableArray<ciBaseObject*>* deps,
290 int ctxk_i, ciKlass* ctxk);
291 #if INCLUDE_JVMCI
292 bool maybe_merge_ctxk(GrowableArray<DepValue>* deps,
293 int ctxk_i, DepValue ctxk);
294 #endif
295
296 void sort_all_deps();
297 size_t estimate_size_in_bytes();
298
299 // Initialize _deps, etc.
300 void initialize(ciEnv* env);
301
302 // State for making a new set of dependencies:
303 OopRecorder* _oop_recorder;
304
305 // Logging support
306 CompileLog* _log;
307
308 address _content_bytes; // everything but the oop references, encoded
309 size_t _size_in_bytes;
310
311 public:
312 // Make a new empty dependencies set.
313 Dependencies(ciEnv* env) {
314 initialize(env);
315 }
316 #if INCLUDE_JVMCI
317 Dependencies(Arena* arena, OopRecorder* oop_recorder, CompileLog* log);
318 #endif
319
320 private:
321 // Check for a valid context type.
322 // Enforce the restriction against array types.
323 static void check_ctxk(ciKlass* ctxk) {
324 assert(ctxk->is_instance_klass(), "java types only");
325 }
326 static void check_ctxk_concrete(ciKlass* ctxk) {
327 assert(is_concrete_klass(ctxk->as_instance_klass()), "must be concrete");
328 }
329 static void check_ctxk_abstract(ciKlass* ctxk) {
330 check_ctxk(ctxk);
331 assert(!is_concrete_klass(ctxk->as_instance_klass()), "must be abstract");
332 }
333
334 void assert_common_1(DepType dept, ciBaseObject* x);
335 void assert_common_2(DepType dept, ciBaseObject* x0, ciBaseObject* x1);
336 void assert_common_3(DepType dept, ciKlass* ctxk, ciBaseObject* x1, ciBaseObject* x2);
337
338 public:
339 // Adding assertions to a new dependency set at compile time:
340 void assert_evol_method(ciMethod* m);
341 void assert_leaf_type(ciKlass* ctxk);
342 void assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck);
343 void assert_abstract_with_no_concrete_subtype(ciKlass* ctxk);
344 void assert_concrete_with_no_concrete_subtype(ciKlass* ctxk);
345 void assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm);
346 void assert_abstract_with_exclusive_concrete_subtypes(ciKlass* ctxk, ciKlass* k1, ciKlass* k2);
347 void assert_exclusive_concrete_methods(ciKlass* ctxk, ciMethod* m1, ciMethod* m2);
348 void assert_has_no_finalizable_subclasses(ciKlass* ctxk);
349 void assert_call_site_target_value(ciCallSite* call_site, ciMethodHandle* method_handle);
350
351 #if INCLUDE_JVMCI
352 private:
353 static void check_ctxk(Klass* ctxk) {
354 assert(ctxk->oop_is_instance(), "java types only");
355 }
356 static void check_ctxk_abstract(Klass* ctxk) {
357 check_ctxk(ctxk);
358 assert(ctxk->is_abstract(), "must be abstract");
359 }
360 void assert_common_1(DepType dept, DepValue x);
361 void assert_common_2(DepType dept, DepValue x0, DepValue x1);
362
363 public:
364 void assert_evol_method(Method* m);
365 void assert_has_no_finalizable_subclasses(Klass* ctxk);
366 void assert_leaf_type(Klass* ctxk);
367 void assert_unique_concrete_method(Klass* ctxk, Method* uniqm);
368 void assert_abstract_with_unique_concrete_subtype(Klass* ctxk, Klass* conck);
369 void assert_call_site_target_value(oop callSite, oop methodHandle);
370 #endif // INCLUDE_JVMCI
371
372 // Define whether a given method or type is concrete.
373 // These methods define the term "concrete" as used in this module.
374 // For this module, an "abstract" class is one which is non-concrete.
375 //
376 // Future optimizations may allow some classes to remain
377 // non-concrete until their first instantiation, and allow some
378 // methods to remain non-concrete until their first invocation.
379 // In that case, there would be a middle ground between concrete
380 // and abstract (as defined by the Java language and VM).
381 static bool is_concrete_klass(Klass* k); // k is instantiable
382 static bool is_concrete_method(Method* m, Klass* k); // m is invocable
383 static Klass* find_finalizable_subclass(Klass* k);
384
385 // These versions of the concreteness queries work through the CI.
386 // The CI versions are allowed to skew sometimes from the VM
387 // (oop-based) versions. The cost of such a difference is a
388 // (safely) aborted compilation, or a deoptimization, or a missed
389 // optimization opportunity.
390 //
391 // In order to prevent spurious assertions, query results must
495 bool _is_oop;
496 bool _valid;
497 void* _value;
498 public:
499 DepArgument() : _is_oop(false), _value(NULL), _valid(false) {}
500 DepArgument(oop v): _is_oop(true), _value(v), _valid(true) {}
501 DepArgument(Metadata* v): _is_oop(false), _value(v), _valid(true) {}
502
503 bool is_null() const { return _value == NULL; }
504 bool is_oop() const { return _is_oop; }
505 bool is_metadata() const { return !_is_oop; }
506 bool is_klass() const { return is_metadata() && metadata_value()->is_klass(); }
507 bool is_method() const { return is_metadata() && metadata_value()->is_method(); }
508
509 oop oop_value() const { assert(_is_oop && _valid, "must be"); return (oop) _value; }
510 Metadata* metadata_value() const { assert(!_is_oop && _valid, "must be"); return (Metadata*) _value; }
511 };
512
513 static void print_dependency(DepType dept,
514 GrowableArray<DepArgument>* args,
515 Klass* witness = NULL, outputStream* st = tty);
516
517 private:
518 // helper for encoding common context types as zero:
519 static ciKlass* ctxk_encoded_as_null(DepType dept, ciBaseObject* x);
520
521 static Klass* ctxk_encoded_as_null(DepType dept, Metadata* x);
522
523 static void write_dependency_to(CompileLog* log,
524 DepType dept,
525 GrowableArray<ciBaseObject*>* args,
526 Klass* witness = NULL);
527 static void write_dependency_to(CompileLog* log,
528 DepType dept,
529 GrowableArray<DepArgument>* args,
530 Klass* witness = NULL);
531 static void write_dependency_to(xmlStream* xtty,
532 DepType dept,
533 GrowableArray<DepArgument>* args,
534 Klass* witness = NULL);
535 public:
607 Metadata* x = argument(i);
608 assert(x->is_klass(), "type");
609 return (Klass*) x;
610 }
611
612 // The point of the whole exercise: Is this dep still OK?
613 Klass* check_dependency() {
614 Klass* result = check_klass_dependency(NULL);
615 if (result != NULL) return result;
616 return check_call_site_dependency(NULL);
617 }
618
619 // A lighter version: Checks only around recent changes in a class
620 // hierarchy. (See Universe::flush_dependents_on.)
621 Klass* spot_check_dependency_at(DepChange& changes);
622
623 // Log the current dependency to xtty or compilation log.
624 void log_dependency(Klass* witness = NULL);
625
626 // Print the current dependency to tty.
627 void print_dependency(Klass* witness = NULL, bool verbose = false, outputStream* st = tty);
628 };
629 friend class Dependencies::DepStream;
630
631 static void print_statistics() PRODUCT_RETURN;
632 };
633
634
635 class DependencySignature : public ResourceObj {
636 private:
637 int _args_count;
638 uintptr_t _argument_hash[Dependencies::max_arg_count];
639 Dependencies::DepType _type;
640
641 public:
642 DependencySignature(Dependencies::DepStream& dep) {
643 _args_count = dep.argument_count();
644 _type = dep.type();
645 for (int i = 0; i < _args_count; i++) {
646 _argument_hash[i] = dep.get_identifier(i);
647 }
|