changeset 2018:73b9ce7485d3

Backport of 6795356
author Denis Lila <dlila@redhat.com>
date Mon, 13 Dec 2010 18:05:36 -0500
parents c7fb03394c5b
children af20d64bc8b9
files ChangeLog Makefile.am NEWS patches/openjdk/6795356-proxylazyvalue-leak.patch
diffstat 4 files changed, 333 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Dec 10 14:43:53 2010 -0500
+++ b/ChangeLog	Mon Dec 13 18:05:36 2010 -0500
@@ -1,3 +1,11 @@
+2010-12-13  Denis Lila <dlila@redhat.com>
+
+	Backport S6795356.
+	* NEWS: Updated with fixes.
+	* Makefile.am: Apply patch.
+	* patches/openjdk/patches/openjdk/6795356-proxylazyvalue-leak.patch: New file. Backport
+	of S6795356, and fix for S7004655 and PR590.
+
 2010-12-10  Omair Majid  <omajid@redhat.com>
 
 	Backport S4356282, S6954424, RH525870.
--- a/Makefile.am	Fri Dec 10 14:43:53 2010 -0500
+++ b/Makefile.am	Mon Dec 13 18:05:36 2010 -0500
@@ -379,7 +379,8 @@
 	patches/openjdk/6967436-6976265-6967434-pisces.patch \
 	patches/openjdk/6438179-systray_check.patch \
 	patches/openjdk/4356282-opentype.patch \
-	patches/openjdk/6954424-opentype_javadoc.patch
+	patches/openjdk/6954424-opentype_javadoc.patch \
+	patches/openjdk/6795356-proxylazyvalue-leak.patch
 
 if WITH_ALT_HSBUILD
 ICEDTEA_PATCHES += patches/hotspot/$(HSBUILD)/openjdk-6886353-ignore_deoptimizealot.patch \
--- a/NEWS	Fri Dec 10 14:43:53 2010 -0500
+++ b/NEWS	Mon Dec 13 18:05:36 2010 -0500
@@ -13,6 +13,9 @@
   - S6438179, RH569121: XToolkit.isTraySupported() result has nothing to do with the system tray
   - S4356282: RFE: JDK should support OpenType/CFF fonts
   - S6954424, RH525870: Support OpenType/CFF fonts in JDK 7
