Path: blob/master/runtime/compiler/x/codegen/CheckFailureSnippet.hpp
6004 views
/*******************************************************************************1* Copyright (c) 2000, 2020 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/2122#ifndef X86CHECKFAILURESNIPPET_INCL23#define X86CHECKFAILURESNIPPET_INCL2425#include "codegen/Snippet.hpp"2627#include <stdint.h>28#include "codegen/Instruction.hpp"29#include "compile/Compilation.hpp"30#include "control/Options.hpp"31#include "il/SymbolReference.hpp"3233namespace TR { class CodeGenerator; }34namespace TR { class LabelSymbol; }35namespace TR { class Symbol; }3637#define TR_BREAKONTHROW_NPE 138#define TR_BREAKONTHROW_AIOB 23940namespace TR {4142class X86CheckFailureSnippet : public TR::Snippet43{44TR::SymbolReference *_destination;45TR::Instruction *_checkInstruction;46bool _requiresFPstackPop;47uint8_t _breakOnThrowType;4849public:5051X86CheckFailureSnippet(52TR::CodeGenerator * cg,53TR::SymbolReference * dest,54TR::LabelSymbol * lab,55TR::Instruction * checkInstruction,56bool popFPstack = false,57uint8_t breakOnThrowType = 0)58: TR::Snippet(cg, checkInstruction->getNode(), lab, dest->canCauseGC()),59_destination(dest),60_checkInstruction(checkInstruction),61_requiresFPstackPop(popFPstack),62_breakOnThrowType(breakOnThrowType)63{64// No registers preserved at this call65//66gcMap().setGCRegisterMask(0);67checkBreakOnThrowOption();68}6970virtual Kind getKind() { return IsCheckFailure; }7172TR::SymbolReference *getDestination() {return _destination;}73TR::SymbolReference *setDestination(TR::SymbolReference *s) {return (_destination = s);}7475TR::Instruction *getCheckInstruction() {return _checkInstruction;}76TR::Instruction *setCheckInstruction(TR::Instruction *ci) {return (_checkInstruction = ci);}7778bool getRequiredFPstackPop() { return _requiresFPstackPop; }7980virtual uint8_t *emitSnippetBody();81uint8_t *emitCheckFailureSnippetBody(uint8_t *buffer);8283virtual uint32_t getLength(int32_t estimatedSnippetStart);84void checkBreakOnThrowOption();8586};878889class X86BoundCheckWithSpineCheckSnippet : public TR::X86CheckFailureSnippet90{91TR::LabelSymbol *_restartLabel;9293public:9495X86BoundCheckWithSpineCheckSnippet(96TR::CodeGenerator *cg,97TR::SymbolReference *bndchkSymRef,98TR::LabelSymbol *snippetLabel,99TR::LabelSymbol *restartLabel,100TR::Instruction *checkInstruction,101bool popFPstack = false) :102TR::X86CheckFailureSnippet(103cg,104bndchkSymRef,105snippetLabel,106checkInstruction,107popFPstack),108_restartLabel(restartLabel)109{110}111112virtual Kind getKind() { return IsBoundCheckWithSpineCheck; }113114virtual uint8_t *emitSnippetBody();115116virtual uint32_t getLength(int32_t estimatedSnippetStart);117118};119120121// This is not the final shape of this snippet. Its just here to122// make everything compile.123//124class X86SpineCheckSnippet : public TR::X86CheckFailureSnippet125{126TR::LabelSymbol *_restartLabel;127128public:129130X86SpineCheckSnippet(131TR::CodeGenerator *cg,132TR::SymbolReference *bndchkSymRef,133TR::LabelSymbol *snippetLabel,134TR::LabelSymbol *restartLabel,135TR::Instruction *checkInstruction,136bool popFPstack = false) :137TR::X86CheckFailureSnippet(138cg,139bndchkSymRef,140snippetLabel,141checkInstruction,142popFPstack),143_restartLabel(restartLabel)144{145}146147virtual Kind getKind() { return IsSpineCheck; }148149virtual uint8_t *emitSnippetBody();150151virtual uint32_t getLength(int32_t estimatedSnippetStart);152153};154155156class X86CheckFailureSnippetWithResolve : public TR::X86CheckFailureSnippet157{158TR::SymbolReference *_dataSymbolReference;159flags8_t _flags;160TR_RuntimeHelper _helper;161uint8_t _numLiveX87FPRs;162163enum164{165hasLiveXMMRs = 0x04166};167168public:169170X86CheckFailureSnippetWithResolve(171TR::CodeGenerator *cg,172TR::SymbolReference *dest,173TR::SymbolReference *dataSymbolRef,174TR_RuntimeHelper resolverCall,175TR::LabelSymbol *snippetLabel,176TR::Instruction *checkInstruction,177bool popFPstack = false) :178TR::X86CheckFailureSnippet(179cg,180dest,181snippetLabel,182checkInstruction),183_dataSymbolReference(dataSymbolRef),184_helper(resolverCall),185_numLiveX87FPRs(0),186_flags(0)187{188}189190virtual Kind getKind() { return IsCheckFailureWithResolve; }191192TR::Symbol *getDataSymbol() {return _dataSymbolReference->getSymbol();}193194TR::SymbolReference *getDataSymbolReference() {return _dataSymbolReference;}195TR::SymbolReference *setDataSymbolReference(TR::SymbolReference *sr) {return (_dataSymbolReference = sr);}196197TR_RuntimeHelper getHelper() { return _helper; }198199virtual uint8_t *emitSnippetBody();200201virtual uint32_t getLength(int32_t estimatedSnippetStart);202203bool getHasLiveXMMRs() {return _flags.testAny(hasLiveXMMRs);}204void setHasLiveXMMRs() {_flags.set(hasLiveXMMRs);}205void resetHasLiveXMMRs() {_flags.reset(hasLiveXMMRs);}206void setHasLiveXMMRs(bool b) {_flags.set(hasLiveXMMRs, b);}207208uint8_t setNumLiveX87Registers(uint8_t l) {return (_numLiveX87FPRs = l);}209uint8_t getNumLiveX87Registers() {return _numLiveX87FPRs;}210211};212213}214215#endif216217218