|
1 /* |
|
2 * Copyright (c) 2011, 2016, 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 * @test |
|
26 * @bug 7068051 |
|
27 * @summary SIGSEGV in PhaseIdealLoop::build_loop_late_post on T5440 |
|
28 * @library /test/lib |
|
29 * @modules java.base/jdk.internal.misc |
|
30 * java.management |
|
31 * |
|
32 * @run main/othervm -showversion -Xbatch compiler.c2.Test7068051 |
|
33 */ |
|
34 |
|
35 package compiler.c2; |
|
36 |
|
37 import jdk.test.lib.JDKToolLauncher; |
|
38 import jdk.test.lib.process.OutputAnalyzer; |
|
39 |
|
40 import java.io.IOException; |
|
41 import java.io.InputStream; |
|
42 import java.nio.file.Files; |
|
43 import java.nio.file.Path; |
|
44 import java.nio.file.Paths; |
|
45 import java.nio.file.StandardCopyOption; |
|
46 import java.util.ArrayList; |
|
47 import java.util.Enumeration; |
|
48 import java.util.List; |
|
49 import java.util.zip.ZipEntry; |
|
50 import java.util.zip.ZipFile; |
|
51 |
|
52 public class Test7068051 { |
|
53 private static final String SELF_NAME = Test7068051.class.getSimpleName(); |
|
54 private static final String SELF_FILE_NAME = SELF_NAME + ".java"; |
|
55 private static final String JAR_NAME = "foo.jar"; |
|
56 private static final String TEST_PATH = System.getProperty("test.src"); |
|
57 private static final Path CURRENT_DIR = Paths.get("."); |
|
58 private static final Path TEST_SOURCE_PATH = Paths.get(TEST_PATH, SELF_FILE_NAME); |
|
59 |
|
60 public static void main (String[] args) throws IOException { |
|
61 createTestJarFile(); |
|
62 System.out.println("Running test..."); |
|
63 |
|
64 try (ZipFile zf = new ZipFile(JAR_NAME)) { |
|
65 |
|
66 Enumeration<? extends ZipEntry> entries = zf.entries(); |
|
67 ArrayList<String> names = new ArrayList<String>(); |
|
68 while (entries.hasMoreElements()) { |
|
69 names.add(entries.nextElement().getName()); |
|
70 } |
|
71 |
|
72 byte[] bytes = new byte[16]; |
|
73 for (String name : names) { |
|
74 ZipEntry e = zf.getEntry(name); |
|
75 |
|
76 if (e.isDirectory()) { |
|
77 continue; |
|
78 } |
|
79 |
|
80 try (final InputStream is = zf.getInputStream(e)) { |
|
81 try { |
|
82 while (is.read(bytes) >= 0) { |
|
83 } |
|
84 } catch (IOException x) { |
|
85 System.out.println(".................................."); |
|
86 System.out.println(" --> is :" + is); |
|
87 System.out.println(" is.hash :" + is.hashCode()); |
|
88 System.out.println(); |
|
89 System.out.println(" e.name :" + e.getName()); |
|
90 System.out.println(" e.hash :" + e.hashCode()); |
|
91 System.out.println(" e.method :" + e.getMethod()); |
|
92 System.out.println(" e.size :" + e.getSize()); |
|
93 System.out.println(" e.csize :" + e.getCompressedSize()); |
|
94 System.out.println(".................................."); |
|
95 |
|
96 throw new AssertionError("IOException was throwing while read the archive. Test failed.", x); |
|
97 } |
|
98 } |
|
99 } |
|
100 } |
|
101 System.out.println("Test passed."); |
|
102 } |
|
103 |
|
104 private static void createTestJarFile() { |
|
105 ArrayList<String> jarOptions = new ArrayList<>(); |
|
106 |
|
107 // jar cf foo.jar * |
|
108 System.out.println("Creating jar file.."); |
|
109 jarOptions.add("cf"); |
|
110 jarOptions.add(JAR_NAME); |
|
111 try { |
|
112 for (int i = 0; i < 100; ++i) { |
|
113 Path temp = Files.createTempFile(CURRENT_DIR, SELF_NAME, ".java"); |
|
114 Files.copy(TEST_SOURCE_PATH, temp, StandardCopyOption.REPLACE_EXISTING); |
|
115 jarOptions.add(temp.toString()); |
|
116 } |
|
117 } catch (IOException ex) { |
|
118 throw new AssertionError("TESTBUG: Creating temp files failed.", ex); |
|
119 } |
|
120 runJar(jarOptions); |
|
121 |
|
122 // jar -uf0 foo.jar Test7068051.java |
|
123 System.out.println("Adding unpacked file..."); |
|
124 jarOptions.clear(); |
|
125 jarOptions.add("-uf0"); |
|
126 jarOptions.add(JAR_NAME); |
|
127 jarOptions.add(TEST_SOURCE_PATH.toString()); |
|
128 runJar(jarOptions); |
|
129 } |
|
130 |
|
131 private static void runJar(List<String> params) { |
|
132 JDKToolLauncher jar = JDKToolLauncher.create("jar"); |
|
133 for (String p : params) { |
|
134 jar.addToolArg(p); |
|
135 } |
|
136 ProcessBuilder pb = new ProcessBuilder(jar.getCommand()); |
|
137 try { |
|
138 OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
|
139 output.shouldHaveExitValue(0); |
|
140 } catch (IOException ex) { |
|
141 throw new AssertionError("TESTBUG: jar failed.", ex); |
|
142 } |
|
143 } |
|
144 } |