+  - S6795356: Leak caused by javax.swing.UIDefaults.ProxyLazyValue.acc
+* Fixes:
+  - S7004655, PR590: Unable to activate (click) checkboxes in jtable
 
 New in release 1.7.6 (2010-11-24):
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/openjdk/6795356-proxylazyvalue-leak.patch	Mon Dec 13 18:05:36 2010 -0500
@@ -0,0 +1,320 @@
+diff -Nr --unified=5 ./openjdk.old/jdk/src/share/classes/javax/swing/JTable.java ./openjdk/jdk/src/share/classes/javax/swing/JTable.java
+--- ./openjdk.old/jdk/src/share/classes/javax/swing/JTable.java	2010-12-11 15:41:51.203717238 -0500
++++ ./openjdk/jdk/src/share/classes/javax/swing/JTable.java	2010-12-11 15:45:31.417460179 -0500
+@@ -55,10 +55,11 @@
+ 
+ import sun.swing.SwingUtilities2;
+ import sun.swing.SwingUtilities2.Section;
+ import static sun.swing.SwingUtilities2.Section.*;
+ import sun.swing.PrintingStatus;
++import sun.swing.SwingLazyValue;
+ 
+ /**
+  * The <code>JTable</code> is used to display and edit regular two-dimensional tables
+  * of cells.
+  * See <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/table.html">How to Use Tables</a>
+@@ -5248,11 +5249,11 @@
+         }
+         return retValue;
+     }
+ 
+     private void setLazyValue(Hashtable h, Class c, String s) {
+-        h.put(c, new UIDefaults.ProxyLazyValue(s));
++        h.put(c, new SwingLazyValue(s));
+     }
+ 
+     private void setLazyRenderer(Class c, String s) {
+         setLazyValue(defaultRenderersByColumnClass, c, s);
+     }
+diff -Nr --unified=5 ./openjdk.old/jdk/src/share/classes/javax/swing/plaf/metal/OceanTheme.java ./openjdk/jdk/src/share/classes/javax/swing/plaf/metal/OceanTheme.java
+--- ./openjdk.old/jdk/src/share/classes/javax/swing/plaf/metal/OceanTheme.java	2010-12-11 15:41:51.218648213 -0500
++++ ./openjdk/jdk/src/share/classes/javax/swing/plaf/metal/OceanTheme.java	2010-12-11 15:44:52.567448764 -0500
+@@ -30,10 +30,11 @@
+ import java.util.*;
+ import javax.swing.*;
+ import javax.swing.plaf.*;
+ import sun.swing.SwingUtilities2;
+ import sun.swing.PrintColorUIResource;
++import sun.swing.SwingLazyValue;
+ 
+ /**
+  * The default theme for the {@code MetalLookAndFeel}.
+  * <p>
+  * The designers
+@@ -126,11 +127,11 @@
+      *
+      * @param table the defaults table, non-null
+      * @throws NullPointerException if {@code table} is {@code null}
+      */
+     public void addCustomEntriesToTable(UIDefaults table) {
+-        Object focusBorder = new UIDefaults.ProxyLazyValue(
++        Object focusBorder = new SwingLazyValue(
+                       "javax.swing.plaf.BorderUIResource$LineBorderUIResource",
+                       new Object[] {getPrimary1()});
+         // .30 0 DDE8F3 white secondary2
+         java.util.List buttonGradient = Arrays.asList(
+                  new Object[] {new Float(.3f), new Float(0f),
+diff -Nr --unified=5 ./openjdk.old/jdk/src/share/classes/sun/swing/SwingLazyValue.java ./openjdk/jdk/src/share/classes/sun/swing/SwingLazyValue.java
+--- ./openjdk.old/jdk/src/share/classes/sun/swing/SwingLazyValue.java	2010-12-11 15:41:51.181648174 -0500
++++ ./openjdk/jdk/src/share/classes/sun/swing/SwingLazyValue.java	2010-12-11 15:48:07.460461645 -0500
+@@ -24,10 +24,13 @@
+  */
+ package sun.swing;
+ 
+ import java.lang.reflect.Constructor;
+ import java.lang.reflect.Method;
++import java.lang.reflect.AccessibleObject;
++import java.security.AccessController;
++import java.security.PrivilegedAction; 
+ import javax.swing.UIDefaults;
+ 
+ /**
+  * SwingLazyValue is a copy of ProxyLazyValue that does not snapshot the
+  * AccessControlContext or use a doPrivileged to resolve the class name.
+@@ -64,26 +67,37 @@
+             Object cl;
+             c = Class.forName(className, true, null);
+             if (methodName != null) {
+                 Class[] types = getClassArray(args);
+                 Method m = c.getMethod(methodName, types);
++                makeAccessible(m);
+                 return m.invoke(c, args);
+             } else {
+                 Class[] types = getClassArray(args);
+                 Constructor constructor = c.getConstructor(types);
++                makeAccessible(constructor);
+                 return constructor.newInstance(args);
+             }
+-        } catch(Exception e) {
++        } catch (Exception e) {
+             // Ideally we would throw an exception, unfortunately
+             // often times there are errors as an initial look and
+             // feel is loaded before one can be switched. Perhaps a
+             // flag should be added for debugging, so that if true
+             // the exception would be thrown.
+         }
+         return null;
+     }
+ 
++    private void makeAccessible(final AccessibleObject object) {
++        AccessController.doPrivileged(new PrivilegedAction<Void>() {
++            public Void run() {
++                object.setAccessible(true);
++                return null;
++            }
++        });
++    } 
++
+     private Class[] getClassArray(Object[] args) {
+         Class[] types = null;
+         if (args!=null) {
+             types = new Class[args.length];
+             for (int i = 0; i< args.length; i++) {
+diff -Nr --unified=5 ./openjdk.old/jdk/test/javax/swing/UIDefaults/6795356/bug6795356.java ./openjdk/jdk/test/javax/swing/UIDefaults/6795356/bug6795356.java
+--- ./openjdk.old/jdk/test/javax/swing/UIDefaults/6795356/bug6795356.java	1969-12-31 19:00:00.000000000 -0500
++++ ./openjdk/jdk/test/javax/swing/UIDefaults/6795356/bug6795356.java	2010-12-11 15:41:51.244638297 -0500
+@@ -0,0 +1,100 @@
++/*
++ * Copyright (c) 2009, 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 6795356
++ * @summary Leak caused by javax.swing.UIDefaults.ProxyLazyValue.acc
++ * @author Alexander Potochkin
++ * @run main bug6795356
++ */
++
++import java.lang.ref.WeakReference;
++import java.security.ProtectionDomain;
++import java.security.AccessController;
++import java.security.PrivilegedAction;
++import java.security.AccessControlContext;
++import java.util.LinkedList;
++import java.util.List;
++import javax.swing.*;
++
++public class bug6795356 {
++    volatile static WeakReference<ProtectionDomain> weakRef;
++
++    public static void main(String[] args) throws Exception {
++
++        ProtectionDomain domain = new ProtectionDomain(null, null);
++
++        AccessController.doPrivileged(new PrivilegedAction<Object>() {
++            public Object run() {
++
++                // this initialize ProxyLazyValues
++                UIManager.getLookAndFeel();
++
++                return null;
++            }
++        }, new AccessControlContext(new ProtectionDomain[]{domain}));
++
++        weakRef = new WeakReference<ProtectionDomain>(domain);
++        domain = null;
++
++        // Generate OutOfMemory and check the weak ref
++        generateOOME();
++
++        if (weakRef.get() != null) {
++            throw new RuntimeException("Memory leak found!");
++        }
++        System.out.println("Test passed");
++    }
++
++    static void generateOOME() {
++        List<Object> bigLeak = new LinkedList<Object>();
++        boolean oome = false;
++        System.out.print("Filling the heap");
++        try {
++            for(int i = 0; true ; i++) {
++                // Now, use up all RAM
++                bigLeak.add(new byte[1024 * 1024]);
++                System.out.print(".");
++
++                // Give the GC a change at that weakref
++                if (i % 10 == 0) {
++                    System.gc();
++                    try {
++                        Thread.sleep(100);
++                    } catch (InterruptedException e) {
++                        e.printStackTrace();
++                    }
++                }
++            }
++        } catch (OutOfMemoryError e) {
++            bigLeak = null;
++            oome = true;
++        }
++        System.out.println("");
++        if (!oome) {
++            throw new RuntimeException("Problem with test case - never got OOME");
++        }
++        System.out.println("Got OOME");
++    }
++}
+diff -Nr --unified=5 ./openjdk.old/jdk/test/javax/swing/UIDefaults/6795356/SwingLazyValueTest.java ./openjdk/jdk/test/javax/swing/UIDefaults/6795356/SwingLazyValueTest.java
+--- ./openjdk.old/jdk/test/javax/swing/UIDefaults/6795356/SwingLazyValueTest.java	1969-12-31 19:00:00.000000000 -0500
++++ ./openjdk/jdk/test/javax/swing/UIDefaults/6795356/SwingLazyValueTest.java	2010-12-11 15:41:51.229699508 -0500
+@@ -0,0 +1,44 @@
++/*
++ * Copyright (c) 2009, 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 6795356
++ * @summary Checks that SwingLazyValue class correclty works
++ * @author Alexander Potochkin
++ * @run main SwingLazyValueTest
++ */
++
++import sun.swing.SwingLazyValue;
++
++import javax.swing.*;
++
++public class SwingLazyValueTest {
++
++    public static void main(String[] args) throws Exception {
++        if(new SwingLazyValue("javax.swing.JTable$DoubleRenderer").
++                createValue(null) == null) {
++            throw new RuntimeException("SwingLazyValue doesn't work");
++        }
++    }
++}
+diff -Nr --unified=5 ./openjdk.old/jdk/test/javax/swing/UIDefaults/6795356/TableTest.java ./openjdk/jdk/test/javax/swing/UIDefaults/6795356/TableTest.java
+--- ./openjdk.old/jdk/test/javax/swing/UIDefaults/6795356/TableTest.java	1969-12-31 19:00:00.000000000 -0500
++++ ./openjdk/jdk/test/javax/swing/UIDefaults/6795356/TableTest.java	2010-12-11 15:41:51.236636317 -0500
+@@ -0,0 +1,52 @@
++/*
++ * Copyright (c) 2009, 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 6795356
++ * @summary Checks that SwingLazyValue class correclty works
++ * @author Alexander Potochkin
++ * @run main/othervm TableTest
++ */
++
++import sun.applet.AppletSecurity;
++
++import javax.swing.*;
++import javax.swing.table.TableCellEditor;
++import java.awt.*;
++
++public class TableTest {
++
++    public static void main(String[] args) throws Exception {
++
++        KeyboardFocusManager.getCurrentKeyboardFocusManager();
++        System.setSecurityManager(new AppletSecurity());
++
++        JTable table = new JTable();
++        TableCellEditor de = table.getDefaultEditor(Double.class);
++        if (de == null) {
++            throw new RuntimeException("Table default editor is null");
++        }
++    }
++}
++