--- /dev/null 2016-08-24 15:41:39.598575000 -0400 +++ new/src/cpu/arm/vm/metaspaceShared_arm.cpp 2016-12-13 12:52:10.353914485 -0500 @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#include "precompiled.hpp" +#include "asm/macroAssembler.hpp" +#include "assembler_arm.inline.hpp" +#include "memory/metaspaceShared.hpp" + +// Generate the self-patching vtable method: +// +// This method will be called (as any other Klass virtual method) with +// the Klass itself as the first argument. Example: +// +// oop obj; +// int size = obj->klass()->oop_size(this); +// +// for which the virtual method call is Klass::oop_size(); +// +// The dummy method is called with the Klass object as the first +// operand, and an object as the second argument. +// + +//===================================================================== + +// All of the dummy methods in the vtable are essentially identical, +// differing only by an ordinal constant, and they bear no relationship +// to the original method which the caller intended. Also, there needs +// to be 'vtbl_list_size' instances of the vtable in order to +// differentiate between the 'vtable_list_size' original Klass objects. + +#define __ masm-> + +void MetaspaceShared::generate_vtable_methods(void** vtbl_list, + void** vtable, + char** md_top, + char* md_end, + char** mc_top, + char* mc_end) { + intptr_t vtable_bytes = (num_virtuals * vtbl_list_size) * sizeof(void*); + *(intptr_t *)(*md_top) = vtable_bytes; + *md_top += sizeof(intptr_t); + void** dummy_vtable = (void**)*md_top; + *vtable = dummy_vtable; + *md_top += vtable_bytes; + + CodeBuffer cb((unsigned char*)*mc_top, mc_end - *mc_top); + MacroAssembler* masm = new MacroAssembler(&cb); + + for (int i = 0; i < vtbl_list_size; ++i) { + Label common_code; + for (int j = 0; j < num_virtuals; ++j) { + dummy_vtable[num_virtuals * i + j] = (void*) __ pc(); + __ mov(Rtemp, j); // Rtemp contains an index of a virtual method in the table + __ b(common_code); + } + + InlinedAddress vtable_address((address)&vtbl_list[i]); + __ bind(common_code); + const Register tmp2 = AARCH64_ONLY(Rtemp2) NOT_AARCH64(R4); + assert_different_registers(Rtemp, tmp2); +#ifndef AARCH64 + __ push(tmp2); +#endif // !AARCH64 + // Do not use ldr_global since the code must be portable across all ARM architectures + __ ldr_literal(tmp2, vtable_address); + __ ldr(tmp2, Address(tmp2)); // get correct vtable address + __ ldr(Rtemp, Address::indexed_ptr(tmp2, Rtemp)); // get real method pointer + __ str(tmp2, Address(R0)); // update vtable. R0 = "this" +#ifndef AARCH64 + __ pop(tmp2); +#endif // !AARCH64 + __ jump(Rtemp); + __ bind_literal(vtable_address); + } + + __ flush(); + *mc_top = (char*) __ pc(); +}