Fri, 29 Jan 2010 08:33:24 -0800
6921339: backout 6917766
Reviewed-by: mr
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 1997-2005 Sun Microsystems, Inc. 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 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | //----------------------------------------------------------------------------- |
duke@435 | 26 | // The CompiledIC represents a compiled inline cache. |
duke@435 | 27 | // |
duke@435 | 28 | // In order to make patching of the inline cache MT-safe, we only allow the following |
duke@435 | 29 | // transitions (when not at a safepoint): |
duke@435 | 30 | // |
duke@435 | 31 | // |
duke@435 | 32 | // [1] --<-- Clean -->--- [1] |
duke@435 | 33 | // / (null) \ |
duke@435 | 34 | // / \ /-<-\ |
duke@435 | 35 | // / [2] \ / \ |
duke@435 | 36 | // Interpreted ---------> Monomorphic | [3] |
duke@435 | 37 | // (compiledICHolderOop) (klassOop) | |
duke@435 | 38 | // \ / \ / |
duke@435 | 39 | // [4] \ / [4] \->-/ |
duke@435 | 40 | // \->- Megamorphic -<-/ |
duke@435 | 41 | // (methodOop) |
duke@435 | 42 | // |
duke@435 | 43 | // The text in paranteses () refere to the value of the inline cache receiver (mov instruction) |
duke@435 | 44 | // |
duke@435 | 45 | // The numbers in square brackets refere to the kind of transition: |
duke@435 | 46 | // [1]: Initial fixup. Receiver it found from debug information |
duke@435 | 47 | // [2]: Compilation of a method |
duke@435 | 48 | // [3]: Recompilation of a method (note: only entry is changed. The klassOop must stay the same) |
duke@435 | 49 | // [4]: Inline cache miss. We go directly to megamorphic call. |
duke@435 | 50 | // |
duke@435 | 51 | // The class automatically inserts transition stubs (using the InlineCacheBuffer) when an MT-unsafe |
duke@435 | 52 | // transition is made to a stub. |
duke@435 | 53 | // |
duke@435 | 54 | class CompiledIC; |
duke@435 | 55 | |
duke@435 | 56 | class CompiledICInfo { |
duke@435 | 57 | friend class CompiledIC; |
duke@435 | 58 | private: |
duke@435 | 59 | address _entry; // entry point for call |
duke@435 | 60 | Handle _cached_oop; // Value of cached_oop (either in stub or inline cache) |
duke@435 | 61 | bool _is_optimized; // it is an optimized virtual call (i.e., can be statically bound) |
duke@435 | 62 | bool _to_interpreter; // Call it to interpreter |
duke@435 | 63 | public: |
duke@435 | 64 | address entry() const { return _entry; } |
duke@435 | 65 | Handle cached_oop() const { return _cached_oop; } |
duke@435 | 66 | bool is_optimized() const { return _is_optimized; } |
duke@435 | 67 | }; |
duke@435 | 68 | |
duke@435 | 69 | class CompiledIC: public ResourceObj { |
duke@435 | 70 | friend class InlineCacheBuffer; |
duke@435 | 71 | friend class ICStub; |
duke@435 | 72 | |
duke@435 | 73 | |
duke@435 | 74 | private: |
duke@435 | 75 | NativeCall* _ic_call; // the call instruction |
duke@435 | 76 | oop* _oop_addr; // patchable oop cell for this IC |
duke@435 | 77 | RelocIterator _oops; // iteration over any and all set-oop instructions |
duke@435 | 78 | bool _is_optimized; // an optimized virtual call (i.e., no compiled IC) |
duke@435 | 79 | |
duke@435 | 80 | CompiledIC(NativeCall* ic_call); |
duke@435 | 81 | CompiledIC(Relocation* ic_reloc); // Must be of virtual_call_type/opt_virtual_call_type |
duke@435 | 82 | |
duke@435 | 83 | // low-level inline-cache manipulation. Cannot be accessed directly, since it might not be MT-safe |
duke@435 | 84 | // to change an inline-cache. These changes the underlying inline-cache directly. They *newer* make |
duke@435 | 85 | // changes to a transition stub. |
duke@435 | 86 | void set_ic_destination(address entry_point); |
duke@435 | 87 | void set_cached_oop(oop cache); |
duke@435 | 88 | |
duke@435 | 89 | // Reads the location of the transition stub. This will fail with an assertion, if no transition stub is |
duke@435 | 90 | // associated with the inline cache. |
duke@435 | 91 | address stub_address() const; |
duke@435 | 92 | bool is_in_transition_state() const; // Use InlineCacheBuffer |
duke@435 | 93 | |
duke@435 | 94 | public: |
duke@435 | 95 | // conversion (machine PC to CompiledIC*) |
duke@435 | 96 | friend CompiledIC* CompiledIC_before(address return_addr); |
duke@435 | 97 | friend CompiledIC* CompiledIC_at(address call_site); |
duke@435 | 98 | friend CompiledIC* CompiledIC_at(Relocation* call_site); |
duke@435 | 99 | |
duke@435 | 100 | // Return the cached_oop/destination associated with this inline cache. If the cache currently points |
duke@435 | 101 | // to a transition stub, it will read the values from the transition stub. |
duke@435 | 102 | oop cached_oop() const; |
duke@435 | 103 | address ic_destination() const; |
duke@435 | 104 | |
duke@435 | 105 | bool is_optimized() const { return _is_optimized; } |
duke@435 | 106 | |
duke@435 | 107 | // State |
duke@435 | 108 | bool is_clean() const; |
duke@435 | 109 | bool is_megamorphic() const; |
duke@435 | 110 | bool is_call_to_compiled() const; |
duke@435 | 111 | bool is_call_to_interpreted() const; |
duke@435 | 112 | |
duke@435 | 113 | address end_of_call() { return _ic_call->return_address(); } |
duke@435 | 114 | |
duke@435 | 115 | // MT-safe patching of inline caches. Note: Only safe to call is_xxx when holding the CompiledIC_ock |
duke@435 | 116 | // so you are guaranteed that no patching takes place. The same goes for verify. |
duke@435 | 117 | // |
duke@435 | 118 | // Note: We do not provide any direct access to the stub code, to prevent parts of the code |
duke@435 | 119 | // to manipulate the inline cache in MT-unsafe ways. |
duke@435 | 120 | // |
duke@435 | 121 | // They all takes a TRAP argument, since they can cause a GC if the inline-cache buffer is full. |
duke@435 | 122 | // |
duke@435 | 123 | void set_to_clean(); // Can only be called during a safepoint operation |
duke@435 | 124 | void set_to_monomorphic(const CompiledICInfo& info); |
duke@435 | 125 | void set_to_megamorphic(CallInfo* call_info, Bytecodes::Code bytecode, TRAPS); |
duke@435 | 126 | |
duke@435 | 127 | static void compute_monomorphic_entry(methodHandle method, KlassHandle receiver_klass, |
duke@435 | 128 | bool is_optimized, bool static_bound, CompiledICInfo& info, TRAPS); |
duke@435 | 129 | |
duke@435 | 130 | // Location |
duke@435 | 131 | address instruction_address() const { return _ic_call->instruction_address(); } |
duke@435 | 132 | |
duke@435 | 133 | // Misc |
duke@435 | 134 | void print() PRODUCT_RETURN; |
duke@435 | 135 | void print_compiled_ic() PRODUCT_RETURN; |
duke@435 | 136 | void verify() PRODUCT_RETURN; |
duke@435 | 137 | }; |
duke@435 | 138 | |
duke@435 | 139 | inline CompiledIC* CompiledIC_before(address return_addr) { |
duke@435 | 140 | CompiledIC* c_ic = new CompiledIC(nativeCall_before(return_addr)); |
duke@435 | 141 | c_ic->verify(); |
duke@435 | 142 | return c_ic; |
duke@435 | 143 | } |
duke@435 | 144 | |
duke@435 | 145 | inline CompiledIC* CompiledIC_at(address call_site) { |
duke@435 | 146 | CompiledIC* c_ic = new CompiledIC(nativeCall_at(call_site)); |
duke@435 | 147 | c_ic->verify(); |
duke@435 | 148 | return c_ic; |
duke@435 | 149 | } |
duke@435 | 150 | |
duke@435 | 151 | inline CompiledIC* CompiledIC_at(Relocation* call_site) { |
duke@435 | 152 | CompiledIC* c_ic = new CompiledIC(call_site); |
duke@435 | 153 | c_ic->verify(); |
duke@435 | 154 | return c_ic; |
duke@435 | 155 | } |
duke@435 | 156 | |
duke@435 | 157 | |
duke@435 | 158 | //----------------------------------------------------------------------------- |
duke@435 | 159 | // The CompiledStaticCall represents a call to a static method in the compiled |
duke@435 | 160 | // |
duke@435 | 161 | // Transition diagram of a static call site is somewhat simpler than for an inlined cache: |
duke@435 | 162 | // |
duke@435 | 163 | // |
duke@435 | 164 | // -----<----- Clean ----->----- |
duke@435 | 165 | // / \ |
duke@435 | 166 | // / \ |
duke@435 | 167 | // compilled code <------------> interpreted code |
duke@435 | 168 | // |
duke@435 | 169 | // Clean: Calls directly to runtime method for fixup |
duke@435 | 170 | // Compiled code: Calls directly to compiled code |
duke@435 | 171 | // Interpreted code: Calls to stub that set methodOop reference |
duke@435 | 172 | // |
duke@435 | 173 | // |
duke@435 | 174 | class CompiledStaticCall; |
duke@435 | 175 | |
duke@435 | 176 | class StaticCallInfo { |
duke@435 | 177 | private: |
duke@435 | 178 | address _entry; // Entrypoint |
duke@435 | 179 | methodHandle _callee; // Callee (used when calling interpreter) |
duke@435 | 180 | bool _to_interpreter; // call to interpreted method (otherwise compiled) |
duke@435 | 181 | |
duke@435 | 182 | friend class CompiledStaticCall; |
duke@435 | 183 | public: |
duke@435 | 184 | address entry() const { return _entry; } |
duke@435 | 185 | methodHandle callee() const { return _callee; } |
duke@435 | 186 | }; |
duke@435 | 187 | |
duke@435 | 188 | |
duke@435 | 189 | class CompiledStaticCall: public NativeCall { |
duke@435 | 190 | friend class CompiledIC; |
duke@435 | 191 | |
duke@435 | 192 | // Also used by CompiledIC |
duke@435 | 193 | void set_to_interpreted(methodHandle callee, address entry); |
duke@435 | 194 | bool is_optimized_virtual(); |
duke@435 | 195 | |
duke@435 | 196 | public: |
duke@435 | 197 | friend CompiledStaticCall* compiledStaticCall_before(address return_addr); |
duke@435 | 198 | friend CompiledStaticCall* compiledStaticCall_at(address native_call); |
duke@435 | 199 | friend CompiledStaticCall* compiledStaticCall_at(Relocation* call_site); |
duke@435 | 200 | |
duke@435 | 201 | // State |
duke@435 | 202 | bool is_clean() const; |
duke@435 | 203 | bool is_call_to_compiled() const; |
duke@435 | 204 | bool is_call_to_interpreted() const; |
duke@435 | 205 | |
duke@435 | 206 | // Clean static call (will force resolving on next use) |
duke@435 | 207 | void set_to_clean(); |
duke@435 | 208 | |
duke@435 | 209 | // Set state. The entry must be the same, as computed by compute_entry. |
duke@435 | 210 | // Computation and setting is split up, since the actions are separate during |
duke@435 | 211 | // a OptoRuntime::resolve_xxx. |
duke@435 | 212 | void set(const StaticCallInfo& info); |
duke@435 | 213 | |
duke@435 | 214 | // Compute entry point given a method |
duke@435 | 215 | static void compute_entry(methodHandle m, StaticCallInfo& info); |
duke@435 | 216 | |
duke@435 | 217 | // Stub support |
duke@435 | 218 | address find_stub(); |
duke@435 | 219 | static void set_stub_to_clean(static_stub_Relocation* static_stub); |
duke@435 | 220 | |
duke@435 | 221 | // Misc. |
duke@435 | 222 | void print() PRODUCT_RETURN; |
duke@435 | 223 | void verify() PRODUCT_RETURN; |
duke@435 | 224 | }; |
duke@435 | 225 | |
duke@435 | 226 | |
duke@435 | 227 | inline CompiledStaticCall* compiledStaticCall_before(address return_addr) { |
duke@435 | 228 | CompiledStaticCall* st = (CompiledStaticCall*)nativeCall_before(return_addr); |
duke@435 | 229 | st->verify(); |
duke@435 | 230 | return st; |
duke@435 | 231 | } |
duke@435 | 232 | |
duke@435 | 233 | inline CompiledStaticCall* compiledStaticCall_at(address native_call) { |
duke@435 | 234 | CompiledStaticCall* st = (CompiledStaticCall*)native_call; |
duke@435 | 235 | st->verify(); |
duke@435 | 236 | return st; |
duke@435 | 237 | } |
duke@435 | 238 | |
duke@435 | 239 | inline CompiledStaticCall* compiledStaticCall_at(Relocation* call_site) { |
duke@435 | 240 | return compiledStaticCall_at(call_site->addr()); |
duke@435 | 241 | } |