Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/code/vtableStubs.hpp
32285 views
/*1* Copyright (c) 1997, 2018, 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_VM_CODE_VTABLESTUBS_HPP25#define SHARE_VM_CODE_VTABLESTUBS_HPP2627#include "code/vmreg.hpp"28#include "memory/allocation.hpp"2930// A VtableStub holds an individual code stub for a pair (vtable index, #args) for either itables or vtables31// There's a one-to-one relationship between a VtableStub and such a pair.3233class VtableStub {34private:35friend class VtableStubs;3637static address _chunk; // For allocation38static address _chunk_end; // For allocation39static VMReg _receiver_location; // Where to find receiver4041VtableStub* _next; // Pointer to next entry in hash table42const short _index; // vtable index43short _ame_offset; // Where an AbstractMethodError might occur44short _npe_offset; // Where a NullPointerException might occur45bool _is_vtable_stub; // True if vtable stub, false, is itable stub46/* code follows here */ // The vtableStub code4748void* operator new(size_t size, int code_size) throw();4950VtableStub(bool is_vtable_stub, int index)51: _next(NULL), _is_vtable_stub(is_vtable_stub),52_index(index), _ame_offset(-1), _npe_offset(-1) {}53VtableStub* next() const { return _next; }54int index() const { return _index; }55static VMReg receiver_location() { return _receiver_location; }56void set_next(VtableStub* n) { _next = n; }5758public:59address code_begin() const { return (address)(this + 1); }60address code_end() const { return code_begin() + pd_code_size_limit(_is_vtable_stub); }61address entry_point() const { return code_begin(); }62static int entry_offset() { return sizeof(class VtableStub); }6364bool matches(bool is_vtable_stub, int index) const {65return _index == index && _is_vtable_stub == is_vtable_stub;66}67bool contains(address pc) const { return code_begin() <= pc && pc < code_end(); }6869private:70void set_exception_points(address npe_addr, address ame_addr) {71_npe_offset = npe_addr - code_begin();72_ame_offset = ame_addr - code_begin();73assert(is_abstract_method_error(ame_addr), "offset must be correct");74assert(is_null_pointer_exception(npe_addr), "offset must be correct");75assert(!is_abstract_method_error(npe_addr), "offset must be correct");76assert(!is_null_pointer_exception(ame_addr), "offset must be correct");77}7879// platform-dependent routines80static int pd_code_size_limit(bool is_vtable_stub);81static int pd_code_alignment();82// CNC: Removed because vtable stubs are now made with an ideal graph83// static bool pd_disregard_arg_size();8485static void align_chunk() {86uintptr_t off = (uintptr_t)( _chunk + sizeof(VtableStub) ) % pd_code_alignment();87if (off != 0) _chunk += pd_code_alignment() - off;88}8990public:91// Query92bool is_itable_stub() { return !_is_vtable_stub; }93bool is_vtable_stub() { return _is_vtable_stub; }94bool is_abstract_method_error(address epc) { return epc == code_begin()+_ame_offset; }95bool is_null_pointer_exception(address epc) { return epc == code_begin()+_npe_offset; }9697void print_on(outputStream* st) const;98void print() const { print_on(tty); }99100};101102103// VtableStubs creates the code stubs for compiled calls through vtables.104// There is one stub per (vtable index, args_size) pair, and the stubs are105// never deallocated. They don't need to be GCed because they contain no oops.106107class VtableStubs : AllStatic {108public: // N must be public (some compilers need this for _table)109enum {110N = 256, // size of stub table; must be power of two111mask = N - 1112};113114private:115static VtableStub* _table[N]; // table of existing stubs116static int _number_of_vtable_stubs; // number of stubs created so far (for statistics)117118static VtableStub* create_vtable_stub(int vtable_index);119static VtableStub* create_itable_stub(int vtable_index);120static VtableStub* lookup (bool is_vtable_stub, int vtable_index);121static void enter (bool is_vtable_stub, int vtable_index, VtableStub* s);122static inline uint hash (bool is_vtable_stub, int vtable_index);123static address find_stub (bool is_vtable_stub, int vtable_index);124125public:126static address find_vtable_stub(int vtable_index) { return find_stub(true, vtable_index); }127static address find_itable_stub(int itable_index) { return find_stub(false, itable_index); }128static VtableStub* entry_point(address pc); // vtable stub entry point for a pc129static bool contains(address pc); // is pc within any stub?130static VtableStub* stub_containing(address pc); // stub containing pc or NULL131static int number_of_vtable_stubs() { return _number_of_vtable_stubs; }132static void initialize();133static void vtable_stub_do(void f(VtableStub*)); // iterates over all vtable stubs134};135136#endif // SHARE_VM_CODE_VTABLESTUBS_HPP137138139