提交 2ffa3bd2 编写于 作者: M malenkov

6921057: REGRESSION: persistence delegate issue on Windows and Linux against 5.u23b03/6u17b11

Reviewed-by: peterz, art
上级 d7ee29a0
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -29,6 +29,8 @@ import com.sun.beans.WeakCache; ...@@ -29,6 +29,8 @@ import com.sun.beans.WeakCache;
import com.sun.beans.finder.BeanInfoFinder; import com.sun.beans.finder.BeanInfoFinder;
import com.sun.beans.finder.ClassFinder; 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.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
...@@ -39,6 +41,7 @@ import java.util.Iterator; ...@@ -39,6 +41,7 @@ import java.util.Iterator;
import java.util.EventListener; import java.util.EventListener;
import java.util.List; import java.util.List;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.WeakHashMap;
import sun.awt.AppContext; import sun.awt.AppContext;
import sun.reflect.misc.ReflectUtil; import sun.reflect.misc.ReflectUtil;
...@@ -155,11 +158,11 @@ public class Introspector { ...@@ -155,11 +158,11 @@ public class Introspector {
return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo(); return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo();
} }
synchronized (BEANINFO_CACHE) { synchronized (BEANINFO_CACHE) {
WeakCache<Class<?>, BeanInfo> beanInfoCache = Map<Class<?>, BeanInfo> beanInfoCache =
(WeakCache<Class<?>, BeanInfo>) AppContext.getAppContext().get(BEANINFO_CACHE); (Map<Class<?>, BeanInfo>) AppContext.getAppContext().get(BEANINFO_CACHE);
if (beanInfoCache == null) { if (beanInfoCache == null) {
beanInfoCache = new WeakCache<Class<?>, BeanInfo>(); beanInfoCache = new WeakHashMap<Class<?>, BeanInfo>();
AppContext.getAppContext().put(BEANINFO_CACHE, beanInfoCache); AppContext.getAppContext().put(BEANINFO_CACHE, beanInfoCache);
} }
BeanInfo beanInfo = beanInfoCache.get(beanClass); BeanInfo beanInfo = beanInfoCache.get(beanClass);
...@@ -341,7 +344,7 @@ public class Introspector { ...@@ -341,7 +344,7 @@ public class Introspector {
public static void flushCaches() { public static void flushCaches() {
synchronized (BEANINFO_CACHE) { synchronized (BEANINFO_CACHE) {
WeakCache beanInfoCache = (WeakCache) AppContext.getAppContext().get(BEANINFO_CACHE); Map beanInfoCache = (Map) AppContext.getAppContext().get(BEANINFO_CACHE);
if (beanInfoCache != null) { if (beanInfoCache != null) {
beanInfoCache.clear(); beanInfoCache.clear();
} }
...@@ -369,7 +372,7 @@ public class Introspector { ...@@ -369,7 +372,7 @@ public class Introspector {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (BEANINFO_CACHE) { synchronized (BEANINFO_CACHE) {
WeakCache beanInfoCache = (WeakCache) AppContext.getAppContext().get(BEANINFO_CACHE); Map beanInfoCache = (Map) AppContext.getAppContext().get(BEANINFO_CACHE);
if (beanInfoCache != null) { if (beanInfoCache != null) {
beanInfoCache.put(clz, null); beanInfoCache.put(clz, null);
} }
...@@ -1458,7 +1461,7 @@ class GenericBeanInfo extends SimpleBeanInfo { ...@@ -1458,7 +1461,7 @@ class GenericBeanInfo extends SimpleBeanInfo {
private PropertyDescriptor[] properties; private PropertyDescriptor[] properties;
private int defaultProperty; private int defaultProperty;
private MethodDescriptor[] methods; private MethodDescriptor[] methods;
private BeanInfo targetBeanInfo; private final Reference<BeanInfo> targetBeanInfoRef;
public GenericBeanInfo(BeanDescriptor beanDescriptor, public GenericBeanInfo(BeanDescriptor beanDescriptor,
EventSetDescriptor[] events, int defaultEvent, EventSetDescriptor[] events, int defaultEvent,
...@@ -1470,7 +1473,7 @@ class GenericBeanInfo extends SimpleBeanInfo { ...@@ -1470,7 +1473,7 @@ class GenericBeanInfo extends SimpleBeanInfo {
this.properties = properties; this.properties = properties;
this.defaultProperty = defaultProperty; this.defaultProperty = defaultProperty;
this.methods = methods; this.methods = methods;
this.targetBeanInfo = targetBeanInfo; this.targetBeanInfoRef = new SoftReference<BeanInfo>(targetBeanInfo);
} }
/** /**
...@@ -1509,7 +1512,7 @@ class GenericBeanInfo extends SimpleBeanInfo { ...@@ -1509,7 +1512,7 @@ class GenericBeanInfo extends SimpleBeanInfo {
methods[i] = new MethodDescriptor(old.methods[i]); methods[i] = new MethodDescriptor(old.methods[i]);
} }
} }
targetBeanInfo = old.targetBeanInfo; this.targetBeanInfoRef = old.targetBeanInfoRef;
} }
public PropertyDescriptor[] getPropertyDescriptors() { public PropertyDescriptor[] getPropertyDescriptors() {
...@@ -1537,6 +1540,7 @@ class GenericBeanInfo extends SimpleBeanInfo { ...@@ -1537,6 +1540,7 @@ class GenericBeanInfo extends SimpleBeanInfo {
} }
public java.awt.Image getIcon(int iconKind) { public java.awt.Image getIcon(int iconKind) {
BeanInfo targetBeanInfo = this.targetBeanInfoRef.get();
if (targetBeanInfo != null) { if (targetBeanInfo != null) {
return targetBeanInfo.getIcon(iconKind); return targetBeanInfo.getIcon(iconKind);
} }
......
/** /**
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -38,6 +38,7 @@ import infos.ThirdBeanBeanInfo; ...@@ -38,6 +38,7 @@ import infos.ThirdBeanBeanInfo;
import java.beans.BeanInfo; import java.beans.BeanInfo;
import java.beans.Introspector; import java.beans.Introspector;
import java.lang.ref.Reference;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
...@@ -61,9 +62,10 @@ public class TestBeanInfo implements Runnable { ...@@ -61,9 +62,10 @@ public class TestBeanInfo implements Runnable {
try { try {
actual = Introspector.getBeanInfo(type); actual = Introspector.getBeanInfo(type);
type = actual.getClass(); type = actual.getClass();
Field field = type.getDeclaredField("targetBeanInfo"); // NON-NLS: field name Field field = type.getDeclaredField("targetBeanInfoRef"); // NON-NLS: field name
field.setAccessible(true); field.setAccessible(true);
actual = (BeanInfo) field.get(actual); Reference ref = (Reference) field.get(actual);
actual = (BeanInfo) ref.get();
} }
catch (Exception exception) { catch (Exception exception) {
throw new Error("unexpected error", exception); throw new Error("unexpected error", exception);
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -24,9 +24,9 @@ ...@@ -24,9 +24,9 @@
/* /*
* @test * @test
* @bug 5102804 * @bug 5102804
* @ignore This test is not predictable with regards to GC
* @summary Tests memory leak * @summary Tests memory leak
* @author Sergey Malenkov * @author Sergey Malenkov
* @run main/othervm -ms16m -mx16m Test5102804
*/ */
import java.beans.BeanInfo; import java.beans.BeanInfo;
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
* @bug 4646747 * @bug 4646747
* @summary Tests that persistence delegate is correct after memory stress * @summary Tests that persistence delegate is correct after memory stress
* @author Mark Davidson * @author Mark Davidson
* @run main/othervm -ms16m -mx16m Test4646747
*/ */
import java.beans.DefaultPersistenceDelegate; import java.beans.DefaultPersistenceDelegate;
...@@ -41,11 +42,14 @@ public class Test4646747 { ...@@ -41,11 +42,14 @@ public class Test4646747 {
encoder.setPersistenceDelegate(Test4646747.class, new MyPersistenceDelegate()); encoder.setPersistenceDelegate(Test4646747.class, new MyPersistenceDelegate());
// WARNING: This can eat up a lot of memory // WARNING: This can eat up a lot of memory
Object[] obs = new Object[10000]; Object[] obs = new Object[10000];
for (int i = 0; i < obs.length; i++) { while (obs != null) {
obs[i] = new int[1000]; try {
obs = new Object[obs.length + obs.length / 3];
}
catch (OutOfMemoryError error) {
obs = null;
}
} }
System.gc();
System.gc();
PersistenceDelegate pd = encoder.getPersistenceDelegate(Test4646747.class); PersistenceDelegate pd = encoder.getPersistenceDelegate(Test4646747.class);
if (!(pd instanceof MyPersistenceDelegate)) if (!(pd instanceof MyPersistenceDelegate))
throw new Error("persistence delegate has been lost"); throw new Error("persistence delegate has been lost");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册