0N/A/*
2273N/A * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "assembler_sparc.inline.hpp"
1879N/A#include "memory/compactingPermGenGen.hpp"
1879N/A#include "memory/generation.inline.hpp"
1879N/A#include "memory/space.inline.hpp"
0N/A
0N/A
0N/A
0N/A// Generate the self-patching vtable method:
0N/A//
0N/A// This method will be called (as any other Klass virtual method) with
0N/A// the Klass itself as the first argument. Example:
0N/A//
0N/A// oop obj;
0N/A// int size = obj->klass()->klass_part()->oop_size(this);
0N/A//
0N/A// for which the virtual method call is Klass::oop_size();
0N/A//
0N/A// The dummy method is called with the Klass object as the first
0N/A// operand, and an object as the second argument.
0N/A//
0N/A
0N/A//=====================================================================
0N/A
0N/A// All of the dummy methods in the vtable are essentially identical,
0N/A// differing only by an ordinal constant, and they bear no releationship
0N/A// to the original method which the caller intended. Also, there needs
0N/A// to be 'vtbl_list_size' instances of the vtable in order to
0N/A// differentiate between the 'vtable_list_size' original Klass objects.
0N/A
0N/A#define __ masm->
0N/A
0N/Avoid CompactingPermGenGen::generate_vtable_methods(void** vtbl_list,
0N/A void** vtable,
0N/A char** md_top,
0N/A char* md_end,
0N/A char** mc_top,
0N/A char* mc_end) {
0N/A
0N/A intptr_t vtable_bytes = (num_virtuals * vtbl_list_size) * sizeof(void*);
0N/A *(intptr_t *)(*md_top) = vtable_bytes;
0N/A *md_top += sizeof(intptr_t);
0N/A void** dummy_vtable = (void**)*md_top;
0N/A *vtable = dummy_vtable;
0N/A *md_top += vtable_bytes;
0N/A
0N/A guarantee(*md_top <= md_end, "Insufficient space for vtables.");
0N/A
0N/A // Get ready to generate dummy methods.
0N/A
0N/A CodeBuffer cb((unsigned char*)*mc_top, mc_end - *mc_top);
0N/A MacroAssembler* masm = new MacroAssembler(&cb);
0N/A
0N/A Label common_code;
0N/A for (int i = 0; i < vtbl_list_size; ++i) {
0N/A for (int j = 0; j < num_virtuals; ++j) {
0N/A dummy_vtable[num_virtuals * i + j] = (void*)masm->pc();
0N/A __ save(SP, -256, SP);
2223N/A int offset = (i << 8) + j;
2223N/A Register src = G0;
2223N/A if (!Assembler::is_simm13(offset)) {
2223N/A __ sethi(offset, L0);
2223N/A src = L0;
2223N/A offset = offset & ((1 << 10) - 1);
2223N/A }
0N/A __ brx(Assembler::always, false, Assembler::pt, common_code);
0N/A
0N/A // Load L0 with a value indicating vtable/offset pair.
0N/A // -- bits[ 7..0] (8 bits) which virtual method in table?
2223N/A // -- bits[13..8] (6 bits) which virtual method table?
2223N/A __ delayed()->or3(src, offset, L0);
0N/A }
0N/A }
0N/A
0N/A __ bind(common_code);
0N/A
0N/A // Expecting to be called with the "this" pointer in O0/I0 (where
0N/A // "this" is a Klass object). In addition, L0 was set (above) to
0N/A // identify the method and table.
0N/A
0N/A // Look up the correct vtable pointer.
0N/A
0N/A __ set((intptr_t)vtbl_list, L2); // L2 = address of new vtable list.
0N/A __ srl(L0, 8, L3); // Isolate L3 = vtable identifier.
0N/A __ sll(L3, LogBytesPerWord, L3);
0N/A __ ld_ptr(L2, L3, L3); // L3 = new (correct) vtable pointer.
0N/A __ st_ptr(L3, Address(I0, 0)); // Save correct vtable ptr in entry.
0N/A
0N/A // Restore registers and jump to the correct method;
0N/A
0N/A __ and3(L0, 255, L4); // Isolate L3 = method offset;.
0N/A __ sll(L4, LogBytesPerWord, L4);
0N/A __ ld_ptr(L3, L4, L4); // Get address of correct virtual method
727N/A __ jmpl(L4, 0, G0); // Jump to correct method.
0N/A __ delayed()->restore(); // Restore registers.
0N/A
0N/A __ flush();
0N/A *mc_top = (char*)__ pc();
0N/A
0N/A guarantee(*mc_top <= mc_end, "Insufficient space for method wrappers.");
0N/A}