-
Notifications
You must be signed in to change notification settings - Fork 476
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
8244297: Provide utility for testing for memory leaks #204
8244297: Provide utility for testing for memory leaks #204
Conversation
Added test utility class copied from JMemoryBuddy and used it to simplify 4 of the exiting unit tests.
👋 Welcome back fkirmaier! A progress list of the required criteria for merging this PR into |
Webrevs
|
/reviewers 2 |
@kevinrushforth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll put this on my queue to review and test it. I left some high-level comments below.
modules/javafx.base/src/test/java/de/sandec/jmemorybuddy/JMemoryBuddy.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
|
||
public static void createHeapDump() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want automatic creation of heap dumps by our unit test suite. That would need a larger discussion. I recommend to either comment this out, or else to qualify it with a system property that could be passed in via a gradle
property (e.g., as is done for UNSTABLE_TEST
), with a default of false
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made it configurable in the Library with system-parameters and I've changed the default not create a heap dump.
Is that ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that seems fine.
modules/javafx.base/src/test/java/de/sandec/jmemorybuddy/JMemoryBuddy.java
Outdated
Show resolved
Hide resolved
I would suggest making everything configurable in the original library which will be suggested here to be changed. I will improve the documentation in the original Library. How should I add the documentation to the JavaFX project? Ideally, I would just reference somewhere to the documentation of the original library. How/Where should I do that? |
It's also worth mentioning that this utility allows checking whether an object can not be collected. This is important because the applications, which are using WeakReferences/WeakListeners often introduce bugs that are hard to debug because they only happen after the GC has been run. |
Updated JMemoeryBuddy Added Copyright header disabled default heapdump
Added some javadoc to the testutility Some methods/fields are now private
I've now added also some JavaDoc to the public methods. |
Hi @jskovjyskebankdk, thanks for making a comment in an OpenJDK project! All comments and discussions in the OpenJDK Community must be made available under the OpenJDK Terms of Use. If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please Use "Add GitHub user jskovjyskebankdk for the summary. If you are not an OpenJDK Author, Committer or Reviewer, simply check the box below to accept the OpenJDK Terms of Use for your comments.
Your comment will be automatically restored once you have accepted the OpenJDK Terms of Use. |
Improved the JavaDoc for JMemoryBuddy
What I tried asking from my work account is: what is the purpose of createGarbage? |
The createGarbage method stimulates the GC. All unit tests are green without it, but according to my memory some tests in an earlier version of this library were unstable without this. |
Any news about this PR? |
Now that |
Any news? I will probably soon have some PR which would like to use it for the tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests fail to compile, please correct the import.
Pointed error in ToggleButtonTest
, please check other files also when correcting this.
modules/javafx.controls/src/test/java/test/javafx/scene/control/ToggleButtonTest.java
Outdated
Show resolved
Hide resolved
modules/javafx.controls/src/test/java/test/javafx/scene/control/ToggleButtonTest.java
Show resolved
Hide resolved
Fixing some wrong imports
I've fixed the wrong imports. It would be great if Travis could check whether all systemTests are compiling. |
Thanks, we'll review it now. Btw, we don't plan to hook up Travis, but instead will be looking at GitHub actions now that the |
It looks like you are missing an import statement in one of the tests:
You can run the following locally on your system once you have fixed this to verify that there are no others.
|
Fixed unit-test
I've checked the 4 changed tests with the following commands: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reviewed only in perspective of Java coding guidelines. I still have to review the functionality.
Most of the comments are minor like variable name change and typos. I would recommend you to please go through all of the code to find and fix any other corrections related to Coding guidelines.
modules/javafx.base/src/test/java/test/util/memory/JMemoryBuddy.java
Outdated
Show resolved
Hide resolved
modules/javafx.base/src/test/java/test/util/memory/JMemoryBuddy.java
Outdated
Show resolved
Hide resolved
modules/javafx.base/src/test/java/test/util/memory/JMemoryBuddy.java
Outdated
Show resolved
Hide resolved
modules/javafx.base/src/test/java/test/util/memory/JMemoryBuddy.java
Outdated
Show resolved
Hide resolved
modules/javafx.base/src/test/java/test/util/memory/JMemoryBuddy.java
Outdated
Show resolved
Hide resolved
|
||
if(weakReference.get() == null && counter < steps / 3) { | ||
int percentageUsed = (int) ((steps - counter) / steps * 100); | ||
System.out.println("Warning test seems to be unstable. time used: " + percentageUsed + "%"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like candidate for System.err.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might be true, but honestly, I'm using System.err so rarely (never) that I have a better feeling avoiding it altogether and eliminating the chance for rare cornercases.
@kevinrushforth |
3 similar comments
@kevinrushforth |
@kevinrushforth |
@kevinrushforth |
Updated JMemoryBuddy based on codereview.
Updated JMemoryBuddy based on codereview.
Updated JMemoryBuddy based on codereview.
First, thank you both for all your comments! The title should be correct now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a quick note, since I don't have time to review it today. Thanks for making the changes. I see that you added the space after if
(except in the new method you added), but not after for
and while
.
I'll do more testing next week as part of my review.
modules/javafx.base/src/test/java/test/util/memory/JMemoryBuddy.java
Outdated
Show resolved
Hide resolved
Added some more whitespaces based on review
Just added some more spaces! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the suggested changes. I left one more comment inline and a couple very minor points (which I only mention as something you might want to fix when you take care of the one issue I raised).
The rest looks good. I see that you modified the InitialNodesMemoryLeakTest to use JMemeoryBuddy. In order to verify that the assertions are working, I injected an error by reverting the fix for the JDK-8216377. The modified test still correctly catches the bug:
$ gradle --info -PFULL_TEST=true cleanTest :systemTests:test --tests InitialNodesMemoryLeakTest
...
test.javafx.scene.InitialNodesMemoryLeakTest > testRootNodeMemoryLeak STANDARD_OUT
No Heapdump was created. You might want to change the configuration to get a HeapDump.
Gradle Test Executor 1 finished executing tests.
> Task :systemTests:test FAILED
test.javafx.scene.InitialNodesMemoryLeakTest > testRootNodeMemoryLeak FAILED
java.lang.AssertionError: Content of WeakReference was not collected. content: Group@149ab2ce
at test.util.memory.JMemoryBuddy.assertCollectable(JMemoryBuddy.java:91)
at test.javafx.scene.InitialNodesMemoryLeakTest.testRootNodeMemoryLeak(InitialNodesMemoryLeakTest.java:89)
1 test completed, 1 failed
Good.
modules/javafx.base/src/test/java/test/util/memory/JMemoryBuddy.java
Outdated
Show resolved
Hide resolved
modules/javafx.base/src/test/java/test/util/memory/JMemoryBuddy.java
Outdated
Show resolved
Hide resolved
more improvements based on code-review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me too...
@FlorianKirmaier This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 151 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@kevinrushforth, @arapte) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
/integrate |
@FlorianKirmaier |
/sponsor |
@arapte @FlorianKirmaier Since your change was applied there have been 151 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 1a11334. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
It's based on the discussion of my previous PR: #71
I Added test utility class copied from JMemoryBuddy and used it to simplify 4 of the existing unit tests.
It's a direct copy of my project JMemoryBuddy without any changes.
I'm also using it in most of the projects I'm involved with and in my experience, the tests with this Library are very stable. I can't remember wrong test results. Sometimes the memory behaviour of some libraries itself is not stable but the tests with JMemoryBuddy are basically always correct.
Progress
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jfx pull/204/head:pull/204
$ git checkout pull/204