src/share/vm/code/compiledIC.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 1
2d8a650513c2
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial