JDK-8263567 : gtests don't terminate the VM safely
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 11,17
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-03-15
  • Updated: 2022-01-15
  • Resolved: 2021-08-09
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 17 JDK 18
17.0.3-oracleFixed 18 b10Fixed
Related Reports
Relates :  
Relates :  
Description
When a non-asserting gtest loads and initializes the JVM via JNI_CreateJavaVM, there is no corresponding clean shutdown via JNI_DestroyJavaVM. Instead the gtest wrapper macros just call ::exit to terminate the process. This can lead to problems if the atexit actions (including global destructors) trigger failures in concurrently executing threads in the JVM. A clean JVM exit will brings the system to a safepoint before performing shutdown actions, and then finally any atexit related actions.

We should look at providing a safe/safer termination process, either by using JNI_DestroyJavaVM, or more crudely (but perhaps expeditiously) calling _exit() instead of exit() so that we get a more immediate termination of the process without executing atexit hooks etc.
Comments
Fix request [17u] I backport this for parity with 17.0.3-oracle. No risk, only a test change. Clean backport. SAP nightly testing passed.
14-01-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk17u-dev/pull/90 Date: 2022-01-13 14:22:46 +0000
13-01-2022

Changeset: 843943c2 Author: David Holmes <dholmes@openjdk.org> Date: 2021-08-09 20:59:22 +0000 URL: https://git.openjdk.java.net/jdk/commit/843943c204f6e8ca046919eae4e727bef6e3326c
09-08-2021

