Path: blob/master/src/hotspot/share/code/icBuffer.hpp
40931 views
/*1* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_CODE_ICBUFFER_HPP25#define SHARE_CODE_ICBUFFER_HPP2627#include "asm/codeBuffer.hpp"28#include "code/stubs.hpp"29#include "interpreter/bytecodes.hpp"30#include "memory/allocation.hpp"31#include "runtime/safepointVerifiers.hpp"32#include "utilities/align.hpp"33#include "utilities/debug.hpp"34#include "utilities/macros.hpp"3536class CompiledIC;37class CompiledICHolder;3839//40// For CompiledIC's:41//42// In cases where we do not have MT-safe state transformation,43// we go to a transition state, using ICStubs. At a safepoint,44// the inline caches are transferred from the transitional code:45//46// instruction_address --> 01 set xxx_oop, Ginline_cache_klass47// 23 jump_to Gtemp, yyyy48// 4 nop4950class ICStub: public Stub {51private:52int _size; // total size of the stub incl. code53address _ic_site; // points at call instruction of owning ic-buffer54/* stub code follows here */55protected:56friend class ICStubInterface;57// This will be called only by ICStubInterface58void initialize(int size,59CodeStrings strings) { _size = size; _ic_site = NULL; }60void finalize(); // called when a method is removed6162// General info63int size() const { return _size; }64static int code_size_to_size(int code_size) { return align_up((int)sizeof(ICStub), CodeEntryAlignment) + code_size; }6566public:67// Creation68void set_stub(CompiledIC *ic, void* cached_value, address dest_addr);6970// Code info71address code_begin() const { return (address)this + align_up(sizeof(ICStub), CodeEntryAlignment); }72address code_end() const { return (address)this + size(); }7374// Call site info75address ic_site() const { return _ic_site; }76void clear();77bool is_empty() const { return _ic_site == NULL; }7879// stub info80address destination() const; // destination of jump instruction81void* cached_value() const; // cached_value for stub8283// Debugging84void verify() PRODUCT_RETURN;85void print() PRODUCT_RETURN;8687// Creation88friend ICStub* ICStub_from_destination_address(address destination_address);89};9091// ICStub Creation92inline ICStub* ICStub_from_destination_address(address destination_address) {93ICStub* stub = (ICStub*) (destination_address - align_up(sizeof(ICStub), CodeEntryAlignment));94#ifdef ASSERT95stub->verify();96#endif97return stub;98}99100#ifdef ASSERT101// The ICRefillVerifier class is a stack allocated RAII object used to102// detect if a failed IC transition that required IC stub refilling has103// been accidentally missed. It is up to the caller to in that case104// refill IC stubs.105class ICRefillVerifier: StackObj {106bool _refill_requested;107bool _refill_remembered;108109public:110ICRefillVerifier();111~ICRefillVerifier();112113void request_refill() { _refill_requested = true; }114void request_remembered() { _refill_remembered = true; }115};116117// The ICRefillVerifierMark is used to set the thread's current118// ICRefillVerifier to a provided one. This is useful in particular119// when transitioning IC stubs in parallel and refilling from the120// master thread invoking the IC stub transitioning code.121class ICRefillVerifierMark: StackObj {122public:123ICRefillVerifierMark(ICRefillVerifier* verifier);124~ICRefillVerifierMark();125};126#else127class ICRefillVerifier: StackObj {128public:129ICRefillVerifier() {}130};131class ICRefillVerifierMark: StackObj {132public:133ICRefillVerifierMark(ICRefillVerifier* verifier) {}134};135#endif136137class InlineCacheBuffer: public AllStatic {138private:139// friends140friend class ICStub;141142static int ic_stub_code_size();143144static StubQueue* _buffer;145146static CompiledICHolder* _pending_released;147static int _pending_count;148149static StubQueue* buffer() { return _buffer; }150151static ICStub* new_ic_stub();152153// Machine-dependent implementation of ICBuffer154static void assemble_ic_buffer_code(address code_begin, void* cached_value, address entry_point);155static address ic_buffer_entry_point (address code_begin);156static void* ic_buffer_cached_value (address code_begin);157158public:159160// Initialization; must be called before first usage161static void initialize();162163// Access164static bool contains(address instruction_address);165166// removes the ICStubs after backpatching167static void update_inline_caches();168static void refill_ic_stubs();169170// for debugging171static bool is_empty();172173static void release_pending_icholders();174static void queue_for_release(CompiledICHolder* icholder);175static int pending_icholder_count() { return _pending_count; }176177// New interface178static bool create_transition_stub(CompiledIC *ic, void* cached_value, address entry);179static address ic_destination_for(CompiledIC *ic);180static void* cached_value_for(CompiledIC *ic);181};182183#endif // SHARE_CODE_ICBUFFER_HPP184185186