7064279: Introspector.getBeanInfo() should release some resources in timely manner

Reviewed-by: art, alexp
This commit is contained in:
Sergey Malenkov 2011-11-10 17:27:40 +04:00
parent 66bc904d36
commit 0fdddc243e
11 changed files with 230 additions and 97 deletions

View file

@ -29,7 +29,6 @@
*/
import java.beans.Beans;
import sun.awt.SunToolkit;
public class TestDesignTime implements Runnable {
public static void main(String[] args) throws InterruptedException {
@ -44,7 +43,6 @@ public class TestDesignTime implements Runnable {
}
public void run() {
SunToolkit.createNewAppContext();
if (Beans.isDesignTime()) {
throw new Error("shared DesignTime property");
}

View file

@ -30,7 +30,6 @@
import java.awt.GraphicsEnvironment;
import java.beans.Beans;
import sun.awt.SunToolkit;
public class TestGuiAvailable implements Runnable {
public static void main(String[] args) throws InterruptedException {
@ -45,7 +44,6 @@ public class TestGuiAvailable implements Runnable {
}
public void run() {
SunToolkit.createNewAppContext();
if (Beans.isGuiAvailable() == GraphicsEnvironment.isHeadless()) {
throw new Error("shared GuiAvailable property");
}

View file

@ -41,8 +41,6 @@ import java.beans.Introspector;
import java.lang.ref.Reference;
import java.lang.reflect.Field;
import sun.awt.SunToolkit;
public class TestBeanInfo implements Runnable {
private static final String[] SEARCH_PATH = { "infos" }; // NON-NLS: package name
@ -81,9 +79,6 @@ public class TestBeanInfo implements Runnable {
private boolean passed;
public void run() {
if (this.passed) {
SunToolkit.createNewAppContext();
}
Introspector.flushCaches();
test(FirstBean.class, FirstBeanBeanInfo.class);
@ -98,7 +93,5 @@ public class TestBeanInfo implements Runnable {
test(SecondBean.class, SecondBeanBeanInfo.class);
test(ThirdBean.class, null);
test(ThirdBeanBeanInfo.class, ThirdBeanBeanInfo.class);
this.passed = true;
}
}

View file

@ -0,0 +1,75 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7064279
* @summary Tests that Introspector does not have strong references to context class loader
* @author Sergey Malenkov
*/
import java.beans.Introspector;
import java.io.File;
import java.lang.ref.WeakReference;
import java.net.URL;
import java.net.URLClassLoader;
public class Test7064279 {
public static void main(String[] args) throws Exception {
WeakReference ref = new WeakReference(test("test.jar", "test.Test"));
try {
int[] array = new int[1024];
while (true) {
array = new int[array.length << 1];
}
}
catch (OutOfMemoryError error) {
System.gc();
}
if (null != ref.get()) {
throw new Error("ClassLoader is not released");
}
}
private static Object test(String jarName, String className) throws Exception {
StringBuilder sb = new StringBuilder(256);
sb.append("file:");
sb.append(System.getProperty("test.src", "."));
sb.append(File.separatorChar);
sb.append(jarName);
ClassLoader newLoader = new URLClassLoader(new URL[] { new URL(sb.toString()) });
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(newLoader);
test(newLoader.loadClass(className));
Thread.currentThread().setContextClassLoader(oldLoader);
return newLoader;
}
private static void test(Class type) throws Exception {
Introspector.getBeanInfo(type);
}
}

Binary file not shown.

View file

@ -28,8 +28,6 @@
* @author Sergey Malenkov
*/
import sun.awt.SunToolkit;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
@ -49,7 +47,6 @@ public class Test6660539 implements Runnable {
}
public void run() {
SunToolkit.createNewAppContext();
for (PropertyDescriptor pd : getPropertyDescriptors()) {
if (pd.getDisplayName().equals(NAME))
throw new Error("shared BeanInfo cache");

View file

@ -36,7 +36,6 @@ import java.awt.Font;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
import sun.awt.SunToolkit;
import sun.beans.editors.BooleanEditor;
import sun.beans.editors.ByteEditor;
import sun.beans.editors.ColorEditor;
@ -77,12 +76,7 @@ public class TestPropertyEditor implements Runnable {
}
}
private boolean passed;
public void run() {
if (this.passed) {
SunToolkit.createNewAppContext();
}
PropertyEditorManager.registerEditor(ThirdBean.class, ThirdBeanEditor.class);
test(FirstBean.class, FirstBeanEditor.class);
@ -135,7 +129,5 @@ public class TestPropertyEditor implements Runnable {
test(Color.class, null);
test(Font.class, null);
test(Enumeration.class, EnumEditor.class);
this.passed = true;
}
}