Skip to content

Commit 08e3ce6

Browse files
committed
[GR-45208] [GR-45232] Properly align VMMutex on Windows.
PullRequest: graal/14190
2 parents 2506086 + 940a538 commit 08e3ce6

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxVMSemaphoreFeature.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ public void beforeCompilation(BeforeCompilationAccess access) {
9999
LinuxVMSemaphore[] semaphores = semaphoreReplacer.getReplacements().toArray(new LinuxVMSemaphore[0]);
100100
int semaphoreSize = NumUtil.roundUp(SizeOf.get(Semaphore.sem_t.class), alignment);
101101
for (LinuxVMSemaphore semaphore : semaphores) {
102-
semaphore.structOffset = WordFactory.unsigned(layout.getArrayElementOffset(JavaKind.Byte, nextIndex));
102+
long offset = layout.getArrayElementOffset(JavaKind.Byte, nextIndex);
103+
assert offset % alignment == 0;
104+
semaphore.structOffset = WordFactory.unsigned(offset);
103105
nextIndex += semaphoreSize;
104106
}
105107

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,18 @@ public void beforeCompilation(BeforeCompilationAccess access) {
123123
PthreadVMMutex[] mutexes = mutexReplacer.getReplacements().toArray(new PthreadVMMutex[0]);
124124
int mutexSize = NumUtil.roundUp(SizeOf.get(Pthread.pthread_mutex_t.class), alignment);
125125
for (PthreadVMMutex mutex : mutexes) {
126-
mutex.structOffset = WordFactory.unsigned(layout.getArrayElementOffset(JavaKind.Byte, nextIndex));
126+
long offset = layout.getArrayElementOffset(JavaKind.Byte, nextIndex);
127+
assert offset % alignment == 0;
128+
mutex.structOffset = WordFactory.unsigned(offset);
127129
nextIndex += mutexSize;
128130
}
129131

130132
PthreadVMCondition[] conditions = conditionReplacer.getReplacements().toArray(new PthreadVMCondition[0]);
131133
int conditionSize = NumUtil.roundUp(SizeOf.get(Pthread.pthread_cond_t.class), alignment);
132134
for (PthreadVMCondition condition : conditions) {
133-
condition.structOffset = WordFactory.unsigned(layout.getArrayElementOffset(JavaKind.Byte, nextIndex));
135+
long offset = layout.getArrayElementOffset(JavaKind.Byte, nextIndex);
136+
assert offset % alignment == 0;
137+
condition.structOffset = WordFactory.unsigned(offset);
134138
nextIndex += conditionSize;
135139
}
136140

substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsVMLockSupport.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,29 @@ public void duringSetup(DuringSetupAccess access) {
103103

104104
@Override
105105
public void beforeCompilation(BeforeCompilationAccess access) {
106+
final int alignment = 8;
107+
106108
ObjectLayout layout = ConfigurationValues.getObjectLayout();
107-
int nextIndex = 0;
109+
final int baseOffset = layout.getArrayBaseOffset(JavaKind.Byte);
110+
111+
// Align the first element to word boundary.
112+
int nextIndex = NumUtil.roundUp(baseOffset, alignment) - baseOffset;
108113

109114
WindowsVMMutex[] mutexes = mutexReplacer.getReplacements().toArray(new WindowsVMMutex[0]);
110-
int mutexSize = NumUtil.roundUp(SizeOf.get(Process.CRITICAL_SECTION.class), 8);
115+
int mutexSize = NumUtil.roundUp(SizeOf.get(Process.CRITICAL_SECTION.class), alignment);
111116
for (WindowsVMMutex mutex : mutexes) {
112-
mutex.structOffset = WordFactory.unsigned(layout.getArrayElementOffset(JavaKind.Byte, nextIndex));
117+
long offset = layout.getArrayElementOffset(JavaKind.Byte, nextIndex);
118+
assert offset % alignment == 0;
119+
mutex.structOffset = WordFactory.unsigned(offset);
113120
nextIndex += mutexSize;
114121
}
115122

116123
WindowsVMCondition[] conditions = conditionReplacer.getReplacements().toArray(new WindowsVMCondition[0]);
117-
int conditionSize = NumUtil.roundUp(SizeOf.get(Process.CONDITION_VARIABLE.class), 8);
124+
int conditionSize = NumUtil.roundUp(SizeOf.get(Process.CONDITION_VARIABLE.class), alignment);
118125
for (WindowsVMCondition condition : conditions) {
119-
condition.structOffset = WordFactory.unsigned(layout.getArrayElementOffset(JavaKind.Byte, nextIndex));
126+
long offset = layout.getArrayElementOffset(JavaKind.Byte, nextIndex);
127+
assert offset % alignment == 0;
128+
condition.structOffset = WordFactory.unsigned(offset);
120129
nextIndex += conditionSize;
121130
}
122131

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateDiagnostics.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,6 @@ public static boolean printFatalError(Log log, Pointer sp, CodePointer ip) {
213213
*/
214214
public static boolean printFatalError(Log log, Pointer sp, CodePointer ip, RegisterDumper.Context registerContext, boolean frameHasCalleeSavedRegisters) {
215215
log.newline();
216-
/*
217-
* Save the state of the initial error so that this state is consistently used, even if
218-
* further errors occur while printing diagnostics.
219-
*/
220-
if (!fatalErrorState().trySet(log, sp, ip, registerContext, frameHasCalleeSavedRegisters) && !isFatalErrorHandlingThread()) {
221-
log.string("Error: printFatalError already in progress by another thread.").newline();
222-
log.newline();
223-
return false;
224-
}
225216

226217
/*
227218
* Execute an endless loop if requested. This makes it easier to attach a debugger lazily.
@@ -232,6 +223,16 @@ public static boolean printFatalError(Log log, Pointer sp, CodePointer ip, Regis
232223
PauseNode.pause();
233224
}
234225

226+
/*
227+
* Save the state of the initial error so that this state is consistently used, even if
228+
* further errors occur while printing diagnostics.
229+
*/
230+
if (!fatalErrorState().trySet(log, sp, ip, registerContext, frameHasCalleeSavedRegisters) && !isFatalErrorHandlingThread()) {
231+
log.string("Error: printFatalError already in progress by another thread.").newline();
232+
log.newline();
233+
return false;
234+
}
235+
235236
printFatalErrorForCurrentState();
236237
return true;
237238
}
@@ -977,9 +978,9 @@ public boolean printLocationInfo(Log log, UnsignedWord value) {
977978
}
978979

979980
if (CodeInfoAccess.contains(imageCodeInfo, (CodePointer) value)) {
981+
log.string("points into AOT compiled code ");
980982
FrameInfoQueryResult compilationRoot = getCompilationRoot(imageCodeInfo, (CodePointer) value);
981983
if (compilationRoot != null) {
982-
log.string("points into AOT compiled code ");
983984
compilationRoot.log(log);
984985
}
985986
return true;

0 commit comments

Comments
 (0)