Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/x/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 "x/codegen/ForceRecompilationSnippet.hpp"
24
25
#include "codegen/Relocation.hpp"
26
#include "env/CompilerEnv.hpp"
27
#include "env/IO.hpp"
28
#include "env/OMRMemory.hpp"
29
#include "env/jittypes.h"
30
#include "env/VMJ9.h"
31
#include "il/LabelSymbol.hpp"
32
#include "il/MethodSymbol.hpp"
33
#include "il/Node.hpp"
34
#include "il/Node_inlines.hpp"
35
#include "il/RegisterMappedSymbol.hpp"
36
#include "il/ResolvedMethodSymbol.hpp"
37
#include "il/StaticSymbol.hpp"
38
#include "il/Symbol.hpp"
39
#include "runtime/CodeCacheManager.hpp"
40
#include "x/codegen/X86Recompilation.hpp"
41
42
// TODO: Combine this with TR::X86RecompilationSnippet
43
// TODO: This class should be named TR::X86InduceRecompilationSnippet
44
45
uint8_t *TR::X86ForceRecompilationSnippet::emitSnippetBody()
46
{
47
TR_J9VMBase *fej9 = (TR_J9VMBase *)(cg()->fe());
48
uint8_t *buffer = cg()->getBinaryBufferCursor();
49
getSnippetLabel()->setCodeLocation(buffer);
50
51
TR::SymbolReference *helper = cg()->symRefTab()->findOrCreateRuntimeHelper(cg()->comp()->target().is64Bit()? TR_AMD64induceRecompilation : TR_IA32induceRecompilation);
52
intptr_t helperAddress = (intptr_t)helper->getMethodAddress();
53
*buffer++ = 0xe8; // CallImm4
54
if (NEEDS_TRAMPOLINE(helperAddress, buffer+4, cg()))
55
{
56
helperAddress = TR::CodeCacheManager::instance()->findHelperTrampoline(helper->getReferenceNumber(), (void *)buffer);
57
TR_ASSERT(IS_32BIT_RIP(helperAddress, buffer+4), "Local helper trampoline should be reachable directly.\n");
58
}
59
*(int32_t *)buffer = ((uint8_t*)helperAddress - buffer) - 4;
60
61
cg()->addExternalRelocation(new (cg()->trHeapMemory())
62
TR::ExternalRelocation(
63
buffer,
64
(uint8_t *)helper,
65
TR_HelperAddress, cg()),
66
__FILE__, __LINE__, getNode());
67
68
buffer += 4;
69
70
uint8_t *bufferBase = buffer;
71
72
buffer = genRestartJump(buffer);
73
74
// Offset to the startPC. We don't store the startPC itself, because on
75
// AMD64 that would require 4 more bytes.
76
//
77
*(uint32_t *)buffer = (uint32_t)(cg()->getCodeStart() - bufferBase);
78
buffer += 4;
79
80
return buffer;
81
}
82
83
84
void
85
TR_Debug::print(TR::FILE *pOutFile, TR::X86ForceRecompilationSnippet * snippet)
86
{
87
if (pOutFile == NULL)
88
return;
89
90
uint8_t *bufferPos = snippet->getSnippetLabel()->getCodeLocation();
91
printSnippetLabel(pOutFile, snippet->getSnippetLabel(), bufferPos, getName(snippet));
92
93
TR::SymbolReference *helper = _cg->getSymRef(_comp->target().is64Bit()? TR_AMD64induceRecompilation : TR_IA32induceRecompilation);
94
intptr_t helperAddress = (intptr_t)helper->getMethodAddress();
95
printPrefix(pOutFile, NULL, bufferPos, 5);
96
trfprintf(pOutFile, "call\t%s \t%s Helper Address = " POINTER_PRINTF_FORMAT,
97
getName(helper),
98
commentString(),
99
helperAddress);
100
bufferPos += 5;
101
102
uint8_t *offsetBase = bufferPos;
103
104
printPrefix(pOutFile, NULL, bufferPos, 5);
105
printLabelInstruction(pOutFile, "jmp", snippet->getRestartLabel());
106
bufferPos += 5;
107
108
printPrefix(pOutFile, NULL, bufferPos, 4);
109
trfprintf(pOutFile, "%s \t%s%08x%s\t\t%s Offset to startPC",
110
ddString(),
111
hexPrefixString(),
112
_cg->getCodeStart() - offsetBase,
113
hexSuffixString(),
114
commentString());
115
bufferPos += 4;
116
}
117
118
119
uint32_t TR::X86ForceRecompilationSnippet::getLength(int32_t estimatedSnippetStart)
120
{
121
return 14;
122
}
123
124