src/share/vm/code/dependencies.hpp

Print this page




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_CODE_DEPENDENCIES_HPP
  26 #define SHARE_VM_CODE_DEPENDENCIES_HPP
  27 
  28 #include "ci/ciCallSite.hpp"
  29 #include "ci/ciKlass.hpp"

  30 #include "ci/ciMethodHandle.hpp"
  31 #include "classfile/systemDictionary.hpp"
  32 #include "code/compressedStream.hpp"
  33 #include "code/nmethod.hpp"
  34 #include "utilities/growableArray.hpp"
  35 
  36 //** Dependencies represent assertions (approximate invariants) within
  37 // the runtime system, e.g. class hierarchy changes.  An example is an
  38 // assertion that a given method is not overridden; another example is
  39 // that a type has only one concrete subtype.  Compiled code which
  40 // relies on such assertions must be discarded if they are overturned
  41 // by changes in the runtime system.  We can think of these assertions
  42 // as approximate invariants, because we expect them to be overturned
  43 // very infrequently.  We are willing to perform expensive recovery
  44 // operations when they are overturned.  The benefit, of course, is
  45 // performing optimistic optimizations (!) on the object code.
  46 //
  47 // Changes in the class hierarchy due to dynamic linking or
  48 // class evolution can violate dependencies.  There is enough
  49 // indexing between classes and nmethods to make dependency


 183     //
 184     // If a dependency does not have a context type, there is a
 185     // default context, depending on the type of the dependency.
 186     // This bit signals that a default context has been compressed away.
 187     default_context_type_bit = (1<<LG2_TYPE_LIMIT)
 188   };
 189 
 190   static const char* dep_name(DepType dept);
 191   static int         dep_args(DepType dept);
 192 
 193   static bool is_klass_type(           DepType dept) { return dept_in_mask(dept, klass_types        ); }
 194 
 195   static bool has_explicit_context_arg(DepType dept) { return dept_in_mask(dept, explicit_ctxk_types); }
 196   static bool has_implicit_context_arg(DepType dept) { return dept_in_mask(dept, implicit_ctxk_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();

 218     assert(_dep_seen != NULL, "deps must be writable");
 219     int seen = _dep_seen->at_grow(x_id, 0);
 220     _dep_seen->at_put(x_id, seen | (1<<dept));
 221     // return true if we've already seen dept/x
 222     return (seen & (1<<dept)) != 0;
 223   }
 224 
 225   bool maybe_merge_ctxk(GrowableArray<ciBaseObject*>* deps,
 226                         int ctxk_i, ciKlass* ctxk);
 227 
 228   void sort_all_deps();
 229   size_t estimate_size_in_bytes();
 230 
 231   // Initialize _deps, etc.
 232   void initialize(ciEnv* env);
 233 
 234   // State for making a new set of dependencies:
 235   OopRecorder* _oop_recorder;
 236 
 237   // Logging support
 238   CompileLog* _log;
 239 
 240   address  _content_bytes;  // everything but the oop references, encoded
 241   size_t   _size_in_bytes;
 242 
 243  public:
 244   // Make a new empty dependencies set.
 245   Dependencies(ciEnv* env) {
 246     initialize(env);
 247   }
 248 
 249  private:
 250   // Check for a valid context type.
 251   // Enforce the restriction against array types.
 252   static void check_ctxk(ciKlass* ctxk) {
 253     assert(ctxk->is_instance_klass(), "java types only");
 254   }
 255   static void check_ctxk_concrete(ciKlass* ctxk) {
 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 
 263   void assert_common_1(DepType dept, ciBaseObject* x);
 264   void assert_common_2(DepType dept, ciBaseObject* x0, ciBaseObject* x1);
 265   void assert_common_3(DepType dept, ciKlass* ctxk, ciBaseObject* x1, ciBaseObject* x2);
 266 
 267  public:
 268   // Adding assertions to a new dependency set at compile time:
 269   void assert_evol_method(ciMethod* m);
 270   void assert_leaf_type(ciKlass* ctxk);
 271   void assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck);
 272   void assert_abstract_with_no_concrete_subtype(ciKlass* ctxk);
 273   void assert_concrete_with_no_concrete_subtype(ciKlass* ctxk);
 274   void assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm);
 275   void assert_abstract_with_exclusive_concrete_subtypes(ciKlass* ctxk, ciKlass* k1, ciKlass* k2);
 276   void assert_exclusive_concrete_methods(ciKlass* ctxk, ciMethod* m1, ciMethod* m2);
 277   void assert_has_no_finalizable_subclasses(ciKlass* ctxk);
 278   void assert_call_site_target_value(ciCallSite* call_site, ciMethodHandle* method_handle);
































 279 
 280   // Define whether a given method or type is concrete.
 281   // These methods define the term "concrete" as used in this module.
 282   // For this module, an "abstract" class is one which is non-concrete.
 283   //
 284   // Future optimizations may allow some classes to remain
 285   // non-concrete until their first instantiation, and allow some
 286   // methods to remain non-concrete until their first invocation.
 287   // In that case, there would be a middle ground between concrete
 288   // and abstract (as defined by the Java language and VM).
 289   static bool is_concrete_klass(Klass* k);    // k is instantiable
 290   static bool is_concrete_method(Method* m);  // m is invocable
 291   static Klass* find_finalizable_subclass(Klass* k);
 292 
 293   // These versions of the concreteness queries work through the CI.
 294   // The CI versions are allowed to skew sometimes from the VM
 295   // (oop-based) versions.  The cost of such a difference is a
 296   // (safely) aborted compilation, or a deoptimization, or a missed
 297   // optimization opportunity.
 298   //


 351   static int       find_exclusive_concrete_methods(Klass* ctxk, int mlen, Method* m[]);
 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   void log_dependency(DepType dept, int nargs, ciBaseObject* args[]) {
 372     write_dependency_to(log(), dept, nargs, args);
 373   }
 374   void log_dependency(DepType dept,
 375                       ciBaseObject* x0,
 376                       ciBaseObject* x1 = NULL,
 377                       ciBaseObject* x2 = NULL) {
 378     if (log() == NULL)  return;
 379     ciBaseObject* args[max_arg_count];
 380     args[0] = x0;
 381     args[1] = x1;
 382     args[2] = x2;
 383     assert(2 < max_arg_count, "");
 384     log_dependency(dept, dep_args(dept), args);
 385   }
 386 
 387   class DepArgument : public ResourceObj {
 388    private:
 389     bool  _is_oop;
 390     bool  _valid;
 391     void* _value;
 392    public:
 393     DepArgument() : _is_oop(false), _value(NULL), _valid(false) {}
 394     DepArgument(oop v): _is_oop(true), _value(v), _valid(true) {}
 395     DepArgument(Metadata* v): _is_oop(false), _value(v), _valid(true) {}
 396 
 397     bool is_null() const               { return _value == NULL; }
 398     bool is_oop() const                { return _is_oop; }
 399     bool is_metadata() const           { return !_is_oop; }
 400     bool is_klass() const              { return is_metadata() && metadata_value()->is_klass(); }
 401     bool is_method() const              { return is_metadata() && metadata_value()->is_method(); }
 402 
 403     oop oop_value() const              { assert(_is_oop && _valid, "must be"); return (oop) _value; }
 404     Metadata* metadata_value() const { assert(!_is_oop && _valid, "must be"); return (Metadata*) _value; }
 405   };
 406 
 407   static void write_dependency_to(CompileLog* log,
 408                                   DepType dept,
 409                                   int nargs, ciBaseObject* args[],
 410                                   Klass* witness = NULL);
 411   static void write_dependency_to(CompileLog* log,
 412                                   DepType dept,
 413                                   int nargs, DepArgument args[],
 414                                   Klass* witness = NULL);




 415   static void write_dependency_to(xmlStream* xtty,
 416                                   DepType dept,
 417                                   int nargs, DepArgument args[],
 418                                   Klass* witness = NULL);
 419   static void print_dependency(DepType dept,
 420                                int nargs, DepArgument args[],
 421                                Klass* witness = NULL);
 422 
 423  private:
 424   // helper for encoding common context types as zero:
 425   static ciKlass* ctxk_encoded_as_null(DepType dept, ciBaseObject* x);
 426 
 427   static Klass* ctxk_encoded_as_null(DepType dept, Metadata* x);
 428 
 429  public:
 430   // Use this to iterate over an nmethod's dependency set.
 431   // Works on new and old dependency sets.
 432   // Usage:
 433   //
 434   // ;
 435   // Dependencies::DepType dept;
 436   // for (Dependencies::DepStream deps(nm); deps.next(); ) {
 437   //   ...
 438   // }
 439   //
 440   // The caller must be in the VM, since oops are not wrapped in handles.
 441   class DepStream {
 442   private:
 443     nmethod*              _code;   // null if in a compiler thread
 444     Dependencies*         _deps;   // null if not in a compiler thread
 445     CompressedReadStream  _bytes;




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_CODE_DEPENDENCIES_HPP
  26 #define SHARE_VM_CODE_DEPENDENCIES_HPP
  27 
  28 #include "ci/ciCallSite.hpp"
  29 #include "ci/ciKlass.hpp"
  30 #include "ci/ciMethod.hpp"
  31 #include "ci/ciMethodHandle.hpp"
  32 #include "classfile/systemDictionary.hpp"
  33 #include "code/compressedStream.hpp"
  34 #include "code/nmethod.hpp"
  35 #include "utilities/growableArray.hpp"
  36 
  37 //** Dependencies represent assertions (approximate invariants) within
  38 // the runtime system, e.g. class hierarchy changes.  An example is an
  39 // assertion that a given method is not overridden; another example is
  40 // that a type has only one concrete subtype.  Compiled code which
  41 // relies on such assertions must be discarded if they are overturned
  42 // by changes in the runtime system.  We can think of these assertions
  43 // as approximate invariants, because we expect them to be overturned
  44 // very infrequently.  We are willing to perform expensive recovery
  45 // operations when they are overturned.  The benefit, of course, is
  46 // performing optimistic optimizations (!) on the object code.
  47 //
  48 // Changes in the class hierarchy due to dynamic linking or
  49 // class evolution can violate dependencies.  There is enough
  50 // indexing between classes and nmethods to make dependency


 184     //
 185     // If a dependency does not have a context type, there is a
 186     // default context, depending on the type of the dependency.
 187     // This bit signals that a default context has been compressed away.
 188     default_context_type_bit = (1<<LG2_TYPE_LIMIT)
 189   };
 190 
 191   static const char* dep_name(DepType dept);
 192   static int         dep_args(DepType dept);
 193 
 194   static bool is_klass_type(           DepType dept) { return dept_in_mask(dept, klass_types        ); }
 195 
 196   static bool has_explicit_context_arg(DepType dept) { return dept_in_mask(dept, explicit_ctxk_types); }
 197   static bool has_implicit_context_arg(DepType dept) { return dept_in_mask(dept, implicit_ctxk_types); }
 198 
 199   static int           dep_context_arg(DepType dept) { return has_explicit_context_arg(dept) ? 0 : -1; }
 200   static int  dep_implicit_context_arg(DepType dept) { return has_implicit_context_arg(dept) ? 0 : -1; }
 201 
 202   static void check_valid_dependency_type(DepType dept);
 203 
 204   // A Metadata* or object value recorded in an OopRecorder
 205   class DepValue VALUE_OBJ_CLASS_SPEC {
 206    private:
 207     // Unique identifier of the value within the associated OopRecorder that
 208     // encodes both the category of the value (0: invalid, positive: metadata, negative: object)
 209     // and the index within a category specific array (metadata: index + 1, object: -(index + 1))
 210     int _id;
 211 
 212    public:
 213     DepValue() : _id(0) {}
 214     DepValue(OopRecorder* rec, Metadata* metadata, DepValue* candidate = NULL) {
 215       assert(candidate == NULL || candidate->is_metadata(), "oops");
 216       if (candidate != NULL && candidate->as_metadata(rec) == metadata) {
 217         _id = candidate->_id;
 218       } else {
 219         _id = rec->find_index(metadata) + 1;
 220       }
 221     }
 222     DepValue(OopRecorder* rec, jobject obj, DepValue* candidate = NULL) {
 223       assert(candidate == NULL || candidate->is_object(), "oops");
 224       if (candidate != NULL && candidate->as_object(rec) == obj) {
 225         _id = candidate->_id;
 226       } else {
 227         _id = -(rec->find_index(obj) + 1);
 228       }
 229     }
 230 
 231     // Used to sort values in ascending order of index() with metadata values preceding object values
 232     int sort_key() const { return -_id; }
 233 
 234     bool operator == (const DepValue& other) const   { return other._id == _id; }
 235 
 236     bool is_valid() const             { return _id != 0; }
 237     int  index() const                { assert(is_valid(), "oops"); return _id < 0 ? -(_id + 1) : _id - 1; }
 238     bool is_metadata() const          { assert(is_valid(), "oops"); return _id > 0; }
 239     bool is_object() const            { assert(is_valid(), "oops"); return _id < 0; }
 240 
 241     Metadata*  as_metadata(OopRecorder* rec) const    { assert(is_metadata(), "oops"); return rec->metadata_at(index()); }
 242     Klass*     as_klass(OopRecorder* rec) const       { assert(as_metadata(rec)->is_klass(), "oops"); return (Klass*) as_metadata(rec); }
 243     Method*    as_method(OopRecorder* rec) const      { assert(as_metadata(rec)->is_method(), "oops"); return (Method*) as_metadata(rec); }
 244     jobject    as_object(OopRecorder* rec) const      { assert(is_object(), "oops"); return rec->oop_at(index()); }
 245   };
 246 
 247  private:
 248   // State for writing a new set of dependencies:
 249   GrowableArray<int>*       _dep_seen;  // (seen[h->ident] & (1<<dept))
 250   GrowableArray<DepValue>*  _deps[TYPE_LIMIT];
 251 
 252   static const char* _dep_name[TYPE_LIMIT];
 253   static int         _dep_args[TYPE_LIMIT];
 254 
 255   static bool dept_in_mask(DepType dept, int mask) {
 256     return (int)dept >= 0 && dept < TYPE_LIMIT && ((1<<dept) & mask) != 0;
 257   }
 258 
 259   bool note_dep_seen(int dept, DepValue x) {
 260     assert(dept < BitsPerInt, "oops");
 261     // place metadata deps at even indexes, object deps at odd indexes
 262     int x_id = x.is_metadata() ? x.index() * 2 : (x.index() * 2) + 1;
 263     assert(_dep_seen != NULL, "deps must be writable");
 264     int seen = _dep_seen->at_grow(x_id, 0);
 265     _dep_seen->at_put(x_id, seen | (1<<dept));
 266     // return true if we've already seen dept/x
 267     return (seen & (1<<dept)) != 0;
 268   }
 269 
 270   bool maybe_merge_ctxk(GrowableArray<DepValue>* deps,
 271                         int ctxk_i, Klass* ctxk);
 272 
 273   void sort_all_deps();
 274   size_t estimate_size_in_bytes();
 275 
 276   // Initialize _deps, etc.
 277   void initialize(ciEnv* env);
 278 
 279   // State for making a new set of dependencies:
 280   OopRecorder* _oop_recorder;
 281 
 282   // Logging support
 283   CompileLog* _log;
 284 
 285   address  _content_bytes;  // everything but the oop references, encoded
 286   size_t   _size_in_bytes;
 287 
 288  public:
 289   // Make a new empty dependencies set.
 290   Dependencies(ciEnv* env) {
 291     initialize(env);
 292   }
 293 
 294  private:
 295   // Check for a valid context type.
 296   // Enforce the restriction against array types.
 297   static void check_ctxk(Klass* ctxk) {
 298     assert(ctxk->oop_is_instance(), "java types only");
 299   }
 300   static void check_ctxk_concrete(Klass* ctxk) {
 301     check_ctxk(ctxk);
 302     assert(!ctxk->is_abstract(), "must be abstract");
 303   }
 304   static void check_ctxk_abstract(Klass* ctxk) {
 305     check_ctxk(ctxk);
 306     assert(ctxk->is_abstract(), "must be abstract");
 307   }
 308 
 309   void assert_common_1(DepType dept, DepValue x);
 310   void assert_common_2(DepType dept, DepValue x0, DepValue x1);
 311   void assert_common_3(DepType dept, Klass* ctxk, DepValue x1, DepValue x2);
 312 
 313  public:
 314   // Adding assertions to a new dependency set at compile time:
 315   void assert_evol_method(Method* m);
 316   void assert_leaf_type(Klass* ctxk);
 317   void assert_abstract_with_unique_concrete_subtype(Klass* ctxk, Klass* conck);
 318   void assert_abstract_with_no_concrete_subtype(Klass* ctxk);
 319   void assert_concrete_with_no_concrete_subtype(Klass* ctxk);
 320   void assert_unique_concrete_method(Klass* ctxk, Method* uniqm);
 321   void assert_abstract_with_exclusive_concrete_subtypes(Klass* ctxk, Klass* k1, Klass* k2);
 322   void assert_exclusive_concrete_methods(Klass* ctxk, Method* m1, Method* m2);
 323   void assert_has_no_finalizable_subclasses(Klass* ctxk);
 324   void assert_call_site_target_value(jobject call_site, jobject method_handle);
 325 
 326   // Wrappers for the above in terms of ci classes:
 327   void assert_evol_method(ciMethod* m) {
 328     assert_evol_method(m->get_Method());
 329   }
 330   void assert_leaf_type(ciKlass* ctxk) {
 331     assert_leaf_type(ctxk->get_Klass());
 332   }
 333   void assert_abstract_with_unique_concrete_subtype(ciKlass* ctxk, ciKlass* conck) {
 334     assert_abstract_with_unique_concrete_subtype(ctxk->get_Klass(), conck->get_Klass());
 335   }
 336   void assert_abstract_with_no_concrete_subtype(ciKlass* ctxk) {
 337     assert_abstract_with_no_concrete_subtype(ctxk->get_Klass());
 338   }
 339   void assert_concrete_with_no_concrete_subtype(ciKlass* ctxk) {
 340     assert_concrete_with_no_concrete_subtype(ctxk->get_Klass());
 341   }
 342   void assert_unique_concrete_method(ciKlass* ctxk, ciMethod* uniqm) {
 343     assert_unique_concrete_method(ctxk->get_Klass(), uniqm->get_Method());
 344   }
 345   void assert_abstract_with_exclusive_concrete_subtypes(ciKlass* ctxk, ciKlass* k1, ciKlass* k2) {
 346     assert_abstract_with_exclusive_concrete_subtypes(ctxk->get_Klass(), k1->get_Klass(), k2->get_Klass());
 347   }
 348   void assert_exclusive_concrete_methods(ciKlass* ctxk, ciMethod* m1, ciMethod* m2) {
 349     assert_exclusive_concrete_methods(ctxk->get_Klass(), m1->get_Method(), m2->get_Method());
 350   }
 351   void assert_has_no_finalizable_subclasses(ciKlass* ctxk) {
 352     assert_has_no_finalizable_subclasses(ctxk->get_Klass());
 353   }
 354   void assert_call_site_target_value(ciCallSite* call_site, ciMethodHandle* method_handle) {
 355     assert_call_site_target_value(call_site->constant_encoding(), method_handle->constant_encoding());
 356   }
 357 
 358   // Define whether a given method or type is concrete.
 359   // These methods define the term "concrete" as used in this module.
 360   // For this module, an "abstract" class is one which is non-concrete.
 361   //
 362   // Future optimizations may allow some classes to remain
 363   // non-concrete until their first instantiation, and allow some
 364   // methods to remain non-concrete until their first invocation.
 365   // In that case, there would be a middle ground between concrete
 366   // and abstract (as defined by the Java language and VM).
 367   static bool is_concrete_klass(Klass* k);    // k is instantiable
 368   static bool is_concrete_method(Method* m);  // m is invocable
 369   static Klass* find_finalizable_subclass(Klass* k);
 370 
 371   // These versions of the concreteness queries work through the CI.
 372   // The CI versions are allowed to skew sometimes from the VM
 373   // (oop-based) versions.  The cost of such a difference is a
 374   // (safely) aborted compilation, or a deoptimization, or a missed
 375   // optimization opportunity.
 376   //


 429   static int       find_exclusive_concrete_methods(Klass* ctxk, int mlen, Method* m[]);
 430 
 431   // Create the encoding which will be stored in an nmethod.
 432   void encode_content_bytes();
 433 
 434   address content_bytes() {
 435     assert(_content_bytes != NULL, "encode it first");
 436     return _content_bytes;
 437   }
 438   size_t size_in_bytes() {
 439     assert(_content_bytes != NULL, "encode it first");
 440     return _size_in_bytes;
 441   }
 442 
 443   OopRecorder* oop_recorder() { return _oop_recorder; }
 444   CompileLog*  log()          { return _log; }
 445 
 446   void copy_to(nmethod* nm);
 447 
 448   void log_all_dependencies();
 449   void log_dependency(DepType dept, int nargs, DepValue args[]) {
 450     write_dependency_to(log(), dept, nargs, args);
 451   }
 452   void log_dependency(DepType dept,
 453                       DepValue x0,
 454                       DepValue x1 = DepValue(),
 455                       DepValue x2 = DepValue()) {
 456     if (log() == NULL)  return;
 457     DepValue args[max_arg_count];
 458     args[0] = x0;
 459     args[1] = x1;
 460     args[2] = x2;
 461     assert(2 < max_arg_count, "");
 462     log_dependency(dept, dep_args(dept), args);
 463   }
 464 
 465   class DepArgument : public ResourceObj {
 466    private:
 467     bool  _is_oop;
 468     bool  _valid;
 469     void* _value;
 470    public:
 471     DepArgument() : _is_oop(false), _value(NULL), _valid(false) {}
 472     DepArgument(oop v): _is_oop(true), _value(v), _valid(true) {}
 473     DepArgument(Metadata* v): _is_oop(false), _value(v), _valid(true) {}
 474 
 475     bool is_null() const               { return _value == NULL; }
 476     bool is_oop() const                { return _is_oop; }
 477     bool is_metadata() const           { return !_is_oop; }
 478     bool is_klass() const              { return is_metadata() && metadata_value()->is_klass(); }
 479     bool is_method() const              { return is_metadata() && metadata_value()->is_method(); }
 480 
 481     oop oop_value() const              { assert(_is_oop && _valid, "must be"); return (oop) _value; }
 482     Metadata* metadata_value() const { assert(!_is_oop && _valid, "must be"); return (Metadata*) _value; }
 483   };
 484 
 485   static void write_dependency_to(CompileLog* log,
 486                                   DepType dept,
 487                                   int nargs, ciBaseObject* args[],
 488                                   Klass* witness = NULL);
 489   static void write_dependency_to(CompileLog* log,
 490                                   DepType dept,
 491                                   int nargs, DepArgument args[],
 492                                   Klass* witness = NULL);
 493          void write_dependency_to(CompileLog* log,
 494                                   DepType dept,
 495                                   int nargs, DepValue args[],
 496                                   Klass* witness = NULL);
 497   static void write_dependency_to(xmlStream* xtty,
 498                                   DepType dept,
 499                                   int nargs, DepArgument args[],
 500                                   Klass* witness = NULL);
 501   static void print_dependency(DepType dept,
 502                                int nargs, DepArgument args[],
 503                                Klass* witness = NULL);
 504 
 505  private:
 506   // helper for encoding common context types as zero:
 507   static Klass* ctxk_encoded_as_null(OopRecorder* oop_recorder, DepType dept, DepValue x);
 508 
 509   static Klass* ctxk_encoded_as_null(DepType dept, Metadata* x);
 510 
 511  public:
 512   // Use this to iterate over an nmethod's dependency set.
 513   // Works on new and old dependency sets.
 514   // Usage:
 515   //
 516   // ;
 517   // Dependencies::DepType dept;
 518   // for (Dependencies::DepStream deps(nm); deps.next(); ) {
 519   //   ...
 520   // }
 521   //
 522   // The caller must be in the VM, since oops are not wrapped in handles.
 523   class DepStream {
 524   private:
 525     nmethod*              _code;   // null if in a compiler thread
 526     Dependencies*         _deps;   // null if not in a compiler thread
 527     CompressedReadStream  _bytes;