Path: blob/master/runtime/compiler/z/codegen/ReduceSynchronizedFieldLoad.hpp
6004 views
/*******************************************************************************1* Copyright (c) 2000, 2019 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 REDUCE_SYNCHRONIZED_FIELD_LOAD_NODE23#define REDUCE_SYNCHRONIZED_FIELD_LOAD_NODE2425#include "codegen/CodeGenerator.hpp"26#include "compile/Compilation.hpp"27#include "env/TRMemory.hpp"28#include "il/Node.hpp"29#include "infra/List.hpp"30#include "infra/ILWalk.hpp"3132/** \brief33* Reduces synchronized regions around a single field load into a codegen inlined recognized method call which34* generates a hardware optimized instruction sequence which is semantically equivalent to the synchronized field35* load.36*37* \details38* This codegen phase pass pattern matches the following tree sequences (modulo NOP trees such as aRegLoad):39*40* \code41* monent42* object43* aloadi / iloadi / i2a44* ==> object45* monexitfence46* monexit47* ==> object48* \endcode49*50* And replaces the entire treetop sequence, excluding the monexitfence, with a call to a codegen inlined method51* <synchronizedFieldLoad>.52*/53class ReduceSynchronizedFieldLoad54{55public:5657TR_ALLOC(TR_Memory::CodeGenerator)5859/** \brief60* Initializes the ReduceSynchronizedFieldLoad codegen phase.61*62* \param cg63* The code generator used to generate the instructions.64*/65ReduceSynchronizedFieldLoad(TR::CodeGenerator* cg)66: cg(cg)67{68// Void69}7071/** \brief72* Inlines a fast synchronized field load sequence using a load pair disjoint (LPD) instruction.73*74* \param node75* The node which encapsulates the reduced tree sequence via an inlined call node. The node must have the76* following shape:77*78* call <synchronizedFieldLoad>79* object80* aloadi / iloadi / lloadi81* iconst82* call jitMonitorEntry83* ==>object84* call jitMonitorExit85* ==>object86*87* It carries five children:88*89* 1. The object on which we are synchronizing90* 2. The field which we are to load91* 3. The offset (in bytes) from the synchronized object to its lock word92* 4. The symbol reference of the original monent in the synchronized region93* 5. The symbol reference of the original monexit in the synchronized region94*95* \param cg96* The code generator used to generate the instructions.97*98*/99static void inlineSynchronizedFieldLoad(TR::Node* node, TR::CodeGenerator* cg);100101/** \brief102* Performs the optimization on this compilation unit.103*104* \return105* true if any transformation was performed; false otherwise.106*/107bool perform();108109/** \brief110* Performs the optimization on this compilation unit.111*112* \param startTreeTop113* The tree top on which to begin looking for opportunities to perform this optimization.114*115* \param endTreeTop116* The tree top on which to end looking for opportunities to perform this optimization.117*118* \return119* true if any transformation was performed; false otherwise.120*/121bool performOnTreeTops(TR::TreeTop* startTreeTop, TR::TreeTop* endTreeTop);122123private:124125/** \brief126* Looks for a load within the monitored region that is a candidate for the reduced synchronized field load127* optimization taking into account other operations within the monitored region.128*129* \param startTreeTop130* The start of the extended basic block the monitored region is contained in.131*132* \param endTreeTop133* The end of the extended basic block the monitored region is contained in.134*135* \param monentTreeTop136* The start of the monitored region.137*138* \param monexitTreeTop139* The end of the monitored region.140*141* \param synchronizedObjectNode142* The object on which the monitored region is synchronized on.143144* \return145* The candidate load within the monitored region to perform the optimization on; <c>NULL</c> if no candidate146* was found.147*/148TR::Node* findLoadInSynchornizedRegion(TR::TreeTop* startTreeTop, TR::TreeTop* endTreeTop, TR::TreeTop* monentTreeTop, TR::TreeTop* monexitTreeTop, TR::Node* synchronizedObjectNode);149150/** \brief151* The cached code generator used to generate the instructions.152*/153TR::CodeGenerator* cg;154};155156#endif157158159