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