/* * Copyright (c) 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 "jvmci/jvmciCodeInstaller.hpp" #include "jvmci/jvmciRuntime.hpp" #include "jvmci/jvmciCompilerToVM.hpp" #include "jvmci/jvmciJavaClasses.hpp" #include "oops/oop.inline.hpp" #include "runtime/sharedRuntime.hpp" #include "vmreg_aarch64.inline.hpp" jint CodeInstaller::pd_next_offset(NativeInstruction* inst, jint pc_offset, oop method) { address pc = _instructions->start() + pc_offset; if (inst->is_call() || inst->is_jump()) { assert(NativeCall::instruction_size == (int)NativeJump::instruction_size, "unexpected size"); return pc_offset + NativeCall::instruction_size; } else { // mov+call instruction pair return nativeMovConstReg_at(pc)->next_instruction_address() - pc; } } void CodeInstaller::pd_patch_OopConstant(int pc_offset, Handle& constant) { address pc = _instructions->start() + pc_offset; Handle obj = HotSpotObjectConstantImpl::object(constant); jobject value = JNIHandles::make_local(obj()); MacroAssembler::patch_oop(pc, (address)value); int oop_index = _oop_recorder->find_index(value); _instructions->relocate(pc, oop_Relocation::spec(oop_index)); TRACE_jvmci_3("relocating (oop constant) at " PTR_FORMAT, p2i(pc)); } void CodeInstaller::pd_patch_DataSectionReference(int pc_offset, int data_offset) { Unimplemented(); } void CodeInstaller::pd_relocate_CodeBlob(CodeBlob* cb, NativeInstruction* inst) { if (cb->is_nmethod()) { nmethod* nm = (nmethod*) cb; nativeJump_at((address)inst)->set_jump_destination(nm->verified_entry_point()); } else { nativeJump_at((address)inst)->set_jump_destination(cb->code_begin()); } _instructions->relocate((address)inst, runtime_call_Relocation::spec()); } void CodeInstaller::pd_relocate_ForeignCall(NativeInstruction* inst, jlong foreign_call_destination) { address pc = (address) inst; address dest = (address) foreign_call_destination; assert(inst->is_call(), "should be a call here"); if (inst->is_call()) { address trampoline = nativeCall_at(pc)->get_trampoline(); if (trampoline) { nativeCall_at(pc)->set_destination_mt_safe(dest, /* assert_lock */false); TRACE_jvmci_3("relocating trampoline (foreign call) at " PTR_FORMAT, p2i(inst)); return; } } assert(pc != (address) foreign_call_destination, "call instruction in an infinite loop"); MacroAssembler::pd_patch_instruction(pc, dest); TRACE_jvmci_3("relocating (foreign call) at " PTR_FORMAT, p2i(inst)); } void CodeInstaller::pd_relocate_JavaMethod(oop hotspot_method, jint pc_offset) { #ifdef ASSERT Method* method = NULL; // we need to check, this might also be an unresolved method if (hotspot_method->is_a(HotSpotResolvedJavaMethodImpl::klass())) { method = getMethodFromHotSpotMethod(hotspot_method); } #endif switch (_next_call_type) { case INLINE_INVOKE: break; case INVOKEVIRTUAL: case INVOKEINTERFACE: { assert(method == NULL || !method->is_static(), "cannot call static method with invokeinterface"); NativeCall* call = nativeCall_at(_instructions->start() + pc_offset); call->set_destination(SharedRuntime::get_resolve_virtual_call_stub()); _instructions->relocate(call->instruction_address(), virtual_call_Relocation::spec(_invoke_mark_pc)); break; } case INVOKESTATIC: { assert(method == NULL || method->is_static(), "cannot call non-static method with invokestatic"); NativeCall* call = nativeCall_at(_instructions->start() + pc_offset); call->set_destination(SharedRuntime::get_resolve_static_call_stub()); _instructions->relocate(call->instruction_address(), relocInfo::static_call_type); break; } case INVOKESPECIAL: { assert(method == NULL || !method->is_static(), "cannot call static method with invokespecial"); NativeCall* call = nativeCall_at(_instructions->start() + pc_offset); call->set_destination(SharedRuntime::get_resolve_opt_virtual_call_stub()); _instructions->relocate(call->instruction_address(), relocInfo::opt_virtual_call_type); break; } default: break; } } void CodeInstaller::pd_relocate_poll(address pc, jint mark) { MacroAssembler::pd_patch_instruction_size(pc, os::get_polling_page()); } // convert JVMCI register indices (as used in oop maps) to HotSpot registers VMReg CodeInstaller::get_hotspot_reg(jint jvmci_reg) { if (jvmci_reg < RegisterImpl::number_of_registers) { return as_Register(jvmci_reg)->as_VMReg(); } else { jint floatRegisterNumber = jvmci_reg - RegisterImpl::number_of_registers; if (floatRegisterNumber < FloatRegisterImpl::number_of_registers) { return as_FloatRegister(floatRegisterNumber)->as_VMReg(); } ShouldNotReachHere(); return NULL; } } bool CodeInstaller::is_general_purpose_reg(VMReg hotspotRegister) { return !(hotspotRegister->is_FloatRegister() || hotspotRegister->is_FloatRegister()); }