Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On big endian architecture IntegerType based values are incorrectly decoded #1104

Conversation

matthiasblaesing
Copy link
Member

No description provided.

@matthiasblaesing matthiasblaesing force-pushed the direct-invoke-integer-big-endian branch 2 times, most recently from 8564e24 to 6509b73 Compare June 8, 2019 07:55
@matthiasblaesing
Copy link
Member Author

@nealef @twall could you please have a look at this? This is intended to fix the issue reported as #1103. The core part of the fix is commit 36dfac3:

36dfac3

Does the fix make sense to you? The commits surrounding that fix build issues on the s390x architecture.

@@ -32,31 +32,31 @@
* and result in deterministic behaviour and not in a JVM crash.
*/
public class ArgumentsMarshalNullableTest extends TestCase {
public static class Int32Integer extends IntegerType {
public static class Int16Integer extends IntegerType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to entirely replace the 32-bit tests with 16-bit tests? Unless you have a compelling reason to remove them, the 32-bit tests should remain in place.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this was intentional. Some background: I added the test when I implemented nullable IntegerTypes in the direct invoke path in 1a2a94f. I used the mapped function because they used the fixed size int32_t. Reduzing the size should expose more systems, that show problematic behavior. If sizeof(targettype) >= sizeof(ffi_arg) we will see no problem, so reducing the size of the argument makes it more likely to hit the problematic path. I see no benefit keeping both variants.

@matthiasblaesing matthiasblaesing force-pushed the direct-invoke-integer-big-endian branch from 6509b73 to 64bafab Compare June 22, 2019 10:07
@nealef
Copy link

nealef commented Jun 22, 2019

Do you know why s390x is unable to do the Crash Protection test? Is it something I can help with?

@matthiasblaesing matthiasblaesing force-pushed the direct-invoke-integer-big-endian branch 4 times, most recently from 6221435 to 689273c Compare June 22, 2019 18:32
…ecoded in the direct invocation path

For IntegerType base values, the member number is read by a direct field
read from C. This results in a jlong. If the target site expects a
datatype smaller than a jlong only parts of that value are read. On
little endian architectures the "correct" part of the long value is
read, but on big endian architectures, unused high bytes are read
instead of the required low bytes.

This can be worked around by bitshifting the value by the size
difference between the target type and the real type.
@matthiasblaesing matthiasblaesing force-pushed the direct-invoke-integer-big-endian branch from 689273c to 21da80a Compare June 22, 2019 18:39
@matthiasblaesing
Copy link
Member Author

The crash protection on non-windows systems is not reliable. If I'm asked, I strongly advise not to use the crash protection, as the non-windows systems depend on signal handling and signals are not reliably delivered into the right thread and if I remember correctly I have seen strange behavior with it in place.

For s390x it seems not so much a problem of the architecture, but an implementation detail. I normally use a JVM with hotspot, but on your installation it is OpenJ9 that is used as the VM and it seems J9 handles the signals itself:

