Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/tools/pack200/UnpackerMemoryTest.java
38833 views
/*1* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 653134526* @summary check for unpacker memory leaks27* @compile -XDignore.symbol.file Utils.java UnpackerMemoryTest.java28* @run main/othervm/timeout=1200 -Xmx32m UnpackerMemoryTest29* @author ksrini30*/3132import java.io.File;33import java.io.FileOutputStream;34import java.io.PrintStream;35import java.io.IOException;36import java.util.jar.JarFile;37import java.util.jar.JarOutputStream;3839public class UnpackerMemoryTest {4041private static void createPackFile(File packFile) throws IOException {42File tFile = new File("test.dat");43FileOutputStream fos = null;44PrintStream ps = null;45String jarFileName = Utils.baseName(packFile, Utils.PACK_FILE_EXT)46+ Utils.JAR_FILE_EXT;47JarFile jarFile = null;48try {49fos = new FileOutputStream(tFile);50ps = new PrintStream(fos);51ps.println("A quick brown fox");52Utils.jar("cvf", jarFileName, tFile.getName());53jarFile = new JarFile(jarFileName);54Utils.pack(jarFile, packFile);55} finally {56Utils.close(ps);57tFile.delete();58Utils.close(jarFile);59}60}6162public static void main(String[] args) throws Exception {63String name = "foo";64File packFile = new File(name + Utils.PACK_FILE_EXT);65createPackFile(packFile);66if (!packFile.exists()) {67throw new RuntimeException(packFile + " not found");68}69File jarOut = new File(name + ".out");70for (int i = 0; i < 2000; i++) {71JarOutputStream jarOS = null;72FileOutputStream fos = null;73try {74fos = new FileOutputStream(jarOut);75jarOS = new JarOutputStream(fos);76System.out.println("Unpacking[" + i + "]" + packFile);77Utils.unpackn(packFile, jarOS);78} finally {79Utils.close(jarOS);80Utils.close(fos);81}82}83Utils.cleanup();84}85}86878889