<Beans Dev> Fwd: Re: [PATCH] test/jdk/java/beans/PropertyEditor/Test6397609.java failed in JITed code
Fu Jie
fujie at loongson.cn
Fri Jan 4 08:47:43 UTC 2019
Hi,
I think Alan's approach is more readable and more elegant.
And it can also fix the issue mentioned by Sergey.
---------------------------------------------
diff -r 2345e253e677 test/jdk/java/beans/PropertyEditor/Test6397609.java
--- a/test/jdk/java/beans/PropertyEditor/Test6397609.java Thu Jan 03
15:54:01 2019 -0500
+++ b/test/jdk/java/beans/PropertyEditor/Test6397609.java Fri Jan 04
16:32:48 2019 +0800
@@ -32,6 +32,8 @@
*/
import java.beans.PropertyEditorManager;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
public class Test6397609 {
public static void main(String[] args) throws Exception {
@@ -44,6 +46,7 @@
if (!isEditorExist(Object.class)) {
throw new Error("the editor is lost");
}
+ Reference.reachabilityFence(loader);
loader = null; // clean the reference
if (isEditorExist(Object.class)) {
throw new Error("unexpected editor is found");
@@ -51,12 +54,23 @@
}
private static boolean isEditorExist(Class type) {
- for (int i = 0; i < 10; i++) {
- System.gc(); // clean all weak references
- if (null == PropertyEditorManager.findEditor(type)) {
- return false;
+ Object object = new Object();
+ final WeakReference<Object> ref = new WeakReference<>(object);
+ object = null;
+ // clean all weak references
+ while (ref.get() != null) {
+ System.gc();
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException ex) {
+ // pass
}
}
- return true;
+
+ if (null == PropertyEditorManager.findEditor(type)) {
+ return false;
+ } else {
+ return true;
+ }
}
}
---------------------------------------------
Would you please review it and give me some advice?
Thanks.
Best Regards,
Jie
On 2019/1/4 下午3:50, Alan Bateman wrote:
> On 04/01/2019 06:44, Fu Jie wrote:
>> Hi,
>>
>> I think it's really hard to say that all weak references would be
>> reclaimed by just calling "System.gc()" 10 times.
> I don't like the new patch or catching OOME and do not wish to be a
> Reviewer on that version. The approach that we use in dozens of other
> tests is to call System.gc(), sleep, test if the reference has been
> cleared, and retry if needed.
>
> -Alan.
More information about the beans-dev
mailing list