Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/shark/sharkCacheDecache.cpp
32285 views
/*1* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.2* Copyright 2008, 2009 Red Hat, Inc.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "ci/ciMethod.hpp"27#include "code/debugInfoRec.hpp"28#include "shark/llvmValue.hpp"29#include "shark/sharkBuilder.hpp"30#include "shark/sharkCacheDecache.hpp"31#include "shark/sharkFunction.hpp"32#include "shark/sharkState.hpp"3334using namespace llvm;3536void SharkDecacher::start_frame() {37// Start recording the debug information38_pc_offset = code_buffer()->create_unique_offset();39_oopmap = new OopMap(40oopmap_slot_munge(stack()->oopmap_frame_size()),41oopmap_slot_munge(arg_size()));42debug_info()->add_safepoint(pc_offset(), oopmap());43}4445void SharkDecacher::start_stack(int stack_depth) {46// Create the array we'll record our stack slots in47_exparray = new GrowableArray<ScopeValue*>(stack_depth);4849// Set the stack pointer50stack()->CreateStoreStackPointer(51builder()->CreatePtrToInt(52stack()->slot_addr(53stack()->stack_slots_offset() + max_stack() - stack_depth),54SharkType::intptr_type()));55}5657void SharkDecacher::process_stack_slot(int index,58SharkValue** addr,59int offset) {60SharkValue *value = *addr;6162// Write the value to the frame if necessary63if (stack_slot_needs_write(index, value)) {64write_value_to_frame(65SharkType::to_stackType(value->basic_type()),66value->generic_value(),67adjusted_offset(value, offset));68}6970// Record the value in the oopmap if necessary71if (stack_slot_needs_oopmap(index, value)) {72oopmap()->set_oop(slot2reg(offset));73}7475// Record the value in the debuginfo if necessary76if (stack_slot_needs_debuginfo(index, value)) {77exparray()->append(slot2lv(offset, stack_location_type(index, addr)));78}79}8081void SharkDecacher::start_monitors(int num_monitors) {82// Create the array we'll record our monitors in83_monarray = new GrowableArray<MonitorValue*>(num_monitors);84}8586void SharkDecacher::process_monitor(int index, int box_offset, int obj_offset) {87oopmap()->set_oop(slot2reg(obj_offset));8889monarray()->append(new MonitorValue(90slot2lv (obj_offset, Location::oop),91slot2loc(box_offset, Location::normal)));92}9394void SharkDecacher::process_oop_tmp_slot(Value** value, int offset) {95// Decache the temporary oop slot96if (*value) {97write_value_to_frame(98SharkType::oop_type(),99*value,100offset);101102oopmap()->set_oop(slot2reg(offset));103}104}105106void SharkDecacher::process_method_slot(Value** value, int offset) {107// Decache the method pointer108write_value_to_frame(109SharkType::Method_type(),110*value,111offset);112113}114115void SharkDecacher::process_pc_slot(int offset) {116// Record the PC117builder()->CreateStore(118builder()->code_buffer_address(pc_offset()),119stack()->slot_addr(offset));120}121122void SharkDecacher::start_locals() {123// Create the array we'll record our local variables in124_locarray = new GrowableArray<ScopeValue*>(max_locals());}125126void SharkDecacher::process_local_slot(int index,127SharkValue** addr,128int offset) {129SharkValue *value = *addr;130131// Write the value to the frame if necessary132if (local_slot_needs_write(index, value)) {133write_value_to_frame(134SharkType::to_stackType(value->basic_type()),135value->generic_value(),136adjusted_offset(value, offset));137}138139// Record the value in the oopmap if necessary140if (local_slot_needs_oopmap(index, value)) {141oopmap()->set_oop(slot2reg(offset));142}143144// Record the value in the debuginfo if necessary145if (local_slot_needs_debuginfo(index, value)) {146locarray()->append(slot2lv(offset, local_location_type(index, addr)));147}148}149150void SharkDecacher::end_frame() {151// Record the scope152debug_info()->describe_scope(153pc_offset(),154target(),155bci(),156true,157false,158false,159debug_info()->create_scope_values(locarray()),160debug_info()->create_scope_values(exparray()),161debug_info()->create_monitor_values(monarray()));162163// Finish recording the debug information164debug_info()->end_safepoint(pc_offset());165}166167void SharkCacher::process_stack_slot(int index,168SharkValue** addr,169int offset) {170SharkValue *value = *addr;171172// Read the value from the frame if necessary173if (stack_slot_needs_read(index, value)) {174*addr = SharkValue::create_generic(175value->type(),176read_value_from_frame(177SharkType::to_stackType(value->basic_type()),178adjusted_offset(value, offset)),179value->zero_checked());180}181}182183void SharkOSREntryCacher::process_monitor(int index,184int box_offset,185int obj_offset) {186// Copy the monitor from the OSR buffer to the frame187int src_offset = max_locals() + index * 2;188builder()->CreateStore(189builder()->CreateLoad(190CreateAddressOfOSRBufEntry(src_offset, SharkType::intptr_type())),191stack()->slot_addr(box_offset, SharkType::intptr_type()));192builder()->CreateStore(193builder()->CreateLoad(194CreateAddressOfOSRBufEntry(src_offset + 1, SharkType::oop_type())),195stack()->slot_addr(obj_offset, SharkType::oop_type()));196}197198void SharkCacher::process_oop_tmp_slot(Value** value, int offset) {199// Cache the temporary oop200if (*value)201*value = read_value_from_frame(SharkType::oop_type(), offset);202}203204void SharkCacher::process_method_slot(Value** value, int offset) {205// Cache the method pointer206*value = read_value_from_frame(SharkType::Method_type(), offset);207}208209void SharkFunctionEntryCacher::process_method_slot(Value** value, int offset) {210// "Cache" the method pointer211*value = method();212}213214void SharkCacher::process_local_slot(int index,215SharkValue** addr,216int offset) {217SharkValue *value = *addr;218219// Read the value from the frame if necessary220if (local_slot_needs_read(index, value)) {221*addr = SharkValue::create_generic(222value->type(),223read_value_from_frame(224SharkType::to_stackType(value->basic_type()),225adjusted_offset(value, offset)),226value->zero_checked());227}228}229230Value* SharkOSREntryCacher::CreateAddressOfOSRBufEntry(int offset,231Type* type) {232Value *result = builder()->CreateStructGEP(osr_buf(), offset);233if (type != SharkType::intptr_type())234result = builder()->CreateBitCast(result, PointerType::getUnqual(type));235return result;236}237238void SharkOSREntryCacher::process_local_slot(int index,239SharkValue** addr,240int offset) {241SharkValue *value = *addr;242243// Read the value from the OSR buffer if necessary244if (local_slot_needs_read(index, value)) {245*addr = SharkValue::create_generic(246value->type(),247builder()->CreateLoad(248CreateAddressOfOSRBufEntry(249adjusted_offset(value, max_locals() - 1 - index),250SharkType::to_stackType(value->basic_type()))),251value->zero_checked());252}253}254255void SharkDecacher::write_value_to_frame(Type* type,256Value* value,257int offset) {258builder()->CreateStore(value, stack()->slot_addr(offset, type));259}260261Value* SharkCacher::read_value_from_frame(Type* type, int offset) {262return builder()->CreateLoad(stack()->slot_addr(offset, type));263}264265266