< prev index next >

src/share/vm/code/dependencies.hpp

Print this page




  42 // relies on such assertions must be discarded if they are overturned
  43 // by changes in the runtime system.  We can think of these assertions
  44 // as approximate invariants, because we expect them to be overturned
  45 // very infrequently.  We are willing to perform expensive recovery
  46 // operations when they are overturned.  The benefit, of course, is
  47 // performing optimistic optimizations (!) on the object code.
  48 //
  49 // Changes in the class hierarchy due to dynamic linking or
  50 // class evolution can violate dependencies.  There is enough
  51 // indexing between classes and nmethods to make dependency
  52 // checking reasonably efficient.
  53 
  54 class ciEnv;
  55 class nmethod;
  56 class OopRecorder;
  57 class xmlStream;
  58 class CompileLog;
  59 class DepChange;
  60 class   KlassDepChange;
  61 class   CallSiteDepChange;

  62 class No_Safepoint_Verifier;
  63 
  64 class Dependencies: public ResourceObj {
  65  public:
  66   // Note: In the comments on dependency types, most uses of the terms
  67   // subtype and supertype are used in a "non-strict" or "inclusive"
  68   // sense, and are starred to remind the reader of this fact.
  69   // Strict uses of the terms use the word "proper".
  70   //
  71   // Specifically, every class is its own subtype* and supertype*.
  72   // (This trick is easier than continually saying things like "Y is a
  73   // subtype of X or X itself".)
  74   //
  75   // Sometimes we write X > Y to mean X is a proper supertype of Y.
  76   // The notation X > {Y, Z} means X has proper subtypes Y, Z.
  77   // The notation X.m > Y means that Y inherits m from X, while
  78   // X.m > Y.m means Y overrides X.m.  A star denotes abstractness,
  79   // as *I > A, meaning (abstract) interface I is a super type of A,
  80   // or A.*m > B.m, meaning B.m implements abstract method A.m.
  81   //


 145     // count, for robustness in the face of complex schema changes.
 146 
 147     // A context class CX (which may be either abstract or concrete)
 148     // has two exclusive concrete subtypes* C1, C2 if every concrete
 149     // subtype* of CX is either C1 or C2.  Note that if neither C1 or C2
 150     // are equal to CX, then CX itself must be abstract.  But it is
 151     // also possible (for example) that C1 is CX (a concrete class)
 152     // and C2 is a proper subtype of C1.
 153     abstract_with_exclusive_concrete_subtypes_2,
 154 
 155     // This dependency asserts that MM(CX, M1) is no greater than {M1,M2}.
 156     exclusive_concrete_methods_2,
 157 
 158     // This dependency asserts that no instances of class or it's
 159     // subclasses require finalization registration.
 160     no_finalizable_subclasses,
 161 
 162     // This dependency asserts when the CallSite.target value changed.
 163     call_site_target_value,
 164 



 165     TYPE_LIMIT
 166   };
 167   enum {
 168     LG2_TYPE_LIMIT = 4,  // assert(TYPE_LIMIT <= (1<<LG2_TYPE_LIMIT))
 169 
 170     // handy categorizations of dependency types:
 171     all_types           = ((1 << TYPE_LIMIT) - 1) & ((-1) << FIRST_TYPE),
 172 
 173     non_klass_types     = (1 << call_site_target_value),
 174     klass_types         = all_types & ~non_klass_types,
 175 
 176     non_ctxk_types      = (1 << evol_method) | (1 << call_site_target_value),
 177     implicit_ctxk_types = 0,
 178     explicit_ctxk_types = all_types & ~(non_ctxk_types | implicit_ctxk_types),
 179 
 180     max_arg_count = 3,   // current maximum number of arguments (incl. ctxk)
 181 
 182     // A "context type" is a class or interface that
 183     // provides context for evaluating a dependency.
 184     // When present, it is one of the arguments (dep_context_arg).


 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


 333   static Klass* check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes = NULL);
 334   // A returned Klass* is NULL if the dependency assertion is still
 335   // valid.  A non-NULL Klass* is a 'witness' to the assertion
 336   // failure, a point in the class hierarchy where the assertion has
 337   // been proven false.  For example, if check_leaf_type returns
 338   // non-NULL, the value is a subtype of the supposed leaf type.  This
 339   // witness value may be useful for logging the dependency failure.
 340   // Note that, when a dependency fails, there may be several possible
 341   // witnesses to the failure.  The value returned from the check_foo
 342   // method is chosen arbitrarily.
 343 
 344   // The 'changes' value, if non-null, requests a limited spot-check
 345   // near the indicated recent changes in the class hierarchy.
 346   // It is used by DepStream::spot_check_dependency_at.
 347 
 348   // Detecting possible new assertions:
 349   static Klass*    find_unique_concrete_subtype(Klass* ctxk);
 350   static Method*   find_unique_concrete_method(Klass* ctxk, Method* m);
 351   static int       find_exclusive_concrete_subtypes(Klass* ctxk, int klen, Klass* k[]);
 352 


 353   // Create the encoding which will be stored in an nmethod.
 354   void encode_content_bytes();
 355 
 356   address content_bytes() {
 357     assert(_content_bytes != NULL, "encode it first");
 358     return _content_bytes;
 359   }
 360   size_t size_in_bytes() {
 361     assert(_content_bytes != NULL, "encode it first");
 362     return _size_in_bytes;
 363   }
 364 
 365   OopRecorder* oop_recorder() { return _oop_recorder; }
 366   CompileLog*  log()          { return _log; }
 367 
 368   void copy_to(nmethod* nm);
 369 
 370   void log_all_dependencies();
 371 
 372   void log_dependency(DepType dept, GrowableArray<ciBaseObject*>* args) {


 383                       ciBaseObject* x2 = NULL) {
 384     if (log() == NULL) {
 385       return;
 386     }
 387     ResourceMark rm;
 388     GrowableArray<ciBaseObject*>* ciargs =
 389                 new GrowableArray<ciBaseObject*>(dep_args(dept));
 390     assert (x0 != NULL, "no log x0");
 391     ciargs->push(x0);
 392 
 393     if (x1 != NULL) {
 394       ciargs->push(x1);
 395     }
 396     if (x2 != NULL) {
 397       ciargs->push(x2);
 398     }
 399     assert(ciargs->length() == dep_args(dept), "");
 400     log_dependency(dept, ciargs);
 401   }
 402 






 403   class DepArgument : public ResourceObj {
 404    private:
 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 


 479 
 480   public:
 481     DepStream(Dependencies* deps)
 482       : _deps(deps),
 483         _code(NULL),
 484         _bytes(deps->content_bytes())
 485     {
 486       initial_asserts(deps->size_in_bytes());
 487     }
 488     DepStream(nmethod* code)
 489       : _deps(NULL),
 490         _code(code),
 491         _bytes(code->dependencies_begin())
 492     {
 493       initial_asserts(code->dependencies_size());
 494     }
 495 
 496     bool next();
 497 
 498     DepType type()               { return _type; }
 499     bool is_oop_argument(int i)  { return type() == call_site_target_value; }















 500     uintptr_t get_identifier(int i);
 501 
 502     int argument_count()         { return dep_args(type()); }
 503     int argument_index(int i)    { assert(0 <= i && i < argument_count(), "oob");
 504                                    return _xi[i]; }
 505     Metadata* argument(int i);     // => recorded_oop_at(argument_index(i))
 506     oop argument_oop(int i);         // => recorded_oop_at(argument_index(i))

 507     Klass* context_type();
 508 
 509     bool is_klass_type()         { return Dependencies::is_klass_type(type()); }
 510 
 511     Method* method_argument(int i) {
 512       Metadata* x = argument(i);
 513       assert(x->is_method(), "type");
 514       return (Method*) x;
 515     }
 516     Klass* type_argument(int i) {
 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);


 556       _argument_hash[i] = dep.get_identifier(i);
 557     }
 558   }
 559 
 560   static bool     equals(DependencySignature const& s1, DependencySignature const& s2);
 561   static unsigned hash  (DependencySignature const& s1) { return s1.arg(0) >> 2; }
 562 
 563   int args_count()             const { return _args_count; }
 564   uintptr_t arg(int idx)       const { return _argument_hash[idx]; }
 565   Dependencies::DepType type() const { return _type; }
 566 
 567 };
 568 
 569 
 570 // Every particular DepChange is a sub-class of this class.
 571 class DepChange : public StackObj {
 572  public:
 573   // What kind of DepChange is this?
 574   virtual bool is_klass_change()     const { return false; }
 575   virtual bool is_call_site_change() const { return false; }

 576 
 577   // Subclass casting with assertions.
 578   KlassDepChange*    as_klass_change() {
 579     assert(is_klass_change(), "bad cast");
 580     return (KlassDepChange*) this;
 581   }
 582   CallSiteDepChange* as_call_site_change() {
 583     assert(is_call_site_change(), "bad cast");
 584     return (CallSiteDepChange*) this;
 585   }




 586 
 587   void print();
 588 
 589  public:
 590   enum ChangeType {
 591     NO_CHANGE = 0,              // an uninvolved klass
 592     Change_new_type,            // a newly loaded type
 593     Change_new_sub,             // a super with a new subtype
 594     Change_new_impl,            // an interface with a new implementation
 595     CHANGE_LIMIT,
 596     Start_Klass = CHANGE_LIMIT  // internal indicator for ContextStream
 597   };
 598 
 599   // Usage:
 600   // for (DepChange::ContextStream str(changes); str.next(); ) {
 601   //   Klass* k = str.klass();
 602   //   switch (str.change_type()) {
 603   //     ...
 604   //   }
 605   // }


 675  private:
 676   Handle _call_site;
 677   Handle _method_handle;
 678 
 679  public:
 680   CallSiteDepChange(Handle call_site, Handle method_handle)
 681     : _call_site(call_site),
 682       _method_handle(method_handle)
 683   {
 684     assert(_call_site()    ->is_a(SystemDictionary::CallSite_klass()),     "must be");
 685     assert(_method_handle.is_null() || _method_handle()->is_a(SystemDictionary::MethodHandle_klass()), "must be");
 686   }
 687 
 688   // What kind of DepChange is this?
 689   virtual bool is_call_site_change() const { return true; }
 690 
 691   oop call_site()     const { return _call_site();     }
 692   oop method_handle() const { return _method_handle(); }
 693 };
 694 
















 695 #endif // SHARE_VM_CODE_DEPENDENCIES_HPP


  42 // relies on such assertions must be discarded if they are overturned
  43 // by changes in the runtime system.  We can think of these assertions
  44 // as approximate invariants, because we expect them to be overturned
  45 // very infrequently.  We are willing to perform expensive recovery
  46 // operations when they are overturned.  The benefit, of course, is
  47 // performing optimistic optimizations (!) on the object code.
  48 //
  49 // Changes in the class hierarchy due to dynamic linking or
  50 // class evolution can violate dependencies.  There is enough
  51 // indexing between classes and nmethods to make dependency
  52 // checking reasonably efficient.
  53 
  54 class ciEnv;
  55 class nmethod;
  56 class OopRecorder;
  57 class xmlStream;
  58 class CompileLog;
  59 class DepChange;
  60 class   KlassDepChange;
  61 class   CallSiteDepChange;
  62 class   ConstantFieldDepChange;
  63 class No_Safepoint_Verifier;
  64 
  65 class Dependencies: public ResourceObj {
  66  public:
  67   // Note: In the comments on dependency types, most uses of the terms
  68   // subtype and supertype are used in a "non-strict" or "inclusive"
  69   // sense, and are starred to remind the reader of this fact.
  70   // Strict uses of the terms use the word "proper".
  71   //
  72   // Specifically, every class is its own subtype* and supertype*.
  73   // (This trick is easier than continually saying things like "Y is a
  74   // subtype of X or X itself".)
  75   //
  76   // Sometimes we write X > Y to mean X is a proper supertype of Y.
  77   // The notation X > {Y, Z} means X has proper subtypes Y, Z.
  78   // The notation X.m > Y means that Y inherits m from X, while
  79   // X.m > Y.m means Y overrides X.m.  A star denotes abstractness,
  80   // as *I > A, meaning (abstract) interface I is a super type of A,
  81   // or A.*m > B.m, meaning B.m implements abstract method A.m.
  82   //


 146     // count, for robustness in the face of complex schema changes.
 147 
 148     // A context class CX (which may be either abstract or concrete)
 149     // has two exclusive concrete subtypes* C1, C2 if every concrete
 150     // subtype* of CX is either C1 or C2.  Note that if neither C1 or C2
 151     // are equal to CX, then CX itself must be abstract.  But it is
 152     // also possible (for example) that C1 is CX (a concrete class)
 153     // and C2 is a proper subtype of C1.
 154     abstract_with_exclusive_concrete_subtypes_2,
 155 
 156     // This dependency asserts that MM(CX, M1) is no greater than {M1,M2}.
 157     exclusive_concrete_methods_2,
 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     constant_field_value_instance,
 167     constant_field_value_klass,
 168 
 169     TYPE_LIMIT
 170   };
 171   enum {
 172     LG2_TYPE_LIMIT = 4,  // assert(TYPE_LIMIT <= (1<<LG2_TYPE_LIMIT))
 173 
 174     // handy categorizations of dependency types:
 175     all_types           = ((1 << TYPE_LIMIT) - 1) & ((-1) << FIRST_TYPE),
 176 
 177     non_klass_types     = (1 << call_site_target_value),
 178     klass_types         = all_types & ~non_klass_types,
 179 
 180     non_ctxk_types      = (1 << evol_method) | (1 << call_site_target_value),
 181     implicit_ctxk_types = 0,
 182     explicit_ctxk_types = all_types & ~(non_ctxk_types | implicit_ctxk_types),
 183 
 184     max_arg_count = 3,   // current maximum number of arguments (incl. ctxk)
 185 
 186     // A "context type" is a class or interface that
 187     // provides context for evaluating a dependency.
 188     // When present, it is one of the arguments (dep_context_arg).


 266     assert(!is_concrete_klass(ctxk->as_instance_klass()), "must be abstract");
 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_3(DepType dept, ciKlass* ctxk, ciBaseObject* x1, ciBaseObject* x2);
 272 
 273  public:
 274   // Adding assertions to a new dependency set at compile time:
 275   void assert_evol_method(ciMethod* m);
 276   void assert_leaf_type(ciKlass* ctxk);
 277   void assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck);
 278   void assert_abstract_with_no_concrete_subtype(ciKlass* ctxk);
 279   void assert_concrete_with_no_concrete_subtype(ciKlass* ctxk);
 280   void assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm);
 281   void assert_abstract_with_exclusive_concrete_subtypes(ciKlass* ctxk, ciKlass* k1, ciKlass* k2);
 282   void assert_exclusive_concrete_methods(ciKlass* ctxk, ciMethod* m1, ciMethod* m2);
 283   void assert_has_no_finalizable_subclasses(ciKlass* ctxk);
 284   void assert_call_site_target_value(ciCallSite* call_site, ciMethodHandle* method_handle);
 285 
 286   void assert_constant_field_value_klass(ciField* field, ciKlass* ctxk);
 287   void assert_constant_field_value_instance(ciField* field, ciObject* obj);
 288 
 289   // Define whether a given method or type is concrete.
 290   // These methods define the term "concrete" as used in this module.
 291   // For this module, an "abstract" class is one which is non-concrete.
 292   //
 293   // Future optimizations may allow some classes to remain
 294   // non-concrete until their first instantiation, and allow some
 295   // methods to remain non-concrete until their first invocation.
 296   // In that case, there would be a middle ground between concrete
 297   // and abstract (as defined by the Java language and VM).
 298   static bool is_concrete_klass(Klass* k);    // k is instantiable
 299   static bool is_concrete_method(Method* m, Klass* k);  // m is invocable
 300   static Klass* find_finalizable_subclass(Klass* k);
 301 
 302   // These versions of the concreteness queries work through the CI.
 303   // The CI versions are allowed to skew sometimes from the VM
 304   // (oop-based) versions.  The cost of such a difference is a
 305   // (safely) aborted compilation, or a deoptimization, or a missed
 306   // optimization opportunity.
 307   //
 308   // In order to prevent spurious assertions, query results must


 340   static Klass* check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes = NULL);
 341   // A returned Klass* is NULL if the dependency assertion is still
 342   // valid.  A non-NULL Klass* is a 'witness' to the assertion
 343   // failure, a point in the class hierarchy where the assertion has
 344   // been proven false.  For example, if check_leaf_type returns
 345   // non-NULL, the value is a subtype of the supposed leaf type.  This
 346   // witness value may be useful for logging the dependency failure.
 347   // Note that, when a dependency fails, there may be several possible
 348   // witnesses to the failure.  The value returned from the check_foo
 349   // method is chosen arbitrarily.
 350 
 351   // The 'changes' value, if non-null, requests a limited spot-check
 352   // near the indicated recent changes in the class hierarchy.
 353   // It is used by DepStream::spot_check_dependency_at.
 354 
 355   // Detecting possible new assertions:
 356   static Klass*    find_unique_concrete_subtype(Klass* ctxk);
 357   static Method*   find_unique_concrete_method(Klass* ctxk, Method* m);
 358   static int       find_exclusive_concrete_subtypes(Klass* ctxk, int klen, Klass* k[]);
 359 
 360   static void invalidate_dependent_nmethods(instanceKlassHandle ctxk, DepChange& changes, TRAPS);
 361 
 362   // Create the encoding which will be stored in an nmethod.
 363   void encode_content_bytes();
 364 
 365   address content_bytes() {
 366     assert(_content_bytes != NULL, "encode it first");
 367     return _content_bytes;
 368   }
 369   size_t size_in_bytes() {
 370     assert(_content_bytes != NULL, "encode it first");
 371     return _size_in_bytes;
 372   }
 373 
 374   OopRecorder* oop_recorder() { return _oop_recorder; }
 375   CompileLog*  log()          { return _log; }
 376 
 377   void copy_to(nmethod* nm);
 378 
 379   void log_all_dependencies();
 380 
 381   void log_dependency(DepType dept, GrowableArray<ciBaseObject*>* args) {


 392                       ciBaseObject* x2 = NULL) {
 393     if (log() == NULL) {
 394       return;
 395     }
 396     ResourceMark rm;
 397     GrowableArray<ciBaseObject*>* ciargs =
 398                 new GrowableArray<ciBaseObject*>(dep_args(dept));
 399     assert (x0 != NULL, "no log x0");
 400     ciargs->push(x0);
 401 
 402     if (x1 != NULL) {
 403       ciargs->push(x1);
 404     }
 405     if (x2 != NULL) {
 406       ciargs->push(x2);
 407     }
 408     assert(ciargs->length() == dep_args(dept), "");
 409     log_dependency(dept, ciargs);
 410   }
 411 
 412   static PerfCounter* _perf_dependency_checking_time;
 413   static PerfCounter* _perf_dependencies_checked_count;
 414   static PerfCounter* _perf_dependencies_context_traversals;
 415   static PerfCounter* _perf_dependencies_invalidated;
 416   static PerfCounter* _perf_dependencies_total_count;
 417 
 418   class DepArgument : public ResourceObj {
 419    private:
 420     bool  _is_oop;
 421     bool  _valid;
 422     void* _value;
 423    public:
 424     DepArgument() : _is_oop(false), _value(NULL), _valid(false) {}
 425     DepArgument(oop v): _is_oop(true), _value(v), _valid(true) {}
 426     DepArgument(Metadata* v): _is_oop(false), _value(v), _valid(true) {}
 427 
 428     bool is_null() const               { return _value == NULL; }
 429     bool is_oop() const                { return _is_oop; }
 430     bool is_metadata() const           { return !_is_oop; }
 431     bool is_klass() const              { return is_metadata() && metadata_value()->is_klass(); }
 432     bool is_method() const              { return is_metadata() && metadata_value()->is_method(); }
 433 
 434     oop oop_value() const              { assert(_is_oop && _valid, "must be"); return (oop) _value; }
 435     Metadata* metadata_value() const { assert(!_is_oop && _valid, "must be"); return (Metadata*) _value; }
 436   };
 437 


 494 
 495   public:
 496     DepStream(Dependencies* deps)
 497       : _deps(deps),
 498         _code(NULL),
 499         _bytes(deps->content_bytes())
 500     {
 501       initial_asserts(deps->size_in_bytes());
 502     }
 503     DepStream(nmethod* code)
 504       : _deps(NULL),
 505         _code(code),
 506         _bytes(code->dependencies_begin())
 507     {
 508       initial_asserts(code->dependencies_size());
 509     }
 510 
 511     bool next();
 512 
 513     DepType type()               { return _type; }
 514     bool is_oop_argument(int i)  {
 515       assert(0 <= i && i < argument_count(), "oob");
 516       switch (type()) {
 517         case call_site_target_value:        return true;
 518         case constant_field_value_instance: return (i == 1);
 519         default:                            return false;
 520       }
 521     }
 522     bool is_int_argument(int i) {
 523       assert(0 <= i && i < argument_count(), "oob");
 524       switch (type()) {
 525         case constant_field_value_instance: return (i == 2);
 526         case constant_field_value_klass:    return (i == 1);
 527         default:                            return false;
 528       }
 529     }
 530     uintptr_t get_identifier(int i);
 531 
 532     int argument_count()         { return dep_args(type()); }
 533     int argument_index(int i)    { assert(0 <= i && i < argument_count(), "oob");
 534                                    return _xi[i]; }
 535     Metadata* argument(int i);     // => recorded_oop_at(argument_index(i))
 536     oop argument_oop(int i);       // => recorded_oop_at(argument_index(i))
 537     int argument_int(int i)      { return argument_index(i); }
 538     Klass* context_type();
 539 
 540     bool is_klass_type()         { return Dependencies::is_klass_type(type()); }
 541 
 542     Method* method_argument(int i) {
 543       Metadata* x = argument(i);
 544       assert(x->is_method(), "type");
 545       return (Method*) x;
 546     }
 547     Klass* type_argument(int i) {
 548       Metadata* x = argument(i);
 549       assert(x->is_klass(), "type");
 550       return (Klass*) x;
 551     }
 552 
 553     // The point of the whole exercise:  Is this dep still OK?
 554     Klass* check_dependency() {
 555       Klass* result = check_klass_dependency(NULL);
 556       if (result != NULL)  return result;
 557       return check_call_site_dependency(NULL);


 587       _argument_hash[i] = dep.get_identifier(i);
 588     }
 589   }
 590 
 591   static bool     equals(DependencySignature const& s1, DependencySignature const& s2);
 592   static unsigned hash  (DependencySignature const& s1) { return s1.arg(0) >> 2; }
 593 
 594   int args_count()             const { return _args_count; }
 595   uintptr_t arg(int idx)       const { return _argument_hash[idx]; }
 596   Dependencies::DepType type() const { return _type; }
 597 
 598 };
 599 
 600 
 601 // Every particular DepChange is a sub-class of this class.
 602 class DepChange : public StackObj {
 603  public:
 604   // What kind of DepChange is this?
 605   virtual bool is_klass_change()     const { return false; }
 606   virtual bool is_call_site_change() const { return false; }
 607   virtual bool is_constant_field_change() const { return false; }
 608 
 609   // Subclass casting with assertions.
 610   KlassDepChange*    as_klass_change() {
 611     assert(is_klass_change(), "bad cast");
 612     return (KlassDepChange*) this;
 613   }
 614   CallSiteDepChange* as_call_site_change() {
 615     assert(is_call_site_change(), "bad cast");
 616     return (CallSiteDepChange*) this;
 617   }
 618   ConstantFieldDepChange* as_constant_field_change() {
 619     assert(is_constant_field_change(), "bad cast");
 620     return (ConstantFieldDepChange*) this;
 621   }
 622 
 623   void print();
 624 
 625  public:
 626   enum ChangeType {
 627     NO_CHANGE = 0,              // an uninvolved klass
 628     Change_new_type,            // a newly loaded type
 629     Change_new_sub,             // a super with a new subtype
 630     Change_new_impl,            // an interface with a new implementation
 631     CHANGE_LIMIT,
 632     Start_Klass = CHANGE_LIMIT  // internal indicator for ContextStream
 633   };
 634 
 635   // Usage:
 636   // for (DepChange::ContextStream str(changes); str.next(); ) {
 637   //   Klass* k = str.klass();
 638   //   switch (str.change_type()) {
 639   //     ...
 640   //   }
 641   // }


 711  private:
 712   Handle _call_site;
 713   Handle _method_handle;
 714 
 715  public:
 716   CallSiteDepChange(Handle call_site, Handle method_handle)
 717     : _call_site(call_site),
 718       _method_handle(method_handle)
 719   {
 720     assert(_call_site()    ->is_a(SystemDictionary::CallSite_klass()),     "must be");
 721     assert(_method_handle.is_null() || _method_handle()->is_a(SystemDictionary::MethodHandle_klass()), "must be");
 722   }
 723 
 724   // What kind of DepChange is this?
 725   virtual bool is_call_site_change() const { return true; }
 726 
 727   oop call_site()     const { return _call_site();     }
 728   oop method_handle() const { return _method_handle(); }
 729 };
 730 
 731 class ConstantFieldDepChange : public DepChange {
 732  private:
 733   Handle _holder;
 734   int _offset;
 735 
 736  public:
 737   ConstantFieldDepChange(Handle holder, int offset) : _holder(holder), _offset(offset) {}
 738 
 739   // What kind of DepChange is this?
 740   virtual bool is_constant_field_change() const { return true; }
 741 
 742   oop holder() const { return _holder(); }
 743   int offset() const { return _offset;   }
 744 };
 745 
 746 
 747 #endif // SHARE_VM_CODE_DEPENDENCIES_HPP
< prev index next >