    [junit] Testsuite: com.sun.jna.VMCrashProtectionTest
    [junit] Unhandled exception
    [junit] Type=Segmentation error vmState=0x00040000
    [junit] J9Generic_Signal_Number=00000004 Signal_Number=0000000b Error_Value=7823da70 Signal_Code=00000001
    [junit] Handler1=000003FFA37488A8 Handler2=000003FFA3527960 InaccessibleAddress=0000000000000000
    [junit] gpr0=FFFFFFFF00000010 gpr1=0000000000000000 gpr2=0000000000000000 gpr3=0000000000000001
    [junit] gpr4=005F4B629A084CE7 gpr5=005F4B62BA4F2323 gpr6=0000000000000000 gpr7=000003FF8450BA58
    [junit] gpr8=0000000000013728 gpr9=0000000000000000 gpr10=000003FF00000000 gpr11=000003FFA417D4E0
    [junit] gpr12=000003FFA417DE20 gpr13=000003FFA380132C gpr14=000003FF8450BB24 gpr15=000003FFA417D4E0
    [junit] psw=000003FF8450BAA2 mask=0705000180000000 fpc=0008fe00 bea=000003FF8450BB32
    [junit] fpr0 000003ffa372b508 (f: 2742203648,000000, d: 2,172157e-311)
    [junit] fpr1 402ed2eeef6ef9cf (f: 4017027584,000000, d: 1,541198e+01)
    [junit] fpr2 000003ffa417d610 (f: 2753025536,000000, d: 2,172162e-311)
    [junit] fpr3 402ed2eed28a3a33 (f: 3532274176,000000, d: 1,541198e+01)
    [junit] fpr4 0000000000000000 (f: 0,000000, d: 0,000000e+00)
    [junit] fpr5 beb1000000000000 (f: 0,000000, d: -1,013279e-06)
    [junit] fpr6 0000000000000000 (f: 0,000000, d: 0,000000e+00)
    [junit] fpr7 3bbcc86800000000 (f: 0,000000, d: 6,095003e-21)
    [junit] fpr8 0000000000000000 (f: 0,000000, d: 0,000000e+00)
    [junit] fpr9 0000000000000000 (f: 0,000000, d: 0,000000e+00)
    [junit] fpr10 0000000000000000 (f: 0,000000, d: 0,000000e+00)
    [junit] fpr11 0000000000000000 (f: 0,000000, d: 0,000000e+00)
    [junit] fpr12 0000000000000000 (f: 0,000000, d: 0,000000e+00)
    [junit] fpr13 0000000000000000 (f: 0,000000, d: 0,000000e+00)
    [junit] fpr14 0000000000000000 (f: 0,000000, d: 0,000000e+00)
    [junit] fpr15 0000000000000000 (f: 0,000000, d: 0,000000e+00)
    [junit] Module=/home/matthias/.cache/JNA/temp/jna2607712805546693289.tmp
    [junit] Module_base_address=000003FF84500000 Symbol=Java_com_sun_jna_Native_setInt
    [junit] Symbol_address=000003FF8450BA58
    [junit] Target=2_90_20190521_318 (Linux 3.10.0-957.12.2.el7.s390x)
    [junit] CPU=s390x (2 logical CPUs) (0x3ed6dd000 RAM)
    [junit] ----------- Stack Backtrace -----------
    [junit] Java_com_sun_jna_Native_setInt+0x4a (0x000003FF8450BAA2 [jna2607712805546693289.tmp+0xbaa2])
    [junit] (0x000003FFA380132C [libj9vm29.so+0x18132c])
    [junit] (0x000003FFA37FF1A6 [libj9vm29.so+0x17f1a6])
    [junit] (0x000003FFA36B4F3C [libj9vm29.so+0x34f3c])
    [junit] (0x000003FFA369ACD4 [libj9vm29.so+0x1acd4])
    [junit] (0x000003FFA378A42C [libj9vm29.so+0x10a42c])
    [junit] ---------------------------------------
    [junit] JVMDUMP039I Speicherauszugsereignis "gpf", Detail "" um 2019/06/22 15:01:21 - bitte warten.
    [junit] JVMDUMP032I JVM forderte als Antwort auf ein Ereignis einen Speicherauszug von System mit "/home/matthias/jna/core.20190622.150121.27095.0001.dmp" an

At that point, the testsuite stops.

@matthiasblaesing matthiasblaesing merged commit e6ab3ec into java-native-access:master Jun 22, 2019
@nealef
Copy link

nealef commented Jun 22, 2019 via email

@matthiasblaesing
Copy link
Member Author

I don't think this is a bug in J9, in fact the output looks reasonable, it is just a different behavior than Hotspot. Given that signal handling is not part of the platform differences are ok. Raising an exception is a good way in fact to report a segfault.

@matthiasblaesing matthiasblaesing deleted the direct-invoke-integer-big-endian branch August 4, 2019 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants