Re: Testing no memory leak occurs via references

2023-03-08 Thread John Hendrikx
On 08/03/2023 10:36, David Holmes wrote: On 7/03/2023 8:16 pm, Kim Barrett wrote: On Mar 6, 2023, at 10:11 AM, Aleksei Ivanov wrote: On 06/03/2023 13:51, Albert Yang wrote: Upon a cursory inspection of ForceGC.java, it seems that the fundamental logic involves waiting for a certain duratio

Re: Testing no memory leak occurs via references

2023-03-08 Thread David Holmes
On 7/03/2023 8:16 pm, Kim Barrett wrote: On Mar 6, 2023, at 10:11 AM, Aleksei Ivanov wrote: On 06/03/2023 13:51, Albert Yang wrote: Upon a cursory inspection of ForceGC.java, it seems that the fundamental logic involves waiting for a certain duration and relying on chance. However, I am of t

Re: Testing no memory leak occurs via references

2023-03-07 Thread Philip Race
Having just a very few sources of wisdom on this in the JDK test suites is a good idea because then any tests that might be affected by policy changes would be easily spotted. I say this despite an instinctive reticence to rely on "frameworks" and "utilities" in jtreg tests. As resources allow

Re: Testing no memory leak occurs via references

2023-03-07 Thread Kim Barrett
> On Mar 6, 2023, at 10:11 AM, Aleksei Ivanov wrote: > > On 06/03/2023 13:51, Albert Yang wrote: >> Upon a cursory inspection of ForceGC.java, it seems that the fundamental >> logic involves waiting for a certain duration and relying on chance. >> However, I am of the opinion that utilizing the

Re: Testing no memory leak occurs via references

2023-03-06 Thread Aleksei Ivanov
On 06/03/2023 13:51, Albert Yang wrote: Upon a cursory inspection of ForceGC.java, it seems that the fundamental logic involves waiting for a certain duration and relying on chance. However, I am of the opinion that utilizing the WhiteBox API can provide greater determinism and potentially str

Re: Testing no memory leak occurs via references

2023-03-06 Thread Roger Riggs
Hi Albert, The only  downside of the WhiteBox API is the need to link and run with native code. It make adhoc testing more difficult. I would not say ForceGC relies on chance, since it is testing the specific condition as requested by the caller. It uses mechanisms available to normal applica

Re: Testing no memory leak occurs via references

2023-03-06 Thread Albert Yang
Upon a cursory inspection of ForceGC.java, it seems that the fundamental logic involves waiting for a certain duration and relying on chance. However, I am of the opinion that utilizing the WhiteBox API can provide greater determinism and potentially strengthen some of the assertions. > I decid

Re: Testing no memory leak occurs via references

2023-03-06 Thread Aleksei Ivanov
Thank you, Stuart and Roger, for the suggestion. I didn't know about ForceGC class. We should use the common library, I have updated my PR [7] with ForceGC. Albert and Thomas suggested using WhiteBox API. It would probably work too, however, I decided ForceGC is simpler and easier to use, so

Re: Testing no memory leak occurs via references

2023-03-04 Thread Thomas Schatzl
Hi, On 03.03.23 19:02, Aleksei Ivanov wrote: > Hello, > > In clientlibs, there's occasionally a need to verify an object isn't > leaked. For this purpose, WeakReference or PhantomReference is used. > > Then, we need to make the reference object be cleared, so a GC cycle > need to be triggered. Th

Re: Testing no memory leak occurs via references

2023-03-03 Thread Stuart Marks
As Roger mentioned, there is a ForceGC utility in the test library:     test/lib/jdk/test/lib/util/ForceGC.java and it's used in a variety of places in the core libs tests. Essentially it sets up a PhantomReference and a ReferenceQueue and runs System.gc() in a loop. I'd strongly recommend usi

Re: Testing no memory leak occurs via references

2023-03-03 Thread Albert Yang
I wonder if `WhiteBoxAPI` can be used if the goal is to trigger a (Full) GC cycle. An example is `whitebox.fullGC()` in `test/jdk/java/lang/ref/CleanerTest.java`. /Albert

Re: Testing no memory leak occurs via references

2023-03-03 Thread Roger Riggs
Hi, There is test library class jdk.test.lib.util.ForceGC that is useful for that case. It uses a PhantomReference to detect that gc has been run. And it can be called with a function that can test for another condition. For an example, look at the tests that use ForceGC in test/jdk/... Regar

Testing no memory leak occurs via references

2023-03-03 Thread Aleksei Ivanov
Hello, In clientlibs, there's occasionally a need to verify an object isn't leaked. For this purpose, WeakReference or PhantomReference is used. Then, we need to make the reference object be cleared, so a GC cycle need to be triggered. The common approach is generating OutOfMemoryError, catc