Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/x/codegen/J9LinkageUtils.cpp
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 2021 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 "codegen/Linkage_inlines.hpp"
24
#include "codegen/RealRegister.hpp"
25
#include "codegen/Register.hpp"
26
#include "codegen/CodeGenerator.hpp"
27
#include "il/LabelSymbol.hpp"
28
#include "il/MethodSymbol.hpp"
29
#include "il/Node.hpp"
30
#include "il/Node_inlines.hpp"
31
#include "il/RegisterMappedSymbol.hpp"
32
#include "il/ResolvedMethodSymbol.hpp"
33
#include "il/StaticSymbol.hpp"
34
#include "il/Symbol.hpp"
35
#include "codegen/X86Instruction.hpp"
36
#include "x/codegen/J9LinkageUtils.hpp"
37
#include "env/VMJ9.h"
38
#include "codegen/Machine.hpp"
39
#include "x/codegen/IA32LinkageUtils.hpp"
40
#include "compile/ResolvedMethod.hpp"
41
#include "env/CompilerEnv.hpp"
42
#include "env/VMJ9.h"
43
44
namespace TR
45
{
46
47
// can be commoned
48
void J9LinkageUtils::cleanupReturnValue(
49
TR::Node *callNode,
50
TR::Register *linkageReturnReg,
51
TR::Register *targetReg,
52
TR::CodeGenerator *cg)
53
{
54
if (!callNode->getOpCode().isFloatingPoint())
55
{
56
// Native and JNI methods may not return a full register in some cases so we need to get the declared
57
// type so that we sign and zero extend the narrower integer return types properly.
58
//
59
TR::InstOpCode::Mnemonic op;
60
TR::ResolvedMethodSymbol *callSymbol = callNode->getSymbol()->castToResolvedMethodSymbol();
61
TR_ResolvedMethod *resolvedMethod = callSymbol->getResolvedMethod();
62
TR::Compilation *comp = cg->comp();
63
64
bool isUnsigned = resolvedMethod->returnTypeIsUnsigned();
65
switch (resolvedMethod->returnType())
66
{
67
case TR::Int8:
68
if (isUnsigned)
69
{
70
op = comp->target().is64Bit() ? TR::InstOpCode::MOVZXReg8Reg1 : TR::InstOpCode::MOVZXReg4Reg1;
71
}
72
else
73
{
74
op = comp->target().is64Bit() ? TR::InstOpCode::MOVSXReg8Reg1 : TR::InstOpCode::MOVSXReg4Reg1;
75
}
76
break;
77
case TR::Int16:
78
if (isUnsigned)
79
{
80
op = comp->target().is64Bit() ? TR::InstOpCode::MOVZXReg8Reg2 : TR::InstOpCode::MOVZXReg4Reg2;
81
}
82
else
83
{
84
op = comp->target().is64Bit() ? TR::InstOpCode::MOVSXReg8Reg2 : TR::InstOpCode::MOVSXReg4Reg2;
85
}
86
break;
87
default:
88
// TR::Address, TR_[US]Int64, TR_[US]Int32
89
//
90
op = (linkageReturnReg != targetReg) ? TR::InstOpCode::MOVRegReg() : TR::InstOpCode::bad;
91
break;
92
}
93
94
if (op != TR::InstOpCode::bad)
95
generateRegRegInstruction(op, callNode, targetReg, linkageReturnReg, cg);
96
}
97
}
98
99
void J9LinkageUtils::switchToMachineCStack(TR::Node *callNode, TR::CodeGenerator *cg)
100
{
101
TR_J9VMBase *fej9 = (TR_J9VMBase *)(cg->fe());
102
TR::RealRegister *espReal = cg->machine()->getRealRegister(TR::RealRegister::esp);
103
TR::Register *vmThreadReg = cg->getMethodMetaDataRegister();
104
105
// Squirrel Java SP away into VM thread.
106
//
107
generateMemRegInstruction(TR::InstOpCode::SMemReg(),
108
callNode,
109
generateX86MemoryReference(vmThreadReg, fej9->thisThreadGetJavaSPOffset(), cg),
110
espReal,
111
cg);
112
113
// Load machine SP from VM thread.
114
//
115
generateRegMemInstruction(TR::InstOpCode::LRegMem(),
116
callNode,
117
espReal,
118
generateX86MemoryReference(vmThreadReg, fej9->thisThreadGetMachineSPOffset(), cg),
119
cg);
120
}
121
122
void J9LinkageUtils::switchToJavaStack(TR::Node *callNode, TR::CodeGenerator *cg)
123
{
124
TR_J9VMBase *fej9 = (TR_J9VMBase *)(cg->fe());
125
TR::RealRegister *espReal = cg->machine()->getRealRegister(TR::RealRegister::esp);
126
TR::Register *vmThreadReg = cg->getMethodMetaDataRegister();
127
128
// Load up the java sp so we have the callout frame on top of the java stack.
129
//
130
generateRegMemInstruction(
131
TR::InstOpCode::LRegMem(),
132
callNode,
133
espReal,
134
generateX86MemoryReference(vmThreadReg, cg->fej9()->thisThreadGetJavaSPOffset(), cg),
135
cg);
136
137
// Add DF check on return of JNI/System call
138
if (cg->canEmitBreakOnDFSet())
139
generateBreakOnDFSet(cg);
140
}
141
142
}
143
144