From 733b1d638e5bdcb5aa54df1d0b352cb55a9ac08e Mon Sep 17 00:00:00 2001 From: David Buck Date: Wed, 21 Mar 2012 18:41:42 -0700 Subject: [PATCH 01/53] 7104147: the fix for cr6887286 was not appropriate for backporting Memory leak in the list of ImageObservers watching an object. We use recursion to iterate over the list. So once the list gets too big, we overflow the stack. Fix is to execute a prune operation on ever add, so there is no way we can get indefinite growth of stale nodes. Reviewed-by: prr, flar --- .../classes/sun/awt/image/ImageWatched.java | 3 +- .../sun/awt/image/ImageWatched/AddNoLeak.java | 59 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 jdk/test/sun/awt/image/ImageWatched/AddNoLeak.java diff --git a/jdk/src/share/classes/sun/awt/image/ImageWatched.java b/jdk/src/share/classes/sun/awt/image/ImageWatched.java index 4d7220ac0d1..b740aa1870e 100644 --- a/jdk/src/share/classes/sun/awt/image/ImageWatched.java +++ b/jdk/src/share/classes/sun/awt/image/ImageWatched.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2012, 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 @@ -143,6 +143,7 @@ public abstract class ImageWatched { if (iw != null && !isWatcher(iw)) { watcherList = new WeakLink(iw, watcherList); } + watcherList = watcherList.removeWatcher(null); } public synchronized boolean isWatcher(ImageObserver iw) { diff --git a/jdk/test/sun/awt/image/ImageWatched/AddNoLeak.java b/jdk/test/sun/awt/image/ImageWatched/AddNoLeak.java new file mode 100644 index 00000000000..110a4152f38 --- /dev/null +++ b/jdk/test/sun/awt/image/ImageWatched/AddNoLeak.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2012, 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. + */ + +import java.awt.image.ImageObserver; +import java.awt.image.ImageProducer; +import java.awt.image.ImageConsumer; +import java.awt.Image; +import java.awt.Container; + +/* @test 1.0 12/01/17 + @bug 7104151 + @summary Make sure that we don't leak image observers (or related objects) + @run main/othervm AddNoLeak + @author David Buck +*/ + +public class AddNoLeak { + public static void main(String[] args) { + System.setProperty("java.awt.headless", "true"); + Container cont = new Container(); + Image img = cont.createImage(new DummyImageSource()); + for(int i=0;i < 15000;i++) { + img.getWidth(new ImageObserver() { + public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {return false;} + }); + if (i % 100 == 0) { + System.gc(); + } + } + } + + private static class DummyImageSource implements ImageProducer { + public void addConsumer(ImageConsumer ic){} + public boolean isConsumer(ImageConsumer ic){return false;} + public void removeConsumer(ImageConsumer ic){} + public void startProduction(ImageConsumer ic){} + public void requestTopDownLeftRightResend(ImageConsumer ic){} + } +} From 650337cafa2da5a8e5af657e2ff9345687ab38d4 Mon Sep 17 00:00:00 2001 From: Jonathan Lu Date: Thu, 22 Mar 2012 12:47:39 +0800 Subject: [PATCH 02/53] 7152519: Dependency on non-POSIX header file causes portability problem Reviewed-by: prr, igor --- jdk/src/solaris/native/sun/awt/fontpath.c | 3 --- jdk/src/solaris/native/sun/java2d/opengl/OGLFuncs_md.h | 3 --- jdk/src/solaris/native/sun/java2d/x11/XRBackendNative.c | 1 - 3 files changed, 7 deletions(-) diff --git a/jdk/src/solaris/native/sun/awt/fontpath.c b/jdk/src/solaris/native/sun/awt/fontpath.c index e549b4f11d6..214ecd0b073 100644 --- a/jdk/src/solaris/native/sun/awt/fontpath.c +++ b/jdk/src/solaris/native/sun/awt/fontpath.c @@ -583,9 +583,6 @@ JNIEXPORT jstring JNICALL Java_sun_awt_X11FontManager_getFontPathNative } #include -#if !(defined(__linux__) || defined(MACOSX)) -#include -#endif #include "fontconfig.h" diff --git a/jdk/src/solaris/native/sun/java2d/opengl/OGLFuncs_md.h b/jdk/src/solaris/native/sun/java2d/opengl/OGLFuncs_md.h index 14fe6f166aa..593d32f80dc 100644 --- a/jdk/src/solaris/native/sun/java2d/opengl/OGLFuncs_md.h +++ b/jdk/src/solaris/native/sun/java2d/opengl/OGLFuncs_md.h @@ -27,9 +27,6 @@ #define OGLFuncs_md_h_Included #include -#ifndef MACOSX -#include -#endif #include "jvm_md.h" #include "J2D_GL/glx.h" #include "OGLFuncMacros.h" diff --git a/jdk/src/solaris/native/sun/java2d/x11/XRBackendNative.c b/jdk/src/solaris/native/sun/java2d/x11/XRBackendNative.c index a2b481574ce..0f8d0a83382 100644 --- a/jdk/src/solaris/native/sun/java2d/x11/XRBackendNative.c +++ b/jdk/src/solaris/native/sun/java2d/x11/XRBackendNative.c @@ -70,7 +70,6 @@ typedef struct _XRadialGradient { #ifdef __solaris__ /* Solaris 10 will not have these symbols at runtime */ -#include typedef Picture (*XRenderCreateLinearGradientFuncType) (Display *dpy, From ecc9a141a1133f9afd78c1f61c2d9aa14457cb92 Mon Sep 17 00:00:00 2001 From: David Buck Date: Fri, 30 Mar 2012 10:18:04 -0700 Subject: [PATCH 03/53] 7154822: forward port fix for Bug 13645891 to JDK8 jcmd (1024 byte file size limit issue) Changed so that jcmd breaks input into individual lines and sends each one to the jvm separately. Reviewed-by: dcubed, sla --- .../share/classes/sun/tools/jcmd/JCmd.java | 27 +++--- jdk/test/sun/tools/jcmd/dcmd-big-script.txt | 95 +++++++++++++++++++ jdk/test/sun/tools/jcmd/jcmd-big-script.sh | 70 ++++++++++++++ 3 files changed, 180 insertions(+), 12 deletions(-) create mode 100644 jdk/test/sun/tools/jcmd/dcmd-big-script.txt create mode 100644 jdk/test/sun/tools/jcmd/jcmd-big-script.sh diff --git a/jdk/src/share/classes/sun/tools/jcmd/JCmd.java b/jdk/src/share/classes/sun/tools/jcmd/JCmd.java index b84f1124043..3ec79968fed 100644 --- a/jdk/src/share/classes/sun/tools/jcmd/JCmd.java +++ b/jdk/src/share/classes/sun/tools/jcmd/JCmd.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. *com.sun.tools.attach.AttachNotSupportedException @@ -142,17 +142,20 @@ public class JCmd { // Cast to HotSpotVirtualMachine as this is an // implementation specific method. HotSpotVirtualMachine hvm = (HotSpotVirtualMachine) vm; - try (InputStream in = hvm.executeJCmd(command);) { - // read to EOF and just print output - byte b[] = new byte[256]; - int n; - do { - n = in.read(b); - if (n > 0) { - String s = new String(b, 0, n, "UTF-8"); - System.out.print(s); - } - } while (n > 0); + String lines[] = command .split("\\n"); + for (String line : lines) { + try (InputStream in = hvm.executeJCmd(line);) { + // read to EOF and just print output + byte b[] = new byte[256]; + int n; + do { + n = in.read(b); + if (n > 0) { + String s = new String(b, 0, n, "UTF-8"); + System.out.print(s); + } + } while (n > 0); + } } vm.detach(); } diff --git a/jdk/test/sun/tools/jcmd/dcmd-big-script.txt b/jdk/test/sun/tools/jcmd/dcmd-big-script.txt new file mode 100644 index 00000000000..401d3f2849f --- /dev/null +++ b/jdk/test/sun/tools/jcmd/dcmd-big-script.txt @@ -0,0 +1,95 @@ +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version +VM.version diff --git a/jdk/test/sun/tools/jcmd/jcmd-big-script.sh b/jdk/test/sun/tools/jcmd/jcmd-big-script.sh new file mode 100644 index 00000000000..a101c8cf2a8 --- /dev/null +++ b/jdk/test/sun/tools/jcmd/jcmd-big-script.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +# +# Copyright (c) 2012, 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 7154822 +# @summary test if we can send a file over 1024 bytes large via jcmd -f +# @author David Buck +# +# @library ../common +# @build SimpleApplication ShutdownSimpleApplication +# @run shell jcmd-big-script.sh + +. ${TESTSRC}/../common/CommonSetup.sh +. ${TESTSRC}/../common/ApplicationSetup.sh + +# Start application and use PORTFILE for coordination +PORTFILE="${TESTCLASSES}"/shutdown.port +startApplication SimpleApplication "${PORTFILE}" + +failed=0; + +# -f