JDK-8303549 : [AIX] TestNativeStack.java is failing with exit value 1
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: aix
  • CPU: ppc
  • Submitted: 2023-03-03
  • Updated: 2023-08-08
  • Resolved: 2023-06-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21 JDK 22
21Fixed 22 b04Fixed
Related Reports
Relates :  
Relates :  
Description
Stackoverflow exception has caused an exit value 1 when native thread is attaching as daemon. 

On AIX the default stack size of POSIX thread is 192 KB [https://www.ibm.com/docs/en/aix/7.1?topic=p-pthread-attr-getstacksize-subroutine ]. But in VM's thread creation logic, we set the default thread stack size to 2 MB [ https://github.com/openjdk/jdk/blob/master/src/hotspot/os_cpu/aix_ppc/globals_aix_ppc.hpp#LL33C64-L33C64 ] . So, in the absence of an explicit -Xss value the Java threads have 2M as the default stack size. 
 
This stack size is used by the function CallJavaMainInNewThread() to explicitly set the pthread attribute for stack size: https://github.com/openjdk/jdk/blob/master/src/java.base/unix/native/libjli/java_md.c#L671
 
But on this particular test we are not going through any particular JVM thread creation routines instead we are using a pthread_create() function which is defined in pthread library, hence we are getting 192 KB as default stack size which is default stack size of posix thread on AIX.
 

Log:

stdout: [Triggering a JNI warning
Native thread is running and attaching as daemon ...
];
 stderr: [ Test ERROR. Can't attach current thread: -1 ]
 exitValue = 1

java.lang.RuntimeException: Expected to get exit value of [0], exit value is: [1]`
Comments
A pull request was submitted for review. URL: https://git.openjdk.org/jdk21/pull/155 Date: 2023-08-01 15:56:01 +0000
01-08-2023

Changeset: 5ff42d14 Author: Varada M <mvarada2000@gmail.com> Committer: Tyler Steele <tsteele@openjdk.org> Date: 2023-06-26 14:28:40 +0000 URL: https://git.openjdk.org/jdk/commit/5ff42d14294199eb3bf10b66530f9249fb68810d
26-06-2023

JDK-8219652 lists other tests that likely need the same fix.
31-05-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/14209 Date: 2023-05-30 04:55:36 +0000
30-05-2023

Varada is working on this issue.
10-03-2023

Filed JDK-8303624 for the VM bug.
06-03-2023

Thanks! So there are two issues here: 1. Something is going wrong on AIX and the attempt to execute the Thread constructor throws an exception. 2. There is a bug in the VM doe to the relocation of certain Thread fields to a FieldHolder object as part of Loom - that fieldholder may not be set when we try to access it. I will file a bug for #2 and fix it. In the meantime please run with -Xlog:exceptions and see why AIX is failing this simple code. Thanks.
06-03-2023

It is now available in attachment.
04-03-2023

Okay but I think we need to understand the full reason as to why there is a problem, and exactly how it manifest as reported - a too small stack should trigger StackOverflowError or a crash. The above failure mode suggests we may not be checking for a pending exception somewhere. Can you provide a full hs_err file please?
03-03-2023

Please elaborate on what you think is happening. The pthread_create using the default attributes is obviously not failing (and one would never expect it to!). So what is actually going wrong?
03-03-2023

@dholmes The default stack size on AIX as 196608 bytes. It might require a larger stack size, setting to 1MB solves the problem. She also noted that on AIX the stack size for primordial thread is not defined. It is just ignoring by assert statement -" os_aix.cpp" on line number 405 : guarantee0(!os::is_primordial_thread()); . She further need to investigate ,why default size is not enough for thread to initialise.
03-03-2023