vtableStubs.hpp revision 3932
0N/A/*
1879N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_CODE_VTABLESTUBS_HPP
1879N/A#define SHARE_VM_CODE_VTABLESTUBS_HPP
1879N/A
1890N/A#include "code/vmreg.hpp"
1879N/A#include "memory/allocation.hpp"
1879N/A
0N/A// A VtableStub holds an individual code stub for a pair (vtable index, #args) for either itables or vtables
0N/A// There's a one-to-one relationship between a VtableStub and such a pair.
0N/A
0N/Aclass VtableStub {
0N/A private:
0N/A friend class VtableStubs;
0N/A
0N/A static address _chunk; // For allocation
0N/A static address _chunk_end; // For allocation
0N/A static VMReg _receiver_location; // Where to find receiver
0N/A
0N/A VtableStub* _next; // Pointer to next entry in hash table
0N/A const short _index; // vtable index
0N/A short _ame_offset; // Where an AbstractMethodError might occur
0N/A short _npe_offset; // Where a NullPointerException might occur
0N/A bool _is_vtable_stub; // True if vtable stub, false, is itable stub
0N/A /* code follows here */ // The vtableStub code
0N/A
0N/A void* operator new(size_t size, int code_size);
0N/A
0N/A VtableStub(bool is_vtable_stub, int index)
0N/A : _next(NULL), _is_vtable_stub(is_vtable_stub),
0N/A _index(index), _ame_offset(-1), _npe_offset(-1) {}
0N/A VtableStub* next() const { return _next; }
0N/A int index() const { return _index; }
0N/A static VMReg receiver_location() { return _receiver_location; }
0N/A void set_next(VtableStub* n) { _next = n; }
3932N/A
3932N/A public:
0N/A address code_begin() const { return (address)(this + 1); }
0N/A address code_end() const { return code_begin() + pd_code_size_limit(_is_vtable_stub); }
0N/A address entry_point() const { return code_begin(); }
0N/A static int entry_offset() { return sizeof(class VtableStub); }
0N/A
0N/A bool matches(bool is_vtable_stub, int index) const {
0N/A return _index == index && _is_vtable_stub == is_vtable_stub;
0N/A }
0N/A bool contains(address pc) const { return code_begin() <= pc && pc < code_end(); }
0N/A
3932N/A private:
0N/A void set_exception_points(address npe_addr, address ame_addr) {
0N/A _npe_offset = npe_addr - code_begin();
0N/A _ame_offset = ame_addr - code_begin();
0N/A assert(is_abstract_method_error(ame_addr), "offset must be correct");
0N/A assert(is_null_pointer_exception(npe_addr), "offset must be correct");
0N/A assert(!is_abstract_method_error(npe_addr), "offset must be correct");
0N/A assert(!is_null_pointer_exception(ame_addr), "offset must be correct");
0N/A }
0N/A
0N/A // platform-dependent routines
0N/A static int pd_code_size_limit(bool is_vtable_stub);
0N/A static int pd_code_alignment();
0N/A // CNC: Removed because vtable stubs are now made with an ideal graph
0N/A // static bool pd_disregard_arg_size();
0N/A
0N/A static void align_chunk() {
0N/A uintptr_t off = (uintptr_t)( _chunk + sizeof(VtableStub) ) % pd_code_alignment();
0N/A if (off != 0) _chunk += pd_code_alignment() - off;
0N/A }
0N/A
0N/A public:
0N/A // Query
0N/A bool is_itable_stub() { return !_is_vtable_stub; }
0N/A bool is_vtable_stub() { return _is_vtable_stub; }
0N/A bool is_abstract_method_error(address epc) { return epc == code_begin()+_ame_offset; }
0N/A bool is_null_pointer_exception(address epc) { return epc == code_begin()+_npe_offset; }
0N/A
1601N/A void print_on(outputStream* st) const;
1601N/A void print() const { print_on(tty); }
1601N/A
0N/A};
0N/A
0N/A
0N/A// VtableStubs creates the code stubs for compiled calls through vtables.
0N/A// There is one stub per (vtable index, args_size) pair, and the stubs are
0N/A// never deallocated. They don't need to be GCed because they contain no oops.
0N/A
0N/Aclass VtableStubs : AllStatic {
0N/A public: // N must be public (some compilers need this for _table)
0N/A enum {
0N/A N = 256, // size of stub table; must be power of two
0N/A mask = N - 1
0N/A };
0N/A
0N/A private:
0N/A static VtableStub* _table[N]; // table of existing stubs
0N/A static int _number_of_vtable_stubs; // number of stubs created so far (for statistics)
0N/A
0N/A static VtableStub* create_vtable_stub(int vtable_index);
0N/A static VtableStub* create_itable_stub(int vtable_index);
0N/A static VtableStub* lookup (bool is_vtable_stub, int vtable_index);
0N/A static void enter (bool is_vtable_stub, int vtable_index, VtableStub* s);
0N/A static inline uint hash (bool is_vtable_stub, int vtable_index);
0N/A
0N/A public:
0N/A static address create_stub(bool is_vtable_stub, int vtable_index, methodOop method); // return the entry point of a stub for this call
0N/A static bool is_entry_point(address pc); // is pc a vtable stub entry point?
0N/A static bool contains(address pc); // is pc within any stub?
0N/A static VtableStub* stub_containing(address pc); // stub containing pc or NULL
0N/A static int number_of_vtable_stubs() { return _number_of_vtable_stubs; }
0N/A static void initialize();
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_CODE_VTABLESTUBS_HPP