Skip to content

8298783: java/lang/ref/FinalizerHistogramTest.java failed with "RuntimeException: MyObject is not found in test output"#3074

Open
sendaoYan wants to merge 10 commits into
openjdk:masterfrom
openjdk-bots:backport-sendaoYan-fe29cad5-master
Open

8298783: java/lang/ref/FinalizerHistogramTest.java failed with "RuntimeException: MyObject is not found in test output"#3074
sendaoYan wants to merge 10 commits into
openjdk:masterfrom
openjdk-bots:backport-sendaoYan-fe29cad5-master

Conversation

@sendaoYan

@sendaoYan sendaoYan commented Aug 22, 2025

Copy link
Copy Markdown
Member

Hi all,

FinalizerHistogramTest exercises the internal java.lang.ref.FinalizerHistogram API. The test:

  1. Creates 1000 MyObject instances, each with a finalize() that acquires a ReentrantLock held by the main thread, permanently blocking the finalizer thread on the first finalized object.

  2. Triggers GC and waits until reference/finalizer processing has progressed.

  3. Reads FinalizerHistogram.getFinalizerHistogram() and expects to see MyObject entries — objects still waiting in the finalizer queue while the finalizer thread is blocked.

The intermittent failure (RuntimeException: MyObject is not found in test output) was a test bug, not a product bug. The old test called System.gc() and then spun on while (wasTrapped < 1), proceeding as soon as the first finalize() was entered. At that point, other MyObject instances might not yet have been discovered and enqueued for finalization, so the histogram could legitimately be empty.

This backport makes the test more robust by:

  • Running in othervm, since the test blocks the global finalizer thread.

  • Replacing non-atomic volatile int counters with AtomicInteger.

  • Using WhiteBox.fullGC() plus a loop on WhiteBox.waitForReferenceProcessing() instead of System.gc() plus a busy-wait on wasTrapped.

  • Adapting the WhiteBox path for jdk11u (sun.hotspot.WhiteBox / ClassFileInstaller instead of jdk.test.whitebox.WhiteBox).

This PR is intend to fix the test bug which cause test intermittent fails. Backport not clean because the path of sun.hotspot.WhiteBox different to main-line, the path should adopt to jdk11u-dev when backport from main-line to jdk11u-dev, Other parts is cleanly.

I have verified this backport plus with #3105.

Thanks!



Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • JDK-8298783 needs maintainer approval

Error

 ⚠️ OCA signatory status must be verified

Issue

  • JDK-8298783: java/lang/ref/FinalizerHistogramTest.java failed with "RuntimeException: MyObject is not found in test output" (Bug - P4 - Requested)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk11u-dev.git pull/3074/head:pull/3074
$ git checkout pull/3074

Update a local copy of the PR:
$ git checkout pull/3074
$ git pull https://git.openjdk.org/jdk11u-dev.git pull/3074/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 3074

View PR using the GUI difftool:
$ git pr show -t 3074

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk11u-dev/pull/3074.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper

bridgekeeper Bot commented Aug 22, 2025

Copy link
Copy Markdown

👋 Welcome back syan! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk

openjdk Bot commented Aug 22, 2025

Copy link
Copy Markdown

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk Bot changed the title Backport fe29cad5e0b10cd088fc39967599f5a8dcaa445c 8298783: java/lang/ref/FinalizerHistogramTest.java failed with "RuntimeException: MyObject is not found in test output" Aug 22, 2025
@openjdk

openjdk Bot commented Aug 22, 2025

Copy link
Copy Markdown

This backport pull request has now been updated with issue from the original commit.

@openjdk openjdk Bot added backport Port of a pull request already in a different code base clean Identical backport; no merge resolution required labels Aug 22, 2025
@openjdk

openjdk Bot commented Aug 22, 2025

Copy link
Copy Markdown

⚠️ @sendaoYan This change is now ready for you to apply for maintainer approval. This can be done directly in each associated issue or by using the /approval command.

@openjdk openjdk Bot added the rfr Pull request is ready for review label Aug 22, 2025
@mlbridge

mlbridge Bot commented Aug 22, 2025

Copy link
Copy Markdown

@bridgekeeper

bridgekeeper Bot commented Sep 19, 2025

Copy link
Copy Markdown

