Path: blob/master/src/hotspot/cpu/x86/icBuffer_x86.cpp
41144 views
/*1* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "asm/macroAssembler.hpp"26#include "asm/macroAssembler.inline.hpp"27#include "code/icBuffer.hpp"28#include "gc/shared/collectedHeap.inline.hpp"29#include "interpreter/bytecodes.hpp"30#include "memory/resourceArea.hpp"31#include "nativeInst_x86.hpp"32#include "oops/oop.inline.hpp"3334int InlineCacheBuffer::ic_stub_code_size() {35// Worst case, if destination is not a near call:36// lea rax, lit137// lea scratch, lit238// jmp scratch3940// Best case41// lea rax, lit142// jmp lit24344int best = NativeMovConstReg::instruction_size + NativeJump::instruction_size;45int worst = 2 * NativeMovConstReg::instruction_size + 3;46return MAX2(best, worst);47}48495051void InlineCacheBuffer::assemble_ic_buffer_code(address code_begin, void* cached_value, address entry_point) {52ResourceMark rm;53CodeBuffer code(code_begin, ic_stub_code_size());54MacroAssembler* masm = new MacroAssembler(&code);55// note: even though the code contains an embedded value, we do not need reloc info56// because57// (1) the value is old (i.e., doesn't matter for scavenges)58// (2) these ICStubs are removed *before* a GC happens, so the roots disappear59// assert(cached_value == NULL || cached_oop->is_perm(), "must be perm oop");60masm->lea(rax, AddressLiteral((address) cached_value, relocInfo::metadata_type));61masm->jump(ExternalAddress(entry_point));62}636465address InlineCacheBuffer::ic_buffer_entry_point(address code_begin) {66NativeMovConstReg* move = nativeMovConstReg_at(code_begin); // creation also verifies the object67address jmp = move->next_instruction_address();68NativeInstruction* ni = nativeInstruction_at(jmp);69if (ni->is_jump()) {70NativeJump* jump = nativeJump_at(jmp);71return jump->jump_destination();72} else {73assert(ni->is_far_jump(), "unexpected instruction");74NativeFarJump* jump = nativeFarJump_at(jmp);75return jump->jump_destination();76}77}787980void* InlineCacheBuffer::ic_buffer_cached_value(address code_begin) {81// creation also verifies the object82NativeMovConstReg* move = nativeMovConstReg_at(code_begin);83// Verifies the jump84address jmp = move->next_instruction_address();85NativeInstruction* ni = nativeInstruction_at(jmp);86if (ni->is_jump()) {87NativeJump* jump = nativeJump_at(jmp);88} else {89assert(ni->is_far_jump(), "unexpected instruction");90NativeFarJump* jump = nativeFarJump_at(jmp);91}92void* o = (void*)move->data();93return o;94}959697