Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/p/codegen/PPCRecompilationSnippet.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 "p/codegen/PPCRecompilationSnippet.hpp"
24
25
#include <stdint.h>
26
#include "codegen/CodeGenerator.hpp"
27
#include "codegen/Machine.hpp"
28
#include "codegen/Relocation.hpp"
29
#include "env/CompilerEnv.hpp"
30
#include "env/IO.hpp"
31
#include "env/jittypes.h"
32
#include "env/VMJ9.h"
33
#include "il/LabelSymbol.hpp"
34
#include "il/MethodSymbol.hpp"
35
#include "il/Node.hpp"
36
#include "il/Node_inlines.hpp"
37
#include "il/RegisterMappedSymbol.hpp"
38
#include "il/ResolvedMethodSymbol.hpp"
39
#include "il/StaticSymbol.hpp"
40
#include "il/Symbol.hpp"
41
#include "p/codegen/PPCInstruction.hpp"
42
#include "p/codegen/PPCRecompilation.hpp"
43
#include "runtime/CodeCacheManager.hpp"
44
45
uint8_t *TR::PPCRecompilationSnippet::emitSnippetBody()
46
{
47
uint8_t *buffer = cg()->getBinaryBufferCursor();
48
TR::Compilation *comp = cg()->comp();
49
TR::SymbolReference *countingRecompMethodSymRef = cg()->symRefTab()->findOrCreateRuntimeHelper(TR_PPCcountingRecompileMethod);
50
bool longPrologue = getBranchToSnippet()->getFarRelocation();
51
52
getSnippetLabel()->setCodeLocation(buffer);
53
54
intptr_t helperAddress = (intptr_t)countingRecompMethodSymRef->getMethodAddress();
55
if (cg()->directCallRequiresTrampoline(helperAddress, (intptr_t)buffer))
56
{
57
helperAddress = TR::CodeCacheManager::instance()->findHelperTrampoline(countingRecompMethodSymRef->getReferenceNumber(), (void *)buffer);
58
TR_ASSERT_FATAL(comp->target().cpu.isTargetWithinIFormBranchRange(helperAddress, (intptr_t)buffer), "Helper address is out of range");
59
}
60
61
// bl distance
62
*(int32_t *)buffer = 0x48000001 | ((helperAddress - (intptr_t)buffer) & 0x03ffffff);
63
cg()->addExternalRelocation(new (cg()->trHeapMemory()) TR::ExternalRelocation(buffer,(uint8_t *)countingRecompMethodSymRef,TR_HelperAddress, cg()),
64
__FILE__,
65
__LINE__,
66
getNode());
67
68
buffer += 4;
69
70
// bodyinfo
71
uintptr_t valueBits = (uintptr_t)comp->getRecompilationInfo()->getJittedBodyInfo();
72
*(uintptr_t *)buffer = valueBits;
73
74
buffer += sizeof(uintptr_t);
75
76
// startPC
77
valueBits = (uintptr_t)cg()->getCodeStart() | (longPrologue?1:0);
78
*(uintptr_t *)buffer = valueBits;
79
80
return buffer + sizeof(uintptr_t);
81
}
82
83
84
void
85
TR_Debug::print(TR::FILE *pOutFile, TR::PPCRecompilationSnippet * snippet)
86
{
87
uint8_t *cursor = snippet->getSnippetLabel()->getCodeLocation();
88
89
printSnippetLabel(pOutFile, snippet->getSnippetLabel(), cursor, "Counting Recompilation Snippet");
90
91
char *info = "";
92
int32_t distance;
93
if (isBranchToTrampoline(_cg->getSymRef(TR_PPCcountingRecompileMethod), cursor, distance))
94
info = " Through trampoline";
95
96
printPrefix(pOutFile, NULL, cursor, 4);
97
distance = *((int32_t *) cursor) & 0x03fffffc;
98
distance = (distance << 6) >> 6; // sign extend
99
trfprintf(pOutFile, "bl \t" POINTER_PRINTF_FORMAT "\t\t;%s", (intptr_t)cursor + distance, info);
100
cursor += 4;
101
102
// methodInfo
103
printPrefix(pOutFile, NULL, cursor, 4);
104
trfprintf(pOutFile, ".long \t0x%08x\t\t;%s", _comp->getRecompilationInfo()->getMethodInfo(), "methodInfo");
105
cursor += 4;
106
107
// startPC
108
printPrefix(pOutFile, NULL, cursor, 4);
109
trfprintf(pOutFile, ".long \t0x%08x\t\t; startPC | longPrologue", _cg->getCodeStart());
110
}
111
112
113
uint32_t TR::PPCRecompilationSnippet::getLength(int32_t estimatedSnippetStart)
114
{
115
return(cg()->comp()->target().is64Bit()? 20 : 12);
116
}
117
118