Skip to content

Commit 9e79f06

Browse files
committed
[GR-36549] Pthread support: Make sure pthread datastructures are stored at object aligned addresses
PullRequest: graal/10908
2 parents 891b7bf + 70e5969 commit 9e79f06

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/pthread/PthreadVMLockSupport.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,21 @@ public void duringSetup(DuringSetupAccess access) {
9696
@Override
9797
public void beforeCompilation(BeforeCompilationAccess access) {
9898
ObjectLayout layout = ConfigurationValues.getObjectLayout();
99-
int nextIndex = 0;
99+
int alignment = layout.getAlignment();
100+
101+
int baseOffset = layout.getArrayBaseOffset(JavaKind.Byte);
102+
/* padding if first element is not object aligned */
103+
int nextIndex = NumUtil.roundUp(baseOffset, alignment) - baseOffset;
100104

101105
PthreadVMMutex[] mutexes = mutexReplacer.getReplacements().toArray(new PthreadVMMutex[0]);
102-
int mutexSize = NumUtil.roundUp(SizeOf.get(Pthread.pthread_mutex_t.class), 8);
106+
int mutexSize = NumUtil.roundUp(SizeOf.get(Pthread.pthread_mutex_t.class), alignment);
103107
for (PthreadVMMutex mutex : mutexes) {
104108
mutex.structOffset = WordFactory.unsigned(layout.getArrayElementOffset(JavaKind.Byte, nextIndex));
105109
nextIndex += mutexSize;
106110
}
107111

108112
PthreadVMCondition[] conditions = conditionReplacer.getReplacements().toArray(new PthreadVMCondition[0]);
109-
int conditionSize = NumUtil.roundUp(SizeOf.get(Pthread.pthread_cond_t.class), 8);
113+
int conditionSize = NumUtil.roundUp(SizeOf.get(Pthread.pthread_cond_t.class), alignment);
110114
for (PthreadVMCondition condition : conditions) {
111115
condition.structOffset = WordFactory.unsigned(layout.getArrayElementOffset(JavaKind.Byte, nextIndex));
112116
nextIndex += conditionSize;

0 commit comments

Comments
 (0)