1 /*
   2  * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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_OOPS_METHOD_HPP
  26 #define SHARE_OOPS_METHOD_HPP
  27 
  28 #include "code/compressedStream.hpp"
  29 #include "compiler/compilerDefinitions.hpp"
  30 #include "interpreter/invocationCounter.hpp"
  31 #include "oops/annotations.hpp"
  32 #include "oops/constantPool.hpp"
  33 #include "oops/methodCounters.hpp"
  34 #include "oops/instanceKlass.hpp"
  35 #include "oops/oop.hpp"
  36 #include "oops/typeArrayOop.hpp"
  37 #include "utilities/accessFlags.hpp"
  38 #include "utilities/align.hpp"
  39 #include "utilities/growableArray.hpp"
  40 #include "utilities/macros.hpp"
  41 #include "utilities/vmEnums.hpp"
  42 #if INCLUDE_JFR
  43 #include "jfr/support/jfrTraceIdExtension.hpp"
  44 #endif
  45 
  46 
  47 // A Method represents a Java method.
  48 //
  49 // Note that most applications load thousands of methods, so keeping the size of this
  50 // class small has a big impact on footprint.
  51 //
  52 // Note that native_function and signature_handler have to be at fixed offsets
  53 // (required by the interpreter)
  54 //
  55 //  Method embedded field layout (after declared fields):
  56 //   [EMBEDDED native_function       (present only if native) ]
  57 //   [EMBEDDED signature_handler     (present only if native) ]
  58 
  59 class CheckedExceptionElement;
  60 class LocalVariableTableElement;
  61 class AdapterHandlerEntry;
  62 class MethodData;
  63 class MethodCounters;
  64 class ConstMethod;
  65 class InlineTableSizes;
  66 class CompiledMethod;
  67 class InterpreterOopMap;
  68 
  69 class Method : public Metadata {
  70  friend class VMStructs;
  71  friend class JVMCIVMStructs;
  72  friend class MethodTest;
  73  private:
  74   // If you add a new field that points to any metaspace object, you
  75   // must add this field to Method::metaspace_pointers_do().
  76   ConstMethod*      _constMethod;                // Method read-only data.
  77   MethodData*       _method_data;
  78   MethodCounters*   _method_counters;
  79   AdapterHandlerEntry* _adapter;
  80   AccessFlags       _access_flags;               // Access flags
  81   int               _vtable_index;               // vtable index of this method (see VtableIndexFlag)
  82                                                  // note: can have vtables with >2**16 elements (because of inheritance)
  83   u2                _intrinsic_id;               // vmSymbols::intrinsic_id (0 == _none)
  84 
  85   // Flags
  86   enum Flags {
  87     _caller_sensitive       = 1 << 0,
  88     _force_inline           = 1 << 1,
  89     _dont_inline            = 1 << 2,
  90     _hidden                 = 1 << 3,
  91     _has_injected_profile   = 1 << 4,
  92     _intrinsic_candidate    = 1 << 5,
  93     _reserved_stack_access  = 1 << 6,
  94     _scalarized_args        = 1 << 7,
  95     _scalarized_return      = 1 << 8,
  96     _c1_needs_stack_repair  = 1 << 9,
  97     _c2_needs_stack_repair  = 1 << 10,
  98     _scoped                 = 1 << 11,
  99     _changes_current_thread = 1 << 12,
 100     _jvmti_mount_transition = 1 << 13,
 101   };
 102   mutable u2 _flags;
 103 
 104   JFR_ONLY(DEFINE_TRACE_FLAG;)
 105 
 106 #ifndef PRODUCT
 107   int64_t _compiled_invocation_count;
 108 
 109   Symbol* _name;
 110 #endif
 111   // Entry point for calling both from and to the interpreter.
 112   address _i2i_entry;           // All-args-on-stack calling convention
 113   // Entry point for calling from compiled code, to compiled code if it exists
 114   // or else the interpreter.
 115   volatile address _from_compiled_entry;           // Cache of: _code ? _code->verified_entry_point()           : _adapter->c2i_entry()
 116   volatile address _from_compiled_inline_ro_entry; // Cache of: _code ? _code->verified_inline_ro_entry_point() : _adapter->c2i_inline_ro_entry()
 117   volatile address _from_compiled_inline_entry;    // Cache of: _code ? _code->verified_inline_entry_point()    : _adapter->c2i_inline_entry()
 118   // The entry point for calling both from and to compiled code is
 119   // "_code->entry_point()".  Because of tiered compilation and de-opt, this
 120   // field can come and go.  It can transition from NULL to not-null at any
 121   // time (whenever a compile completes).  It can transition from not-null to
 122   // NULL only at safepoints (because of a de-opt).
 123   CompiledMethod* volatile _code;                       // Points to the corresponding piece of native code
 124   volatile address           _from_interpreted_entry; // Cache of _code ? _adapter->i2c_entry() : _i2i_entry
 125 
 126   // Constructor
 127   Method(ConstMethod* xconst, AccessFlags access_flags, Symbol* name);
 128  public:
 129 
 130   static Method* allocate(ClassLoaderData* loader_data,
 131                           int byte_code_size,
 132                           AccessFlags access_flags,
 133                           InlineTableSizes* sizes,
 134                           ConstMethod::MethodType method_type,
 135                           Symbol* name,
 136                           TRAPS);
 137 
 138   // CDS and vtbl checking can create an empty Method to get vtbl pointer.
 139   Method(){}
 140 
 141   virtual bool is_method() const { return true; }
 142 
 143 #if INCLUDE_CDS
 144   void remove_unshareable_info();
 145   void restore_unshareable_info(TRAPS);
 146 #endif
 147 
 148   // accessors for instance variables
 149 
 150   ConstMethod* constMethod() const             { return _constMethod; }
 151   void set_constMethod(ConstMethod* xconst)    { _constMethod = xconst; }
 152 
 153 
 154   static address make_adapters(const methodHandle& mh, TRAPS);
 155   address from_compiled_entry() const;
 156   address from_compiled_inline_ro_entry() const;
 157   address from_compiled_inline_entry() const;
 158   address from_compiled_entry_no_trampoline(bool caller_is_c1) const;
 159   address from_interpreted_entry() const;
 160 
 161   // access flag
 162   AccessFlags access_flags() const               { return _access_flags;  }
 163   void set_access_flags(AccessFlags flags)       { _access_flags = flags; }
 164 
 165   // name
 166   Symbol* name() const                           { return constants()->symbol_at(name_index()); }
 167   int name_index() const                         { return constMethod()->name_index();         }
 168   void set_name_index(int index)                 { constMethod()->set_name_index(index);       }
 169 
 170   // signature
 171   Symbol* signature() const                      { return constants()->symbol_at(signature_index()); }
 172   int signature_index() const                    { return constMethod()->signature_index();         }
 173   void set_signature_index(int index)            { constMethod()->set_signature_index(index);       }
 174 
 175   // generics support
 176   Symbol* generic_signature() const              { int idx = generic_signature_index(); return ((idx != 0) ? constants()->symbol_at(idx) : (Symbol*)NULL); }
 177   int generic_signature_index() const            { return constMethod()->generic_signature_index(); }
 178   void set_generic_signature_index(int index)    { constMethod()->set_generic_signature_index(index); }
 179 
 180   // annotations support
 181   AnnotationArray* annotations() const           {
 182     return constMethod()->method_annotations();
 183   }
 184   AnnotationArray* parameter_annotations() const {
 185     return constMethod()->parameter_annotations();
 186   }
 187   AnnotationArray* annotation_default() const    {
 188     return constMethod()->default_annotations();
 189   }
 190   AnnotationArray* type_annotations() const      {
 191     return constMethod()->type_annotations();
 192   }
 193 
 194   // Helper routine: get klass name + "." + method name + signature as
 195   // C string, for the purpose of providing more useful
 196   // fatal error handling. The string is allocated in resource
 197   // area if a buffer is not provided by the caller.
 198   char* name_and_sig_as_C_string() const;
 199   char* name_and_sig_as_C_string(char* buf, int size) const;
 200 
 201   // Static routine in the situations we don't have a Method*
 202   static char* name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature);
 203   static char* name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature, char* buf, int size);
 204 
 205   // Get return type + klass name + "." + method name + ( parameters types )
 206   // as a C string or print it to an outputStream.
 207   // This is to be used to assemble strings passed to Java, so that
 208   // the text more resembles Java code. Used in exception messages.
 209   // Memory is allocated in the resource area; the caller needs
 210   // a ResourceMark.
 211   const char* external_name() const;
 212   void  print_external_name(outputStream *os) const;
 213 
 214   static const char* external_name(                  Klass* klass, Symbol* method_name, Symbol* signature);
 215   static void  print_external_name(outputStream *os, Klass* klass, Symbol* method_name, Symbol* signature);
 216 
 217   Bytecodes::Code java_code_at(int bci) const {
 218     return Bytecodes::java_code_at(this, bcp_from(bci));
 219   }
 220   Bytecodes::Code code_at(int bci) const {
 221     return Bytecodes::code_at(this, bcp_from(bci));
 222   }
 223 
 224   // JVMTI breakpoints
 225 #if !INCLUDE_JVMTI
 226   Bytecodes::Code orig_bytecode_at(int bci) const {
 227     ShouldNotReachHere();
 228     return Bytecodes::_shouldnotreachhere;
 229   }
 230   void set_orig_bytecode_at(int bci, Bytecodes::Code code) {
 231     ShouldNotReachHere();
 232   };
 233   u2   number_of_breakpoints() const {return 0;}
 234 #else // !INCLUDE_JVMTI
 235   Bytecodes::Code orig_bytecode_at(int bci) const;
 236   void set_orig_bytecode_at(int bci, Bytecodes::Code code);
 237   void set_breakpoint(int bci);
 238   void clear_breakpoint(int bci);
 239   void clear_all_breakpoints();
 240   // Tracking number of breakpoints, for fullspeed debugging.
 241   // Only mutated by VM thread.
 242   u2   number_of_breakpoints() const {
 243     MethodCounters* mcs = method_counters();
 244     if (mcs == NULL) {
 245       return 0;
 246     } else {
 247       return mcs->number_of_breakpoints();
 248     }
 249   }
 250   void incr_number_of_breakpoints(Thread* current) {
 251     MethodCounters* mcs = get_method_counters(current);
 252     if (mcs != NULL) {
 253       mcs->incr_number_of_breakpoints();
 254     }
 255   }
 256   void decr_number_of_breakpoints(Thread* current) {
 257     MethodCounters* mcs = get_method_counters(current);
 258     if (mcs != NULL) {
 259       mcs->decr_number_of_breakpoints();
 260     }
 261   }
 262   // Initialization only
 263   void clear_number_of_breakpoints() {
 264     MethodCounters* mcs = method_counters();
 265     if (mcs != NULL) {
 266       mcs->clear_number_of_breakpoints();
 267     }
 268   }
 269 #endif // !INCLUDE_JVMTI
 270 
 271   // index into InstanceKlass methods() array
 272   // note: also used by jfr
 273   u2 method_idnum() const           { return constMethod()->method_idnum(); }
 274   void set_method_idnum(u2 idnum)   { constMethod()->set_method_idnum(idnum); }
 275 
 276   u2 orig_method_idnum() const           { return constMethod()->orig_method_idnum(); }
 277   void set_orig_method_idnum(u2 idnum)   { constMethod()->set_orig_method_idnum(idnum); }
 278 
 279   // code size
 280   int code_size() const                  { return constMethod()->code_size(); }
 281 
 282   // method size in words
 283   int method_size() const                { return sizeof(Method)/wordSize + ( is_native() ? 2 : 0 ); }
 284 
 285   // constant pool for Klass* holding this method
 286   ConstantPool* constants() const              { return constMethod()->constants(); }
 287   void set_constants(ConstantPool* c)          { constMethod()->set_constants(c); }
 288 
 289   // max stack
 290   // return original max stack size for method verification
 291   int  verifier_max_stack() const                { return constMethod()->max_stack(); }
 292   int           max_stack() const                { return constMethod()->max_stack() + extra_stack_entries(); }
 293   void      set_max_stack(int size)              {        constMethod()->set_max_stack(size); }
 294 
 295   // max locals
 296   int  max_locals() const                        { return constMethod()->max_locals(); }
 297   void set_max_locals(int size)                  { constMethod()->set_max_locals(size); }
 298 
 299   int highest_comp_level() const;
 300   void set_highest_comp_level(int level);
 301   int highest_osr_comp_level() const;
 302   void set_highest_osr_comp_level(int level);
 303 
 304 #if COMPILER2_OR_JVMCI
 305   // Count of times method was exited via exception while interpreting
 306   void interpreter_throwout_increment(Thread* current) {
 307     MethodCounters* mcs = get_method_counters(current);
 308     if (mcs != NULL) {
 309       mcs->interpreter_throwout_increment();
 310     }
 311   }
 312 #endif
 313 
 314   int  interpreter_throwout_count() const        {
 315     MethodCounters* mcs = method_counters();
 316     if (mcs == NULL) {
 317       return 0;
 318     } else {
 319       return mcs->interpreter_throwout_count();
 320     }
 321   }
 322 
 323   // Derive stuff from the signature at load time.
 324   void compute_from_signature(Symbol* sig);
 325 
 326   // size of parameters (receiver if any + arguments)
 327   int  size_of_parameters() const                { return constMethod()->size_of_parameters(); }
 328   void set_size_of_parameters(int size)          { constMethod()->set_size_of_parameters(size); }
 329 
 330   bool has_stackmap_table() const {
 331     return constMethod()->has_stackmap_table();
 332   }
 333 
 334   Array<u1>* stackmap_data() const {
 335     return constMethod()->stackmap_data();
 336   }
 337 
 338   void set_stackmap_data(Array<u1>* sd) {
 339     constMethod()->set_stackmap_data(sd);
 340   }
 341 
 342   // exception handler table
 343   bool has_exception_handler() const
 344                              { return constMethod()->has_exception_handler(); }
 345   int exception_table_length() const
 346                              { return constMethod()->exception_table_length(); }
 347   ExceptionTableElement* exception_table_start() const
 348                              { return constMethod()->exception_table_start(); }
 349 
 350   // Finds the first entry point bci of an exception handler for an
 351   // exception of klass ex_klass thrown at throw_bci. A value of NULL
 352   // for ex_klass indicates that the exception klass is not known; in
 353   // this case it matches any constraint class. Returns -1 if the
 354   // exception cannot be handled in this method. The handler
 355   // constraint classes are loaded if necessary. Note that this may
 356   // throw an exception if loading of the constraint classes causes
 357   // an IllegalAccessError (bugid 4307310) or an OutOfMemoryError.
 358   // If an exception is thrown, returns the bci of the
 359   // exception handler which caused the exception to be thrown, which
 360   // is needed for proper retries. See, for example,
 361   // InterpreterRuntime::exception_handler_for_exception.
 362   static int fast_exception_handler_bci_for(const methodHandle& mh, Klass* ex_klass, int throw_bci, TRAPS);
 363 
 364   static bool register_native(Klass* k,
 365                               Symbol* name,
 366                               Symbol* signature,
 367                               address entry,
 368                               TRAPS);
 369 
 370   // method data access
 371   MethodData* method_data() const              {
 372     return _method_data;
 373   }
 374 
 375   void set_method_data(MethodData* data);
 376 
 377   MethodCounters* method_counters() const {
 378     return _method_counters;
 379   }
 380 
 381   void clear_method_counters() {
 382     _method_counters = NULL;
 383   }
 384 
 385   bool init_method_counters(MethodCounters* counters);
 386 
 387   int prev_event_count() const {
 388     MethodCounters* mcs = method_counters();
 389     return mcs == NULL ? 0 : mcs->prev_event_count();
 390   }
 391   void set_prev_event_count(int count) {
 392     MethodCounters* mcs = method_counters();
 393     if (mcs != NULL) {
 394       mcs->set_prev_event_count(count);
 395     }
 396   }
 397   jlong prev_time() const {
 398     MethodCounters* mcs = method_counters();
 399     return mcs == NULL ? 0 : mcs->prev_time();
 400   }
 401   void set_prev_time(jlong time) {
 402     MethodCounters* mcs = method_counters();
 403     if (mcs != NULL) {
 404       mcs->set_prev_time(time);
 405     }
 406   }
 407   float rate() const {
 408     MethodCounters* mcs = method_counters();
 409     return mcs == NULL ? 0 : mcs->rate();
 410   }
 411   void set_rate(float rate) {
 412     MethodCounters* mcs = method_counters();
 413     if (mcs != NULL) {
 414       mcs->set_rate(rate);
 415     }
 416   }
 417 
 418   int invocation_count() const;
 419   int backedge_count() const;
 420 
 421   bool was_executed_more_than(int n);
 422   bool was_never_executed()                     { return !was_executed_more_than(0);  }
 423 
 424   static void build_profiling_method_data(const methodHandle& method, TRAPS);
 425 
 426   static MethodCounters* build_method_counters(Thread* current, Method* m);
 427 
 428   int interpreter_invocation_count()            { return invocation_count();          }
 429 
 430 #ifndef PRODUCT
 431   int64_t  compiled_invocation_count() const    { return _compiled_invocation_count;}
 432   void set_compiled_invocation_count(int count) { _compiled_invocation_count = (int64_t)count; }
 433 #else
 434   // for PrintMethodData in a product build
 435   int64_t  compiled_invocation_count() const    { return 0; }
 436 #endif // not PRODUCT
 437 
 438   // nmethod/verified compiler entry
 439   address verified_code_entry();
 440   address verified_inline_code_entry();
 441   address verified_inline_ro_code_entry();
 442   bool check_code() const;      // Not inline to avoid circular ref
 443   CompiledMethod* volatile code() const;
 444 
 445   // Locks CompiledMethod_lock if not held.
 446   void unlink_code(CompiledMethod *compare);
 447   // Locks CompiledMethod_lock if not held.
 448   void unlink_code();
 449 
 450 private:
 451   // Either called with CompiledMethod_lock held or from constructor.
 452   void clear_code();
 453 
 454 public:
 455   static void set_code(const methodHandle& mh, CompiledMethod* code);
 456   void set_adapter_entry(AdapterHandlerEntry* adapter) {
 457     _adapter = adapter;
 458   }
 459   void set_from_compiled_entry(address entry) {
 460     _from_compiled_entry = entry;
 461   }
 462   void set_from_compiled_inline_ro_entry(address entry) {
 463     _from_compiled_inline_ro_entry = entry;
 464   }
 465   void set_from_compiled_inline_entry(address entry) {
 466     _from_compiled_inline_entry = entry;
 467   }
 468 
 469   address get_i2c_entry();
 470   address get_c2i_entry();
 471   address get_c2i_inline_entry();
 472   address get_c2i_unverified_entry();
 473   address get_c2i_unverified_inline_entry();
 474   address get_c2i_no_clinit_check_entry();
 475   AdapterHandlerEntry* adapter() const {
 476     return _adapter;
 477   }
 478   // setup entry points
 479   void link_method(const methodHandle& method, TRAPS);
 480   // clear entry points. Used by sharing code during dump time
 481   void unlink_method() NOT_CDS_RETURN;
 482 
 483   // the number of argument reg slots that the compiled method uses on the stack.
 484   int num_stack_arg_slots() const { return constMethod()->num_stack_arg_slots(); }
 485 
 486   virtual void metaspace_pointers_do(MetaspaceClosure* iter);
 487   virtual MetaspaceObj::Type type() const { return MethodType; }
 488 
 489   // vtable index
 490   enum VtableIndexFlag {
 491     // Valid vtable indexes are non-negative (>= 0).
 492     // These few negative values are used as sentinels.
 493     itable_index_max        = -10, // first itable index, growing downward
 494     pending_itable_index    = -9,  // itable index will be assigned
 495     invalid_vtable_index    = -4,  // distinct from any valid vtable index
 496     garbage_vtable_index    = -3,  // not yet linked; no vtable layout yet
 497     nonvirtual_vtable_index = -2   // there is no need for vtable dispatch
 498     // 6330203 Note:  Do not use -1, which was overloaded with many meanings.
 499   };
 500   DEBUG_ONLY(bool valid_vtable_index() const     { return _vtable_index >= nonvirtual_vtable_index; })
 501   bool has_vtable_index() const                  { return _vtable_index >= 0; }
 502   int  vtable_index() const                      { return _vtable_index; }
 503   void set_vtable_index(int index);
 504   DEBUG_ONLY(bool valid_itable_index() const     { return _vtable_index <= pending_itable_index; })
 505   bool has_itable_index() const                  { return _vtable_index <= itable_index_max; }
 506   int  itable_index() const                      { assert(valid_itable_index(), "");
 507                                                    return itable_index_max - _vtable_index; }
 508   void set_itable_index(int index);
 509 
 510   // interpreter entry
 511   address interpreter_entry() const              { return _i2i_entry; }
 512   // Only used when first initialize so we can set _i2i_entry and _from_interpreted_entry
 513   void set_interpreter_entry(address entry) {
 514     if (_i2i_entry != entry) {
 515       _i2i_entry = entry;
 516     }
 517     if (_from_interpreted_entry != entry) {
 518       _from_interpreted_entry = entry;
 519     }
 520   }
 521 
 522   // native function (used for native methods only)
 523   enum {
 524     native_bind_event_is_interesting = true
 525   };
 526   address native_function() const                { return *(native_function_addr()); }
 527 
 528   // Must specify a real function (not NULL).
 529   // Use clear_native_function() to unregister.
 530   void set_native_function(address function, bool post_event_flag);
 531   bool has_native_function() const;
 532   void clear_native_function();
 533 
 534   // signature handler (used for native methods only)
 535   address signature_handler() const              { return *(signature_handler_addr()); }
 536   void set_signature_handler(address handler);
 537 
 538   // Interpreter oopmap support
 539   void mask_for(int bci, InterpreterOopMap* mask);
 540 
 541   // operations on invocation counter
 542   void print_invocation_count();
 543 
 544   // byte codes
 545   void    set_code(address code)      { return constMethod()->set_code(code); }
 546   address code_base() const           { return constMethod()->code_base(); }
 547   bool    contains(address bcp) const { return constMethod()->contains(bcp); }
 548 
 549   // prints byte codes
 550   void print_codes() const            { print_codes_on(tty); }
 551   void print_codes_on(outputStream* st) const;
 552   void print_codes_on(int from, int to, outputStream* st) const;
 553 
 554   // method parameters
 555   bool has_method_parameters() const
 556                          { return constMethod()->has_method_parameters(); }
 557   int method_parameters_length() const
 558                          { return constMethod()->method_parameters_length(); }
 559   MethodParametersElement* method_parameters_start() const
 560                           { return constMethod()->method_parameters_start(); }
 561 
 562   // checked exceptions
 563   int checked_exceptions_length() const
 564                          { return constMethod()->checked_exceptions_length(); }
 565   CheckedExceptionElement* checked_exceptions_start() const
 566                           { return constMethod()->checked_exceptions_start(); }
 567 
 568   // localvariable table
 569   bool has_localvariable_table() const
 570                           { return constMethod()->has_localvariable_table(); }
 571   int localvariable_table_length() const
 572                         { return constMethod()->localvariable_table_length(); }
 573   LocalVariableTableElement* localvariable_table_start() const
 574                          { return constMethod()->localvariable_table_start(); }
 575 
 576   bool has_linenumber_table() const
 577                               { return constMethod()->has_linenumber_table(); }
 578   u_char* compressed_linenumber_table() const
 579                        { return constMethod()->compressed_linenumber_table(); }
 580 
 581   // method holder (the Klass* holding this method)
 582   InstanceKlass* method_holder() const         { return constants()->pool_holder(); }
 583 
 584   Symbol* klass_name() const;                    // returns the name of the method holder
 585   BasicType result_type() const                  { return constMethod()->result_type(); }
 586   bool is_returning_oop() const                  { BasicType r = result_type(); return is_reference_type(r); }
 587   InlineKlass* returns_inline_type(Thread* thread) const;
 588 
 589   // Checked exceptions thrown by this method (resolved to mirrors)
 590   objArrayHandle resolved_checked_exceptions(TRAPS) { return resolved_checked_exceptions_impl(this, THREAD); }
 591 
 592   // Access flags
 593   bool is_public() const                         { return access_flags().is_public();      }
 594   bool is_private() const                        { return access_flags().is_private();     }
 595   bool is_protected() const                      { return access_flags().is_protected();   }
 596   bool is_package_private() const                { return !is_public() && !is_private() && !is_protected(); }
 597   bool is_static() const                         { return access_flags().is_static();      }
 598   bool is_final() const                          { return access_flags().is_final();       }
 599   bool is_synchronized() const                   { return access_flags().is_synchronized();}
 600   bool is_native() const                         { return access_flags().is_native();      }
 601   bool is_abstract() const                       { return access_flags().is_abstract();    }
 602   bool is_synthetic() const                      { return access_flags().is_synthetic();   }
 603 
 604   // returns true if contains only return operation
 605   bool is_empty_method() const;
 606 
 607   // returns true if this is a vanilla constructor
 608   bool is_vanilla_constructor() const;
 609 
 610   // checks method and its method holder
 611   bool is_final_method() const;
 612   bool is_final_method(AccessFlags class_access_flags) const;
 613   // interface method declared with 'default' - excludes private interface methods
 614   bool is_default_method() const;
 615 
 616   // true if method needs no dynamic dispatch (final and/or no vtable entry)
 617   bool can_be_statically_bound() const;
 618   bool can_be_statically_bound(InstanceKlass* context) const;
 619   bool can_be_statically_bound(AccessFlags class_access_flags) const;
 620 
 621   // true if method can omit stack trace in throw in compiled code.
 622   bool can_omit_stack_trace();
 623 
 624   // returns true if the method has any backward branches.
 625   bool has_loops() {
 626     return access_flags().loops_flag_init() ? access_flags().has_loops() : compute_has_loops_flag();
 627   };
 628 
 629   bool compute_has_loops_flag();
 630 
 631   bool has_jsrs() {
 632     return access_flags().has_jsrs();
 633   };
 634   void set_has_jsrs() {
 635     _access_flags.set_has_jsrs();
 636   }
 637 
 638   // returns true if the method has any monitors.
 639   bool has_monitors() const                      { return is_synchronized() || access_flags().has_monitor_bytecodes(); }
 640   bool has_monitor_bytecodes() const             { return access_flags().has_monitor_bytecodes(); }
 641 
 642   void set_has_monitor_bytecodes()               { _access_flags.set_has_monitor_bytecodes(); }
 643 
 644   // monitor matching. This returns a conservative estimate of whether the monitorenter/monitorexit bytecodes
 645   // propererly nest in the method. It might return false, even though they actually nest properly, since the info.
 646   // has not been computed yet.
 647   bool guaranteed_monitor_matching() const       { return access_flags().is_monitor_matching(); }
 648   void set_guaranteed_monitor_matching()         { _access_flags.set_monitor_matching(); }
 649 
 650   // returns true if the method is an accessor function (setter/getter).
 651   bool is_accessor() const;
 652 
 653   // returns true if the method is a getter
 654   bool is_getter() const;
 655 
 656   // returns true if the method is a setter
 657   bool is_setter() const;
 658 
 659   // returns true if the method does nothing but return a constant of primitive type
 660   bool is_constant_getter() const;
 661 
 662   // returns true if the method name is <clinit> and the method has
 663   // valid static initializer flags.
 664   bool is_class_initializer() const;
 665 
 666   // returns true if the method name is <init> and the method is not a static factory
 667   bool is_object_constructor() const;
 668 
 669   // returns true if the method is an object constructor or class initializer
 670   // (non-static <init> or <clinit>), but false for factories (static <init>).
 671   bool is_object_constructor_or_class_initializer() const;
 672 
 673   // returns true if the method name is <init> and the method is static
 674   bool is_static_init_factory() const;
 675 
 676   // compiled code support
 677   // NOTE: code() is inherently racy as deopt can be clearing code
 678   // simultaneously. Use with caution.
 679   bool has_compiled_code() const;
 680 
 681   bool needs_clinit_barrier() const;
 682 
 683   // sizing
 684   static int header_size()                       {
 685     return align_up((int)sizeof(Method), wordSize) / wordSize;
 686   }
 687   static int size(bool is_native);
 688   int size() const                               { return method_size(); }
 689   void log_touched(Thread* current);
 690   static void print_touched_methods(outputStream* out);
 691 
 692   // interpreter support
 693   static ByteSize const_offset()                 { return byte_offset_of(Method, _constMethod       ); }
 694   static ByteSize access_flags_offset()          { return byte_offset_of(Method, _access_flags      ); }
 695   static ByteSize from_compiled_offset()         { return byte_offset_of(Method, _from_compiled_entry); }
 696   static ByteSize from_compiled_inline_offset()  { return byte_offset_of(Method, _from_compiled_inline_entry); }
 697   static ByteSize from_compiled_inline_ro_offset(){ return byte_offset_of(Method, _from_compiled_inline_ro_entry); }
 698   static ByteSize code_offset()                  { return byte_offset_of(Method, _code); }
 699   static ByteSize flags_offset()                 { return byte_offset_of(Method, _flags); }
 700   static ByteSize method_data_offset()           {
 701     return byte_offset_of(Method, _method_data);
 702   }
 703   static ByteSize method_counters_offset()       {
 704     return byte_offset_of(Method, _method_counters);
 705   }
 706 #ifndef PRODUCT
 707   static ByteSize compiled_invocation_counter_offset() { return byte_offset_of(Method, _compiled_invocation_count); }
 708 #endif // not PRODUCT
 709   static ByteSize native_function_offset()       { return in_ByteSize(sizeof(Method));                 }
 710   static ByteSize from_interpreted_offset()      { return byte_offset_of(Method, _from_interpreted_entry ); }
 711   static ByteSize interpreter_entry_offset()     { return byte_offset_of(Method, _i2i_entry ); }
 712   static ByteSize signature_handler_offset()     { return in_ByteSize(sizeof(Method) + wordSize);      }
 713   static ByteSize itable_index_offset()          { return byte_offset_of(Method, _vtable_index ); }
 714 
 715   // for code generation
 716   static int method_data_offset_in_bytes()       { return offset_of(Method, _method_data); }
 717   static int intrinsic_id_offset_in_bytes()      { return offset_of(Method, _intrinsic_id); }
 718   static int intrinsic_id_size_in_bytes()        { return sizeof(u2); }
 719 
 720   // Static methods that are used to implement member methods where an exposed this pointer
 721   // is needed due to possible GCs
 722   static objArrayHandle resolved_checked_exceptions_impl(Method* method, TRAPS);
 723 
 724   // Returns the byte code index from the byte code pointer
 725   int     bci_from(address bcp) const;
 726   address bcp_from(int bci) const;
 727   address bcp_from(address bcp) const;
 728   int validate_bci_from_bcp(address bcp) const;
 729   int validate_bci(int bci) const;
 730 
 731   // Returns the line number for a bci if debugging information for the method is prowided,
 732   // -1 is returned otherwise.
 733   int line_number_from_bci(int bci) const;
 734 
 735   // Reflection support
 736   bool is_overridden_in(Klass* k) const;
 737 
 738   // Stack walking support
 739   bool is_ignored_by_security_stack_walk() const;
 740 
 741   // JSR 292 support
 742   bool is_method_handle_intrinsic() const;          // MethodHandles::is_signature_polymorphic_intrinsic(intrinsic_id)
 743   bool is_compiled_lambda_form() const;             // intrinsic_id() == vmIntrinsics::_compiledLambdaForm
 744   bool has_member_arg() const;                      // intrinsic_id() == vmIntrinsics::_linkToSpecial, etc.
 745   static methodHandle make_method_handle_intrinsic(vmIntrinsicID iid, // _invokeBasic, _linkToVirtual
 746                                                    Symbol* signature, //anything at all
 747                                                    TRAPS);
 748 
 749 
 750   // Continuation
 751   inline bool is_continuation_enter_intrinsic() const;
 752   inline bool is_continuation_yield_intrinsic() const;
 753   inline bool is_continuation_native_intrinsic() const;
 754   inline bool is_special_native_intrinsic() const;
 755 
 756   static Klass* check_non_bcp_klass(Klass* klass);
 757 
 758   enum {
 759     // How many extra stack entries for invokedynamic
 760     extra_stack_entries_for_jsr292 = 1
 761   };
 762 
 763   // this operates only on invoke methods:
 764   // presize interpreter frames for extra interpreter stack entries, if needed
 765   // Account for the extra appendix argument for invokehandle/invokedynamic
 766   static int extra_stack_entries() { return extra_stack_entries_for_jsr292; }
 767   static int extra_stack_words();  // = extra_stack_entries() * Interpreter::stackElementSize
 768 
 769   // RedefineClasses() support:
 770   bool is_old() const                               { return access_flags().is_old(); }
 771   void set_is_old()                                 { _access_flags.set_is_old(); }
 772   bool is_obsolete() const                          { return access_flags().is_obsolete(); }
 773   void set_is_obsolete()                            { _access_flags.set_is_obsolete(); }
 774   bool is_deleted() const                           { return access_flags().is_deleted(); }
 775   void set_is_deleted()                             { _access_flags.set_is_deleted(); }
 776 
 777   bool on_stack() const                             { return access_flags().on_stack(); }
 778   void set_on_stack(const bool value);
 779 
 780   void record_gc_epoch();
 781 
 782   // see the definition in Method*.cpp for the gory details
 783   bool should_not_be_cached() const;
 784 
 785   // JVMTI Native method prefixing support:
 786   bool is_prefixed_native() const                   { return access_flags().is_prefixed_native(); }
 787   void set_is_prefixed_native()                     { _access_flags.set_is_prefixed_native(); }
 788 
 789   // Rewriting support
 790   static methodHandle clone_with_new_data(const methodHandle& m, u_char* new_code, int new_code_length,
 791                                           u_char* new_compressed_linenumber_table, int new_compressed_linenumber_size, TRAPS);
 792 
 793   // jmethodID handling
 794   // Because the useful life-span of a jmethodID cannot be determined,
 795   // once created they are never reclaimed.  The methods to which they refer,
 796   // however, can be GC'ed away if the class is unloaded or if the method is
 797   // made obsolete or deleted -- in these cases, the jmethodID
 798   // refers to NULL (as is the case for any weak reference).
 799   static jmethodID make_jmethod_id(ClassLoaderData* loader_data, Method* mh);
 800   static void destroy_jmethod_id(ClassLoaderData* loader_data, jmethodID mid);
 801 
 802   // Ensure there is enough capacity in the internal tracking data
 803   // structures to hold the number of jmethodIDs you plan to generate.
 804   // This saves substantial time doing allocations.
 805   static void ensure_jmethod_ids(ClassLoaderData* loader_data, int capacity);
 806 
 807   // Use resolve_jmethod_id() in situations where the caller is expected
 808   // to provide a valid jmethodID; the only sanity checks are in asserts;
 809   // result guaranteed not to be NULL.
 810   inline static Method* resolve_jmethod_id(jmethodID mid) {
 811     assert(mid != NULL, "JNI method id should not be null");
 812     return *((Method**)mid);
 813   }
 814 
 815   // Use checked_resolve_jmethod_id() in situations where the caller
 816   // should provide a valid jmethodID, but might not. NULL is returned
 817   // when the jmethodID does not refer to a valid method.
 818   static Method* checked_resolve_jmethod_id(jmethodID mid);
 819 
 820   static void change_method_associated_with_jmethod_id(jmethodID old_jmid_ptr, Method* new_method);
 821   static bool is_method_id(jmethodID mid);
 822 
 823   // Clear methods
 824   static void clear_jmethod_ids(ClassLoaderData* loader_data);
 825   static void print_jmethod_ids_count(const ClassLoaderData* loader_data, outputStream* out) PRODUCT_RETURN;
 826 
 827   // Get this method's jmethodID -- allocate if it doesn't exist
 828   jmethodID jmethod_id();
 829 
 830   // Lookup the jmethodID for this method.  Return NULL if not found.
 831   // NOTE that this function can be called from a signal handler
 832   // (see AsyncGetCallTrace support for Forte Analyzer) and this
 833   // needs to be async-safe. No allocation should be done and
 834   // so handles are not used to avoid deadlock.
 835   jmethodID find_jmethod_id_or_null()               { return method_holder()->jmethod_id_or_null(this); }
 836 
 837   // Support for inlining of intrinsic methods
 838   vmIntrinsicID intrinsic_id() const          { return (vmIntrinsicID) _intrinsic_id;           }
 839   void     set_intrinsic_id(vmIntrinsicID id) {                           _intrinsic_id = (u2) id; }
 840 
 841   // Helper routines for intrinsic_id() and vmIntrinsics::method().
 842   void init_intrinsic_id(vmSymbolID klass_id);     // updates from _none if a match
 843   static vmSymbolID klass_id_for_intrinsics(const Klass* holder);
 844 
 845   bool caller_sensitive() {
 846     return (_flags & _caller_sensitive) != 0;
 847   }
 848   void set_caller_sensitive(bool x) {
 849     _flags = x ? (_flags | _caller_sensitive) : (_flags & ~_caller_sensitive);
 850   }
 851 
 852   bool force_inline() {
 853     return (_flags & _force_inline) != 0;
 854   }
 855   void set_force_inline(bool x) {
 856     _flags = x ? (_flags | _force_inline) : (_flags & ~_force_inline);
 857   }
 858 
 859   bool dont_inline() {
 860     return (_flags & _dont_inline) != 0;
 861   }
 862   void set_dont_inline(bool x) {
 863     _flags = x ? (_flags | _dont_inline) : (_flags & ~_dont_inline);
 864   }
 865 
 866   bool changes_current_thread() {
 867     return (_flags & _changes_current_thread) != 0;
 868   }
 869   void set_changes_current_thread(bool x) {
 870     _flags = x ? (_flags | _changes_current_thread) : (_flags & ~_changes_current_thread);
 871   }
 872 
 873   bool jvmti_mount_transition() {
 874     return (_flags & _jvmti_mount_transition) != 0;
 875   }
 876   void set_jvmti_mount_transition(bool x) {
 877     _flags = x ? (_flags | _jvmti_mount_transition) : (_flags & ~_jvmti_mount_transition);
 878   }
 879 
 880   bool is_hidden() const {
 881     return (_flags & _hidden) != 0;
 882   }
 883 
 884   void set_hidden(bool x) {
 885     _flags = x ? (_flags | _hidden) : (_flags & ~_hidden);
 886   }
 887 
 888   bool is_scoped() const {
 889     return (_flags & _scoped) != 0;
 890   }
 891 
 892   void set_scoped(bool x) {
 893     _flags = x ? (_flags | _scoped) : (_flags & ~_scoped);
 894   }
 895 
 896   bool intrinsic_candidate() {
 897     return (_flags & _intrinsic_candidate) != 0;
 898   }
 899   void set_intrinsic_candidate(bool x) {
 900     _flags = x ? (_flags | _intrinsic_candidate) : (_flags & ~_intrinsic_candidate);
 901   }
 902 
 903   bool has_injected_profile() {
 904     return (_flags & _has_injected_profile) != 0;
 905   }
 906   void set_has_injected_profile(bool x) {
 907     _flags = x ? (_flags | _has_injected_profile) : (_flags & ~_has_injected_profile);
 908   }
 909 
 910   bool has_reserved_stack_access() {
 911     return (_flags & _reserved_stack_access) != 0;
 912   }
 913 
 914   void set_has_reserved_stack_access(bool x) {
 915     _flags = x ? (_flags | _reserved_stack_access) : (_flags & ~_reserved_stack_access);
 916   }
 917 
 918   bool has_scalarized_args() const {
 919     return (_flags & _scalarized_args) != 0;
 920   }
 921 
 922   void set_has_scalarized_args(bool x) {
 923     _flags = x ? (_flags | _scalarized_args) : (_flags & ~_scalarized_args);
 924   }
 925 
 926   bool has_scalarized_return() const {
 927     return (_flags & _scalarized_return) != 0;
 928   }
 929 
 930   void set_has_scalarized_return(bool x) {
 931     _flags = x ? (_flags | _scalarized_return) : (_flags & ~_scalarized_return);
 932   }
 933 
 934   bool is_scalarized_arg(int idx) const;
 935 
 936   bool c1_needs_stack_repair() {
 937     return (_flags & _c1_needs_stack_repair) != 0;
 938   }
 939 
 940   bool c2_needs_stack_repair() {
 941     return (_flags & _c2_needs_stack_repair) != 0;
 942   }
 943 
 944   void set_c1_needs_stack_repair(bool x) {
 945     _flags = x ? (_flags | _c1_needs_stack_repair) : (_flags & ~_c1_needs_stack_repair);
 946   }
 947 
 948   void set_c2_needs_stack_repair(bool x) {
 949     _flags = x ? (_flags | _c2_needs_stack_repair) : (_flags & ~_c2_needs_stack_repair);
 950   }
 951 
 952   JFR_ONLY(DEFINE_TRACE_FLAG_ACCESSOR;)
 953 
 954   ConstMethod::MethodType method_type() const {
 955       return _constMethod->method_type();
 956   }
 957   bool is_overpass() const { return method_type() == ConstMethod::OVERPASS; }
 958 
 959   // On-stack replacement support
 960   bool has_osr_nmethod(int level, bool match_level) {
 961    return method_holder()->lookup_osr_nmethod(this, InvocationEntryBci, level, match_level) != NULL;
 962   }
 963 
 964   int mark_osr_nmethods() {
 965     return method_holder()->mark_osr_nmethods(this);
 966   }
 967 
 968   nmethod* lookup_osr_nmethod_for(int bci, int level, bool match_level) {
 969     return method_holder()->lookup_osr_nmethod(this, bci, level, match_level);
 970   }
 971 
 972   // Find if klass for method is loaded
 973   bool is_klass_loaded_by_klass_index(int klass_index) const;
 974   bool is_klass_loaded(int refinfo_index, bool must_be_resolved = false) const;
 975 
 976   // Indicates whether compilation failed earlier for this method, or
 977   // whether it is not compilable for another reason like having a
 978   // breakpoint set in it.
 979   bool  is_not_compilable(int comp_level = CompLevel_any) const;
 980   void set_not_compilable(const char* reason, int comp_level = CompLevel_all, bool report = true);
 981   void set_not_compilable_quietly(const char* reason, int comp_level = CompLevel_all) {
 982     set_not_compilable(reason, comp_level, false);
 983   }
 984   bool  is_not_osr_compilable(int comp_level = CompLevel_any) const;
 985   void set_not_osr_compilable(const char* reason, int comp_level = CompLevel_all, bool report = true);
 986   void set_not_osr_compilable_quietly(const char* reason, int comp_level = CompLevel_all) {
 987     set_not_osr_compilable(reason, comp_level, false);
 988   }
 989   bool is_always_compilable() const;
 990 
 991  private:
 992   void print_made_not_compilable(int comp_level, bool is_osr, bool report, const char* reason);
 993 
 994  public:
 995   MethodCounters* get_method_counters(Thread* current) {
 996     if (_method_counters == NULL) {
 997       build_method_counters(current, this);
 998     }
 999     return _method_counters;
1000   }
1001 
1002   bool   is_not_c1_compilable() const         { return access_flags().is_not_c1_compilable();  }
1003   void  set_not_c1_compilable()               {       _access_flags.set_not_c1_compilable();   }
1004   void clear_not_c1_compilable()              {       _access_flags.clear_not_c1_compilable(); }
1005   bool   is_not_c2_compilable() const         { return access_flags().is_not_c2_compilable();  }
1006   void  set_not_c2_compilable()               {       _access_flags.set_not_c2_compilable();   }
1007   void clear_not_c2_compilable()              {       _access_flags.clear_not_c2_compilable(); }
1008 
1009   bool    is_not_c1_osr_compilable() const    { return is_not_c1_compilable(); }  // don't waste an accessFlags bit
1010   void   set_not_c1_osr_compilable()          {       set_not_c1_compilable(); }  // don't waste an accessFlags bit
1011   void clear_not_c1_osr_compilable()          {     clear_not_c1_compilable(); }  // don't waste an accessFlags bit
1012   bool   is_not_c2_osr_compilable() const     { return access_flags().is_not_c2_osr_compilable();  }
1013   void  set_not_c2_osr_compilable()           {       _access_flags.set_not_c2_osr_compilable();   }
1014   void clear_not_c2_osr_compilable()          {       _access_flags.clear_not_c2_osr_compilable(); }
1015 
1016   // Background compilation support
1017   bool queued_for_compilation() const  { return access_flags().queued_for_compilation(); }
1018   void set_queued_for_compilation()    { _access_flags.set_queued_for_compilation();     }
1019   void clear_queued_for_compilation()  { _access_flags.clear_queued_for_compilation();   }
1020 
1021   // Resolve all classes in signature, return 'true' if successful
1022   static bool load_signature_classes(const methodHandle& m, TRAPS);
1023 
1024   // Return if true if not all classes references in signature, including return type, has been loaded
1025   static bool has_unloaded_classes_in_signature(const methodHandle& m, TRAPS);
1026 
1027   // Printing
1028   void print_short_name(outputStream* st = tty) const; // prints as klassname::methodname; Exposed so field engineers can debug VM
1029 #if INCLUDE_JVMTI
1030   void print_name(outputStream* st = tty) const; // prints as "virtual void foo(int)"; exposed for -Xlog:redefine+class
1031 #else
1032   void print_name(outputStream* st = tty) const  PRODUCT_RETURN; // prints as "virtual void foo(int)"
1033 #endif
1034 
1035   typedef int (*method_comparator_func)(Method* a, Method* b);
1036 
1037   // Helper routine used for method sorting
1038   static void sort_methods(Array<Method*>* methods, bool set_idnums = true, method_comparator_func func = NULL);
1039 
1040   // Deallocation function for redefine classes or if an error occurs
1041   void deallocate_contents(ClassLoaderData* loader_data);
1042 
1043   void release_C_heap_structures();
1044 
1045   Method* get_new_method() const {
1046     InstanceKlass* holder = method_holder();
1047     Method* new_method = holder->method_with_idnum(orig_method_idnum());
1048 
1049     assert(new_method != NULL, "method_with_idnum() should not be NULL");
1050     assert(this != new_method, "sanity check");
1051     return new_method;
1052   }
1053 
1054   // Printing
1055 #ifndef PRODUCT
1056   void print_on(outputStream* st) const;
1057 #endif
1058   void print_value_on(outputStream* st) const;
1059   void print_linkage_flags(outputStream* st) PRODUCT_RETURN;
1060 
1061   const char* internal_name() const { return "{method}"; }
1062 
1063   // Check for valid method pointer
1064   static bool has_method_vptr(const void* ptr);
1065   static bool is_valid_method(const Method* m);
1066 
1067   // Verify
1068   void verify() { verify_on(tty); }
1069   void verify_on(outputStream* st);
1070 
1071  private:
1072 
1073   // Inlined elements
1074   address* native_function_addr() const          { assert(is_native(), "must be native"); return (address*) (this+1); }
1075   address* signature_handler_addr() const        { return native_function_addr() + 1; }
1076 
1077   void set_num_stack_arg_slots(int n) { constMethod()->set_num_stack_arg_slots(n); }
1078 };
1079 
1080 
1081 // Utility class for compressing line number tables
1082 
1083 class CompressedLineNumberWriteStream: public CompressedWriteStream {
1084  private:
1085   int _bci;
1086   int _line;
1087  public:
1088   // Constructor
1089   CompressedLineNumberWriteStream(int initial_size) : CompressedWriteStream(initial_size), _bci(0), _line(0) {}
1090   CompressedLineNumberWriteStream(u_char* buffer, int initial_size) : CompressedWriteStream(buffer, initial_size), _bci(0), _line(0) {}
1091 
1092   // Write (bci, line number) pair to stream
1093   void write_pair_regular(int bci_delta, int line_delta);
1094 
1095   // If (bci delta, line delta) fits in (5-bit unsigned, 3-bit unsigned)
1096   // we save it as one byte, otherwise we write a 0xFF escape character
1097   // and use regular compression. 0x0 is used as end-of-stream terminator.
1098   void write_pair_inline(int bci, int line);
1099 
1100   void write_pair(int bci, int line);
1101 
1102   // Write end-of-stream marker
1103   void write_terminator()                        { write_byte(0); }
1104 };
1105 
1106 
1107 // Utility class for decompressing line number tables
1108 
1109 class CompressedLineNumberReadStream: public CompressedReadStream {
1110  private:
1111   int _bci;
1112   int _line;
1113  public:
1114   // Constructor
1115   CompressedLineNumberReadStream(u_char* buffer);
1116   // Read (bci, line number) pair from stream. Returns false at end-of-stream.
1117   bool read_pair();
1118   // Accessing bci and line number (after calling read_pair)
1119   int bci() const                               { return _bci; }
1120   int line() const                              { return _line; }
1121 };
1122 
1123 
1124 #if INCLUDE_JVMTI
1125 
1126 /// Fast Breakpoints.
1127 
1128 // If this structure gets more complicated (because bpts get numerous),
1129 // move it into its own header.
1130 
1131 // There is presently no provision for concurrent access
1132 // to breakpoint lists, which is only OK for JVMTI because
1133 // breakpoints are written only at safepoints, and are read
1134 // concurrently only outside of safepoints.
1135 
1136 class BreakpointInfo : public CHeapObj<mtClass> {
1137   friend class VMStructs;
1138  private:
1139   Bytecodes::Code  _orig_bytecode;
1140   int              _bci;
1141   u2               _name_index;       // of method
1142   u2               _signature_index;  // of method
1143   BreakpointInfo*  _next;             // simple storage allocation
1144 
1145  public:
1146   BreakpointInfo(Method* m, int bci);
1147 
1148   // accessors
1149   Bytecodes::Code orig_bytecode()                     { return _orig_bytecode; }
1150   void        set_orig_bytecode(Bytecodes::Code code) { _orig_bytecode = code; }
1151   int         bci()                                   { return _bci; }
1152 
1153   BreakpointInfo*          next() const               { return _next; }
1154   void                 set_next(BreakpointInfo* n)    { _next = n; }
1155 
1156   // helps for searchers
1157   bool match(const Method* m, int bci) {
1158     return bci == _bci && match(m);
1159   }
1160 
1161   bool match(const Method* m) {
1162     return _name_index == m->name_index() &&
1163       _signature_index == m->signature_index();
1164   }
1165 
1166   void set(Method* method);
1167   void clear(Method* method);
1168 };
1169 
1170 #endif // INCLUDE_JVMTI
1171 
1172 // Utility class for access exception handlers
1173 class ExceptionTable : public StackObj {
1174  private:
1175   ExceptionTableElement* _table;
1176   u2  _length;
1177 
1178  public:
1179   ExceptionTable(const Method* m) {
1180     if (m->has_exception_handler()) {
1181       _table = m->exception_table_start();
1182       _length = m->exception_table_length();
1183     } else {
1184       _table = NULL;
1185       _length = 0;
1186     }
1187   }
1188 
1189   int length() const {
1190     return _length;
1191   }
1192 
1193   u2 start_pc(int idx) const {
1194     assert(idx < _length, "out of bounds");
1195     return _table[idx].start_pc;
1196   }
1197 
1198   void set_start_pc(int idx, u2 value) {
1199     assert(idx < _length, "out of bounds");
1200     _table[idx].start_pc = value;
1201   }
1202 
1203   u2 end_pc(int idx) const {
1204     assert(idx < _length, "out of bounds");
1205     return _table[idx].end_pc;
1206   }
1207 
1208   void set_end_pc(int idx, u2 value) {
1209     assert(idx < _length, "out of bounds");
1210     _table[idx].end_pc = value;
1211   }
1212 
1213   u2 handler_pc(int idx) const {
1214     assert(idx < _length, "out of bounds");
1215     return _table[idx].handler_pc;
1216   }
1217 
1218   void set_handler_pc(int idx, u2 value) {
1219     assert(idx < _length, "out of bounds");
1220     _table[idx].handler_pc = value;
1221   }
1222 
1223   u2 catch_type_index(int idx) const {
1224     assert(idx < _length, "out of bounds");
1225     return _table[idx].catch_type_index;
1226   }
1227 
1228   void set_catch_type_index(int idx, u2 value) {
1229     assert(idx < _length, "out of bounds");
1230     _table[idx].catch_type_index = value;
1231   }
1232 };
1233 
1234 #endif // SHARE_OOPS_METHOD_HPP