Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/shark/sharkCacheDecache.hpp
32285 views
/*1* Copyright (c) 1999, 2010, 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#ifndef SHARE_VM_SHARK_SHARKCACHEDECACHE_HPP26#define SHARE_VM_SHARK_SHARKCACHEDECACHE_HPP2728#include "ci/ciMethod.hpp"29#include "code/debugInfoRec.hpp"30#include "shark/sharkBuilder.hpp"31#include "shark/sharkFunction.hpp"32#include "shark/sharkStateScanner.hpp"3334// Class hierarchy:35// - SharkStateScanner36// - SharkCacherDecacher37// - SharkDecacher38// - SharkJavaCallDecacher39// - SharkVMCallDecacher40// - SharkTrapDecacher41// - SharkCacher42// - SharkJavaCallCacher43// - SharkVMCallCacher44// - SharkFunctionEntryCacher45// - SharkNormalEntryCacher46// - SharkOSREntryCacher4748class SharkCacherDecacher : public SharkStateScanner {49protected:50SharkCacherDecacher(SharkFunction* function)51: SharkStateScanner(function) {}5253// Helper54protected:55static int adjusted_offset(SharkValue* value, int offset) {56if (value->is_two_word())57offset--;58return offset;59}60};6162class SharkDecacher : public SharkCacherDecacher {63protected:64SharkDecacher(SharkFunction* function, int bci)65: SharkCacherDecacher(function), _bci(bci) {}6667private:68int _bci;6970protected:71int bci() const {72return _bci;73}7475private:76int _pc_offset;77OopMap* _oopmap;78GrowableArray<ScopeValue*>* _exparray;79GrowableArray<MonitorValue*>* _monarray;80GrowableArray<ScopeValue*>* _locarray;8182private:83int pc_offset() const {84return _pc_offset;85}86OopMap* oopmap() const {87return _oopmap;88}89GrowableArray<ScopeValue*>* exparray() const {90return _exparray;91}92GrowableArray<MonitorValue*>* monarray() const {93return _monarray;94}95GrowableArray<ScopeValue*>* locarray() const {96return _locarray;97}9899// Callbacks100protected:101void start_frame();102103void start_stack(int stack_depth);104void process_stack_slot(int index, SharkValue** value, int offset);105106void start_monitors(int num_monitors);107void process_monitor(int index, int box_offset, int obj_offset);108109void process_oop_tmp_slot(llvm::Value** value, int offset);110void process_method_slot(llvm::Value** value, int offset);111void process_pc_slot(int offset);112113void start_locals();114void process_local_slot(int index, SharkValue** value, int offset);115116void end_frame();117118// oopmap and debuginfo helpers119private:120static int oopmap_slot_munge(int offset) {121return SharkStack::oopmap_slot_munge(offset);122}123static VMReg slot2reg(int offset) {124return SharkStack::slot2reg(offset);125}126static Location slot2loc(int offset, Location::Type type) {127return Location::new_stk_loc(type, offset * wordSize);128}129static LocationValue* slot2lv(int offset, Location::Type type) {130return new LocationValue(slot2loc(offset, type));131}132static Location::Type location_type(SharkValue** addr, bool maybe_two_word) {133// low addresses this end134// Type 32-bit 64-bit135// ----------------------------------------------------136// stack[0] local[3] jobject oop oop137// stack[1] local[2] NULL normal lng138// stack[2] local[1] jlong normal invalid139// stack[3] local[0] jint normal normal140//141// high addresses this end142143SharkValue *value = *addr;144if (value) {145if (value->is_jobject())146return Location::oop;147#ifdef _LP64148if (value->is_two_word())149return Location::invalid;150#endif // _LP64151return Location::normal;152}153else {154if (maybe_two_word) {155value = *(addr - 1);156if (value && value->is_two_word()) {157#ifdef _LP64158if (value->is_jlong())159return Location::lng;160if (value->is_jdouble())161return Location::dbl;162ShouldNotReachHere();163#else164return Location::normal;165#endif // _LP64166}167}168return Location::invalid;169}170}171172// Stack slot helpers173protected:174virtual bool stack_slot_needs_write(int index, SharkValue* value) = 0;175virtual bool stack_slot_needs_oopmap(int index, SharkValue* value) = 0;176virtual bool stack_slot_needs_debuginfo(int index, SharkValue* value) = 0;177178static Location::Type stack_location_type(int index, SharkValue** addr) {179return location_type(addr, *addr == NULL);180}181182// Local slot helpers183protected:184virtual bool local_slot_needs_write(int index, SharkValue* value) = 0;185virtual bool local_slot_needs_oopmap(int index, SharkValue* value) = 0;186virtual bool local_slot_needs_debuginfo(int index, SharkValue* value) = 0;187188static Location::Type local_location_type(int index, SharkValue** addr) {189return location_type(addr, index > 0);190}191192// Writer helper193protected:194void write_value_to_frame(llvm::Type* type,195llvm::Value* value,196int offset);197};198199class SharkJavaCallDecacher : public SharkDecacher {200public:201SharkJavaCallDecacher(SharkFunction* function, int bci, ciMethod* callee)202: SharkDecacher(function, bci), _callee(callee) {}203204private:205ciMethod* _callee;206207protected:208ciMethod* callee() const {209return _callee;210}211212// Stack slot helpers213protected:214bool stack_slot_needs_write(int index, SharkValue* value) {215return value && (index < callee()->arg_size() || value->is_jobject());216}217bool stack_slot_needs_oopmap(int index, SharkValue* value) {218return value && value->is_jobject() && index >= callee()->arg_size();219}220bool stack_slot_needs_debuginfo(int index, SharkValue* value) {221return index >= callee()->arg_size();222}223224// Local slot helpers225protected:226bool local_slot_needs_write(int index, SharkValue* value) {227return value && value->is_jobject();228}229bool local_slot_needs_oopmap(int index, SharkValue* value) {230return value && value->is_jobject();231}232bool local_slot_needs_debuginfo(int index, SharkValue* value) {233return true;234}235};236237class SharkVMCallDecacher : public SharkDecacher {238public:239SharkVMCallDecacher(SharkFunction* function, int bci)240: SharkDecacher(function, bci) {}241242// Stack slot helpers243protected:244bool stack_slot_needs_write(int index, SharkValue* value) {245return value && value->is_jobject();246}247bool stack_slot_needs_oopmap(int index, SharkValue* value) {248return value && value->is_jobject();249}250bool stack_slot_needs_debuginfo(int index, SharkValue* value) {251return true;252}253254// Local slot helpers255protected:256bool local_slot_needs_write(int index, SharkValue* value) {257return value && value->is_jobject();258}259bool local_slot_needs_oopmap(int index, SharkValue* value) {260return value && value->is_jobject();261}262bool local_slot_needs_debuginfo(int index, SharkValue* value) {263return true;264}265};266267class SharkTrapDecacher : public SharkDecacher {268public:269SharkTrapDecacher(SharkFunction* function, int bci)270: SharkDecacher(function, bci) {}271272// Stack slot helpers273protected:274bool stack_slot_needs_write(int index, SharkValue* value) {275return value != NULL;276}277bool stack_slot_needs_oopmap(int index, SharkValue* value) {278return value && value->is_jobject();279}280bool stack_slot_needs_debuginfo(int index, SharkValue* value) {281return true;282}283284// Local slot helpers285protected:286bool local_slot_needs_write(int index, SharkValue* value) {287return value != NULL;288}289bool local_slot_needs_oopmap(int index, SharkValue* value) {290return value && value->is_jobject();291}292bool local_slot_needs_debuginfo(int index, SharkValue* value) {293return true;294}295};296297class SharkCacher : public SharkCacherDecacher {298protected:299SharkCacher(SharkFunction* function)300: SharkCacherDecacher(function) {}301302// Callbacks303protected:304void process_stack_slot(int index, SharkValue** value, int offset);305306void process_oop_tmp_slot(llvm::Value** value, int offset);307virtual void process_method_slot(llvm::Value** value, int offset);308309virtual void process_local_slot(int index, SharkValue** value, int offset);310311// Stack slot helper312protected:313virtual bool stack_slot_needs_read(int index, SharkValue* value) = 0;314315// Local slot helper316protected:317virtual bool local_slot_needs_read(int index, SharkValue* value) {318return value && value->is_jobject();319}320321// Writer helper322protected:323llvm::Value* read_value_from_frame(llvm::Type* type, int offset);324};325326class SharkJavaCallCacher : public SharkCacher {327public:328SharkJavaCallCacher(SharkFunction* function, ciMethod* callee)329: SharkCacher(function), _callee(callee) {}330331private:332ciMethod* _callee;333334protected:335ciMethod* callee() const {336return _callee;337}338339// Stack slot helper340protected:341bool stack_slot_needs_read(int index, SharkValue* value) {342return value && (index < callee()->return_type()->size() ||343value->is_jobject());344}345};346347class SharkVMCallCacher : public SharkCacher {348public:349SharkVMCallCacher(SharkFunction* function)350: SharkCacher(function) {}351352// Stack slot helper353protected:354bool stack_slot_needs_read(int index, SharkValue* value) {355return value && value->is_jobject();356}357};358359class SharkFunctionEntryCacher : public SharkCacher {360public:361SharkFunctionEntryCacher(SharkFunction* function, llvm::Value* method)362: SharkCacher(function), _method(method) {}363364private:365llvm::Value* _method;366367private:368llvm::Value* method() const {369return _method;370}371372// Method slot callback373protected:374void process_method_slot(llvm::Value** value, int offset);375376// Stack slot helper377protected:378bool stack_slot_needs_read(int index, SharkValue* value) {379ShouldNotReachHere(); // entry block shouldn't have stack380}381382// Local slot helper383protected:384bool local_slot_needs_read(int index, SharkValue* value) {385return value != NULL;386}387};388389class SharkNormalEntryCacher : public SharkFunctionEntryCacher {390public:391SharkNormalEntryCacher(SharkFunction* function, llvm::Value* method)392: SharkFunctionEntryCacher(function, method) {}393};394395class SharkOSREntryCacher : public SharkFunctionEntryCacher {396public:397SharkOSREntryCacher(SharkFunction* function,398llvm::Value* method,399llvm::Value* osr_buf)400: SharkFunctionEntryCacher(function, method),401_osr_buf(402builder()->CreateBitCast(403osr_buf,404llvm::PointerType::getUnqual(405llvm::ArrayType::get(406SharkType::intptr_type(),407max_locals() + max_monitors() * 2)))) {}408409private:410llvm::Value* _osr_buf;411412private:413llvm::Value* osr_buf() const {414return _osr_buf;415}416417// Callbacks418protected:419void process_monitor(int index, int box_offset, int obj_offset);420void process_local_slot(int index, SharkValue** value, int offset);421422// Helper423private:424llvm::Value* CreateAddressOfOSRBufEntry(int offset, llvm::Type* type);425};426427#endif // SHARE_VM_SHARK_SHARKCACHEDECACHE_HPP428429430