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) 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 eax 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 | // Expecting to be called with "thiscall" convections -- the arguments |
aoqi@0 | 90 | // are on the stack and the "this" pointer is in c_rarg0. In addition, rax |
aoqi@0 | 91 | // was set (above) to the offset of the method in the table. |
aoqi@0 | 92 | |
aoqi@0 | 93 | __ push(c_rarg1); // save & free register |
aoqi@0 | 94 | __ push(c_rarg0); // save "this" |
aoqi@0 | 95 | __ mov(c_rarg0, rax); |
aoqi@0 | 96 | __ shrptr(c_rarg0, 8); // isolate vtable identifier. |
aoqi@0 | 97 | __ shlptr(c_rarg0, LogBytesPerWord); |
aoqi@0 | 98 | __ lea(c_rarg1, ExternalAddress((address)vtbl_list)); // ptr to correct vtable list. |
aoqi@0 | 99 | __ addptr(c_rarg1, c_rarg0); // ptr to list entry. |
aoqi@0 | 100 | __ movptr(c_rarg1, Address(c_rarg1, 0)); // get correct vtable address. |
aoqi@0 | 101 | __ pop(c_rarg0); // restore "this" |
aoqi@0 | 102 | __ movptr(Address(c_rarg0, 0), c_rarg1); // update vtable pointer. |
aoqi@0 | 103 | |
aoqi@0 | 104 | __ andptr(rax, 0x00ff); // isolate vtable method index |
aoqi@0 | 105 | __ shlptr(rax, LogBytesPerWord); |
aoqi@0 | 106 | __ addptr(rax, c_rarg1); // address of real method pointer. |
aoqi@0 | 107 | __ pop(c_rarg1); // restore register. |
aoqi@0 | 108 | __ movptr(rax, Address(rax, 0)); // get real method pointer. |
aoqi@0 | 109 | __ jmp(rax); // jump to the real method. |
aoqi@0 | 110 | |
aoqi@0 | 111 | __ flush(); |
aoqi@0 | 112 | |
aoqi@0 | 113 | *mc_top = (char*)__ pc(); |
aoqi@0 | 114 | } |