Wed, 27 Apr 2016 01:25:04 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #ifndef SHARE_VM_CODE_VTABLESTUBS_HPP |
aoqi@0 | 26 | #define SHARE_VM_CODE_VTABLESTUBS_HPP |
aoqi@0 | 27 | |
aoqi@0 | 28 | #include "code/vmreg.hpp" |
aoqi@0 | 29 | #include "memory/allocation.hpp" |
aoqi@0 | 30 | |
aoqi@0 | 31 | // A VtableStub holds an individual code stub for a pair (vtable index, #args) for either itables or vtables |
aoqi@0 | 32 | // There's a one-to-one relationship between a VtableStub and such a pair. |
aoqi@0 | 33 | |
aoqi@0 | 34 | class VtableStub { |
aoqi@0 | 35 | private: |
aoqi@0 | 36 | friend class VtableStubs; |
aoqi@0 | 37 | |
aoqi@0 | 38 | static address _chunk; // For allocation |
aoqi@0 | 39 | static address _chunk_end; // For allocation |
aoqi@0 | 40 | static VMReg _receiver_location; // Where to find receiver |
aoqi@0 | 41 | |
aoqi@0 | 42 | VtableStub* _next; // Pointer to next entry in hash table |
aoqi@0 | 43 | const short _index; // vtable index |
aoqi@0 | 44 | short _ame_offset; // Where an AbstractMethodError might occur |
aoqi@0 | 45 | short _npe_offset; // Where a NullPointerException might occur |
aoqi@0 | 46 | bool _is_vtable_stub; // True if vtable stub, false, is itable stub |
aoqi@0 | 47 | /* code follows here */ // The vtableStub code |
aoqi@0 | 48 | |
aoqi@0 | 49 | void* operator new(size_t size, int code_size) throw(); |
aoqi@0 | 50 | |
aoqi@0 | 51 | VtableStub(bool is_vtable_stub, int index) |
aoqi@0 | 52 | : _next(NULL), _is_vtable_stub(is_vtable_stub), |
aoqi@0 | 53 | _index(index), _ame_offset(-1), _npe_offset(-1) {} |
aoqi@0 | 54 | VtableStub* next() const { return _next; } |
aoqi@0 | 55 | int index() const { return _index; } |
aoqi@0 | 56 | static VMReg receiver_location() { return _receiver_location; } |
aoqi@0 | 57 | void set_next(VtableStub* n) { _next = n; } |
aoqi@0 | 58 | |
aoqi@0 | 59 | public: |
aoqi@0 | 60 | address code_begin() const { return (address)(this + 1); } |
aoqi@0 | 61 | address code_end() const { return code_begin() + pd_code_size_limit(_is_vtable_stub); } |
aoqi@0 | 62 | address entry_point() const { return code_begin(); } |
aoqi@0 | 63 | static int entry_offset() { return sizeof(class VtableStub); } |
aoqi@0 | 64 | |
aoqi@0 | 65 | bool matches(bool is_vtable_stub, int index) const { |
aoqi@0 | 66 | return _index == index && _is_vtable_stub == is_vtable_stub; |
aoqi@0 | 67 | } |
aoqi@0 | 68 | bool contains(address pc) const { return code_begin() <= pc && pc < code_end(); } |
aoqi@0 | 69 | |
aoqi@0 | 70 | private: |
aoqi@0 | 71 | void set_exception_points(address npe_addr, address ame_addr) { |
aoqi@0 | 72 | _npe_offset = npe_addr - code_begin(); |
aoqi@0 | 73 | _ame_offset = ame_addr - code_begin(); |
aoqi@0 | 74 | assert(is_abstract_method_error(ame_addr), "offset must be correct"); |
aoqi@0 | 75 | assert(is_null_pointer_exception(npe_addr), "offset must be correct"); |
aoqi@0 | 76 | assert(!is_abstract_method_error(npe_addr), "offset must be correct"); |
aoqi@0 | 77 | assert(!is_null_pointer_exception(ame_addr), "offset must be correct"); |
aoqi@0 | 78 | } |
aoqi@0 | 79 | |
aoqi@0 | 80 | // platform-dependent routines |
aoqi@0 | 81 | static int pd_code_size_limit(bool is_vtable_stub); |
aoqi@0 | 82 | static int pd_code_alignment(); |
aoqi@0 | 83 | // CNC: Removed because vtable stubs are now made with an ideal graph |
aoqi@0 | 84 | // static bool pd_disregard_arg_size(); |
aoqi@0 | 85 | |
aoqi@0 | 86 | static void align_chunk() { |
aoqi@0 | 87 | uintptr_t off = (uintptr_t)( _chunk + sizeof(VtableStub) ) % pd_code_alignment(); |
aoqi@0 | 88 | if (off != 0) _chunk += pd_code_alignment() - off; |
aoqi@0 | 89 | } |
aoqi@0 | 90 | |
aoqi@0 | 91 | public: |
aoqi@0 | 92 | // Query |
aoqi@0 | 93 | bool is_itable_stub() { return !_is_vtable_stub; } |
aoqi@0 | 94 | bool is_vtable_stub() { return _is_vtable_stub; } |
aoqi@0 | 95 | bool is_abstract_method_error(address epc) { return epc == code_begin()+_ame_offset; } |
aoqi@0 | 96 | bool is_null_pointer_exception(address epc) { return epc == code_begin()+_npe_offset; } |
aoqi@0 | 97 | |
aoqi@0 | 98 | void print_on(outputStream* st) const; |
aoqi@0 | 99 | void print() const { print_on(tty); } |
aoqi@0 | 100 | |
aoqi@0 | 101 | }; |
aoqi@0 | 102 | |
aoqi@0 | 103 | |
aoqi@0 | 104 | // VtableStubs creates the code stubs for compiled calls through vtables. |
aoqi@0 | 105 | // There is one stub per (vtable index, args_size) pair, and the stubs are |
aoqi@0 | 106 | // never deallocated. They don't need to be GCed because they contain no oops. |
aoqi@0 | 107 | |
aoqi@0 | 108 | class VtableStubs : AllStatic { |
aoqi@0 | 109 | public: // N must be public (some compilers need this for _table) |
aoqi@0 | 110 | enum { |
aoqi@0 | 111 | N = 256, // size of stub table; must be power of two |
aoqi@0 | 112 | mask = N - 1 |
aoqi@0 | 113 | }; |
aoqi@0 | 114 | |
aoqi@0 | 115 | private: |
aoqi@0 | 116 | static VtableStub* _table[N]; // table of existing stubs |
aoqi@0 | 117 | static int _number_of_vtable_stubs; // number of stubs created so far (for statistics) |
aoqi@0 | 118 | |
aoqi@0 | 119 | static VtableStub* create_vtable_stub(int vtable_index); |
aoqi@0 | 120 | static VtableStub* create_itable_stub(int vtable_index); |
aoqi@0 | 121 | static VtableStub* lookup (bool is_vtable_stub, int vtable_index); |
aoqi@0 | 122 | static void enter (bool is_vtable_stub, int vtable_index, VtableStub* s); |
aoqi@0 | 123 | static inline uint hash (bool is_vtable_stub, int vtable_index); |
aoqi@0 | 124 | static address find_stub (bool is_vtable_stub, int vtable_index); |
aoqi@0 | 125 | |
aoqi@0 | 126 | public: |
aoqi@0 | 127 | static address find_vtable_stub(int vtable_index) { return find_stub(true, vtable_index); } |
aoqi@0 | 128 | static address find_itable_stub(int itable_index) { return find_stub(false, itable_index); } |
aoqi@0 | 129 | static bool is_entry_point(address pc); // is pc a vtable stub entry point? |
aoqi@0 | 130 | static bool contains(address pc); // is pc within any stub? |
aoqi@0 | 131 | static VtableStub* stub_containing(address pc); // stub containing pc or NULL |
aoqi@0 | 132 | static int number_of_vtable_stubs() { return _number_of_vtable_stubs; } |
aoqi@0 | 133 | static void initialize(); |
aoqi@0 | 134 | static void vtable_stub_do(void f(VtableStub*)); // iterates over all vtable stubs |
aoqi@0 | 135 | }; |
aoqi@0 | 136 | |
aoqi@0 | 137 | #endif // SHARE_VM_CODE_VTABLESTUBS_HPP |