1 /* 2 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 /** 26 * @test 27 * @bug 7068051 28 * @summary SIGSEGV in PhaseIdealLoop::build_loop_late_post on T5440 29 * @library /testlibrary 30 * @modules java.base/jdk.internal.misc 31 * java.management 32 * 33 * @run main/othervm -showversion -Xbatch compiler.c2.Test7068051 34 */ 35 36 package compiler.c2; 37 38 import jdk.test.lib.JDKToolLauncher; 39 import jdk.test.lib.OutputAnalyzer; 40 41 import java.io.IOException; 42 import java.io.InputStream; 43 import java.nio.file.Files; 44 import java.nio.file.Path; 45 import java.nio.file.Paths; 46 import java.nio.file.StandardCopyOption; 47 import java.util.ArrayList; 48 import java.util.Enumeration; 49 import java.util.List; 50 import java.util.zip.ZipEntry; 51 import java.util.zip.ZipFile; 52 53 public class Test7068051 { 54 private static final String SELF_NAME = Test7068051.class.getSimpleName(); 55 private static final String SELF_FILE_NAME = SELF_NAME + ".java"; 56 private static final String JAR_NAME = "foo.jar"; 57 private static final String TEST_PATH = System.getProperty("test.src"); 58 private static final Path CURRENT_DIR = Paths.get("."); 59 private static final Path TEST_SOURCE_PATH = Paths.get(TEST_PATH, SELF_FILE_NAME); 60 61 public static void main (String[] args) throws IOException { 62 createTestJarFile(); 63 System.out.println("Running test..."); 64 65 try (ZipFile zf = new ZipFile(JAR_NAME)) { 66 67 Enumeration<? extends ZipEntry> entries = zf.entries(); 68 ArrayList<String> names = new ArrayList<String>(); 69 while (entries.hasMoreElements()) { 70 names.add(entries.nextElement().getName()); 71 } 72 73 byte[] bytes = new byte[16]; 74 for (String name : names) { 75 ZipEntry e = zf.getEntry(name); 76 77 if (e.isDirectory()) { 78 continue; 79 } 80 81 try (final InputStream is = zf.getInputStream(e)) { 82 try { 83 while (is.read(bytes) >= 0) { 84 } 85 } catch (IOException x) { 86 System.out.println(".................................."); 87 System.out.println(" --> is :" + is); 88 System.out.println(" is.hash :" + is.hashCode()); 89 System.out.println(); 90 System.out.println(" e.name :" + e.getName()); 91 System.out.println(" e.hash :" + e.hashCode()); 92 System.out.println(" e.method :" + e.getMethod()); 93 System.out.println(" e.size :" + e.getSize()); 94 System.out.println(" e.csize :" + e.getCompressedSize()); 95 System.out.println(".................................."); 96 97 throw new AssertionError("IOException was throwing while read the archive. Test failed.", x); 98 } 99 } 100 } 101 } 102 System.out.println("Test passed."); 103 } 104 105 private static void createTestJarFile() { 106 ArrayList<String> jarOptions = new ArrayList<>(); 107 108 // jar cf foo.jar * 109 System.out.println("Creating jar file.."); 110 jarOptions.add("cf"); 111 jarOptions.add(JAR_NAME); 112 try { 113 for (int i = 0; i < 100; ++i) { 114 Path temp = Files.createTempFile(CURRENT_DIR, SELF_NAME, ".java"); 115 Files.copy(TEST_SOURCE_PATH, temp, StandardCopyOption.REPLACE_EXISTING); 116 jarOptions.add(temp.toString()); 117 } 118 } catch (IOException ex) { 119 throw new AssertionError("TESTBUG: Creating temp files failed.", ex); 120 } 121 runJar(jarOptions); 122 123 // jar -uf0 foo.jar Test7068051.java 124 System.out.println("Adding unpacked file..."); 125 jarOptions.clear(); 126 jarOptions.add("-uf0"); 127 jarOptions.add(JAR_NAME); 128 jarOptions.add(TEST_SOURCE_PATH.toString()); 129 runJar(jarOptions); 130 } 131 132 private static void runJar(List<String> params) { 133 JDKToolLauncher jar = JDKToolLauncher.create("jar"); 134 for (String p : params) { 135 jar.addToolArg(p); 136 } 137 ProcessBuilder pb = new ProcessBuilder(jar.getCommand()); 138 try { 139 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 140 output.shouldHaveExitValue(0); 141 } catch (IOException ex) { 142 throw new AssertionError("TESTBUG: jar failed.", ex); 143 } 144 } 145 }