Skip to content

Commit 9914915

Browse files
committed
8262901: [macos_aarch64] NativeCallTest expected:<-3.8194101E18> but was:<3.02668882E10>
8296821: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails after JDK-8262901 Reviewed-by: lucy Backport-of: 6b456f7a9b6344506033dfdc5a59c0f3e95c4b2a
1 parent 2a5daea commit 9914915

File tree

9 files changed

+115
-17
lines changed

9 files changed

+115
-17
lines changed

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/TargetDescription.java

+4
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@
2525
import static jdk.vm.ci.meta.MetaUtil.identityHashCodeString;
2626

2727
import jdk.vm.ci.meta.JavaKind;
28+
import jdk.vm.ci.services.Services;
2829

2930
/**
3031
* Represents the target machine for a compiler, including the CPU architecture, the size of
3132
* pointers and references, alignment of stacks, caches, etc.
3233
*/
3334
public class TargetDescription {
3435

36+
public final boolean linuxOs = Services.getSavedProperty("os.name", "").startsWith("Linux");
37+
public final boolean macOs = Services.getSavedProperty("os.name", "").startsWith("Mac");
38+
3539
public final Architecture arch;
3640

3741
/**

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotJVMCIBackendFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private static RegisterConfig createRegisterConfig(AArch64HotSpotVMConfig config
9393
// ARMv8 defines r18 as being available to the platform ABI. Windows
9494
// and Darwin use it for such. Linux doesn't assign it and thus r18 can
9595
// be used as an additional register.
96-
boolean canUsePlatformRegister = config.linuxOs;
96+
boolean canUsePlatformRegister = target.linuxOs;
9797
return new AArch64HotSpotRegisterConfig(target, config.useCompressedOops, canUsePlatformRegister);
9898
}
9999

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotRegisterConfig.java

+26-3
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,27 @@ public RegisterArray getCallingConventionRegisters(Type type, JavaKind kind) {
228228
}
229229
}
230230

231+
private int parseStackArg(ValueKind<?> valueKind, AllocatableValue[] locations, int index, int currentStackOffset, HotSpotCallingConventionType type) {
232+
int kindSize = valueKind.getPlatformKind().getSizeInBytes();
233+
locations[index] = StackSlot.get(valueKind, currentStackOffset, !type.out);
234+
currentStackOffset += Math.max(kindSize, target.wordSize);
235+
return currentStackOffset;
236+
}
237+
238+
private int parseDarwinNativeStackArg(ValueKind<?> valueKind, AllocatableValue[] locations, int index, int currentStackOffset, HotSpotCallingConventionType type) {
239+
int kindSize = valueKind.getPlatformKind().getSizeInBytes();
240+
if (currentStackOffset % kindSize != 0) {
241+
// In MacOS natural alignment is used
242+
// See https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms
243+
currentStackOffset += kindSize - currentStackOffset % kindSize;
244+
}
245+
locations[index] = StackSlot.get(valueKind, currentStackOffset, !type.out);
246+
// In MacOS "Function arguments may consume slots on the stack that are not multiples of 8 bytes"
247+
// See https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms
248+
currentStackOffset += kindSize;
249+
return currentStackOffset;
250+
}
251+
231252
private CallingConvention callingConvention(RegisterArray generalParameterRegisters, JavaType returnType, JavaType[] parameterTypes, HotSpotCallingConventionType type,
232253
ValueKindFactory<?> valueKindFactory) {
233254
AllocatableValue[] locations = new AllocatableValue[parameterTypes.length];
@@ -264,9 +285,11 @@ private CallingConvention callingConvention(RegisterArray generalParameterRegist
264285
}
265286

266287
if (locations[i] == null) {
267-
ValueKind<?> valueKind = valueKindFactory.getValueKind(kind);
268-
locations[i] = StackSlot.get(valueKind, currentStackOffset, !type.out);
269-
currentStackOffset += Math.max(valueKind.getPlatformKind().getSizeInBytes(), target.wordSize);
288+
if (target.macOs && type == HotSpotCallingConventionType.NativeCall) {
289+
currentStackOffset = parseDarwinNativeStackArg(valueKindFactory.getValueKind(kind), locations, i, currentStackOffset, type);
290+
} else {
291+
currentStackOffset = parseStackArg(valueKindFactory.getValueKind(kind), locations, i, currentStackOffset, type);
292+
}
270293
}
271294
}
272295

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/aarch64/AArch64HotSpotVMConfig.java

-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import jdk.vm.ci.hotspot.HotSpotVMConfigAccess;
2626
import jdk.vm.ci.hotspot.HotSpotVMConfigStore;
27-
import jdk.vm.ci.services.Services;
2827

2928
/**
3029
* Used to access native configuration details.
@@ -37,8 +36,6 @@ class AArch64HotSpotVMConfig extends HotSpotVMConfigAccess {
3736
super(config);
3837
}
3938

40-
final boolean linuxOs = Services.getSavedProperty("os.name", "").startsWith("Linux");
41-
4239
final boolean useCompressedOops = getFlag("UseCompressedOops", Boolean.class);
4340

4441
// CPU Capabilities

test/hotspot/jtreg/ProblemList.txt

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
compiler/ciReplay/TestSAServer.java 8029528 generic-all
4444
compiler/compilercontrol/jcmd/ClearDirectivesFileStackTest.java 8225370 generic-all
4545
compiler/jvmci/compilerToVM/GetFlagValueTest.java 8204459 generic-all
46-
compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java 8262901 macosx-aarch64
4746
compiler/tiered/LevelTransitionTest.java 8067651 generic-all
4847

4948
compiler/cpuflags/TestAESIntrinsicsOnSupportedConfig.java 8190680 generic-all

test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.code.test/libNativeCallTest.c

+33
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,39 @@ JNIEXPORT jfloat JNICALL Java_jdk_vm_ci_code_test_NativeCallTest__1L32SDILDS(JNI
189189
a, b, c, d, e, f);
190190
}
191191

192+
jint JNICALL I32I(jint i00, jint i01, jint i02, jint i03, jint i04, jint i05, jint i06, jint i07,
193+
jint i08, jint i09, jint i0a, jint i0b, jint i0c, jint i0d, jint i0e, jint i0f,
194+
jint i10, jint i11, jint i12, jint i13, jint i14, jint i15, jint i16, jint i17,
195+
jint i18, jint i19, jint i1a, jint i1b, jint i1c, jint i1d, jint i1e, jint i1f,
196+
jint a) {
197+
return i00 + i01 + i02 + i03 + i04 + i05 + i06 + i07 +
198+
i08 + i09 + i0a + i0b + i0c + i0d + i0e + i0f +
199+
i10 + i11 + i12 + i13 + i14 + i15 + i16 + i17 +
200+
i18 + i19 + i1a + i1b + i1c + i1d + i1e + i1f +
201+
a;
202+
}
203+
204+
JNIEXPORT jlong JNICALL Java_jdk_vm_ci_code_test_NativeCallTest_getI32I(JNIEnv *env, jclass clazz) {
205+
return (jlong) (intptr_t) I32I;
206+
}
207+
208+
JNIEXPORT jint JNICALL Java_jdk_vm_ci_code_test_NativeCallTest__1I32I(JNIEnv *env, jclass clazz,
209+
jint i00, jint i01, jint i02, jint i03,
210+
jint i04, jint i05, jint i06, jint i07,
211+
jint i08, jint i09, jint i0a, jint i0b,
212+
jint i0c, jint i0d, jint i0e, jint i0f,
213+
jint i10, jint i11, jint i12, jint i13,
214+
jint i14, jint i15, jint i16, jint i17,
215+
jint i18, jint i19, jint i1a, jint i1b,
216+
jint i1c, jint i1d, jint i1e, jint i1f,
217+
jint a) {
218+
return I32I(i00, i01, i02, i03, i04, i05, i06, i07,
219+
i08, i09, i0a, i0b, i0c, i0d, i0e, i0f,
220+
i10, i11, i12, i13, i14, i15, i16, i17,
221+
i18, i19, i1a, i1b, i1c, i1d, i1e, i1f,
222+
a);
223+
}
224+
192225
#ifdef __cplusplus
193226
}
194227
#endif

test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java

+47-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,26 @@ public void testI32SDILDS() {
125125
test("I32SDILDS", getI32SDILDS(), float.class, argClazz, argValues);
126126
}
127127

128+
@Test
129+
public void testI32I() {
130+
int sCount = 32;
131+
// Pairs of <Object>, <Class>
132+
Object[] remainingArgs = new Object[]{
133+
12, int.class
134+
};
135+
Class<?>[] argClazz = new Class[sCount + remainingArgs.length / 2];
136+
Object[] argValues = new Object[sCount + remainingArgs.length / 2];
137+
for (int i = 0; i < sCount; i++) {
138+
argValues[i] = i;
139+
argClazz[i] = int.class;
140+
}
141+
for (int i = 0; i < remainingArgs.length; i += 2) {
142+
argValues[sCount + i / 2] = remainingArgs[i + 0];
143+
argClazz[sCount + i / 2] = (Class<?>) remainingArgs[i + 1];
144+
}
145+
test("I32I", getI32I(), int.class, argClazz, argValues);
146+
}
147+
128148
public void test(String name, long addr, Class<?> returnClazz, Class<?>[] types, Object[] values) {
129149
try {
130150
test(asm -> {
@@ -138,7 +158,13 @@ public void test(String name, long addr, Class<?> returnClazz, Class<?>[] types,
138158
asm.emitCallPrologue(cc, values);
139159
asm.emitCall(addr);
140160
asm.emitCallEpilogue(cc);
141-
asm.emitFloatRet(((RegisterValue) cc.getReturn()).getRegister());
161+
if (returnClazz == float.class) {
162+
asm.emitFloatRet(((RegisterValue) cc.getReturn()).getRegister());
163+
} else if (returnClazz == int.class) {
164+
asm.emitIntRet(((RegisterValue) cc.getReturn()).getRegister());
165+
} else {
166+
assert false : "Unimplemented return type: " + returnClazz;
167+
}
142168
}, getMethod(name, types), values);
143169
} catch (Throwable e) {
144170
e.printStackTrace();
@@ -244,4 +270,24 @@ public static float L32SDILDS(long l00, long l01, long l02, long l03, long l04,
244270
l18, l19, l1a, l1b, l1c, l1d, l1e, l1f,
245271
a, b, c, d, e, f);
246272
}
273+
274+
public static native long getI32I();
275+
276+
public static native int _I32I(int i00, int i01, int i02, int i03, int i04, int i05, int i06, int i07,
277+
int i08, int i09, int i0a, int i0b, int i0c, int i0d, int i0e, int i0f,
278+
int i10, int i11, int i12, int i13, int i14, int i15, int i16, int i17,
279+
int i18, int i19, int i1a, int i1b, int i1c, int i1d, int i1e, int i1f,
280+
int a);
281+
282+
public static int I32I(int i00, int i01, int i02, int i03, int i04, int i05, int i06, int i07,
283+
int i08, int i09, int i0a, int i0b, int i0c, int i0d, int i0e, int i0f,
284+
int i10, int i11, int i12, int i13, int i14, int i15, int i16, int i17,
285+
int i18, int i19, int i1a, int i1b, int i1c, int i1d, int i1e, int i1f,
286+
int a) {
287+
return _I32I(i00, i01, i02, i03, i04, i05, i06, i07,
288+
i08, i09, i0a, i0b, i0c, i0d, i0e, i0f,
289+
i10, i11, i12, i13, i14, i15, i16, i17,
290+
i18, i19, i1a, i1b, i1c, i1d, i1e, i1f,
291+
a);
292+
}
247293
}

test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/aarch64/AArch64TestAssembler.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ public void emitEpilogue() {
269269

270270
@Override
271271
public void emitCallPrologue(CallingConvention cc, Object... prim) {
272-
emitGrowStack(cc.getStackSize());
273-
frameSize += cc.getStackSize();
272+
growFrame(cc.getStackSize());
274273
AllocatableValue[] args = cc.getArguments();
275274
for (int i = 0; i < args.length; i++) {
276275
emitLoad(args[i], prim[i]);
@@ -279,8 +278,7 @@ public void emitCallPrologue(CallingConvention cc, Object... prim) {
279278

280279
@Override
281280
public void emitCallEpilogue(CallingConvention cc) {
282-
emitGrowStack(-cc.getStackSize());
283-
frameSize -= cc.getStackSize();
281+
growFrame(-cc.getStackSize());
284282
}
285283

286284
@Override

test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/amd64/AMD64TestAssembler.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,7 @@ public void emitLoad(AllocatableValue av, Object prim) {
403403

404404
@Override
405405
public void emitCallPrologue(CallingConvention cc, Object... prim) {
406-
emitGrowStack(cc.getStackSize());
407-
frameSize += cc.getStackSize();
406+
growFrame(cc.getStackSize());
408407
AllocatableValue[] args = cc.getArguments();
409408
// Do the emission in reverse, this avoids register collisons of xmm0 - which is used a
410409
// scratch register when putting arguments on the stack.
@@ -427,7 +426,6 @@ public void emitCall(long addr) {
427426

428427
@Override
429428
public void emitCallEpilogue(CallingConvention cc) {
430-
emitGrowStack(-cc.getStackSize());
431-
frameSize -= cc.getStackSize();
429+
growFrame(-cc.getStackSize());
432430
}
433431
}

0 commit comments

Comments
 (0)