Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/z/codegen/ReduceSynchronizedFieldLoad.hpp
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 2019 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* 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-exception
21
*******************************************************************************/
22
23
#ifndef REDUCE_SYNCHRONIZED_FIELD_LOAD_NODE
24
#define REDUCE_SYNCHRONIZED_FIELD_LOAD_NODE
25
26
#include "codegen/CodeGenerator.hpp"
27
#include "compile/Compilation.hpp"
28
#include "env/TRMemory.hpp"
29
#include "il/Node.hpp"
30
#include "infra/List.hpp"
31
#include "infra/ILWalk.hpp"
32
33
/** \brief
34
* Reduces synchronized regions around a single field load into a codegen inlined recognized method call which
35
* generates a hardware optimized instruction sequence which is semantically equivalent to the synchronized field
36
* load.
37
*
38
* \details
39
* This codegen phase pass pattern matches the following tree sequences (modulo NOP trees such as aRegLoad):
40
*
41
* \code
42
* monent
43
* object
44
* aloadi / iloadi / i2a
45
* ==> object
46
* monexitfence
47
* monexit
48
* ==> object
49
* \endcode
50
*
51
* And replaces the entire treetop sequence, excluding the monexitfence, with a call to a codegen inlined method
52
* <synchronizedFieldLoad>.
53
*/
54
class ReduceSynchronizedFieldLoad
55
{
56
public:
57
58
TR_ALLOC(TR_Memory::CodeGenerator)
59
60
/** \brief
61
* Initializes the ReduceSynchronizedFieldLoad codegen phase.
62
*
63
* \param cg
64
* The code generator used to generate the instructions.
65
*/
66
ReduceSynchronizedFieldLoad(TR::CodeGenerator* cg)
67
: cg(cg)
68
{
69
// Void
70
}
71
72
/** \brief
73
* Inlines a fast synchronized field load sequence using a load pair disjoint (LPD) instruction.
74
*
75
* \param node
76
* The node which encapsulates the reduced tree sequence via an inlined call node. The node must have the
77
* following shape:
78
*
79
* call <synchronizedFieldLoad>
80
* object
81
* aloadi / iloadi / lloadi
82
* iconst
83
* call jitMonitorEntry
84
* ==>object
85
* call jitMonitorExit
86
* ==>object
87
*
88
* It carries five children:
89
*
90
* 1. The object on which we are synchronizing
91
* 2. The field which we are to load
92
* 3. The offset (in bytes) from the synchronized object to its lock word
93
* 4. The symbol reference of the original monent in the synchronized region
94
* 5. The symbol reference of the original monexit in the synchronized region
95
*
96
* \param cg
97
* The code generator used to generate the instructions.
98
*
99
*/
100
static void inlineSynchronizedFieldLoad(TR::Node* node, TR::CodeGenerator* cg);
101
102
/** \brief
103
* Performs the optimization on this compilation unit.
104
*
105
* \return
106
* true if any transformation was performed; false otherwise.
107
*/
108
bool perform();
109
110
/** \brief
111
* Performs the optimization on this compilation unit.
112
*
113
* \param startTreeTop
114
* The tree top on which to begin looking for opportunities to perform this optimization.
115
*
116
* \param endTreeTop
117
* The tree top on which to end looking for opportunities to perform this optimization.
118
*
119
* \return
120
* true if any transformation was performed; false otherwise.
121
*/
122
bool performOnTreeTops(TR::TreeTop* startTreeTop, TR::TreeTop* endTreeTop);
123
124
private:
125
126
/** \brief
127
* Looks for a load within the monitored region that is a candidate for the reduced synchronized field load
128
* optimization taking into account other operations within the monitored region.
129
*
130
* \param startTreeTop
131
* The start of the extended basic block the monitored region is contained in.
132
*
133
* \param endTreeTop
134
* The end of the extended basic block the monitored region is contained in.
135
*
136
* \param monentTreeTop
137
* The start of the monitored region.
138
*
139
* \param monexitTreeTop
140
* The end of the monitored region.
141
*
142
* \param synchronizedObjectNode
143
* The object on which the monitored region is synchronized on.
144
145
* \return
146
* The candidate load within the monitored region to perform the optimization on; <c>NULL</c> if no candidate
147
* was found.
148
*/
149
TR::Node* findLoadInSynchornizedRegion(TR::TreeTop* startTreeTop, TR::TreeTop* endTreeTop, TR::TreeTop* monentTreeTop, TR::TreeTop* monexitTreeTop, TR::Node* synchronizedObjectNode);
150
151
/** \brief
152
* The cached code generator used to generate the instructions.
153
*/
154
TR::CodeGenerator* cg;
155
};
156
157
#endif
158
159