mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-11 23:48:38 +00:00
6921057: REGRESSION: persistence delegate issue on Windows and Linux against 5.u23b03/6u17b11
Reviewed-by: peterz, art
This commit is contained in:
parent
2eabbe8ed9
commit
81397ffe98
@ -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.WeakCache;
|
||||
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.Iterator;
|
||||
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 @@ public class Introspector {
|
||||
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 class Introspector {
|
||||
|
||||
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 @@ public class Introspector {
|
||||
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 @@ class GenericBeanInfo extends SimpleBeanInfo {
|
||||
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 @@ class GenericBeanInfo extends SimpleBeanInfo {
|
||||
this.properties = properties;
|
||||
this.defaultProperty = defaultProperty;
|
||||
this.methods = methods;
|
||||
this.targetBeanInfo = targetBeanInfo;
|
||||
this.targetBeanInfoRef = new SoftReference<BeanInfo>(targetBeanInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1509,7 +1512,7 @@ class GenericBeanInfo extends SimpleBeanInfo {
|
||||
methods[i] = new MethodDescriptor(old.methods[i]);
|
||||
}
|
||||
}
|
||||
targetBeanInfo = old.targetBeanInfo;
|
||||
this.targetBeanInfoRef = old.targetBeanInfoRef;
|
||||
}
|
||||
|
||||
public PropertyDescriptor[] getPropertyDescriptors() {
|
||||
@ -1537,6 +1540,7 @@ class GenericBeanInfo extends SimpleBeanInfo {
|
||||
}
|
||||
|
||||
public java.awt.Image getIcon(int iconKind) {
|
||||
BeanInfo targetBeanInfo = this.targetBeanInfoRef.get();
|
||||
if (targetBeanInfo != null) {
|
||||
return targetBeanInfo.getIcon(iconKind);
|
||||
}
|
||||
|
||||
@ -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 infos.ThirdBeanBeanInfo;
|
||||
|
||||
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 @@ public class TestBeanInfo implements Runnable {
|
||||
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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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 @@ public class Test4646747 {
|
||||
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");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user