@sendaoYan This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@sendaoYan

sendaoYan commented Sep 19, 2025

Copy link
Copy Markdown
Member Author

/approval request Clean backport to make test more robustness which fix the test fails intermittent. Change has been verifiled locally on linux-x64. Test-fix only, risk is low.

@openjdk

openjdk Bot commented Sep 19, 2025

Copy link
Copy Markdown

@sendaoYan
8298783: The approval request has been created successfully.

@openjdk openjdk Bot added the approval Requires approval; will be removed when approval is received label Sep 19, 2025
@bridgekeeper

bridgekeeper Bot commented Oct 17, 2025

Copy link
Copy Markdown

@sendaoYan This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@sendaoYan

sendaoYan commented Oct 20, 2025

Copy link
Copy Markdown
Member Author

I think we should backport JDK-8305186 first.

@sendaoYan

sendaoYan commented Oct 20, 2025

Copy link
Copy Markdown
Member Author

The patch different to mainline:

diff --git a/test/jdk/java/lang/ref/FinalizerHistogramTest.java b/test/jdk/java/lang/ref/FinalizerHistogramTest.java
index 192c229c7b5..4dcea55b1f4 100644
--- a/test/jdk/java/lang/ref/FinalizerHistogramTest.java
+++ b/test/jdk/java/lang/ref/FinalizerHistogramTest.java
@@ -21,7 +21,7 @@
  * questions.
  */
 
-import jdk.test.whitebox.WhiteBox;
+import sun.hotspot.WhiteBox;
 
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.locks.ReentrantLock;
@@ -34,8 +34,8 @@ import java.lang.reflect.Field;
  * @summary Unit test for FinalizerHistogram
  * @modules java.base/java.lang.ref:open
  * @library /test/lib
- * @build jdk.test.whitebox.WhiteBox
- * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
+ * @build sun.hotspot.WhiteBox
+ * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  * @run main/othervm
  *      -Xbootclasspath/a:.
  *      -XX:+UnlockDiagnosticVMOptions

@sendaoYan

sendaoYan commented Oct 20, 2025

Copy link
Copy Markdown
Member Author

/approval cancel

@openjdk openjdk Bot removed the clean Identical backport; no merge resolution required label Oct 20, 2025
@openjdk

openjdk Bot commented Oct 20, 2025

Copy link
Copy Markdown

@sendaoYan
8298783: The approval request has been cancelled successfully.

@openjdk openjdk Bot removed the approval Requires approval; will be removed when approval is received label Oct 20, 2025
@bridgekeeper

bridgekeeper Bot commented Nov 21, 2025

Copy link
Copy Markdown

@sendaoYan This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper

bridgekeeper Bot commented Dec 31, 2025

Copy link
Copy Markdown

@sendaoYan This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@sendaoYan

sendaoYan commented Jan 4, 2026

Copy link
Copy Markdown
Member Author

Waiting #3105 merged.

@bridgekeeper

bridgekeeper Bot commented Feb 2, 2026

Copy link
Copy Markdown

@sendaoYan This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper

bridgekeeper Bot commented Mar 2, 2026

Copy link
Copy Markdown

@sendaoYan This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@openjdk

openjdk Bot commented Mar 13, 2026

Copy link
Copy Markdown

@sendaoYan This pull request has not yet been marked as ready for integration.

@openjdk

openjdk Bot commented Mar 15, 2026

Copy link
Copy Markdown

@sendaoYan
8298783: The approval request has been created successfully.

@openjdk openjdk Bot added the approval Requires approval; will be removed when approval is received label Mar 15, 2026
@sendaoYan

sendaoYan commented Mar 16, 2026

Copy link
Copy Markdown
Member Author

/approval cancel

@openjdk

openjdk Bot commented Mar 16, 2026

Copy link
Copy Markdown

@sendaoYan
8298783: The approval request has been cancelled successfully.

@openjdk openjdk Bot removed the approval Requires approval; will be removed when approval is received label Mar 16, 2026
@bridgekeeper

bridgekeeper Bot commented Apr 13, 2026

Copy link
Copy Markdown

@sendaoYan This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@openjdk openjdk Bot removed the rfr Pull request is ready for review label Apr 13, 2026
@sendaoYan

sendaoYan commented Apr 27, 2026

