Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/z/codegen/ForceRecompilationSnippet.cpp
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 2020 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
#include "z/codegen/ForceRecompilationSnippet.hpp"
24
25
#include "codegen/CodeGenerator.hpp"
26
#include "codegen/Relocation.hpp"
27
#include "env/IO.hpp"
28
#include "env/jittypes.h"
29
#include "env/VMJ9.h"
30
#include "il/LabelSymbol.hpp"
31
#include "il/Node.hpp"
32
#include "il/Node_inlines.hpp"
33
#include "runtime/CodeCacheManager.hpp"
34
35
uint8_t *
36
TR::S390ForceRecompilationSnippet::emitSnippetBody()
37
{
38
uint8_t * cursor = cg()->getBinaryBufferCursor();
39
getSnippetLabel()->setCodeLocation(cursor);
40
TR::Compilation *comp = cg()->comp();
41
TR_J9VMBase *fej9 = (TR_J9VMBase *)(comp->fe());
42
43
uint32_t rEP = (uint32_t) cg()->getEntryPointRegister() - 1;
44
TR::SymbolReference * glueRef = cg()->symRefTab()->findOrCreateRuntimeHelper(TR_S390induceRecompilation);
45
46
// Set up the start of data constants and jump to helper.
47
// We generate:
48
// LARL r14, <Start of DC>
49
// BRCL <Helper Addr>
50
51
// LARL - Add Relocation the data constants to this LARL.
52
cg()->addRelocation(new (cg()->trHeapMemory()) TR::LabelRelative32BitRelocation(cursor, getDataConstantSnippet()->getSnippetLabel()));
53
54
*(int16_t *) cursor = 0xC0E0;
55
cursor += sizeof(int16_t);
56
57
// Place holder. Proper offset will be calculated by relocation.
58
*(int32_t *) cursor = 0xDEADBEEF;
59
cursor += sizeof(int32_t);
60
61
// Generate RIOFF if RI is supported.
62
cursor = generateRuntimeInstrumentationOnOffInstruction(cg(), cursor, TR::InstOpCode::RIOFF);
63
64
// BRCL
65
*(int16_t *) cursor = 0xC0F4;
66
cursor += sizeof(int16_t);
67
68
// Calculate the relative offset to get to helper method.
69
// If MCC is not supported, everything should be reachable.
70
// If MCC is supported, we will look up the appropriate trampoline, if
71
// necessary.
72
intptr_t destAddr = (intptr_t)(glueRef->getMethodAddress());
73
74
#if defined(TR_TARGET_64BIT)
75
#if defined(J9ZOS390)
76
if (comp->getOption(TR_EnableRMODE64))
77
#endif
78
{
79
if (NEEDS_TRAMPOLINE(destAddr, cursor, cg()))
80
{
81
// Destination is beyond our reachable jump distance, we'll find the trampoline.
82
destAddr = TR::CodeCacheManager::instance()->findHelperTrampoline(glueRef->getReferenceNumber(), (void *)cursor);
83
this->setUsedTrampoline(true);
84
}
85
}
86
#endif
87
88
TR_ASSERT(CHECK_32BIT_TRAMPOLINE_RANGE(destAddr, cursor), "Helper Call is not reachable.");
89
this->setSnippetDestAddr(destAddr);
90
91
*(int32_t *) cursor = (int32_t)((destAddr - (intptr_t)(cursor - 2)) / 2);
92
93
AOTcgDiag1(comp, "add TR_HelperAddress cursor=%x\n", cursor);
94
cg()->addExternalRelocation(new (cg()->trHeapMemory()) TR::ExternalRelocation(cursor, (uint8_t*) glueRef, TR_HelperAddress, cg()),
95
__FILE__, __LINE__, getNode());
96
97
cursor += sizeof(int32_t);
98
99
return cursor;
100
101
}
102
103
104
uint32_t
105
TR::S390ForceRecompilationSnippet::getLength(int32_t estimatedSnippetStart)
106
{
107
uint32_t length = 12; // LARL + BRCL
108
length += getRuntimeInstrumentationOnOffInstructionLength(cg());
109
return length;
110
}
111
112
113
void
114
TR_Debug::print(TR::FILE *pOutFile, TR::S390ForceRecompilationSnippet * snippet)
115
{
116
uint8_t * bufferPos = snippet->getSnippetLabel()->getCodeLocation();
117
118
printSnippetLabel(pOutFile, snippet->getSnippetLabel(), bufferPos, "Force Recompilation Call Snippet");
119
120
printPrefix(pOutFile, NULL, bufferPos, 6);
121
trfprintf(pOutFile, "LARL \tGPR14, <%p>\t# Addr of DataConst",
122
(intptr_t) snippet->getDataConstantSnippet()->getSnippetLabel()->getCodeLocation());
123
bufferPos += 6;
124
125
bufferPos = printRuntimeInstrumentationOnOffInstruction(pOutFile, bufferPos, false); // RIOFF
126
127
printPrefix(pOutFile, NULL, bufferPos, 6);
128
trfprintf(pOutFile, "BRCL \t<%p>\t\t# Branch to %s %s",
129
snippet->getSnippetDestAddr(),
130
getName(_cg->getSymRef(TR_S390induceRecompilation)),
131
snippet->usedTrampoline()?"- Trampoline Used.":"");
132
bufferPos += 6;
133
}
134
135
TR::S390ForceRecompilationDataSnippet::S390ForceRecompilationDataSnippet(TR::CodeGenerator *cg,
136
TR::Node *node,
137
TR::LabelSymbol *restartLabel):
138
TR::S390ConstantDataSnippet(cg,node,generateLabelSymbol(cg),0),
139
_restartLabel(restartLabel)
140
{
141
}
142
143
uint8_t *
144
TR::S390ForceRecompilationDataSnippet::emitSnippetBody()
145
{
146
TR::Compilation *comp = cg()->comp();
147
uint8_t * cursor = cg()->getBinaryBufferCursor();
148
AOTcgDiag1(comp, "TR::S390ForceRecompilationDataSnippet::emitSnippetBody cursor=%x\n", cursor);
149
getSnippetLabel()->setCodeLocation(cursor);
150
151
/** IMPORTANT **/
152
// If the fields in this snippet are modified, the respective changes must be reflected
153
// in jitrt.dev/s390/Recompilation.m4
154
// RetAddrInForceRecompSnippet and StartPCInForceRecompSnippet vars.
155
156
// Return Address
157
*(intptr_t *) cursor = (intptr_t)getRestartLabel()->getCodeLocation();
158
AOTcgDiag1(comp, "add TR_AbsoluteMethodAddress cursor=%x\n", cursor);
159
cg()->addExternalRelocation(new (cg()->trHeapMemory()) TR::ExternalRelocation(cursor, NULL, TR_AbsoluteMethodAddress, cg()),
160
__FILE__, __LINE__, getNode());
161
cursor += sizeof(intptr_t);
162
163
// Start PC
164
*(intptr_t *) cursor = (intptr_t)cg()->getCodeStart();
165
AOTcgDiag1(comp, "add TR_AbsoluteMethodAddress cursor=%x\n", cursor);
166
cg()->addExternalRelocation(new (cg()->trHeapMemory()) TR::ExternalRelocation(cursor, NULL, TR_AbsoluteMethodAddress, cg()),
167
__FILE__, __LINE__, getNode());
168
cursor += sizeof(intptr_t);
169
170
return cursor;
171
}
172
173
uint32_t
174
TR::S390ForceRecompilationDataSnippet::getLength(int32_t estimatedSnippetStart)
175
{
176
// Data Snippet is only 2 pointers:
177
// Return Address
178
// StartPC
179
return 2 * sizeof(intptr_t);
180
}
181
182
void
183
TR_Debug::print(TR::FILE *pOutFile, TR::S390ForceRecompilationDataSnippet * snippet)
184
{
185
uint8_t * bufferPos = snippet->getSnippetLabel()->getCodeLocation();
186
187
printSnippetLabel(pOutFile, snippet->getSnippetLabel(), bufferPos, "Force Recompilation Data Snippet");
188
printPrefix(pOutFile, NULL, bufferPos, sizeof(intptr_t));
189
trfprintf(pOutFile, "DC \t%p \t\t# Main Code Return Address", *((intptr_t*)bufferPos));
190
bufferPos += sizeof(intptr_t);
191
192
printPrefix(pOutFile, NULL, bufferPos, sizeof(intptr_t));
193
trfprintf(pOutFile, "DC \t%p \t\t# Method Start PC (to patch)", *((intptr_t*)bufferPos));
194
bufferPos += sizeof(intptr_t);
195
}
196
197
198