Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/x/codegen/J9Linkage.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 "codegen/Linkage.hpp"
24
#include "codegen/Linkage_inlines.hpp"
25
26
/** \brief
27
* Align stackIndex so that rsp+stackIndex is a multiple of localObjectAlignment
28
*
29
* \param stackIndex
30
* Stack offset to be aligned (negative)
31
*
32
* \return
33
* stackIndex is modified in place.
34
*/
35
void J9::X86::Linkage::alignOffset(uint32_t &stackIndex, int32_t localObjectAlignment)
36
{
37
/* On the entry of a method
38
* RSP = 16*N + sizeOfReturnAddress
39
* The address of a local object needs to be aligned to localObjectAlignment
40
* Thus its offset needs to be aligned to localObjectAlignment*N - sizeOfReturnAddress
41
* i.e. (sizeOfReturnAddress -stackIndex) % localObjectAlignment = 0
42
*
43
* Limitation of current implementation:
44
* Only support alignment of 16-byte or less, if larger alignment is required, rsp has to be
45
* localObjectAlignment*N + sizeOfReturnAddress (on the entry of a method)
46
*/
47
uint32_t sizeOfReturnAddress = self()->getProperties().getRetAddressWidth();
48
// sizeOfReturnAddress-stackIndex is always positive if stackIndex is read as a signed integer
49
uint32_t remainder = (sizeOfReturnAddress - stackIndex) % localObjectAlignment;
50
if (remainder)
51
{
52
// Align stackIndex
53
uint32_t adjust = localObjectAlignment - remainder;
54
stackIndex -= adjust;
55
}
56
}
57
58
/** \brief
59
* Align stackIndex as part of alignment for local object with collected fields
60
*
61
* \param stackIndex
62
* Offset of the first collected references or local objects with collected fields
63
*
64
* \return
65
* stackIndex is modified in place
66
*
67
* \note
68
* Only to be called after stackIndex is calculated in mapStack/mapCompactedStack,
69
* and before the real stack mapping for collected references and local objects with collected fields
70
*/
71
void J9::X86::Linkage::alignLocalObjectWithCollectedFields(uint32_t & stackIndex)
72
{
73
int32_t localObjectAlignment = self()->cg()->fej9()->getLocalObjectAlignmentInBytes();
74
TR::GCStackAtlas *atlas = self()->cg()->getStackAtlas();
75
uint8_t pointerSize = self()->getProperties().getPointerSize();
76
// Note that sizeofReferenceAddress is identical to the size of a stack slot
77
// Both sizeofReferenceAddress and localObjectAlignment are powers of 2,
78
// and it's safe to skip the alignment when sizeofReferenceAddress is a multiple
79
// of localObjectAlignment
80
if (localObjectAlignment <= TR::Compiler->om.sizeofReferenceAddress())
81
return;
82
// Collected local objects have gc indice larger than -1
83
// Offset of a collected local object determined by (stackIndex + pointerSize*(localCursor->getGCMapIndex()-firstLocalGCIndex))
84
// In createStackAtlas, we align pointerSize*(localCursor->getGCMapIndex()-firstLocalGCIndex) by modifying local objects' gc indice
85
// Here we align the stackIndex
86
//
87
traceMsg(self()->comp(),"\nLOCAL OBJECT ALIGNMENT: stack offset before alignment: %d,", stackIndex);
88
// When compaction is enabled, stackIndex is calculated using only collected local refs/objects size,
89
// it doesn't include the size of padding slots added by aligning collected local objects' gc indice
90
// Add them to reflect the correct space needed for collected locals
91
if (self()->cg()->getLocalsIG() && self()->cg()->getSupportsCompactedLocals())
92
{
93
uint8_t pointerSize = self()->getProperties().getPointerSize();
94
stackIndex -= pointerSize*atlas->getNumberOfPaddingSlots();
95
traceMsg(self()->comp()," with padding: %d,", stackIndex);
96
}
97
98
uint32_t stackIndexBeforeAlignment = stackIndex;
99
self()->alignOffset(stackIndex, localObjectAlignment);
100
101
traceMsg(self()->comp()," after alignment: %d\n", stackIndex);
102
103
// Update numberOfSlotsMapped in stackAtlas otherwise there will be mis-match
104
// between the compile-time gc maps and the runtime gc maps
105
//
106
uint32_t adjust = stackIndexBeforeAlignment - stackIndex;
107
int32_t numberOfSlotsMapped = atlas->getNumberOfSlotsMapped();
108
atlas->setNumberOfSlotsMapped(numberOfSlotsMapped + adjust/pointerSize);
109
}
110
111
/** \brief
112
* Align stack offset local object without collected fields
113
*
114
* \param stackIndex
115
* Offset of the local object
116
*
117
* \return
118
* stackIndex is modified in place
119
*/
120
void J9::X86::Linkage::alignLocalObjectWithoutCollectedFields(uint32_t & stackIndex)
121
{
122
int32_t localObjectAlignment = self()->cg()->fej9()->getLocalObjectAlignmentInBytes();
123
// Note that sizeofReferenceAddress is identical to the size of a stack slot
124
// Both sizeofReferenceAddress and localObjectAlignment are powers of 2,
125
// and it's safe to skip the alignment when sizeofReferenceAddress is a multiple
126
// of localObjectAlignment
127
if (localObjectAlignment <= TR::Compiler->om.sizeofReferenceAddress())
128
return;
129
// Align uncollected local object
130
traceMsg(self()->comp(), "\nLOCAL OBJECT ALIGNMENT: stack offset before alignment: %d,", stackIndex);
131
132
self()->alignOffset(stackIndex, localObjectAlignment);
133
134
traceMsg(self()->comp(), " after alignment: %d\n", stackIndex);
135
}
136
137