src/share/vm/code/compiledIC.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6198
55fb97c4c58d
parent 1
2d8a650513c2
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2013, 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  */
    25 /*
    26  * This file has been modified by Loongson Technology in 2015. These
    27  * modifications are Copyright (c) 2015 Loongson Technology, and are made
    28  * available on the same license terms set forth above.
    29  */
    31 #ifndef SHARE_VM_CODE_COMPILEDIC_HPP
    32 #define SHARE_VM_CODE_COMPILEDIC_HPP
    34 #include "interpreter/linkResolver.hpp"
    35 #include "oops/compiledICHolder.hpp"
    36 #ifdef TARGET_ARCH_x86
    37 # include "nativeInst_x86.hpp"
    38 #endif
    39 #ifdef TARGET_ARCH_sparc
    40 # include "nativeInst_sparc.hpp"
    41 #endif
    42 #ifdef TARGET_ARCH_zero
    43 # include "nativeInst_zero.hpp"
    44 #endif
    45 #ifdef TARGET_ARCH_arm
    46 # include "nativeInst_arm.hpp"
    47 #endif
    48 #ifdef TARGET_ARCH_ppc
    49 # include "nativeInst_ppc.hpp"
    50 #endif
    51 #ifdef TARGET_ARCH_mips
    52 # include "nativeInst_mips.hpp"
    53 #endif
    55 //-----------------------------------------------------------------------------
    56 // The CompiledIC represents a compiled inline cache.
    57 //
    58 // In order to make patching of the inline cache MT-safe, we only allow the following
    59 // transitions (when not at a safepoint):
    60 //
    61 //
    62 //         [1] --<--  Clean -->---  [1]
    63 //            /       (null)      \
    64 //           /                     \      /-<-\
    65 //          /          [2]          \    /     \
    66 //      Interpreted  ---------> Monomorphic     | [3]
    67 //  (CompiledICHolder*)            (Klass*)     |
    68 //          \                        /   \     /
    69 //       [4] \                      / [4] \->-/
    70 //            \->-  Megamorphic -<-/
    71 //                  (Method*)
    72 //
    73 // The text in paranteses () refere to the value of the inline cache receiver (mov instruction)
    74 //
    75 // The numbers in square brackets refere to the kind of transition:
    76 // [1]: Initial fixup. Receiver it found from debug information
    77 // [2]: Compilation of a method
    78 // [3]: Recompilation of a method (note: only entry is changed. The Klass* must stay the same)
    79 // [4]: Inline cache miss. We go directly to megamorphic call.
    80 //
    81 // The class automatically inserts transition stubs (using the InlineCacheBuffer) when an MT-unsafe
    82 // transition is made to a stub.
    83 //
    84 class CompiledIC;
    85 class ICStub;
    87 class CompiledICInfo : public StackObj {
    88  private:
    89   address _entry;              // entry point for call
    90   void*   _cached_value;         // Value of cached_value (either in stub or inline cache)
    91   bool    _is_icholder;          // Is the cached value a CompiledICHolder*
    92   bool    _is_optimized;       // it is an optimized virtual call (i.e., can be statically bound)
    93   bool    _to_interpreter;     // Call it to interpreter
    94   bool    _release_icholder;
    95  public:
    96   address entry() const        { return _entry; }
    97   Metadata*    cached_metadata() const         { assert(!_is_icholder, ""); return (Metadata*)_cached_value; }
    98   CompiledICHolder*    claim_cached_icholder() {
    99     assert(_is_icholder, "");
   100     assert(_cached_value != NULL, "must be non-NULL");
   101     _release_icholder = false;
   102     CompiledICHolder* icholder = (CompiledICHolder*)_cached_value;
   103     icholder->claim();
   104     return icholder;
   105   }
   106   bool    is_optimized() const { return _is_optimized; }
   107   bool         to_interpreter() const  { return _to_interpreter; }
   109   void set_compiled_entry(address entry, Klass* klass, bool is_optimized) {
   110     _entry      = entry;
   111     _cached_value = (void*)klass;
   112     _to_interpreter = false;
   113     _is_icholder = false;
   114     _is_optimized = is_optimized;
   115     _release_icholder = false;
   116   }
   118   void set_interpreter_entry(address entry, Method* method) {
   119     _entry      = entry;
   120     _cached_value = (void*)method;
   121     _to_interpreter = true;
   122     _is_icholder = false;
   123     _is_optimized = true;
   124     _release_icholder = false;
   125   }
   127   void set_icholder_entry(address entry, CompiledICHolder* icholder) {
   128     _entry      = entry;
   129     _cached_value = (void*)icholder;
   130     _to_interpreter = true;
   131     _is_icholder = true;
   132     _is_optimized = false;
   133     _release_icholder = true;
   134   }
   136   CompiledICInfo(): _entry(NULL), _cached_value(NULL), _is_icholder(false),
   137                     _to_interpreter(false), _is_optimized(false), _release_icholder(false) {
   138   }
   139   ~CompiledICInfo() {
   140     // In rare cases the info is computed but not used, so release any
   141     // CompiledICHolder* that was created
   142     if (_release_icholder) {
   143       assert(_is_icholder, "must be");
   144       CompiledICHolder* icholder = (CompiledICHolder*)_cached_value;
   145       icholder->claim();
   146       delete icholder;
   147     }
   148   }
   149 };
   151 class CompiledIC: public ResourceObj {
   152   friend class InlineCacheBuffer;
   153   friend class ICStub;
   156  private:
   157   NativeCall*   _ic_call;       // the call instruction
   158   NativeMovConstReg* _value;    // patchable value cell for this IC
   159   bool          _is_optimized;  // an optimized virtual call (i.e., no compiled IC)
   161   CompiledIC(nmethod* nm, NativeCall* ic_call);
   163   static bool is_icholder_entry(address entry);
   165   // low-level inline-cache manipulation. Cannot be accessed directly, since it might not be MT-safe
   166   // to change an inline-cache. These changes the underlying inline-cache directly. They *newer* make
   167   // changes to a transition stub.
   168   void internal_set_ic_destination(address entry_point, bool is_icstub, void* cache, bool is_icholder);
   169   void set_ic_destination(ICStub* stub);
   170   void set_ic_destination(address entry_point) {
   171     assert(_is_optimized, "use set_ic_destination_and_value instead");
   172     internal_set_ic_destination(entry_point, false, NULL, false);
   173   }
   174   // This only for use by ICStubs where the type of the value isn't known
   175   void set_ic_destination_and_value(address entry_point, void* value) {
   176     internal_set_ic_destination(entry_point, false, value, is_icholder_entry(entry_point));
   177   }
   178   void set_ic_destination_and_value(address entry_point, Metadata* value) {
   179     internal_set_ic_destination(entry_point, false, value, false);
   180   }
   181   void set_ic_destination_and_value(address entry_point, CompiledICHolder* value) {
   182     internal_set_ic_destination(entry_point, false, value, true);
   183   }
   185   // Reads the location of the transition stub. This will fail with an assertion, if no transition stub is
   186   // associated with the inline cache.
   187   address stub_address() const;
   188   bool is_in_transition_state() const;  // Use InlineCacheBuffer
   190  public:
   191   // conversion (machine PC to CompiledIC*)
   192   friend CompiledIC* CompiledIC_before(nmethod* nm, address return_addr);
   193   friend CompiledIC* CompiledIC_at(nmethod* nm, address call_site);
   194   friend CompiledIC* CompiledIC_at(Relocation* call_site);
   196   // This is used to release CompiledICHolder*s from nmethods that
   197   // are about to be freed.  The callsite might contain other stale
   198   // values of other kinds so it must be careful.
   199   static void cleanup_call_site(virtual_call_Relocation* call_site);
   200   static bool is_icholder_call_site(virtual_call_Relocation* call_site);
   202   // Return the cached_metadata/destination associated with this inline cache. If the cache currently points
   203   // to a transition stub, it will read the values from the transition stub.
   204   void* cached_value() const;
   205   CompiledICHolder* cached_icholder() const {
   206     assert(is_icholder_call(), "must be");
   207     return (CompiledICHolder*) cached_value();
   208   }
   209   Metadata* cached_metadata() const {
   210     assert(!is_icholder_call(), "must be");
   211     return (Metadata*) cached_value();
   212   }
   214   address ic_destination() const;
   216   bool is_optimized() const   { return _is_optimized; }
   218   // State
   219   bool is_clean() const;
   220   bool is_megamorphic() const;
   221   bool is_call_to_compiled() const;
   222   bool is_call_to_interpreted() const;
   224   bool is_icholder_call() const;
   226   address end_of_call() { return  _ic_call->return_address(); }
   228   // MT-safe patching of inline caches. Note: Only safe to call is_xxx when holding the CompiledIC_ock
   229   // so you are guaranteed that no patching takes place. The same goes for verify.
   230   //
   231   // Note: We do not provide any direct access to the stub code, to prevent parts of the code
   232   // to manipulate the inline cache in MT-unsafe ways.
   233   //
   234   // They all takes a TRAP argument, since they can cause a GC if the inline-cache buffer is full.
   235   //
   236   void set_to_clean();  // Can only be called during a safepoint operation
   237   void set_to_monomorphic(CompiledICInfo& info);
   239   // Returns true if successful and false otherwise. The call can fail if memory
   240   // allocation in the code cache fails.
   241   bool set_to_megamorphic(CallInfo* call_info, Bytecodes::Code bytecode, TRAPS);
   243   static void compute_monomorphic_entry(methodHandle method, KlassHandle receiver_klass,
   244                                         bool is_optimized, bool static_bound, CompiledICInfo& info, TRAPS);
   246   // Location
   247   address instruction_address() const { return _ic_call->instruction_address(); }
   249   // Misc
   250   void print()             PRODUCT_RETURN;
   251   void print_compiled_ic() PRODUCT_RETURN;
   252   void verify()            PRODUCT_RETURN;
   253 };
   255 inline CompiledIC* CompiledIC_before(nmethod* nm, address return_addr) {
   256   CompiledIC* c_ic = new CompiledIC(nm, nativeCall_before(return_addr));
   257   c_ic->verify();
   258   return c_ic;
   259 }
   261 inline CompiledIC* CompiledIC_at(nmethod* nm, address call_site) {
   262   CompiledIC* c_ic = new CompiledIC(nm, nativeCall_at(call_site));
   263   c_ic->verify();
   264   return c_ic;
   265 }
   267 inline CompiledIC* CompiledIC_at(Relocation* call_site) {
   268   assert(call_site->type() == relocInfo::virtual_call_type ||
   269          call_site->type() == relocInfo::opt_virtual_call_type, "wrong reloc. info");
   270   CompiledIC* c_ic = new CompiledIC(call_site->code(), nativeCall_at(call_site->addr()));
   271   c_ic->verify();
   272   return c_ic;
   273 }
   276 //-----------------------------------------------------------------------------
   277 // The CompiledStaticCall represents a call to a static method in the compiled
   278 //
   279 // Transition diagram of a static call site is somewhat simpler than for an inlined cache:
   280 //
   281 //
   282 //           -----<----- Clean ----->-----
   283 //          /                             \
   284 //         /                               \
   285 //    compilled code <------------> interpreted code
   286 //
   287 //  Clean:            Calls directly to runtime method for fixup
   288 //  Compiled code:    Calls directly to compiled code
   289 //  Interpreted code: Calls to stub that set Method* reference
   290 //
   291 //
   292 class CompiledStaticCall;
   294 class StaticCallInfo {
   295  private:
   296   address      _entry;          // Entrypoint
   297   methodHandle _callee;         // Callee (used when calling interpreter)
   298   bool         _to_interpreter; // call to interpreted method (otherwise compiled)
   300   friend class CompiledStaticCall;
   301  public:
   302   address      entry() const    { return _entry;  }
   303   methodHandle callee() const   { return _callee; }
   304 };
   307 class CompiledStaticCall: public NativeCall {
   308   friend class CompiledIC;
   310   // Also used by CompiledIC
   311   void set_to_interpreted(methodHandle callee, address entry);
   312   bool is_optimized_virtual();
   314  public:
   315   friend CompiledStaticCall* compiledStaticCall_before(address return_addr);
   316   friend CompiledStaticCall* compiledStaticCall_at(address native_call);
   317   friend CompiledStaticCall* compiledStaticCall_at(Relocation* call_site);
   319   // Code
   320   static void emit_to_interp_stub(CodeBuffer &cbuf);
   321   static int to_interp_stub_size();
   322   static int reloc_to_interp_stub();
   324   // State
   325   bool is_clean() const;
   326   bool is_call_to_compiled() const;
   327   bool is_call_to_interpreted() const;
   329   // Clean static call (will force resolving on next use)
   330   void set_to_clean();
   332   // Set state. The entry must be the same, as computed by compute_entry.
   333   // Computation and setting is split up, since the actions are separate during
   334   // a OptoRuntime::resolve_xxx.
   335   void set(const StaticCallInfo& info);
   337   // Compute entry point given a method
   338   static void compute_entry(methodHandle m, StaticCallInfo& info);
   340   // Stub support
   341   address find_stub();
   342   static void set_stub_to_clean(static_stub_Relocation* static_stub);
   344   // Misc.
   345   void print()  PRODUCT_RETURN;
   346   void verify() PRODUCT_RETURN;
   347 };
   350 inline CompiledStaticCall* compiledStaticCall_before(address return_addr) {
   351   CompiledStaticCall* st = (CompiledStaticCall*)nativeCall_before(return_addr);
   352   st->verify();
   353   return st;
   354 }
   356 inline CompiledStaticCall* compiledStaticCall_at(address native_call) {
   357   CompiledStaticCall* st = (CompiledStaticCall*)native_call;
   358   st->verify();
   359   return st;
   360 }
   362 inline CompiledStaticCall* compiledStaticCall_at(Relocation* call_site) {
   363   return compiledStaticCall_at(call_site->addr());
   364 }
   366 #endif // SHARE_VM_CODE_COMPILEDIC_HPP

mercurial