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_VTABLESTUBS_HPP aoqi@0: #define SHARE_VM_CODE_VTABLESTUBS_HPP aoqi@0: aoqi@0: #include "code/vmreg.hpp" aoqi@0: #include "memory/allocation.hpp" aoqi@0: aoqi@0: // A VtableStub holds an individual code stub for a pair (vtable index, #args) for either itables or vtables aoqi@0: // There's a one-to-one relationship between a VtableStub and such a pair. aoqi@0: aoqi@0: class VtableStub { aoqi@0: private: aoqi@0: friend class VtableStubs; aoqi@0: aoqi@0: static address _chunk; // For allocation aoqi@0: static address _chunk_end; // For allocation aoqi@0: static VMReg _receiver_location; // Where to find receiver aoqi@0: aoqi@0: VtableStub* _next; // Pointer to next entry in hash table aoqi@0: const short _index; // vtable index aoqi@0: short _ame_offset; // Where an AbstractMethodError might occur aoqi@0: short _npe_offset; // Where a NullPointerException might occur aoqi@0: bool _is_vtable_stub; // True if vtable stub, false, is itable stub aoqi@0: /* code follows here */ // The vtableStub code aoqi@0: aoqi@0: void* operator new(size_t size, int code_size) throw(); aoqi@0: aoqi@0: VtableStub(bool is_vtable_stub, int index) aoqi@0: : _next(NULL), _is_vtable_stub(is_vtable_stub), aoqi@0: _index(index), _ame_offset(-1), _npe_offset(-1) {} aoqi@0: VtableStub* next() const { return _next; } aoqi@0: int index() const { return _index; } aoqi@0: static VMReg receiver_location() { return _receiver_location; } aoqi@0: void set_next(VtableStub* n) { _next = n; } aoqi@0: aoqi@0: public: aoqi@0: address code_begin() const { return (address)(this + 1); } aoqi@0: address code_end() const { return code_begin() + pd_code_size_limit(_is_vtable_stub); } aoqi@0: address entry_point() const { return code_begin(); } aoqi@0: static int entry_offset() { return sizeof(class VtableStub); } aoqi@0: aoqi@0: bool matches(bool is_vtable_stub, int index) const { aoqi@0: return _index == index && _is_vtable_stub == is_vtable_stub; aoqi@0: } aoqi@0: bool contains(address pc) const { return code_begin() <= pc && pc < code_end(); } aoqi@0: aoqi@0: private: aoqi@0: void set_exception_points(address npe_addr, address ame_addr) { aoqi@0: _npe_offset = npe_addr - code_begin(); aoqi@0: _ame_offset = ame_addr - code_begin(); aoqi@0: assert(is_abstract_method_error(ame_addr), "offset must be correct"); aoqi@0: assert(is_null_pointer_exception(npe_addr), "offset must be correct"); aoqi@0: assert(!is_abstract_method_error(npe_addr), "offset must be correct"); aoqi@0: assert(!is_null_pointer_exception(ame_addr), "offset must be correct"); aoqi@0: } aoqi@0: aoqi@0: // platform-dependent routines aoqi@0: static int pd_code_size_limit(bool is_vtable_stub); aoqi@0: static int pd_code_alignment(); aoqi@0: // CNC: Removed because vtable stubs are now made with an ideal graph aoqi@0: // static bool pd_disregard_arg_size(); aoqi@0: aoqi@0: static void align_chunk() { aoqi@0: uintptr_t off = (uintptr_t)( _chunk + sizeof(VtableStub) ) % pd_code_alignment(); aoqi@0: if (off != 0) _chunk += pd_code_alignment() - off; aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: // Query aoqi@0: bool is_itable_stub() { return !_is_vtable_stub; } aoqi@0: bool is_vtable_stub() { return _is_vtable_stub; } aoqi@0: bool is_abstract_method_error(address epc) { return epc == code_begin()+_ame_offset; } aoqi@0: bool is_null_pointer_exception(address epc) { return epc == code_begin()+_npe_offset; } aoqi@0: aoqi@0: void print_on(outputStream* st) const; aoqi@0: void print() const { print_on(tty); } aoqi@0: aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // VtableStubs creates the code stubs for compiled calls through vtables. aoqi@0: // There is one stub per (vtable index, args_size) pair, and the stubs are aoqi@0: // never deallocated. They don't need to be GCed because they contain no oops. aoqi@0: aoqi@0: class VtableStubs : AllStatic { aoqi@0: public: // N must be public (some compilers need this for _table) aoqi@0: enum { aoqi@0: N = 256, // size of stub table; must be power of two aoqi@0: mask = N - 1 aoqi@0: }; aoqi@0: aoqi@0: private: aoqi@0: static VtableStub* _table[N]; // table of existing stubs aoqi@0: static int _number_of_vtable_stubs; // number of stubs created so far (for statistics) aoqi@0: aoqi@0: static VtableStub* create_vtable_stub(int vtable_index); aoqi@0: static VtableStub* create_itable_stub(int vtable_index); aoqi@0: static VtableStub* lookup (bool is_vtable_stub, int vtable_index); aoqi@0: static void enter (bool is_vtable_stub, int vtable_index, VtableStub* s); aoqi@0: static inline uint hash (bool is_vtable_stub, int vtable_index); aoqi@0: static address find_stub (bool is_vtable_stub, int vtable_index); aoqi@0: aoqi@0: public: aoqi@0: static address find_vtable_stub(int vtable_index) { return find_stub(true, vtable_index); } aoqi@0: static address find_itable_stub(int itable_index) { return find_stub(false, itable_index); } aoqi@0: static bool is_entry_point(address pc); // is pc a vtable stub entry point? aoqi@0: static bool contains(address pc); // is pc within any stub? aoqi@0: static VtableStub* stub_containing(address pc); // stub containing pc or NULL aoqi@0: static int number_of_vtable_stubs() { return _number_of_vtable_stubs; } aoqi@0: static void initialize(); aoqi@0: static void vtable_stub_do(void f(VtableStub*)); // iterates over all vtable stubs aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_CODE_VTABLESTUBS_HPP