rev 47445 : 8171853: Remove Shark compiler

   1 /*
   2  * Copyright (c) 1999, 2017, 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_VM_CI_CIMETHOD_HPP
  26 #define SHARE_VM_CI_CIMETHOD_HPP
  27 
  28 #include "ci/ciFlags.hpp"
  29 #include "ci/ciInstanceKlass.hpp"
  30 #include "ci/ciObject.hpp"
  31 #include "ci/ciSignature.hpp"
  32 #include "compiler/methodLiveness.hpp"
  33 #include "prims/methodHandles.hpp"
  34 #include "utilities/bitMap.hpp"
  35 #include "trace/tracing.hpp"
  36 
  37 class ciMethodBlocks;
  38 class MethodLiveness;
  39 class Arena;
  40 class BCEscapeAnalyzer;
  41 class InlineTree;
  42 
  43 // Whether profiling found an oop to be always, never or sometimes
  44 // null
  45 enum ProfilePtrKind {
  46   ProfileAlwaysNull,
  47   ProfileNeverNull,
  48   ProfileMaybeNull
  49 };
  50 
  51 // ciMethod
  52 //
  53 // This class represents a Method* in the HotSpot virtual
  54 // machine.
  55 class ciMethod : public ciMetadata {
  56   friend class CompileBroker;
  57   CI_PACKAGE_ACCESS
  58   friend class ciEnv;
  59   friend class ciExceptionHandlerStream;
  60   friend class ciBytecodeStream;
  61   friend class ciMethodHandle;
  62   friend class ciReplay;
  63   friend class InlineTree;
  64 
  65  private:
  66   // General method information.
  67   ciFlags          _flags;
  68   ciSymbol*        _name;
  69   ciInstanceKlass* _holder;
  70   ciSignature*     _signature;
  71   ciMethodData*    _method_data;
  72   ciMethodBlocks*   _method_blocks;
  73 
  74   // Code attributes.
  75   int _code_size;
  76   int _max_stack;
  77   int _max_locals;
  78   vmIntrinsics::ID _intrinsic_id;
  79   int _handler_count;
  80   int _nmethod_age;
  81   int _interpreter_invocation_count;
  82   int _interpreter_throwout_count;
  83   int _instructions_size;
  84   int _size_of_parameters;
  85 
  86   bool _uses_monitors;
  87   bool _balanced_monitors;
  88   bool _is_c1_compilable;
  89   bool _is_c2_compilable;
  90   bool _can_be_statically_bound;
  91   bool _has_reserved_stack_access;
  92 
  93   // Lazy fields, filled in on demand
  94   address              _code;
  95   ciExceptionHandler** _exception_handlers;
  96 
  97   // Optional liveness analyzer.
  98   MethodLiveness* _liveness;
  99 #if defined(COMPILER2) || defined(SHARK)
 100   ciTypeFlow*         _flow;
 101   BCEscapeAnalyzer*   _bcea;
 102 #endif
 103 
 104   ciMethod(const methodHandle& h_m, ciInstanceKlass* holder);
 105   ciMethod(ciInstanceKlass* holder, ciSymbol* name, ciSymbol* signature, ciInstanceKlass* accessor);
 106 
 107   oop loader() const                             { return _holder->loader(); }
 108 
 109   const char* type_string()                      { return "ciMethod"; }
 110 
 111   void print_impl(outputStream* st);
 112 
 113   void load_code();
 114 
 115   bool ensure_method_data(const methodHandle& h_m);
 116 
 117   void code_at_put(int bci, Bytecodes::Code code) {
 118     Bytecodes::check(code);
 119     assert(0 <= bci && bci < code_size(), "valid bci");
 120     address bcp = _code + bci;
 121     *bcp = code;
 122   }
 123 
 124   // Check bytecode and profile data collected are compatible
 125   void assert_virtual_call_type_ok(int bci);
 126   void assert_call_type_ok(int bci);
 127 
 128  public:
 129   void check_is_loaded() const                   { assert(is_loaded(), "not loaded"); }
 130 
 131   // Basic method information.
 132   ciFlags flags() const                          { check_is_loaded(); return _flags; }
 133   ciSymbol* name() const                         { return _name; }
 134   ciInstanceKlass* holder() const                { return _holder; }
 135   ciMethodData* method_data();
 136   ciMethodData* method_data_or_null();
 137 
 138   // Signature information.
 139   ciSignature* signature() const                 { return _signature; }
 140   ciType*      return_type() const               { return _signature->return_type(); }
 141   int          arg_size_no_receiver() const      { return _signature->size(); }
 142   // Can only be used on loaded ciMethods
 143   int          arg_size() const                  {
 144     check_is_loaded();
 145     return _signature->size() + (_flags.is_static() ? 0 : 1);
 146   }
 147   // Report the number of elements on stack when invoking the current method.
 148   // If the method is loaded, arg_size() gives precise information about the
 149   // number of stack elements (using the method's signature and its flags).
 150   // However, if the method is not loaded, the number of stack elements must
 151   // be determined differently, as the method's flags are not yet available.
 152   // The invoke_arg_size() method assumes in that case that all bytecodes except
 153   // invokestatic and invokedynamic have a receiver that is also pushed onto the
 154   // stack by the caller of the current method.
 155   int invoke_arg_size(Bytecodes::Code code) const {
 156     if (is_loaded()) {
 157       return arg_size();
 158     } else {
 159       int arg_size = _signature->size();
 160       if (code != Bytecodes::_invokestatic &&
 161           code != Bytecodes::_invokedynamic) {
 162         arg_size++;
 163       }
 164       return arg_size;
 165     }
 166   }
 167 
 168   Method* get_Method() const {
 169     Method* m = (Method*)_metadata;
 170     assert(m != NULL, "illegal use of unloaded method");
 171     return m;
 172   }
 173 
 174   // Method code and related information.
 175   address code()                                 { if (_code == NULL) load_code(); return _code; }
 176   int code_size() const                          { check_is_loaded(); return _code_size; }
 177   int max_stack() const                          { check_is_loaded(); return _max_stack; }
 178   int max_locals() const                         { check_is_loaded(); return _max_locals; }
 179   vmIntrinsics::ID intrinsic_id() const          { check_is_loaded(); return _intrinsic_id; }
 180   bool has_exception_handlers() const            { check_is_loaded(); return _handler_count > 0; }
 181   int exception_table_length() const             { check_is_loaded(); return _handler_count; }
 182   int interpreter_invocation_count() const       { check_is_loaded(); return _interpreter_invocation_count; }
 183   int interpreter_throwout_count() const         { check_is_loaded(); return _interpreter_throwout_count; }
 184   int size_of_parameters() const                 { check_is_loaded(); return _size_of_parameters; }
 185   int nmethod_age() const                        { check_is_loaded(); return _nmethod_age; }
 186 
 187   // Should the method be compiled with an age counter?
 188   bool profile_aging() const;
 189 
 190   // Code size for inlining decisions.
 191   int code_size_for_inlining();
 192 
 193   bool caller_sensitive()    const { return get_Method()->caller_sensitive();    }
 194   bool force_inline()        const { return get_Method()->force_inline();        }
 195   bool dont_inline()         const { return get_Method()->dont_inline();         }
 196   bool intrinsic_candidate() const { return get_Method()->intrinsic_candidate(); }
 197 
 198   int comp_level();
 199   int highest_osr_comp_level();
 200 
 201   Bytecodes::Code java_code_at_bci(int bci) {
 202     address bcp = code() + bci;
 203     return Bytecodes::java_code_at(NULL, bcp);
 204   }
 205   Bytecodes::Code raw_code_at_bci(int bci) {
 206     address bcp = code() + bci;
 207     return Bytecodes::code_at(NULL, bcp);
 208   }
 209   BCEscapeAnalyzer  *get_bcea();
 210   ciMethodBlocks    *get_method_blocks();
 211 
 212   bool    has_linenumber_table() const;          // length unknown until decompression
 213   u_char* compressed_linenumber_table() const;   // not preserved by gc
 214 
 215   int line_number_from_bci(int bci) const;
 216 
 217   // Runtime information.
 218   int           vtable_index();
 219 #ifdef SHARK
 220   int           itable_index();
 221 #endif // SHARK
 222   address       native_entry();
 223   address       interpreter_entry();
 224 
 225   // Analysis and profiling.
 226   //
 227   // Usage note: liveness_at_bci and init_vars should be wrapped in ResourceMarks.
 228   bool          has_monitor_bytecodes() const    { return _uses_monitors; }
 229   bool          has_balanced_monitors();
 230 
 231   // Returns a bitmap indicating which locals are required to be
 232   // maintained as live for deopt.  raw_liveness_at_bci is always the
 233   // direct output of the liveness computation while liveness_at_bci
 234   // may mark all locals as live to improve support for debugging Java
 235   // code by maintaining the state of as many locals as possible.
 236   MethodLivenessResult raw_liveness_at_bci(int bci);
 237   MethodLivenessResult liveness_at_bci(int bci);
 238 
 239   // Get the interpreters viewpoint on oop liveness.  MethodLiveness is
 240   // conservative in the sense that it may consider locals to be live which
 241   // cannot be live, like in the case where a local could contain an oop or
 242   // a primitive along different paths.  In that case the local must be
 243   // dead when those paths merge. Since the interpreter's viewpoint is
 244   // used when gc'ing an interpreter frame we need to use its viewpoint
 245   // during OSR when loading the locals.
 246 
 247   ResourceBitMap live_local_oops_at_bci(int bci);
 248 
 249 #ifdef COMPILER1
 250   const BitMap& bci_block_start();
 251 #endif
 252 
 253   ciTypeFlow*   get_flow_analysis();
 254   ciTypeFlow*   get_osr_flow_analysis(int osr_bci);  // alternate entry point
 255   ciCallProfile call_profile_at_bci(int bci);
 256   int           interpreter_call_site_count(int bci);
 257 
 258   // Does type profiling provide any useful information at this point?
 259   bool          argument_profiled_type(int bci, int i, ciKlass*& type, ProfilePtrKind& ptr_kind);
 260   bool          parameter_profiled_type(int i, ciKlass*& type, ProfilePtrKind& ptr_kind);
 261   bool          return_profiled_type(int bci, ciKlass*& type, ProfilePtrKind& ptr_kind);
 262 
 263   ciField*      get_field_at_bci( int bci, bool &will_link);
 264   ciMethod*     get_method_at_bci(int bci, bool &will_link, ciSignature* *declared_signature);
 265   ciMethod*     get_method_at_bci(int bci) {
 266     bool ignored_will_link;
 267     ciSignature* ignored_declared_signature;
 268     return get_method_at_bci(bci, ignored_will_link, &ignored_declared_signature);
 269   }
 270 
 271   ciSignature*  get_declared_signature_at_bci(int bci) {
 272     bool ignored_will_link;
 273     ciSignature* declared_signature;
 274     get_method_at_bci(bci, ignored_will_link, &declared_signature);
 275     assert(declared_signature != NULL, "cannot be null");
 276     return declared_signature;
 277   }
 278 
 279   // Given a certain calling environment, find the monomorphic target
 280   // for the call.  Return NULL if the call is not monomorphic in
 281   // its calling environment.
 282   ciMethod* find_monomorphic_target(ciInstanceKlass* caller,
 283                                     ciInstanceKlass* callee_holder,
 284                                     ciInstanceKlass* actual_receiver,
 285                                     bool check_access = true);
 286 
 287   // Given a known receiver klass, find the target for the call.
 288   // Return NULL if the call has no target or is abstract.
 289   ciMethod* resolve_invoke(ciKlass* caller, ciKlass* exact_receiver, bool check_access = true);
 290 
 291   // Find the proper vtable index to invoke this method.
 292   int resolve_vtable_index(ciKlass* caller, ciKlass* receiver);
 293 
 294   bool has_option(const char *option);
 295   bool has_option_value(const char* option, double& value);
 296   bool can_be_compiled();
 297   bool can_be_osr_compiled(int entry_bci);
 298   void set_not_compilable(const char* reason = NULL);
 299   bool has_compiled_code();
 300   void log_nmethod_identity(xmlStream* log);
 301   bool is_not_reached(int bci);
 302   bool was_executed_more_than(int times);
 303   bool has_unloaded_classes_in_signature();
 304   bool is_klass_loaded(int refinfo_index, bool must_be_resolved) const;
 305   bool check_call(int refinfo_index, bool is_static) const;
 306   bool ensure_method_data();  // make sure it exists in the VM also
 307   MethodCounters* ensure_method_counters();
 308   int instructions_size();
 309   int scale_count(int count, float prof_factor = 1.);  // make MDO count commensurate with IIC
 310 
 311   // Stack walking support
 312   bool is_ignored_by_security_stack_walk() const;
 313 
 314   // JSR 292 support
 315   bool is_method_handle_intrinsic()  const;
 316   bool is_compiled_lambda_form() const;
 317   bool has_member_arg() const;
 318 
 319   // What kind of ciObject is this?
 320   bool is_method() const                         { return true; }
 321 
 322   // Java access flags
 323   bool is_public      () const                   { return flags().is_public(); }
 324   bool is_private     () const                   { return flags().is_private(); }
 325   bool is_protected   () const                   { return flags().is_protected(); }
 326   bool is_static      () const                   { return flags().is_static(); }
 327   bool is_final       () const                   { return flags().is_final(); }
 328   bool is_synchronized() const                   { return flags().is_synchronized(); }
 329   bool is_native      () const                   { return flags().is_native(); }
 330   bool is_interface   () const                   { return flags().is_interface(); }
 331   bool is_abstract    () const                   { return flags().is_abstract(); }
 332   bool is_strict      () const                   { return flags().is_strict(); }
 333 
 334   // Other flags
 335   bool is_empty_method() const;
 336   bool is_vanilla_constructor() const;
 337   bool is_final_method() const                   { return is_final() || holder()->is_final(); }
 338   bool has_loops      () const;
 339   bool has_jsrs       () const;
 340   bool is_getter      () const;
 341   bool is_setter      () const;
 342   bool is_accessor    () const;
 343   bool is_initializer () const;
 344   bool can_be_statically_bound() const           { return _can_be_statically_bound; }
 345   bool has_reserved_stack_access() const         { return _has_reserved_stack_access; }
 346   bool is_boxing_method() const;
 347   bool is_unboxing_method() const;
 348   bool is_object_initializer() const;
 349 
 350   // Replay data methods
 351   void dump_name_as_ascii(outputStream* st);
 352   void dump_replay_data(outputStream* st);
 353 
 354   // Print the bytecodes of this method.
 355   void print_codes_on(outputStream* st);
 356   void print_codes() {
 357     print_codes_on(tty);
 358   }
 359   void print_codes_on(int from, int to, outputStream* st);
 360 
 361   // Print the name of this method in various incarnations.
 362   void print_name(outputStream* st = tty);
 363   void print_short_name(outputStream* st = tty);
 364 
 365   static bool is_consistent_info(ciMethod* declared_method, ciMethod* resolved_method);
 366 
 367 #if INCLUDE_TRACE
 368   TraceStructCalleeMethod to_trace_struct() const;
 369 #endif
 370 };
 371 
 372 #endif // SHARE_VM_CI_CIMETHOD_HPP
--- EOF ---