src/share/vm/code/compiledIC.hpp

Thu, 24 May 2018 18:41:44 +0800

author
aoqi
date
Thu, 24 May 2018 18:41:44 +0800
changeset 8856
ac27a9c85bea
parent 8604
04d83ba48607
child 9041
95a08233f46c
permissions
-rw-r--r--

Merge

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);
stefank@6991 162 CompiledIC(RelocIterator* iter);
stefank@6991 163
stefank@6991 164 void initialize_from_iter(RelocIterator* iter);
aoqi@0 165
aoqi@0 166 static bool is_icholder_entry(address entry);
aoqi@0 167
aoqi@0 168 // low-level inline-cache manipulation. Cannot be accessed directly, since it might not be MT-safe
aoqi@0 169 // to change an inline-cache. These changes the underlying inline-cache directly. They *newer* make
aoqi@0 170 // changes to a transition stub.
aoqi@0 171 void internal_set_ic_destination(address entry_point, bool is_icstub, void* cache, bool is_icholder);
aoqi@0 172 void set_ic_destination(ICStub* stub);
aoqi@0 173 void set_ic_destination(address entry_point) {
aoqi@0 174 assert(_is_optimized, "use set_ic_destination_and_value instead");
aoqi@0 175 internal_set_ic_destination(entry_point, false, NULL, false);
aoqi@0 176 }
aoqi@0 177 // This only for use by ICStubs where the type of the value isn't known
aoqi@0 178 void set_ic_destination_and_value(address entry_point, void* value) {
aoqi@0 179 internal_set_ic_destination(entry_point, false, value, is_icholder_entry(entry_point));
aoqi@0 180 }
aoqi@0 181 void set_ic_destination_and_value(address entry_point, Metadata* value) {
aoqi@0 182 internal_set_ic_destination(entry_point, false, value, false);
aoqi@0 183 }
aoqi@0 184 void set_ic_destination_and_value(address entry_point, CompiledICHolder* value) {
aoqi@0 185 internal_set_ic_destination(entry_point, false, value, true);
aoqi@0 186 }
aoqi@0 187
aoqi@0 188 // Reads the location of the transition stub. This will fail with an assertion, if no transition stub is
aoqi@0 189 // associated with the inline cache.
aoqi@0 190 address stub_address() const;
aoqi@0 191 bool is_in_transition_state() const; // Use InlineCacheBuffer
aoqi@0 192
aoqi@0 193 public:
aoqi@0 194 // conversion (machine PC to CompiledIC*)
aoqi@0 195 friend CompiledIC* CompiledIC_before(nmethod* nm, address return_addr);
aoqi@0 196 friend CompiledIC* CompiledIC_at(nmethod* nm, address call_site);
aoqi@0 197 friend CompiledIC* CompiledIC_at(Relocation* call_site);
stefank@6991 198 friend CompiledIC* CompiledIC_at(RelocIterator* reloc_iter);
aoqi@0 199
aoqi@0 200 // This is used to release CompiledICHolder*s from nmethods that
aoqi@0 201 // are about to be freed. The callsite might contain other stale
aoqi@0 202 // values of other kinds so it must be careful.
aoqi@0 203 static void cleanup_call_site(virtual_call_Relocation* call_site);
aoqi@0 204 static bool is_icholder_call_site(virtual_call_Relocation* call_site);
aoqi@0 205
aoqi@0 206 // Return the cached_metadata/destination associated with this inline cache. If the cache currently points
aoqi@0 207 // to a transition stub, it will read the values from the transition stub.
aoqi@0 208 void* cached_value() const;
aoqi@0 209 CompiledICHolder* cached_icholder() const {
aoqi@0 210 assert(is_icholder_call(), "must be");
aoqi@0 211 return (CompiledICHolder*) cached_value();
aoqi@0 212 }
aoqi@0 213 Metadata* cached_metadata() const {
aoqi@0 214 assert(!is_icholder_call(), "must be");
aoqi@0 215 return (Metadata*) cached_value();
aoqi@0 216 }
aoqi@0 217
aoqi@0 218 address ic_destination() const;
aoqi@0 219
aoqi@0 220 bool is_optimized() const { return _is_optimized; }
aoqi@0 221
aoqi@0 222 // State
aoqi@0 223 bool is_clean() const;
aoqi@0 224 bool is_megamorphic() const;
aoqi@0 225 bool is_call_to_compiled() const;
aoqi@0 226 bool is_call_to_interpreted() const;
aoqi@0 227
aoqi@0 228 bool is_icholder_call() const;
aoqi@0 229
aoqi@0 230 address end_of_call() { return _ic_call->return_address(); }
aoqi@0 231
aoqi@0 232 // MT-safe patching of inline caches. Note: Only safe to call is_xxx when holding the CompiledIC_ock
aoqi@0 233 // so you are guaranteed that no patching takes place. The same goes for verify.
aoqi@0 234 //
aoqi@0 235 // Note: We do not provide any direct access to the stub code, to prevent parts of the code
aoqi@0 236 // to manipulate the inline cache in MT-unsafe ways.
aoqi@0 237 //
aoqi@0 238 // They all takes a TRAP argument, since they can cause a GC if the inline-cache buffer is full.
aoqi@0 239 //
thartmann@8075 240 void set_to_clean(bool in_use = true);
aoqi@0 241 void set_to_monomorphic(CompiledICInfo& info);
thartmann@8073 242 void clear_ic_stub();
aoqi@0 243
aoqi@0 244 // Returns true if successful and false otherwise. The call can fail if memory
aoqi@0 245 // allocation in the code cache fails.
aoqi@0 246 bool set_to_megamorphic(CallInfo* call_info, Bytecodes::Code bytecode, TRAPS);
aoqi@0 247
aoqi@0 248 static void compute_monomorphic_entry(methodHandle method, KlassHandle receiver_klass,
aoqi@0 249 bool is_optimized, bool static_bound, CompiledICInfo& info, TRAPS);
aoqi@0 250
aoqi@0 251 // Location
aoqi@0 252 address instruction_address() const { return _ic_call->instruction_address(); }
aoqi@0 253
aoqi@0 254 // Misc
aoqi@0 255 void print() PRODUCT_RETURN;
aoqi@0 256 void print_compiled_ic() PRODUCT_RETURN;
aoqi@0 257 void verify() PRODUCT_RETURN;
aoqi@0 258 };
aoqi@0 259
aoqi@0 260 inline CompiledIC* CompiledIC_before(nmethod* nm, address return_addr) {
aoqi@0 261 CompiledIC* c_ic = new CompiledIC(nm, nativeCall_before(return_addr));
aoqi@0 262 c_ic->verify();
aoqi@0 263 return c_ic;
aoqi@0 264 }
aoqi@0 265
aoqi@0 266 inline CompiledIC* CompiledIC_at(nmethod* nm, address call_site) {
aoqi@0 267 CompiledIC* c_ic = new CompiledIC(nm, nativeCall_at(call_site));
aoqi@0 268 c_ic->verify();
aoqi@0 269 return c_ic;
aoqi@0 270 }
aoqi@0 271
aoqi@0 272 inline CompiledIC* CompiledIC_at(Relocation* call_site) {
aoqi@0 273 assert(call_site->type() == relocInfo::virtual_call_type ||
aoqi@0 274 call_site->type() == relocInfo::opt_virtual_call_type, "wrong reloc. info");
aoqi@0 275 CompiledIC* c_ic = new CompiledIC(call_site->code(), nativeCall_at(call_site->addr()));
aoqi@0 276 c_ic->verify();
aoqi@0 277 return c_ic;
aoqi@0 278 }
aoqi@0 279
stefank@6991 280 inline CompiledIC* CompiledIC_at(RelocIterator* reloc_iter) {
stefank@6991 281 assert(reloc_iter->type() == relocInfo::virtual_call_type ||
stefank@6991 282 reloc_iter->type() == relocInfo::opt_virtual_call_type, "wrong reloc. info");
stefank@6991 283 CompiledIC* c_ic = new CompiledIC(reloc_iter);
stefank@6991 284 c_ic->verify();
stefank@6991 285 return c_ic;
stefank@6991 286 }
aoqi@0 287
aoqi@0 288 //-----------------------------------------------------------------------------
aoqi@0 289 // The CompiledStaticCall represents a call to a static method in the compiled
aoqi@0 290 //
aoqi@0 291 // Transition diagram of a static call site is somewhat simpler than for an inlined cache:
aoqi@0 292 //
aoqi@0 293 //
aoqi@0 294 // -----<----- Clean ----->-----
aoqi@0 295 // / \
aoqi@0 296 // / \
aoqi@0 297 // compilled code <------------> interpreted code
aoqi@0 298 //
aoqi@0 299 // Clean: Calls directly to runtime method for fixup
aoqi@0 300 // Compiled code: Calls directly to compiled code
aoqi@0 301 // Interpreted code: Calls to stub that set Method* reference
aoqi@0 302 //
aoqi@0 303 //
aoqi@0 304 class CompiledStaticCall;
aoqi@0 305
aoqi@0 306 class StaticCallInfo {
aoqi@0 307 private:
aoqi@0 308 address _entry; // Entrypoint
aoqi@0 309 methodHandle _callee; // Callee (used when calling interpreter)
aoqi@0 310 bool _to_interpreter; // call to interpreted method (otherwise compiled)
aoqi@0 311
aoqi@0 312 friend class CompiledStaticCall;
aoqi@0 313 public:
aoqi@0 314 address entry() const { return _entry; }
aoqi@0 315 methodHandle callee() const { return _callee; }
aoqi@0 316 };
aoqi@0 317
aoqi@0 318
aoqi@0 319 class CompiledStaticCall: public NativeCall {
aoqi@0 320 friend class CompiledIC;
aoqi@0 321
aoqi@0 322 // Also used by CompiledIC
aoqi@0 323 void set_to_interpreted(methodHandle callee, address entry);
aoqi@0 324 bool is_optimized_virtual();
aoqi@0 325
aoqi@0 326 public:
aoqi@0 327 friend CompiledStaticCall* compiledStaticCall_before(address return_addr);
aoqi@0 328 friend CompiledStaticCall* compiledStaticCall_at(address native_call);
aoqi@0 329 friend CompiledStaticCall* compiledStaticCall_at(Relocation* call_site);
aoqi@0 330
aoqi@0 331 // Code
vkempik@8427 332 static address emit_to_interp_stub(CodeBuffer &cbuf);
aoqi@0 333 static int to_interp_stub_size();
aoqi@0 334 static int reloc_to_interp_stub();
aoqi@0 335
aoqi@0 336 // State
aoqi@0 337 bool is_clean() const;
aoqi@0 338 bool is_call_to_compiled() const;
aoqi@0 339 bool is_call_to_interpreted() const;
aoqi@0 340
aoqi@0 341 // Clean static call (will force resolving on next use)
aoqi@0 342 void set_to_clean();
aoqi@0 343
aoqi@0 344 // Set state. The entry must be the same, as computed by compute_entry.
aoqi@0 345 // Computation and setting is split up, since the actions are separate during
aoqi@0 346 // a OptoRuntime::resolve_xxx.
aoqi@0 347 void set(const StaticCallInfo& info);
aoqi@0 348
aoqi@0 349 // Compute entry point given a method
aoqi@0 350 static void compute_entry(methodHandle m, StaticCallInfo& info);
aoqi@0 351
aoqi@0 352 // Stub support
aoqi@0 353 address find_stub();
aoqi@0 354 static void set_stub_to_clean(static_stub_Relocation* static_stub);
aoqi@0 355
aoqi@0 356 // Misc.
aoqi@0 357 void print() PRODUCT_RETURN;
aoqi@0 358 void verify() PRODUCT_RETURN;
aoqi@0 359 };
aoqi@0 360
aoqi@0 361
aoqi@0 362 inline CompiledStaticCall* compiledStaticCall_before(address return_addr) {
aoqi@0 363 CompiledStaticCall* st = (CompiledStaticCall*)nativeCall_before(return_addr);
aoqi@0 364 st->verify();
aoqi@0 365 return st;
aoqi@0 366 }
aoqi@0 367
aoqi@0 368 inline CompiledStaticCall* compiledStaticCall_at(address native_call) {
aoqi@0 369 CompiledStaticCall* st = (CompiledStaticCall*)native_call;
aoqi@0 370 st->verify();
aoqi@0 371 return st;
aoqi@0 372 }
aoqi@0 373
aoqi@0 374 inline CompiledStaticCall* compiledStaticCall_at(Relocation* call_site) {
aoqi@0 375 return compiledStaticCall_at(call_site->addr());
aoqi@0 376 }
aoqi@0 377
aoqi@0 378 #endif // SHARE_VM_CODE_COMPILEDIC_HPP

mercurial