jdk/test/sun/awt/font/ClassLoaderLeakTest.java
author stefank
Mon, 04 Apr 2016 09:15:01 +0200
changeset 37241 b9961c99c356
parent 5506 202f599c92aa
permissions -rw-r--r--
8152538: UL doesn't inline the LogTagSet::is_level check Reviewed-by: mlarsson, brutisso
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5275
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5275
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
5275
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
     4
 *
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
     7
 * published by the Free Software Foundation.
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
     8
 *
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    13
 * accompanied this code).
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    14
 *
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5275
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5275
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5275
diff changeset
    21
 * questions.
5275
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    22
 */
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    23
/**
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    24
 * @test
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    25
 * @bug     6936389
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    26
 *
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    27
 * @summary Test verifes that LogManager shutdown hook does not cause
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    28
 *          an application classloader leaks.
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    29
 *
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    30
 * @run     main/othervm ClassLoaderLeakTest FontManagerTest
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    31
 */
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    32
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    33
import java.awt.Font;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    34
import java.awt.Graphics;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    35
import java.io.File;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    36
import java.lang.ref.WeakReference;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    37
import java.lang.reflect.Constructor;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    38
import java.lang.reflect.Method;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    39
import java.net.MalformedURLException;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    40
import java.net.URL;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    41
import java.net.URLClassLoader;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    42
import java.util.concurrent.CountDownLatch;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    43
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    44
public class ClassLoaderLeakTest {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    45
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    46
    private static CountDownLatch doneSignal;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    47
    private static CountDownLatch launchSignal;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    48
    private static Throwable launchFailure = null;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    49
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    50
    public static void main(String[] args) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    51
        doneSignal = new CountDownLatch(1);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    52
        launchSignal = new CountDownLatch(1);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    53
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    54
        String testcase = "FontManagerTest";
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    55
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    56
        if (args.length > 0) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    57
            testcase = args[0];
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    58
        }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    59
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    60
        /* prepare test  class loader */
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    61
        URL pwd = null;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    62
        try {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    63
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    64
            pwd = new File(System.getProperty("test.classes", ".")).toURL();
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    65
        } catch (MalformedURLException e) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    66
            throw new RuntimeException("Test failed.", e);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    67
        }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    68
        System.out.println("PWD: " + pwd);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    69
        URL[] urls = new URL[]{pwd};
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    70
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    71
        MyClassLoader appClassLoader = new MyClassLoader(urls, "test0");
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    72
        WeakReference<MyClassLoader> ref =
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    73
            new WeakReference<MyClassLoader>(appClassLoader);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    74
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    75
        ThreadGroup appsThreadGroup = new ThreadGroup("MyAppsThreadGroup");
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    76
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    77
        Runnable launcher = new TestLauncher(testcase);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    78
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    79
        Thread appThread = new Thread(appsThreadGroup, launcher, "AppThread-0");
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    80
        appThread.setContextClassLoader(appClassLoader);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    81
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    82
        appThread.start();
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    83
        appsThreadGroup = null;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    84
        appClassLoader = null;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    85
        launcher = null;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    86
        appThread = null;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    87
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    88
        /* wait for laucnh completion */
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    89
        try {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    90
            launchSignal.await();
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    91
        } catch (InterruptedException e) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    92
        }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    93
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    94
        /* check if launch failed */
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    95
        if (launchFailure != null) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    96
            throw new RuntimeException("Test failed.", launchFailure);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    97
        }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    98
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
    99
        /* wait for test app excution completion */
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   100
        try {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   101
            doneSignal.await();
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   102
        } catch (InterruptedException e) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   103
        }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   104
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   105
        /* give a chance to GC */
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   106
        waitAndGC(9);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   107
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   108
        if (ref.get() != null) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   109
            throw new RuntimeException("Test failed: classloader is still alive");
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   110
        }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   111
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   112
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   113
        System.out.println("Test passed.");
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   114
    }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   115
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   116
    private static class TestLauncher implements Runnable {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   117
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   118
        private String className;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   119
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   120
        public TestLauncher(String name) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   121
            className = name;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   122
        }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   123
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   124
        public void run() {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   125
            try {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   126
                ClassLoader cl =
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   127
                    Thread.currentThread().getContextClassLoader();
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   128
                Class appMain = cl.loadClass(className);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   129
                Method launch =
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   130
                    appMain.getMethod("launch", doneSignal.getClass());
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   131
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   132
                Constructor c = appMain.getConstructor();
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   133
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   134
                Object o = c.newInstance();
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   135
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   136
                launch.invoke(o, doneSignal);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   137
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   138
            } catch (Throwable e) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   139
                launchFailure = e;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   140
            } finally {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   141
                launchSignal.countDown();
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   142
            }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   143
        }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   144
    }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   145
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   146
    private static class MyClassLoader extends URLClassLoader {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   147
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   148
        private static boolean verbose =
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   149
            Boolean.getBoolean("verboseClassLoading");
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   150
        private String uniqClassName;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   151
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   152
        public MyClassLoader(URL[] urls, String uniq) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   153
            super(urls);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   154
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   155
            uniqClassName = uniq;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   156
        }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   157
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   158
        public Class loadClass(String name) throws ClassNotFoundException {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   159
            if (verbose) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   160
                System.out.printf("%s: load class %s\n", uniqClassName, name);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   161
            }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   162
            if (uniqClassName.equals(name)) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   163
                return Object.class;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   164
            }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   165
            return super.loadClass(name);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   166
        }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   167
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   168
        public String toString() {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   169
            return "MyClassLoader(" + uniqClassName + ")";
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   170
        }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   171
    }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   172
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   173
    private static void waitAndGC(int sec) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   174
        int cnt = sec;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   175
        System.out.print("Wait ");
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   176
        while (cnt-- > 0) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   177
            try {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   178
                Thread.sleep(1000);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   179
            } catch (InterruptedException e) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   180
            }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   181
            // do GC every 3 seconds
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   182
            if (cnt % 3 == 2) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   183
                System.gc();
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   184
                System.out.print("+");
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   185
            } else {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   186
                System.out.print(".");
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   187
            }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   188
            //checkErrors();
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   189
        }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   190
        System.out.println("");
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   191
    }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   192
}
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   193
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   194
abstract class AppTest {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   195
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   196
    public AppTest() {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   197
    }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   198
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   199
    protected abstract void doTest();
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   200
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   201
    public void launch(CountDownLatch done) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   202
        System.out.println("Testcase: " + this.getClass().getName());
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   203
        try {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   204
            doTest();
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   205
        } finally {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   206
            done.countDown();
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   207
        }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   208
    }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   209
}
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   210
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   211
class FontManagerTest extends AppTest {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   212
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   213
    public FontManagerTest() {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   214
    }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   215
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   216
    protected void doTest() {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   217
        Font f = new Font(Font.SANS_SERIF, Font.ITALIC, 24);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   218
        f.getNumGlyphs();
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   219
    }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
diff changeset
   220
}