src/share/vm/code/compiledIC.hpp

Mon, 28 Feb 2011 06:07:12 -0800

author
twisti
date
Mon, 28 Feb 2011 06:07:12 -0800
changeset 2603
1b4e6a5d98e0
parent 2508
b92c45f2bc75
child 2708
1d1603768966
permissions
-rw-r--r--

7012914: JSR 292 MethodHandlesTest C1: frame::verify_return_pc(return_address) failed: must be a return pc
Reviewed-by: never, bdelsart

duke@435 1 /*
stefank@2314 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_CODE_COMPILEDIC_HPP
stefank@2314 26 #define SHARE_VM_CODE_COMPILEDIC_HPP
stefank@2314 27
stefank@2314 28 #include "interpreter/linkResolver.hpp"
stefank@2314 29 #include "oops/compiledICHolderKlass.hpp"
stefank@2314 30 #include "oops/compiledICHolderOop.hpp"
stefank@2314 31 #include "oops/klassOop.hpp"
stefank@2314 32 #ifdef TARGET_ARCH_x86
stefank@2314 33 # include "nativeInst_x86.hpp"
stefank@2314 34 #endif
stefank@2314 35 #ifdef TARGET_ARCH_sparc
stefank@2314 36 # include "nativeInst_sparc.hpp"
stefank@2314 37 #endif
stefank@2314 38 #ifdef TARGET_ARCH_zero
stefank@2314 39 # include "nativeInst_zero.hpp"
stefank@2314 40 #endif
bobv@2508 41 #ifdef TARGET_ARCH_arm
bobv@2508 42 # include "nativeInst_arm.hpp"
bobv@2508 43 #endif
bobv@2508 44 #ifdef TARGET_ARCH_ppc
bobv@2508 45 # include "nativeInst_ppc.hpp"
bobv@2508 46 #endif
stefank@2314 47
duke@435 48 //-----------------------------------------------------------------------------
duke@435 49 // The CompiledIC represents a compiled inline cache.
duke@435 50 //
duke@435 51 // In order to make patching of the inline cache MT-safe, we only allow the following
duke@435 52 // transitions (when not at a safepoint):
duke@435 53 //
duke@435 54 //
duke@435 55 // [1] --<-- Clean -->--- [1]
duke@435 56 // / (null) \
duke@435 57 // / \ /-<-\
duke@435 58 // / [2] \ / \
duke@435 59 // Interpreted ---------> Monomorphic | [3]
duke@435 60 // (compiledICHolderOop) (klassOop) |
duke@435 61 // \ / \ /
duke@435 62 // [4] \ / [4] \->-/
duke@435 63 // \->- Megamorphic -<-/
duke@435 64 // (methodOop)
duke@435 65 //
duke@435 66 // The text in paranteses () refere to the value of the inline cache receiver (mov instruction)
duke@435 67 //
duke@435 68 // The numbers in square brackets refere to the kind of transition:
duke@435 69 // [1]: Initial fixup. Receiver it found from debug information
duke@435 70 // [2]: Compilation of a method
duke@435 71 // [3]: Recompilation of a method (note: only entry is changed. The klassOop must stay the same)
duke@435 72 // [4]: Inline cache miss. We go directly to megamorphic call.
duke@435 73 //
duke@435 74 // The class automatically inserts transition stubs (using the InlineCacheBuffer) when an MT-unsafe
duke@435 75 // transition is made to a stub.
duke@435 76 //
duke@435 77 class CompiledIC;
duke@435 78
duke@435 79 class CompiledICInfo {
duke@435 80 friend class CompiledIC;
duke@435 81 private:
duke@435 82 address _entry; // entry point for call
duke@435 83 Handle _cached_oop; // Value of cached_oop (either in stub or inline cache)
duke@435 84 bool _is_optimized; // it is an optimized virtual call (i.e., can be statically bound)
duke@435 85 bool _to_interpreter; // Call it to interpreter
duke@435 86 public:
duke@435 87 address entry() const { return _entry; }
duke@435 88 Handle cached_oop() const { return _cached_oop; }
duke@435 89 bool is_optimized() const { return _is_optimized; }
duke@435 90 };
duke@435 91
duke@435 92 class CompiledIC: public ResourceObj {
duke@435 93 friend class InlineCacheBuffer;
duke@435 94 friend class ICStub;
duke@435 95
duke@435 96
duke@435 97 private:
duke@435 98 NativeCall* _ic_call; // the call instruction
duke@435 99 oop* _oop_addr; // patchable oop cell for this IC
duke@435 100 RelocIterator _oops; // iteration over any and all set-oop instructions
duke@435 101 bool _is_optimized; // an optimized virtual call (i.e., no compiled IC)
duke@435 102
duke@435 103 CompiledIC(NativeCall* ic_call);
duke@435 104 CompiledIC(Relocation* ic_reloc); // Must be of virtual_call_type/opt_virtual_call_type
duke@435 105
duke@435 106 // low-level inline-cache manipulation. Cannot be accessed directly, since it might not be MT-safe
duke@435 107 // to change an inline-cache. These changes the underlying inline-cache directly. They *newer* make
duke@435 108 // changes to a transition stub.
duke@435 109 void set_ic_destination(address entry_point);
duke@435 110 void set_cached_oop(oop cache);
duke@435 111
duke@435 112 // Reads the location of the transition stub. This will fail with an assertion, if no transition stub is
duke@435 113 // associated with the inline cache.
duke@435 114 address stub_address() const;
duke@435 115 bool is_in_transition_state() const; // Use InlineCacheBuffer
duke@435 116
duke@435 117 public:
duke@435 118 // conversion (machine PC to CompiledIC*)
duke@435 119 friend CompiledIC* CompiledIC_before(address return_addr);
duke@435 120 friend CompiledIC* CompiledIC_at(address call_site);
duke@435 121 friend CompiledIC* CompiledIC_at(Relocation* call_site);
duke@435 122
duke@435 123 // Return the cached_oop/destination associated with this inline cache. If the cache currently points
duke@435 124 // to a transition stub, it will read the values from the transition stub.
duke@435 125 oop cached_oop() const;
duke@435 126 address ic_destination() const;
duke@435 127
duke@435 128 bool is_optimized() const { return _is_optimized; }
duke@435 129
duke@435 130 // State
duke@435 131 bool is_clean() const;
duke@435 132 bool is_megamorphic() const;
duke@435 133 bool is_call_to_compiled() const;
duke@435 134 bool is_call_to_interpreted() const;
duke@435 135
duke@435 136 address end_of_call() { return _ic_call->return_address(); }
duke@435 137
duke@435 138 // MT-safe patching of inline caches. Note: Only safe to call is_xxx when holding the CompiledIC_ock
duke@435 139 // so you are guaranteed that no patching takes place. The same goes for verify.
duke@435 140 //
duke@435 141 // Note: We do not provide any direct access to the stub code, to prevent parts of the code
duke@435 142 // to manipulate the inline cache in MT-unsafe ways.
duke@435 143 //
duke@435 144 // They all takes a TRAP argument, since they can cause a GC if the inline-cache buffer is full.
duke@435 145 //
duke@435 146 void set_to_clean(); // Can only be called during a safepoint operation
duke@435 147 void set_to_monomorphic(const CompiledICInfo& info);
duke@435 148 void set_to_megamorphic(CallInfo* call_info, Bytecodes::Code bytecode, TRAPS);
duke@435 149
duke@435 150 static void compute_monomorphic_entry(methodHandle method, KlassHandle receiver_klass,
duke@435 151 bool is_optimized, bool static_bound, CompiledICInfo& info, TRAPS);
duke@435 152
duke@435 153 // Location
duke@435 154 address instruction_address() const { return _ic_call->instruction_address(); }
duke@435 155
duke@435 156 // Misc
duke@435 157 void print() PRODUCT_RETURN;
duke@435 158 void print_compiled_ic() PRODUCT_RETURN;
duke@435 159 void verify() PRODUCT_RETURN;
duke@435 160 };
duke@435 161
duke@435 162 inline CompiledIC* CompiledIC_before(address return_addr) {
duke@435 163 CompiledIC* c_ic = new CompiledIC(nativeCall_before(return_addr));
duke@435 164 c_ic->verify();
duke@435 165 return c_ic;
duke@435 166 }
duke@435 167
duke@435 168 inline CompiledIC* CompiledIC_at(address call_site) {
duke@435 169 CompiledIC* c_ic = new CompiledIC(nativeCall_at(call_site));
duke@435 170 c_ic->verify();
duke@435 171 return c_ic;
duke@435 172 }
duke@435 173
duke@435 174 inline CompiledIC* CompiledIC_at(Relocation* call_site) {
duke@435 175 CompiledIC* c_ic = new CompiledIC(call_site);
duke@435 176 c_ic->verify();
duke@435 177 return c_ic;
duke@435 178 }
duke@435 179
duke@435 180
duke@435 181 //-----------------------------------------------------------------------------
duke@435 182 // The CompiledStaticCall represents a call to a static method in the compiled
duke@435 183 //
duke@435 184 // Transition diagram of a static call site is somewhat simpler than for an inlined cache:
duke@435 185 //
duke@435 186 //
duke@435 187 // -----<----- Clean ----->-----
duke@435 188 // / \
duke@435 189 // / \
duke@435 190 // compilled code <------------> interpreted code
duke@435 191 //
duke@435 192 // Clean: Calls directly to runtime method for fixup
duke@435 193 // Compiled code: Calls directly to compiled code
duke@435 194 // Interpreted code: Calls to stub that set methodOop reference
duke@435 195 //
duke@435 196 //
duke@435 197 class CompiledStaticCall;
duke@435 198
duke@435 199 class StaticCallInfo {
duke@435 200 private:
duke@435 201 address _entry; // Entrypoint
duke@435 202 methodHandle _callee; // Callee (used when calling interpreter)
duke@435 203 bool _to_interpreter; // call to interpreted method (otherwise compiled)
duke@435 204
duke@435 205 friend class CompiledStaticCall;
duke@435 206 public:
duke@435 207 address entry() const { return _entry; }
duke@435 208 methodHandle callee() const { return _callee; }
duke@435 209 };
duke@435 210
duke@435 211
duke@435 212 class CompiledStaticCall: public NativeCall {
duke@435 213 friend class CompiledIC;
duke@435 214
duke@435 215 // Also used by CompiledIC
duke@435 216 void set_to_interpreted(methodHandle callee, address entry);
duke@435 217 bool is_optimized_virtual();
duke@435 218
duke@435 219 public:
duke@435 220 friend CompiledStaticCall* compiledStaticCall_before(address return_addr);
duke@435 221 friend CompiledStaticCall* compiledStaticCall_at(address native_call);
duke@435 222 friend CompiledStaticCall* compiledStaticCall_at(Relocation* call_site);
duke@435 223
duke@435 224 // State
duke@435 225 bool is_clean() const;
duke@435 226 bool is_call_to_compiled() const;
duke@435 227 bool is_call_to_interpreted() const;
duke@435 228
duke@435 229 // Clean static call (will force resolving on next use)
duke@435 230 void set_to_clean();
duke@435 231
duke@435 232 // Set state. The entry must be the same, as computed by compute_entry.
duke@435 233 // Computation and setting is split up, since the actions are separate during
duke@435 234 // a OptoRuntime::resolve_xxx.
duke@435 235 void set(const StaticCallInfo& info);
duke@435 236
duke@435 237 // Compute entry point given a method
duke@435 238 static void compute_entry(methodHandle m, StaticCallInfo& info);
duke@435 239
duke@435 240 // Stub support
duke@435 241 address find_stub();
duke@435 242 static void set_stub_to_clean(static_stub_Relocation* static_stub);
duke@435 243
duke@435 244 // Misc.
duke@435 245 void print() PRODUCT_RETURN;
duke@435 246 void verify() PRODUCT_RETURN;
duke@435 247 };
duke@435 248
duke@435 249
duke@435 250 inline CompiledStaticCall* compiledStaticCall_before(address return_addr) {
duke@435 251 CompiledStaticCall* st = (CompiledStaticCall*)nativeCall_before(return_addr);
duke@435 252 st->verify();
duke@435 253 return st;
duke@435 254 }
duke@435 255
duke@435 256 inline CompiledStaticCall* compiledStaticCall_at(address native_call) {
duke@435 257 CompiledStaticCall* st = (CompiledStaticCall*)native_call;
duke@435 258 st->verify();
duke@435 259 return st;
duke@435 260 }
duke@435 261
duke@435 262 inline CompiledStaticCall* compiledStaticCall_at(Relocation* call_site) {
duke@435 263 return compiledStaticCall_at(call_site->addr());
duke@435 264 }
stefank@2314 265
stefank@2314 266 #endif // SHARE_VM_CODE_COMPILEDIC_HPP

mercurial