I instrumented the gtest logic to see what code was being executed in what processes to understand when VMs are created and when they can be destroyed. other_vm and vm_assert tests are run in their own processes to get their own JVM. We can destroy the other_vm VM via the TEST_OTHER_VM macro before it calls exit(). same_vm tests all run in the initial process and we create the JVM via the event handler when the first same_vm test runs; we can then destroy it after all tests have completed. Here's sample logging showing the processes and VMs: XXX: runUnitTestsInner (level 1, pid: 440f) for: * XXX: Installing TestEventListener - JVMInitializerListener (pid: 440f) [==========] Running 857 tests from 151 test cases. [----------] Global test environment set-up. [----------] 3 tests from AltHashingTest [ RUN ] AltHashingTest.halfsiphash_test_ByteArray [ OK ] AltHashingTest.halfsiphash_test_ByteArray (1 ms) [ RUN ] AltHashingTest.halfsiphash_test_CharArray [ OK ] AltHashingTest.halfsiphash_test_CharArray (0 ms) [ RUN ] AltHashingTest.halfsiphash_test_FromReference [ OK ] AltHashingTest.halfsiphash_test_FromReference (0 ms) [----------] 3 tests from AltHashingTest (1 ms total) [----------] 1 test from ThreadsListHandle [ RUN ] ThreadsListHandle.sanity_vm XXX: Creating VM for same_vm tests (pid: 440f) XXX: JNI_CreateJavaVM succeeded: 152b65e7e9e0 (pid: 440f) [ OK ] ThreadsListHandle.sanity_vm (0 ms) [----------] 1 test from ThreadsListHandle (228 ms total) [----------] 1 test from Align [ RUN ] Align.alignments [ OK ] Align.alignments (34 ms) [----------] 1 test from Align (34 ms total) [----------] 117 tests from metaspace [ RUN ] metaspace.test_overwriter_vm_assert XXX: runUnitTestsInner (level 1, pid: 4426) for: metaspace.test_overwriter_vm_assert XXX: Creating VM for vm_assert_test (pid: 4426) XXX: JNI_CreateJavaVM succeeded: 14cd5c4d39e0 (pid: 4426) [ OK ] metaspace.test_overwriter_vm_assert (251 ms) [ RUN ] metaspace.arena_growth_policy_ReflectionMetaspaceType_true_vm [ OK ] metaspace.arena_growth_policy_ReflectionMetaspaceType_true_vm (0 ms) ... [----------] 4 tests from CollectorPolicy [ RUN ] CollectorPolicy.young_min_ergo_vm [ OK ] CollectorPolicy.young_min_ergo_vm (0 ms) [ RUN ] CollectorPolicy.young_scaled_initial_ergo_vm [ OK ] CollectorPolicy.young_scaled_initial_ergo_vm (0 ms) [ RUN ] CollectorPolicy.young_cmd_other_vm XXX: runUnitTestsInner (level 1, pid: 444f) for: CollectorPolicy.young_cmd_other_vm XXX: Creating VM for othervm_test (pid: 444f) XXX: JNI_CreateJavaVM succeeded: 150a9d7d99e0 (pid: 444f) XXX: DestroyJavaVM for: 150a9d7d99e0 (pid: 444f) [ OK ] CollectorPolicy.young_cmd_other_vm (279 ms) [ RUN ] CollectorPolicy.old_cmd_other_vm XXX: runUnitTestsInner (level 1, pid: 4463) for: CollectorPolicy.old_cmd_other_vm XXX: Creating VM for othervm_test (pid: 4463) XXX: JNI_CreateJavaVM succeeded: 1528039359e0 (pid: 4463) [0.220s][warning][gc,ergo] Inconsistency between maximum heap size and maximum generation sizes: using maximum heap = 16819159040, -XX:OldSize flag is being ignored [0.220s][warning][gc,ergo] Inconsistency between generation sizes and heap size, resizing the generations to fit the heap. XXX: DestroyJavaVM for: 1528039359e0 (pid: 4463) [ OK ] CollectorPolicy.old_cmd_other_vm (260 ms) [----------] 4 tests from CollectorPolicy (539 ms total) [----------] 1 test from CommittedVirtualMemoryTracker [ RUN ] CommittedVirtualMemoryTracker.test_committed_virtualmemory_region_vm [ OK ] CommittedVirtualMemoryTracker.test_committed_virtualmemory_region_vm (2 ms) [----------] 1 test from CommittedVirtualMemoryTracker (2 ms total) ... [----------] 1 test from LogConfiguration [ RUN ] LogConfiguration.output_reconfigured_other_vm XXX: runUnitTestsInner (level 1, pid: 45d2) for: LogConfiguration.output_reconfigured_other_vm XXX: Creating VM for othervm_test (pid: 45d2) XXX: JNI_CreateJavaVM succeeded: 14c060ec39e0 (pid: 45d2) XXX: DestroyJavaVM for: 14c060ec39e0 (pid: 45d2) [ OK ] LogConfiguration.output_reconfigured_other_vm (266 ms) [----------] 1 test from LogConfiguration (266 ms total) ... [----------] 4 tests from SafepointLockAssertTest [ RUN ] SafepointLockAssertTest.always_check_vm_assert XXX: runUnitTestsInner (level 1, pid: 472d) for: SafepointLockAssertTest.always_check_vm_assert XXX: Creating VM for vm_assert_test (pid: 472d) XXX: JNI_CreateJavaVM succeeded: 1469a87829e0 (pid: 472d) [ OK ] SafepointLockAssertTest.always_check_vm_assert (243 ms) [ RUN ] SafepointLockAssertTest.never_check_vm_assert XXX: runUnitTestsInner (level 1, pid: 4741) for: SafepointLockAssertTest.never_check_vm_assert XXX: Creating VM for vm_assert_test (pid: 4741) XXX: JNI_CreateJavaVM succeeded: 15125e39e9e0 (pid: 4741) [ OK ] SafepointLockAssertTest.never_check_vm_assert (245 ms) [ RUN ] SafepointLockAssertTest.special_locks_vm_assert XXX: runUnitTestsInner (level 1, pid: 4755) for: SafepointLockAssertTest.special_locks_vm_assert XXX: Creating VM for vm_assert_test (pid: 4755) XXX: JNI_CreateJavaVM succeeded: 14be435489e0 (pid: 4755) [ OK ] SafepointLockAssertTest.special_locks_vm_assert (242 ms) [ RUN ] SafepointLockAssertTest.possible_safepoint_lock_vm_assert XXX: runUnitTestsInner (level 1, pid: 4769) for: SafepointLockAssertTest.possible_safepoint_lock_vm_assert XXX: Creating VM for vm_assert_test (pid: 4769) JavaThread state: _thread_in_vm Locks owned: Mutex: [0x000055dcb8d4a3b0] SpecialTest_lock - owner: 0x000055dcb893c610 allow_vm_block safepoint_check_never XXX: JNI_CreateJavaVM succeeded: 150caaea39e0 (pid: 4769) [ OK ] SafepointLockAssertTest.possible_safepoint_lock_vm_assert (242 ms) [----------] 4 tests from SafepointLockAssertTest (972 ms total) ... [----------] Global test environment tear-down [==========] 857 tests from 151 test cases ran. (65447 ms total) [ PASSED ] 857 tests. YOU HAVE 8 DISABLED TESTS XXX: JVMInitializerListener: DestroyJavaVM for: 152b65e7e9e0 (pid: 440f) XXX: RUN_ALL_TESTS (level 1) has completed (pid: 440f)
03-08-2021

I originally filed this under "test" but it appears to have gone unnoticed there.
19-03-2021