6921057: REGRESSION: persistence delegate issue on Windows and Linux against 5.u23b03/6u17b11
Reviewed-by: peterz, art
--- a/jdk/src/share/classes/java/beans/Introspector.java Thu Jan 28 16:12:06 2010 -0800
+++ b/jdk/src/share/classes/java/beans/Introspector.java Fri Feb 05 10:36:12 2010 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright 1996-2009 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1996-2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,8 @@
import com.sun.beans.finder.BeanInfoFinder;
import com.sun.beans.finder.ClassFinder;
+import java.lang.ref.Reference;
+import java.lang.ref.SoftReference;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -39,6 +41,7 @@
import java.util.EventListener;
import java.util.List;
import java.util.TreeMap;
+import java.util.WeakHashMap;
import sun.awt.AppContext;
import sun.reflect.misc.ReflectUtil;
@@ -155,11 +158,11 @@
return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo();
}
synchronized (BEANINFO_CACHE) {
- WeakCache<Class<?>, BeanInfo> beanInfoCache =
- (WeakCache<Class<?>, BeanInfo>) AppContext.getAppContext().get(BEANINFO_CACHE);
+ Map<Class<?>, BeanInfo> beanInfoCache =
+ (Map<Class<?>, BeanInfo>) AppContext.getAppContext().get(BEANINFO_CACHE);
if (beanInfoCache == null) {
- beanInfoCache = new WeakCache<Class<?>, BeanInfo>();
+ beanInfoCache = new WeakHashMap<Class<?>, BeanInfo>();
AppContext.getAppContext().put(BEANINFO_CACHE, beanInfoCache);
}
BeanInfo beanInfo = beanInfoCache.get(beanClass);
@@ -341,7 +344,7 @@
public static void flushCaches() {
synchronized (BEANINFO_CACHE) {
- WeakCache beanInfoCache = (WeakCache) AppContext.getAppContext().get(BEANINFO_CACHE);
+ Map beanInfoCache = (Map) AppContext.getAppContext().get(BEANINFO_CACHE);
if (beanInfoCache != null) {
beanInfoCache.clear();
}
@@ -369,7 +372,7 @@
throw new NullPointerException();
}
synchronized (BEANINFO_CACHE) {
- WeakCache beanInfoCache = (WeakCache) AppContext.getAppContext().get(BEANINFO_CACHE);
+ Map beanInfoCache = (Map) AppContext.getAppContext().get(BEANINFO_CACHE);
if (beanInfoCache != null) {
beanInfoCache.put(clz, null);
}
@@ -1458,7 +1461,7 @@
private PropertyDescriptor[] properties;
private int defaultProperty;
private MethodDescriptor[] methods;
- private BeanInfo targetBeanInfo;
+ private final Reference<BeanInfo> targetBeanInfoRef;
public GenericBeanInfo(BeanDescriptor beanDescriptor,
EventSetDescriptor[] events, int defaultEvent,
@@ -1470,7 +1473,7 @@
this.properties = properties;
this.defaultProperty = defaultProperty;
this.methods = methods;
- this.targetBeanInfo = targetBeanInfo;
+ this.targetBeanInfoRef = new SoftReference<BeanInfo>(targetBeanInfo);
}
/**
@@ -1509,7 +1512,7 @@
methods[i] = new MethodDescriptor(old.methods[i]);
}
}
- targetBeanInfo = old.targetBeanInfo;
+ this.targetBeanInfoRef = old.targetBeanInfoRef;
}
public PropertyDescriptor[] getPropertyDescriptors() {
@@ -1537,6 +1540,7 @@
}
public java.awt.Image getIcon(int iconKind) {
+ BeanInfo targetBeanInfo = this.targetBeanInfoRef.get();
if (targetBeanInfo != null) {
return targetBeanInfo.getIcon(iconKind);
}
--- a/jdk/test/java/beans/Introspector/6380849/TestBeanInfo.java Thu Jan 28 16:12:06 2010 -0800
+++ b/jdk/test/java/beans/Introspector/6380849/TestBeanInfo.java Fri Feb 05 10:36:12 2010 +0300
@@ -1,5 +1,5 @@
/**
- * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -38,6 +38,7 @@
import java.beans.BeanInfo;
import java.beans.Introspector;
+import java.lang.ref.Reference;
import java.lang.reflect.Field;
import sun.awt.SunToolkit;
@@ -61,9 +62,10 @@
try {
actual = Introspector.getBeanInfo(type);
type = actual.getClass();
- Field field = type.getDeclaredField("targetBeanInfo"); // NON-NLS: field name
+ Field field = type.getDeclaredField("targetBeanInfoRef"); // NON-NLS: field name
field.setAccessible(true);
- actual = (BeanInfo) field.get(actual);
+ Reference ref = (Reference) field.get(actual);
+ actual = (BeanInfo) ref.get();
}
catch (Exception exception) {
throw new Error("unexpected error", exception);
--- a/jdk/test/java/beans/Introspector/Test5102804.java Thu Jan 28 16:12:06 2010 -0800
+++ b/jdk/test/java/beans/Introspector/Test5102804.java Fri Feb 05 10:36:12 2010 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -24,9 +24,9 @@
/*
* @test
* @bug 5102804
- * @ignore This test is not predictable with regards to GC
* @summary Tests memory leak
* @author Sergey Malenkov
+ * @run main/othervm -ms16m -mx16m Test5102804
*/
import java.beans.BeanInfo;
--- a/jdk/test/java/beans/XMLEncoder/Test4646747.java Thu Jan 28 16:12:06 2010 -0800
+++ b/jdk/test/java/beans/XMLEncoder/Test4646747.java Fri Feb 05 10:36:12 2010 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 2004-2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
* @bug 4646747
* @summary Tests that persistence delegate is correct after memory stress
* @author Mark Davidson
+ * @run main/othervm -ms16m -mx16m Test4646747
*/
import java.beans.DefaultPersistenceDelegate;
@@ -41,11 +42,14 @@
encoder.setPersistenceDelegate(Test4646747.class, new MyPersistenceDelegate());
// WARNING: This can eat up a lot of memory
Object[] obs = new Object[10000];
- for (int i = 0; i < obs.length; i++) {
- obs[i] = new int[1000];
+ while (obs != null) {
+ try {
+ obs = new Object[obs.length + obs.length / 3];
+ }
+ catch (OutOfMemoryError error) {
+ obs = null;
+ }
}
- System.gc();
- System.gc();
PersistenceDelegate pd = encoder.getPersistenceDelegate(Test4646747.class);
if (!(pd instanceof MyPersistenceDelegate))
throw new Error("persistence delegate has been lost");