Copy link
Copy Markdown
Member Author

/template append

@openjdk

openjdk Bot commented Apr 27, 2026

Copy link
Copy Markdown

@sendaoYan The pull request template has been appended to the pull request body

@openjdk openjdk Bot added the rfr Pull request is ready for review label Apr 27, 2026
@sendaoYan

sendaoYan commented May 12, 2026

Copy link
Copy Markdown
Member Author

/approval request Clean backport to make test more robustness which fix the test fails intermittent. Change has been verifiled locally on linux-x64. Backport parity with 11.0.31-oracle, test-fix only, risk is low.

@openjdk

openjdk Bot commented May 12, 2026

Copy link
Copy Markdown

@sendaoYan
8298783: The approval request has been created successfully.

@openjdk openjdk Bot added the approval Requires approval; will be removed when approval is received label May 12, 2026
@bridgekeeper bridgekeeper Bot added the oca Needs verification of OCA signatory status label May 28, 2026
@openjdk openjdk Bot removed the rfr Pull request is ready for review label May 28, 2026
@gnu-andrew

Copy link
Copy Markdown
Member

Not sure what is going on with oca as I've seen patches from you before.

@tstuefe

tstuefe commented Jun 17, 2026

Copy link
Copy Markdown
Member

Can you please describe what the patch does? Even though it seems simple enough. In general, it saves us time when reviewing, especially in cases like these where the JBS issue does not explain what went wrong or what the fix does (the issue text only lists symptoms, and the comments don't explain anything either).

Even if the patch is simple and self-explanatory, this helps gauge the importance of issues, whether the author has understood the issue and also whether the author's explanation matches the actual patch. For intermittent errors, it would also help to know how intermittent intermittent is (if this is known) with respect to the old stable target release.

while(wasTrapped < 1);
System.out.println("Objects intialized: " + initializedCount.get());
wb = WhiteBox.getWhiteBox();
wb.fullGC();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why the change from System.gc to WB.fullGC?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Use WB.fullGC instead of System.gc is a good practice sometimes, this will make test more robustness and stable, such as openjdk/jdk#29729.

System.gc() is only a hint to the JVM — it does not guarantee that a full collection runs, that all unreachable objects are collected, or that reference/finalizer processing has completed. In this test that was the root cause of the intermittent failure: after System.gc(), the old code spun on while (wasTrapped < 1), i.e. it proceeded as soon as the first MyObject.finalize() was entered. At that moment other MyObject instances might not yet have been discovered and enqueued for finalization, so FinalizerHistogram could legitimately show no MyObject entries.

WhiteBox.fullGC() (see WB_FullGC in whitebox.cpp) forces a full heap collection with GCCause::_wb_full_gc and clears soft references, so unreachable MyObject instances are actually collected. The follow-up loop on wb.waitForReferenceProcessing() (which delegates to Reference.waitForReferenceProcessing()) then waits until pending reference processing — including work handed off to the finalizer thread — has quiesced (false means no active/pending processing). Only after that do we read the histogram, which matches the test's intent: at least one object blocked in finalize(), with others still waiting in the finalizer queue.

So the change is not “use WhiteBox for fun”; it replaces a racy System.gc() + busy-wait with deterministic GC + reference-processing synchronization, which is the actual fix for JDK-8298783.

@sendaoYan

Copy link
Copy Markdown
Member Author

Can you please describe what the patch does? Even though it seems simple enough. In general, it saves us time when reviewing, especially in cases like these where the JBS issue does not explain what went wrong or what the fix does (the issue text only lists symptoms, and the comments don't explain anything either).

Even if the patch is simple and self-explanatory, this helps gauge the importance of issues, whether the author has understood the issue and also whether the author's explanation matches the actual patch. For intermittent errors, it would also help to know how intermittent intermittent is (if this is known) with respect to the old stable target release.

Sorry, I have updated the PR description.

I can not reproduce the intermittent failure locally. But the same failure was observed by jdk11u-dev GHA(Seen the comment in https://bugs.openjdk.org/browse/JDK-8298783). This is test-fix only, I think the risk is very low.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval Requires approval; will be removed when approval is received backport Port of a pull request already in a different code base oca Needs verification of OCA signatory status

Development

Successfully merging this pull request may close these issues.

4 participants