Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/x/codegen/CallSnippet.hpp
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 2022 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
#ifndef X86CALLSNIPPET_INCL
24
#define X86CALLSNIPPET_INCL
25
26
#include "codegen/Snippet.hpp"
27
#include "codegen/UnresolvedDataSnippet.hpp"
28
29
namespace TR { class CodeGenerator; }
30
namespace TR { class Instruction; }
31
namespace TR { class LabelSymbol; }
32
namespace TR { class MethodSymbol; }
33
namespace TR { class SymbolReference; }
34
35
namespace TR {
36
37
class X86PicDataSnippet : public TR::Snippet
38
{
39
TR::SymbolReference *_methodSymRef;
40
TR::SymbolReference *_dispatchSymRef;
41
TR::Instruction *_slotPatchInstruction;
42
TR::Instruction *_startOfPicInstruction;
43
TR::LabelSymbol *_doneLabel;
44
uint8_t *_thunkAddress;
45
int32_t _numberOfSlots;
46
bool _isInterface;
47
bool _hasJ2IThunkInPicData;
48
49
public:
50
51
X86PicDataSnippet(
52
int32_t numberOfSlots,
53
TR::Instruction *startOfPicInstruction,
54
TR::LabelSymbol *snippetLabel,
55
TR::LabelSymbol *doneLabel,
56
TR::SymbolReference *methodSymRef,
57
TR::Instruction *slotPatchInstruction,
58
uint8_t *thunkAddress,
59
bool isInterface,
60
TR::CodeGenerator *cg) :
61
TR::Snippet(cg, NULL, snippetLabel, true),
62
_numberOfSlots(numberOfSlots),
63
_startOfPicInstruction(startOfPicInstruction),
64
_methodSymRef(methodSymRef),
65
_doneLabel(doneLabel),
66
_slotPatchInstruction(slotPatchInstruction),
67
_isInterface(isInterface),
68
_dispatchSymRef(NULL),
69
_thunkAddress(thunkAddress),
70
_hasJ2IThunkInPicData(shouldEmitJ2IThunkPointer())
71
{}
72
73
bool isInterface() {return _isInterface;}
74
int32_t getNumberOfSlots() {return _numberOfSlots;}
75
bool hasJ2IThunkInPicData() {return _hasJ2IThunkInPicData;}
76
77
TR::SymbolReference *getDispatchSymRef() {return _dispatchSymRef;}
78
TR::SymbolReference *getMethodSymRef() {return _methodSymRef;}
79
80
TR::LabelSymbol *getDoneLabel() {return _doneLabel;}
81
82
bool forceUnresolvedDispatch()
83
{
84
// No need to force unresolved dispatch for interface calls, since those
85
// are unresolved anyway.
86
return !isInterface()
87
&& !((TR_J9VMBase*)(cg()->fe()))->isResolvedVirtualDispatchGuaranteed(cg()->comp());
88
}
89
90
bool unresolvedDispatch()
91
{
92
return _methodSymRef->isUnresolved() || forceUnresolvedDispatch();
93
}
94
95
uint8_t *encodeConstantPoolInfo(uint8_t *cursor);
96
uint8_t *encodeJ2IThunkPointer(uint8_t *cursor);
97
98
virtual Kind getKind() { return (_isInterface ? IsIPicData : IsVPicData); }
99
100
virtual uint8_t *emitSnippetBody();
101
102
virtual uint32_t getLength(int32_t estimatedSnippetStart);
103
104
private:
105
bool shouldEmitJ2IThunkPointer();
106
};
107
108
class X86CallSnippet : public TR::Snippet
109
{
110
public:
111
112
X86CallSnippet(TR::CodeGenerator *cg, TR::Node * n, TR::LabelSymbol * lab, bool isGCSafePoint)
113
: TR::Snippet(cg, n, lab, isGCSafePoint)
114
{
115
_realMethodSymbolReference = NULL;
116
}
117
118
X86CallSnippet(TR::CodeGenerator *cg, TR::Node * n, TR::LabelSymbol * lab, TR::SymbolReference* realSymRef, bool isGCSafePoint)
119
: TR::Snippet(cg, n, lab, isGCSafePoint)
120
{
121
_realMethodSymbolReference = realSymRef;
122
}
123
124
virtual Kind getKind() { return IsCall; }
125
126
virtual uint8_t *emitSnippetBody();
127
128
virtual uint32_t getLength(int32_t estimatedSnippetStart);
129
130
TR::SymbolReference *getRealMethodSymbolReference() { return _realMethodSymbolReference; }
131
132
private:
133
134
uint8_t * alignCursorForCodePatching(uint8_t *cursor, bool alignWithNOPs=false);
135
136
TR::SymbolReference * _realMethodSymbolReference;
137
};
138
139
}
140
141
#endif
142
143