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