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