test/jdk/tools/pack200/UnpackerMemoryTest.java
author lancea
Thu, 14 Nov 2019 10:54:32 -0500
changeset 59083 3e4d8b5856f3
parent 47216 71c04702a3d5
permissions -rw-r--r--
8234080: jdk/nio/zipfs/CRCWriteTest.java fails Reviewed-by: clanger, amlu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6320
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
     1
/*
18594
b6a3c9f71ac8 8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents: 6320
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
6320
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
     4
 *
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
     8
 *
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    13
 * accompanied this code).
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    14
 *
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    18
 *
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    21
 * questions.
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    22
 */
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    23
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    24
/*
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    25
 * @test
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    26
 * @bug 6531345
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    27
 * @summary check for unpacker memory leaks
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    28
 * @compile -XDignore.symbol.file Utils.java UnpackerMemoryTest.java
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    29
 * @run main/othervm/timeout=1200 -Xmx32m UnpackerMemoryTest
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    30
 * @author ksrini
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    31
 */
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    32
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    33
import java.io.File;
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    34
import java.io.FileOutputStream;
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    35
import java.io.PrintStream;
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    36
import java.io.IOException;
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    37
import java.util.jar.JarFile;
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    38
import java.util.jar.JarOutputStream;
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    39
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    40
public class UnpackerMemoryTest {
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    41
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    42
    private static void createPackFile(File packFile) throws IOException {
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    43
        File tFile = new File("test.dat");
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    44
        FileOutputStream fos = null;
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    45
        PrintStream ps = null;
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    46
        String jarFileName = Utils.baseName(packFile, Utils.PACK_FILE_EXT)
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    47
                + Utils.JAR_FILE_EXT;
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    48
        JarFile jarFile = null;
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    49
        try {
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    50
            fos = new FileOutputStream(tFile);
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    51
            ps = new PrintStream(fos);
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    52
            ps.println("A quick brown fox");
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    53
            Utils.jar("cvf", jarFileName, tFile.getName());
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    54
            jarFile = new JarFile(jarFileName);
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    55
            Utils.pack(jarFile, packFile);
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    56
        } finally {
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    57
            Utils.close(ps);
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    58
            tFile.delete();
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    59
            Utils.close(jarFile);
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    60
        }
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    61
    }
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    62
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    63
    public static void main(String[] args) throws Exception {
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    64
        String name = "foo";
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    65
        File packFile = new File(name + Utils.PACK_FILE_EXT);
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    66
        createPackFile(packFile);
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    67
        if (!packFile.exists()) {
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    68
           throw new RuntimeException(packFile + " not found");
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    69
        }
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    70
        File jarOut = new File(name + ".out");
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    71
        for (int i = 0; i < 2000; i++) {
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    72
            JarOutputStream jarOS = null;
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    73
            FileOutputStream fos = null;
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    74
            try {
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    75
                fos = new FileOutputStream(jarOut);
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    76
                jarOS = new JarOutputStream(fos);
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    77
                System.out.println("Unpacking[" + i + "]" + packFile);
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    78
                Utils.unpackn(packFile, jarOS);
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    79
            }  finally {
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    80
                Utils.close(jarOS);
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    81
                Utils.close(fos);
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    82
            }
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    83
        }
18594
b6a3c9f71ac8 8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents: 6320
diff changeset
    84
        Utils.cleanup();
6320
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    85
    }
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    86
}
6b48de58428e 6531345: Memory leak in unpack200
ksrini
parents:
diff changeset
    87