aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_CODE_ICBUFFER_HPP aoqi@0: #define SHARE_VM_CODE_ICBUFFER_HPP aoqi@0: aoqi@0: #include "asm/codeBuffer.hpp" aoqi@0: #include "code/stubs.hpp" aoqi@0: #include "interpreter/bytecodes.hpp" aoqi@0: #include "memory/allocation.hpp" aoqi@0: aoqi@0: // aoqi@0: // For CompiledIC's: aoqi@0: // aoqi@0: // In cases where we do not have MT-safe state transformation, aoqi@0: // we go to a transition state, using ICStubs. At a safepoint, aoqi@0: // the inline caches are transferred from the transitional code: aoqi@0: // aoqi@0: // instruction_address --> 01 set xxx_oop, Ginline_cache_klass aoqi@0: // 23 jump_to Gtemp, yyyy aoqi@0: // 4 nop aoqi@0: aoqi@0: class ICStub: public Stub { aoqi@0: private: aoqi@0: int _size; // total size of the stub incl. code aoqi@0: address _ic_site; // points at call instruction of owning ic-buffer aoqi@0: /* stub code follows here */ aoqi@0: protected: aoqi@0: friend class ICStubInterface; aoqi@0: // This will be called only by ICStubInterface aoqi@0: void initialize(int size, aoqi@0: CodeStrings strings) { _size = size; _ic_site = NULL; } aoqi@0: void finalize(); // called when a method is removed aoqi@0: aoqi@0: // General info aoqi@0: int size() const { return _size; } aoqi@0: static int code_size_to_size(int code_size) { return round_to(sizeof(ICStub), CodeEntryAlignment) + code_size; } aoqi@0: aoqi@0: public: aoqi@0: // Creation aoqi@0: void set_stub(CompiledIC *ic, void* cached_value, address dest_addr); aoqi@0: aoqi@0: // Code info aoqi@0: address code_begin() const { return (address)this + round_to(sizeof(ICStub), CodeEntryAlignment); } aoqi@0: address code_end() const { return (address)this + size(); } aoqi@0: aoqi@0: // Call site info aoqi@0: address ic_site() const { return _ic_site; } aoqi@0: void clear(); aoqi@0: bool is_empty() const { return _ic_site == NULL; } aoqi@0: aoqi@0: // stub info aoqi@0: address destination() const; // destination of jump instruction aoqi@0: void* cached_value() const; // cached_value for stub aoqi@0: aoqi@0: // Debugging aoqi@0: void verify() PRODUCT_RETURN; aoqi@0: void print() PRODUCT_RETURN; aoqi@0: aoqi@0: // Creation aoqi@0: friend ICStub* ICStub_from_destination_address(address destination_address); aoqi@0: }; aoqi@0: aoqi@0: // ICStub Creation aoqi@0: inline ICStub* ICStub_from_destination_address(address destination_address) { aoqi@0: ICStub* stub = (ICStub*) (destination_address - round_to(sizeof(ICStub), CodeEntryAlignment)); aoqi@0: #ifdef ASSERT aoqi@0: stub->verify(); aoqi@0: #endif aoqi@0: return stub; aoqi@0: } aoqi@0: aoqi@0: class InlineCacheBuffer: public AllStatic { aoqi@0: private: aoqi@0: // friends aoqi@0: friend class ICStub; aoqi@0: aoqi@0: static int ic_stub_code_size(); aoqi@0: aoqi@0: static StubQueue* _buffer; aoqi@0: static ICStub* _next_stub; aoqi@0: aoqi@0: static CompiledICHolder* _pending_released; aoqi@0: static int _pending_count; aoqi@0: aoqi@0: static StubQueue* buffer() { return _buffer; } aoqi@0: static void set_next_stub(ICStub* next_stub) { _next_stub = next_stub; } aoqi@0: static ICStub* get_next_stub() { return _next_stub; } aoqi@0: aoqi@0: static void init_next_stub(); aoqi@0: aoqi@0: static ICStub* new_ic_stub(); aoqi@0: aoqi@0: aoqi@0: // Machine-dependent implementation of ICBuffer aoqi@0: static void assemble_ic_buffer_code(address code_begin, void* cached_value, address entry_point); aoqi@0: static address ic_buffer_entry_point (address code_begin); aoqi@0: static void* ic_buffer_cached_value (address code_begin); aoqi@0: aoqi@0: public: aoqi@0: aoqi@0: // Initialization; must be called before first usage aoqi@0: static void initialize(); aoqi@0: aoqi@0: // Access aoqi@0: static bool contains(address instruction_address); aoqi@0: aoqi@0: // removes the ICStubs after backpatching aoqi@0: static void update_inline_caches(); aoqi@0: aoqi@0: // for debugging aoqi@0: static bool is_empty(); aoqi@0: aoqi@0: static void release_pending_icholders(); aoqi@0: static void queue_for_release(CompiledICHolder* icholder); aoqi@0: static int pending_icholder_count() { return _pending_count; } aoqi@0: aoqi@0: // New interface aoqi@0: static void create_transition_stub(CompiledIC *ic, void* cached_value, address entry); aoqi@0: static address ic_destination_for(CompiledIC *ic); aoqi@0: static void* cached_value_for(CompiledIC *ic); aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_CODE_ICBUFFER_HPP