Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/x/codegen/RecompilationSnippet.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/RecompilationSnippet.hpp"
24
25
#include "codegen/CodeGenerator.hpp"
26
#include "codegen/Instruction.hpp"
27
#include "codegen/Relocation.hpp"
28
#include "control/Recompilation.hpp"
29
#include "control/RecompilationInfo.hpp"
30
#include "env/CompilerEnv.hpp"
31
#include "env/IO.hpp"
32
#include "env/jittypes.h"
33
#include "env/VMJ9.h"
34
#include "il/LabelSymbol.hpp"
35
#include "il/MethodSymbol.hpp"
36
#include "il/Node.hpp"
37
#include "il/Node_inlines.hpp"
38
#include "il/RegisterMappedSymbol.hpp"
39
#include "il/ResolvedMethodSymbol.hpp"
40
#include "il/StaticSymbol.hpp"
41
#include "il/Symbol.hpp"
42
#include "runtime/CodeCacheManager.hpp"
43
44
TR::X86RecompilationSnippet::X86RecompilationSnippet(TR::LabelSymbol *lab,
45
TR::Node *node,
46
TR::CodeGenerator *cg)
47
: TR::Snippet(cg, node, lab, true)
48
{
49
setDestination(cg->symRefTab()->findOrCreateRuntimeHelper(cg->comp()->target().is64Bit()? TR_AMD64countingRecompileMethod : TR_IA32countingRecompileMethod));
50
}
51
52
uint32_t TR::X86RecompilationSnippet::getLength(int32_t estimatedSnippetStart)
53
{
54
55
return 9;
56
}
57
void
58
TR_Debug::print(TR::FILE *pOutFile, TR::X86RecompilationSnippet * snippet)
59
{
60
if (pOutFile == NULL)
61
return;
62
63
TR::MethodSymbol *recompileSym = snippet->getDestination()->getSymbol()->castToMethodSymbol();
64
65
uint8_t *bufferPos = snippet->getSnippetLabel()->getCodeLocation();
66
67
printSnippetLabel(pOutFile, snippet->getSnippetLabel(), bufferPos, getName(snippet), getName(snippet->getDestination()));
68
69
printPrefix(pOutFile, NULL, bufferPos, 5);
70
trfprintf(pOutFile, "call\t%s \t\t%s Helper Address = " POINTER_PRINTF_FORMAT,
71
getName(snippet->getDestination()),
72
commentString(),
73
recompileSym->getMethodAddress());
74
bufferPos += 5;
75
76
printPrefix(pOutFile, NULL, bufferPos, 4);
77
trfprintf(pOutFile, "%s \t%s%08x%s\t\t%s Offset to startPC",
78
ddString(),
79
hexPrefixString(),
80
_cg->getCodeStart() - bufferPos,
81
hexSuffixString(),
82
commentString());
83
bufferPos += 4;
84
}
85
86
87
88
uint8_t *TR::X86RecompilationSnippet::emitSnippetBody()
89
{
90
91
uint8_t *buffer = cg()->getBinaryBufferCursor();
92
getSnippetLabel()->setCodeLocation(buffer);
93
94
intptr_t helperAddress = (intptr_t)_destination->getMethodAddress();
95
*buffer++ = 0xe8; // CallImm4
96
if (NEEDS_TRAMPOLINE(helperAddress, buffer+4, cg()))
97
{
98
helperAddress = TR::CodeCacheManager::instance()->findHelperTrampoline(_destination->getReferenceNumber(), (void *)buffer);
99
TR_ASSERT(IS_32BIT_RIP(helperAddress, buffer+4), "Local helper trampoline should be reachable directly.\n");
100
}
101
*(int32_t *)buffer = ((uint8_t*)helperAddress - buffer) - 4;
102
cg()->addExternalRelocation(new (cg()->trHeapMemory()) TR::ExternalRelocation(buffer,
103
(uint8_t *)_destination,
104
TR_HelperAddress, cg()),
105
__FILE__, __LINE__, getNode());
106
buffer += 4;
107
108
uint8_t *bufferBase = buffer;
109
110
// Offset to the start of the method. This is the instruction that must be
111
// patched when the new code is built.
112
//
113
*(uint32_t *)buffer = (uint32_t)(cg()->getCodeStart() - bufferBase);
114
buffer += 4;
115
116
return buffer;
117
}
118
119
120