1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/code/vtableStubs.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,137 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_CODE_VTABLESTUBS_HPP 1.29 +#define SHARE_VM_CODE_VTABLESTUBS_HPP 1.30 + 1.31 +#include "code/vmreg.hpp" 1.32 +#include "memory/allocation.hpp" 1.33 + 1.34 +// A VtableStub holds an individual code stub for a pair (vtable index, #args) for either itables or vtables 1.35 +// There's a one-to-one relationship between a VtableStub and such a pair. 1.36 + 1.37 +class VtableStub { 1.38 + private: 1.39 + friend class VtableStubs; 1.40 + 1.41 + static address _chunk; // For allocation 1.42 + static address _chunk_end; // For allocation 1.43 + static VMReg _receiver_location; // Where to find receiver 1.44 + 1.45 + VtableStub* _next; // Pointer to next entry in hash table 1.46 + const short _index; // vtable index 1.47 + short _ame_offset; // Where an AbstractMethodError might occur 1.48 + short _npe_offset; // Where a NullPointerException might occur 1.49 + bool _is_vtable_stub; // True if vtable stub, false, is itable stub 1.50 + /* code follows here */ // The vtableStub code 1.51 + 1.52 + void* operator new(size_t size, int code_size) throw(); 1.53 + 1.54 + VtableStub(bool is_vtable_stub, int index) 1.55 + : _next(NULL), _is_vtable_stub(is_vtable_stub), 1.56 + _index(index), _ame_offset(-1), _npe_offset(-1) {} 1.57 + VtableStub* next() const { return _next; } 1.58 + int index() const { return _index; } 1.59 + static VMReg receiver_location() { return _receiver_location; } 1.60 + void set_next(VtableStub* n) { _next = n; } 1.61 + 1.62 + public: 1.63 + address code_begin() const { return (address)(this + 1); } 1.64 + address code_end() const { return code_begin() + pd_code_size_limit(_is_vtable_stub); } 1.65 + address entry_point() const { return code_begin(); } 1.66 + static int entry_offset() { return sizeof(class VtableStub); } 1.67 + 1.68 + bool matches(bool is_vtable_stub, int index) const { 1.69 + return _index == index && _is_vtable_stub == is_vtable_stub; 1.70 + } 1.71 + bool contains(address pc) const { return code_begin() <= pc && pc < code_end(); } 1.72 + 1.73 + private: 1.74 + void set_exception_points(address npe_addr, address ame_addr) { 1.75 + _npe_offset = npe_addr - code_begin(); 1.76 + _ame_offset = ame_addr - code_begin(); 1.77 + assert(is_abstract_method_error(ame_addr), "offset must be correct"); 1.78 + assert(is_null_pointer_exception(npe_addr), "offset must be correct"); 1.79 + assert(!is_abstract_method_error(npe_addr), "offset must be correct"); 1.80 + assert(!is_null_pointer_exception(ame_addr), "offset must be correct"); 1.81 + } 1.82 + 1.83 + // platform-dependent routines 1.84 + static int pd_code_size_limit(bool is_vtable_stub); 1.85 + static int pd_code_alignment(); 1.86 + // CNC: Removed because vtable stubs are now made with an ideal graph 1.87 + // static bool pd_disregard_arg_size(); 1.88 + 1.89 + static void align_chunk() { 1.90 + uintptr_t off = (uintptr_t)( _chunk + sizeof(VtableStub) ) % pd_code_alignment(); 1.91 + if (off != 0) _chunk += pd_code_alignment() - off; 1.92 + } 1.93 + 1.94 + public: 1.95 + // Query 1.96 + bool is_itable_stub() { return !_is_vtable_stub; } 1.97 + bool is_vtable_stub() { return _is_vtable_stub; } 1.98 + bool is_abstract_method_error(address epc) { return epc == code_begin()+_ame_offset; } 1.99 + bool is_null_pointer_exception(address epc) { return epc == code_begin()+_npe_offset; } 1.100 + 1.101 + void print_on(outputStream* st) const; 1.102 + void print() const { print_on(tty); } 1.103 + 1.104 +}; 1.105 + 1.106 + 1.107 +// VtableStubs creates the code stubs for compiled calls through vtables. 1.108 +// There is one stub per (vtable index, args_size) pair, and the stubs are 1.109 +// never deallocated. They don't need to be GCed because they contain no oops. 1.110 + 1.111 +class VtableStubs : AllStatic { 1.112 + public: // N must be public (some compilers need this for _table) 1.113 + enum { 1.114 + N = 256, // size of stub table; must be power of two 1.115 + mask = N - 1 1.116 + }; 1.117 + 1.118 + private: 1.119 + static VtableStub* _table[N]; // table of existing stubs 1.120 + static int _number_of_vtable_stubs; // number of stubs created so far (for statistics) 1.121 + 1.122 + static VtableStub* create_vtable_stub(int vtable_index); 1.123 + static VtableStub* create_itable_stub(int vtable_index); 1.124 + static VtableStub* lookup (bool is_vtable_stub, int vtable_index); 1.125 + static void enter (bool is_vtable_stub, int vtable_index, VtableStub* s); 1.126 + static inline uint hash (bool is_vtable_stub, int vtable_index); 1.127 + static address find_stub (bool is_vtable_stub, int vtable_index); 1.128 + 1.129 + public: 1.130 + static address find_vtable_stub(int vtable_index) { return find_stub(true, vtable_index); } 1.131 + static address find_itable_stub(int itable_index) { return find_stub(false, itable_index); } 1.132 + static bool is_entry_point(address pc); // is pc a vtable stub entry point? 1.133 + static bool contains(address pc); // is pc within any stub? 1.134 + static VtableStub* stub_containing(address pc); // stub containing pc or NULL 1.135 + static int number_of_vtable_stubs() { return _number_of_vtable_stubs; } 1.136 + static void initialize(); 1.137 + static void vtable_stub_do(void f(VtableStub*)); // iterates over all vtable stubs 1.138 +}; 1.139 + 1.140 +#endif // SHARE_VM_CODE_VTABLESTUBS_HPP