/* * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
//----------------------------------------------------------------------------- // The CompiledIC represents a compiled inline cache. // // In order to make patching of the inline cache MT-safe, we only allow the following // transitions (when not at a safepoint): // // // [1] --<-- Clean -->--- [1] // / (null) \ // / \ /-<-\ // / [2] \ / \ // Interpreted ---------> Monomorphic | [3] // (CompiledICHolder*) (Klass*) | // \ / \ / // [4] \ / [4] \->-/ // \->- Megamorphic -<-/ // (CompiledICHolder*) // // The text in parentheses () refers to the value of the inline cache receiver (mov instruction) // // The numbers in square brackets refer to the kind of transition: // [1]: Initial fixup. Receiver it found from debug information // [2]: Compilation of a method // [3]: Recompilation of a method (note: only entry is changed. The Klass* must stay the same) // [4]: Inline cache miss. We go directly to megamorphic call. // // The class automatically inserts transition stubs (using the InlineCacheBuffer) when an MT-unsafe // transition is made to a stub. // class CompiledIC; class CompiledICProtectionBehaviour; class CompiledMethod; class ICStub;
class CompiledICLocker: public StackObj {
CompiledMethod* _method;
CompiledICProtectionBehaviour* _behaviour; bool _locked;
NoSafepointVerifier _nsv;
CompiledICInfo(): _entry(NULL), _cached_value(NULL), _is_icholder(false),
_is_optimized(false), _to_interpreter(false), _release_icholder(false) {
}
~CompiledICInfo() { // In rare cases the info is computed but not used, so release any // CompiledICHolder* that was created if (_release_icholder) {
assert(_is_icholder, "must be");
CompiledICHolder* icholder = (CompiledICHolder*)_cached_value;
icholder->claim(); delete icholder;
}
}
};
class CompiledIC: public ResourceObj { friendclass InlineCacheBuffer; friendclass ICStub;
private:
NativeCallWrapper* _call;
NativeInstruction* _value; // patchable value cell for this IC bool _is_optimized; // an optimized virtual call (i.e., no compiled IC)
CompiledMethod* _method;
CompiledIC(CompiledMethod* cm, NativeCall* ic_call);
CompiledIC(RelocIterator* iter);
void initialize_from_iter(RelocIterator* iter);
staticbool is_icholder_entry(address entry);
// low-level inline-cache manipulation. Cannot be accessed directly, since it might not be MT-safe // to change an inline-cache. These changes the underlying inline-cache directly. They *newer* make // changes to a transition stub. void internal_set_ic_destination(address entry_point, bool is_icstub, void* cache, boolis_icholder); void set_ic_destination(ICStub* stub); void set_ic_destination(address entry_point) {
assert(_is_optimized, "use set_ic_destination_and_value instead");
internal_set_ic_destination(entry_point, false, NULL, false);
} // This only for use by ICStubs where the type of the value isn't known void set_ic_destination_and_value(address entry_point, void* value) {
internal_set_ic_destination(entry_point, false, value, is_icholder_entry(entry_point));
} void set_ic_destination_and_value(address entry_point, Metadata* value) {
internal_set_ic_destination(entry_point, false, value, false);
} void set_ic_destination_and_value(address entry_point, CompiledICHolder* value) {
internal_set_ic_destination(entry_point, false, value, true);
}
// Reads the location of the transition stub. This will fail with an assertion, if no transition stub is // associated with the inline cache.
address stub_address() const; bool is_in_transition_state() const; // Use InlineCacheBuffer
// Return the cached_metadata/destination associated with this inline cache. If the cache currently points // to a transition stub, it will read the values from the transition stub. void* cached_value() const;
CompiledICHolder* cached_icholder() const {
assert(is_icholder_call(), "must be"); return (CompiledICHolder*) cached_value();
}
Metadata* cached_metadata() const {
assert(!is_icholder_call(), "must be"); return (Metadata*) cached_value();
}
// MT-safe patching of inline caches. Note: Only safe to call is_xxx when holding the CompiledIC_ock // so you are guaranteed that no patching takes place. The same goes for verify. // // Note: We do not provide any direct access to the stub code, to prevent parts of the code // to manipulate the inline cache in MT-unsafe ways. // // They all takes a TRAP argument, since they can cause a GC if the inline-cache buffer is full. // bool set_to_clean(bool in_use = true); bool set_to_monomorphic(CompiledICInfo& info); void clear_ic_stub();
// Returns true if successful and false otherwise. The call can fail if memory // allocation in the code cache fails, or ic stub refill is required. bool set_to_megamorphic(CallInfo* call_info, Bytecodes::Code bytecode, bool& needs_ic_stub_refill, TRAPS);
//----------------------------------------------------------------------------- // The CompiledStaticCall represents a call to a static method in the compiled // // Transition diagram of a static call site is somewhat simpler than for an inlined cache: // // // -----<----- Clean ----->----- // / \ // / \ // compilled code <------------> interpreted code // // Clean: Calls directly to runtime method for fixup // Compiled code: Calls directly to compiled code // Interpreted code: Calls to stub that set Method* reference // //
class StaticCallInfo { private:
address _entry; // Entrypoint
methodHandle _callee; // Callee (used when calling interpreter) bool _to_interpreter; // call to interpreted method (otherwise compiled)
class CompiledStaticCall : public ResourceObj { public: // Code static address emit_to_interp_stub(CodeBuffer &cbuf, address mark = NULL); staticint to_interp_stub_size(); staticint to_trampoline_stub_size(); staticint reloc_to_interp_stub();
// Compute entry point given a method staticvoid compute_entry(const methodHandle& m, bool caller_is_nmethod, StaticCallInfo& info); void compute_entry_for_continuation_entry(const methodHandle& m, StaticCallInfo& info);
public: // Clean static call (will force resolving on next use) virtual address destination() const = 0;
// Clean static call (will force resolving on next use) bool set_to_clean(bool in_use = true);
// Set state. The entry must be the same, as computed by compute_entry. // Computation and setting is split up, since the actions are separate during // a OptoRuntime::resolve_xxx. void set(const StaticCallInfo& info);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.