Sat, 07 Nov 2020 10:30:02 +0800
Added tag mips-jdk8u275-b01 for changeset d3b4d62f391f
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2004, 2012, 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 | #include "precompiled.hpp" |
aoqi@0 | 26 | #include "asm/macroAssembler.hpp" |
aoqi@0 | 27 | #include "asm/codeBuffer.hpp" |
aoqi@0 | 28 | #include "memory/metaspaceShared.hpp" |
aoqi@0 | 29 | |
aoqi@0 | 30 | // Generate the self-patching vtable method: |
aoqi@0 | 31 | // |
aoqi@0 | 32 | // This method will be called (as any other Klass virtual method) with |
aoqi@0 | 33 | // the Klass itself as the first argument. Example: |
aoqi@0 | 34 | // |
aoqi@0 | 35 | // oop obj; |
aoqi@0 | 36 | // int size = obj->klass()->oop_size(this); |
aoqi@0 | 37 | // |
aoqi@0 | 38 | // for which the virtual method call is Klass::oop_size(); |
aoqi@0 | 39 | // |
aoqi@0 | 40 | // The dummy method is called with the Klass object as the first |
aoqi@0 | 41 | // operand, and an object as the second argument. |
aoqi@0 | 42 | // |
aoqi@0 | 43 | |
aoqi@0 | 44 | //===================================================================== |
aoqi@0 | 45 | |
aoqi@0 | 46 | // All of the dummy methods in the vtable are essentially identical, |
aoqi@0 | 47 | // differing only by an ordinal constant, and they bear no relationship |
aoqi@0 | 48 | // to the original method which the caller intended. Also, there needs |
aoqi@0 | 49 | // to be 'vtbl_list_size' instances of the vtable in order to |
aoqi@0 | 50 | // differentiate between the 'vtable_list_size' original Klass objects. |
aoqi@0 | 51 | |
aoqi@0 | 52 | #define __ masm-> |
aoqi@0 | 53 | |
aoqi@0 | 54 | void MetaspaceShared::generate_vtable_methods(void** vtbl_list, |
aoqi@0 | 55 | void** vtable, |
aoqi@0 | 56 | char** md_top, |
aoqi@0 | 57 | char* md_end, |
aoqi@0 | 58 | char** mc_top, |
aoqi@0 | 59 | char* mc_end) { |
aoqi@0 | 60 | |
aoqi@0 | 61 | intptr_t vtable_bytes = (num_virtuals * vtbl_list_size) * sizeof(void*); |
aoqi@0 | 62 | *(intptr_t *)(*md_top) = vtable_bytes; |
aoqi@0 | 63 | *md_top += sizeof(intptr_t); |
aoqi@0 | 64 | void** dummy_vtable = (void**)*md_top; |
aoqi@0 | 65 | *vtable = dummy_vtable; |
aoqi@0 | 66 | *md_top += vtable_bytes; |
aoqi@0 | 67 | |
aoqi@0 | 68 | // Get ready to generate dummy methods. |
aoqi@0 | 69 | |
aoqi@0 | 70 | CodeBuffer cb((unsigned char*)*mc_top, mc_end - *mc_top); |
aoqi@0 | 71 | MacroAssembler* masm = new MacroAssembler(&cb); |
aoqi@0 | 72 | |
aoqi@0 | 73 | Label common_code; |
aoqi@0 | 74 | for (int i = 0; i < vtbl_list_size; ++i) { |
aoqi@0 | 75 | for (int j = 0; j < num_virtuals; ++j) { |
aoqi@0 | 76 | dummy_vtable[num_virtuals * i + j] = (void*)masm->pc(); |
aoqi@0 | 77 | |
aoqi@0 | 78 | // Load rax, with a value indicating vtable/offset pair. |
aoqi@0 | 79 | // -- bits[ 7..0] (8 bits) which virtual method in table? |
aoqi@0 | 80 | // -- bits[12..8] (5 bits) which virtual method table? |
aoqi@0 | 81 | // -- must fit in 13-bit instruction immediate field. |
aoqi@0 | 82 | __ movl(rax, (i << 8) + j); |
aoqi@0 | 83 | __ jmp(common_code); |
aoqi@0 | 84 | } |
aoqi@0 | 85 | } |
aoqi@0 | 86 | |
aoqi@0 | 87 | __ bind(common_code); |
aoqi@0 | 88 | |
aoqi@0 | 89 | #ifdef WIN32 |
aoqi@0 | 90 | // Expecting to be called with "thiscall" conventions -- the arguments |
aoqi@0 | 91 | // are on the stack, except that the "this" pointer is in rcx. |
aoqi@0 | 92 | #else |
aoqi@0 | 93 | // Expecting to be called with Unix conventions -- the arguments |
aoqi@0 | 94 | // are on the stack, including the "this" pointer. |
aoqi@0 | 95 | #endif |
aoqi@0 | 96 | |
aoqi@0 | 97 | // In addition, rax was set (above) to the offset of the method in the |
aoqi@0 | 98 | // table. |
aoqi@0 | 99 | |
aoqi@0 | 100 | #ifdef WIN32 |
aoqi@0 | 101 | __ push(rcx); // save "this" |
aoqi@0 | 102 | #endif |
aoqi@0 | 103 | __ mov(rcx, rax); |
aoqi@0 | 104 | __ shrptr(rcx, 8); // isolate vtable identifier. |
aoqi@0 | 105 | __ shlptr(rcx, LogBytesPerWord); |
aoqi@0 | 106 | Address index(noreg, rcx, Address::times_1); |
aoqi@0 | 107 | ExternalAddress vtbl((address)vtbl_list); |
aoqi@0 | 108 | __ movptr(rdx, ArrayAddress(vtbl, index)); // get correct vtable address. |
aoqi@0 | 109 | #ifdef WIN32 |
aoqi@0 | 110 | __ pop(rcx); // restore "this" |
aoqi@0 | 111 | #else |
aoqi@0 | 112 | __ movptr(rcx, Address(rsp, BytesPerWord)); // fetch "this" |
aoqi@0 | 113 | #endif |
aoqi@0 | 114 | __ movptr(Address(rcx, 0), rdx); // update vtable pointer. |
aoqi@0 | 115 | |
aoqi@0 | 116 | __ andptr(rax, 0x00ff); // isolate vtable method index |
aoqi@0 | 117 | __ shlptr(rax, LogBytesPerWord); |
aoqi@0 | 118 | __ addptr(rax, rdx); // address of real method pointer. |
aoqi@0 | 119 | __ jmp(Address(rax, 0)); // get real method pointer. |
aoqi@0 | 120 | |
aoqi@0 | 121 | __ flush(); |
aoqi@0 | 122 | |
aoqi@0 | 123 | *mc_top = (char*)__ pc(); |
aoqi@0 | 124 | } |