author | martin |
Tue, 15 Sep 2015 21:56:04 -0700 | |
changeset 32649 | 2ee9017c7597 |
parent 30046 | cf2c86e1819e |
permissions | -rw-r--r-- |
7815
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
1 |
/* |
22124
8a31f2817571
8030089: java/util/zip/ZipFile/FinalizeZipFile.java intermittently fails with fastdebug builds
alanb
parents:
15295
diff
changeset
|
2 |
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. |
7815
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
4 |
* |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
8 |
* |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
13 |
* accompanied this code). |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
14 |
* |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
18 |
* |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
21 |
* questions. |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
22 |
*/ |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
23 |
|
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
24 |
/* @test |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
25 |
* @bug 7007609 7009618 |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
26 |
* @summary Check that ZipFile objects are always collected |
30046 | 27 |
* @key randomness |
7815
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
28 |
*/ |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
29 |
|
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
30 |
import java.io.*; |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
31 |
import java.util.Random; |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
32 |
import java.util.zip.*; |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
33 |
import java.util.concurrent.CountDownLatch; |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
34 |
|
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
35 |
public class FinalizeZipFile { |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
36 |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30046
diff
changeset
|
37 |
private static final CountDownLatch finalizersDone = new CountDownLatch(3); |
7815
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
38 |
|
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
39 |
private static class InstrumentedZipFile extends ZipFile { |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
40 |
|
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
41 |
public InstrumentedZipFile(File f) throws Exception { |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
42 |
super(f); |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
43 |
System.out.printf("Using %s%n", f.getPath()); |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
44 |
} |
22124
8a31f2817571
8030089: java/util/zip/ZipFile/FinalizeZipFile.java intermittently fails with fastdebug builds
alanb
parents:
15295
diff
changeset
|
45 |
@Override |
7815
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
46 |
protected void finalize() throws IOException { |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
47 |
System.out.printf("Killing %s%n", getName()); |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
48 |
super.finalize(); |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
49 |
finalizersDone.countDown(); |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
50 |
} |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
51 |
} |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
52 |
|
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
53 |
private static void makeGarbage() throws Throwable { |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
54 |
final Random rnd = new Random(); |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
55 |
// Create some ZipFiles. |
27031
2a1bbbaacbe8
8058855: Update java.util.zip tests to work with modular image
alanb
parents:
22124
diff
changeset
|
56 |
// Find some .jar files in test directory. |
2a1bbbaacbe8
8058855: Update java.util.zip tests to work with modular image
alanb
parents:
22124
diff
changeset
|
57 |
final File testdir = new File(System.getProperty("test.src", ".")); |
2a1bbbaacbe8
8058855: Update java.util.zip tests to work with modular image
alanb
parents:
22124
diff
changeset
|
58 |
check(testdir.isDirectory()); |
2a1bbbaacbe8
8058855: Update java.util.zip tests to work with modular image
alanb
parents:
22124
diff
changeset
|
59 |
final File[] jars = testdir.listFiles( |
7815
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
60 |
new FilenameFilter() { |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
61 |
public boolean accept(File dir, String name) { |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
62 |
return name.endsWith(".jar");}}); |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
63 |
check(jars.length > 1); |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
64 |
|
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
65 |
new InstrumentedZipFile(jars[rnd.nextInt(jars.length)]).close(); |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
66 |
new InstrumentedZipFile(jars[rnd.nextInt(jars.length)]).close(); |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
67 |
|
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
68 |
// Create a ZipFile and get an input stream from it |
15295
1d90347088c3
8006773: test/java/util/zip/ZipFile/FinalizeZipFile.java failing intermittently
sherman
parents:
9035
diff
changeset
|
69 |
for (int i = 0; i < jars.length + 10; i++) { |
1d90347088c3
8006773: test/java/util/zip/ZipFile/FinalizeZipFile.java failing intermittently
sherman
parents:
9035
diff
changeset
|
70 |
ZipFile zf = new InstrumentedZipFile(jars[rnd.nextInt(jars.length)]); |
1d90347088c3
8006773: test/java/util/zip/ZipFile/FinalizeZipFile.java failing intermittently
sherman
parents:
9035
diff
changeset
|
71 |
ZipEntry ze = zf.getEntry("META-INF/MANIFEST.MF"); |
1d90347088c3
8006773: test/java/util/zip/ZipFile/FinalizeZipFile.java failing intermittently
sherman
parents:
9035
diff
changeset
|
72 |
if (ze != null) { |
1d90347088c3
8006773: test/java/util/zip/ZipFile/FinalizeZipFile.java failing intermittently
sherman
parents:
9035
diff
changeset
|
73 |
InputStream is = zf.getInputStream(ze); |
1d90347088c3
8006773: test/java/util/zip/ZipFile/FinalizeZipFile.java failing intermittently
sherman
parents:
9035
diff
changeset
|
74 |
break; |
1d90347088c3
8006773: test/java/util/zip/ZipFile/FinalizeZipFile.java failing intermittently
sherman
parents:
9035
diff
changeset
|
75 |
} |
1d90347088c3
8006773: test/java/util/zip/ZipFile/FinalizeZipFile.java failing intermittently
sherman
parents:
9035
diff
changeset
|
76 |
} |
7815
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
77 |
} |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
78 |
|
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
79 |
public static void realMain(String[] args) throws Throwable { |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
80 |
makeGarbage(); |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
81 |
|
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
82 |
System.gc(); |
22124
8a31f2817571
8030089: java/util/zip/ZipFile/FinalizeZipFile.java intermittently fails with fastdebug builds
alanb
parents:
15295
diff
changeset
|
83 |
finalizersDone.await(); |
7815
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
84 |
|
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
85 |
// Not all ZipFiles were collected? |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
86 |
equal(finalizersDone.getCount(), 0L); |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
87 |
} |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
88 |
|
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
89 |
//--------------------- Infrastructure --------------------------- |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
90 |
static volatile int passed = 0, failed = 0; |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
91 |
static void pass() {passed++;} |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
92 |
static void fail() {failed++; Thread.dumpStack();} |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
93 |
static void fail(String msg) {System.out.println(msg); fail();} |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
94 |
static void unexpected(Throwable t) {failed++; t.printStackTrace();} |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
95 |
static void check(boolean cond) {if (cond) pass(); else fail();} |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
96 |
static void equal(Object x, Object y) { |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
97 |
if (x == null ? y == null : x.equals(y)) pass(); |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
98 |
else fail(x + " not equal to " + y);} |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
99 |
public static void main(String[] args) throws Throwable { |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
100 |
try {realMain(args);} catch (Throwable t) {unexpected(t);} |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
101 |
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
102 |
if (failed > 0) throw new AssertionError("Some tests failed");} |
12cc7f77e459
7009618: regression test failed caused by the fix for 7003462
sherman
parents:
diff
changeset
|
103 |
} |