src/cpu/mips/vm/metaspaceShared_mips_64.cpp

Tue, 31 May 2016 00:22:06 -0400

author
aoqi
date
Tue, 31 May 2016 00:22:06 -0400
changeset 16
3cedde979d75
parent 1
2d8a650513c2
child 6880
52ea28d233d2
permissions
-rw-r--r--

[Code Reorganization] load_two_bytes_from_at_bcp -> get_2_byte_integer_at_bcp
remove useless MacroAssembler::store_two_byts_to_at_bcp
change MacroAssembler::load_two_bytes_from_at_bcp to InterpreterMacroAssembler::get_2_byte_integer_at_bcp
change MacroAssembler::get_4_byte_integer_at_bcp to InterpreterMacroAssembler::get_4_byte_integer_at_bcp

aoqi@1 1 /*
aoqi@1 2 * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@1 3 * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved.
aoqi@1 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@1 5 *
aoqi@1 6 * This code is free software; you can redistribute it and/or modify it
aoqi@1 7 * under the terms of the GNU General Public License version 2 only, as
aoqi@1 8 * published by the Free Software Foundation.
aoqi@1 9 *
aoqi@1 10 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@1 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@1 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@1 13 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@1 14 * accompanied this code).
aoqi@1 15 *
aoqi@1 16 * You should have received a copy of the GNU General Public License version
aoqi@1 17 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@1 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@1 19 *
aoqi@1 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@1 21 * or visit www.oracle.com if you need additional information or have any
aoqi@1 22 * questions.
aoqi@1 23 *
aoqi@1 24 */
aoqi@1 25
aoqi@1 26 #include "precompiled.hpp"
aoqi@1 27 #include "asm/macroAssembler.hpp"
aoqi@1 28 #include "asm/codeBuffer.hpp"
aoqi@1 29 #include "memory/metaspaceShared.hpp"
aoqi@1 30
aoqi@1 31 // Generate the self-patching vtable method:
aoqi@1 32 //
aoqi@1 33 // This method will be called (as any other Klass virtual method) with
aoqi@1 34 // the Klass itself as the first argument. Example:
aoqi@1 35 //
aoqi@1 36 // oop obj;
aoqi@1 37 // int size = obj->klass()->klass_part()->oop_size(this);
aoqi@1 38 //
aoqi@1 39 // for which the virtual method call is Klass::oop_size();
aoqi@1 40 //
aoqi@1 41 // The dummy method is called with the Klass object as the first
aoqi@1 42 // operand, and an object as the second argument.
aoqi@1 43 //
aoqi@1 44
aoqi@1 45 //=====================================================================
aoqi@1 46
aoqi@1 47 // All of the dummy methods in the vtable are essentially identical,
aoqi@1 48 // differing only by an ordinal constant, and they bear no releationship
aoqi@1 49 // to the original method which the caller intended. Also, there needs
aoqi@1 50 // to be 'vtbl_list_size' instances of the vtable in order to
aoqi@1 51 // differentiate between the 'vtable_list_size' original Klass objects.
aoqi@1 52
aoqi@1 53 #define __ masm->
aoqi@1 54
aoqi@1 55 void MetaspaceShared::generate_vtable_methods(void** vtbl_list,
aoqi@1 56 void** vtable,
aoqi@1 57 char** md_top,
aoqi@1 58 char* md_end,
aoqi@1 59 char** mc_top,
aoqi@1 60 char* mc_end) {
aoqi@1 61
aoqi@1 62 intptr_t vtable_bytes = (num_virtuals * vtbl_list_size) * sizeof(void*);
aoqi@1 63 *(intptr_t *)(*md_top) = vtable_bytes;
aoqi@1 64 *md_top += sizeof(intptr_t);
aoqi@1 65 void** dummy_vtable = (void**)*md_top;
aoqi@1 66 *vtable = dummy_vtable;
aoqi@1 67 *md_top += vtable_bytes;
aoqi@1 68
aoqi@1 69 // Get ready to generate dummy methods.
aoqi@1 70
aoqi@1 71 CodeBuffer cb((unsigned char*)*mc_top, mc_end - *mc_top);
aoqi@1 72 MacroAssembler* masm = new MacroAssembler(&cb);
aoqi@1 73
aoqi@1 74 Label common_code;
aoqi@1 75 for (int i = 0; i < vtbl_list_size; ++i) {
aoqi@1 76 for (int j = 0; j < num_virtuals; ++j) {
aoqi@1 77 dummy_vtable[num_virtuals * i + j] = (void*)masm->pc();
aoqi@1 78
aoqi@1 79 // Load eax with a value indicating vtable/offset pair.
aoqi@1 80 // -- bits[ 7..0] (8 bits) which virtual method in table?
aoqi@1 81 // -- bits[12..8] (5 bits) which virtual method table?
aoqi@1 82 // -- must fit in 13-bit instruction immediate field.
aoqi@1 83 __ move(V0, (i << 8) + j);
aoqi@1 84 __ b(common_code);
aoqi@1 85 __ delayed()->nop();
aoqi@1 86 }
aoqi@1 87 }
aoqi@1 88
aoqi@1 89 __ bind(common_code);
aoqi@1 90
aoqi@1 91 __ srl(T9, V0, 8); // isolate vtable identifier.
aoqi@1 92 __ shl(T9, LogBytesPerWord);
aoqi@1 93 __ li(AT, (long)vtbl_list);
aoqi@1 94 __ add(T9, AT, T9);
aoqi@1 95 __ lw(T9, T9, 0); // get correct vtable address.
aoqi@1 96 __ sw(T9, A0, 0); // update vtable pointer.
aoqi@1 97
aoqi@1 98 __ andi(V0, V0, 0x00ff); // isolate vtable method index
aoqi@1 99 __ shl(V0, LogBytesPerWord);
aoqi@1 100 __ add(T9, T9, V0); // address of real method pointer.
aoqi@1 101 __ jr(T9); // get real method pointer.
aoqi@1 102 __ delayed()->nop();
aoqi@1 103
aoqi@1 104 __ flush();
aoqi@1 105
aoqi@1 106 *mc_top = (char*)__ pc();
aoqi@1 107 }

mercurial