author | ctornqvi |
Thu, 16 May 2013 15:31:00 +0200 | |
changeset 17598 | f78d22d3c6c2 |
parent 13409 | fe3ab27ef1a6 |
child 21596 | 0e3a39f29dbc |
permissions | -rw-r--r-- |
13409
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
1 |
/* |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
4 |
* |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
10 |
* |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
15 |
* accompanied this code). |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
16 |
* |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
20 |
* |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
23 |
* questions. |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
24 |
*/ |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
25 |
|
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
26 |
/* @test |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
27 |
* @bug 7188852 |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
28 |
* @summary Test De/Inflater.getBytesRead/Written() |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
29 |
*/ |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
30 |
|
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
31 |
import java.io.*; |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
32 |
import java.util.*; |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
33 |
import java.util.zip.*; |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
34 |
|
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
35 |
|
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
36 |
public class TotalInOut { |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
37 |
static final int BUF_SIZE= 1 * 1024 * 1024; |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
38 |
|
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
39 |
static void realMain (String[] args) throws Throwable { |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
40 |
long dataSize = 128L * 1024L * 1024L; // 128MB |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
41 |
if (args.length > 0 && "large".equals(args[0])) |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
42 |
dataSize = 5L * 1024L * 1024L * 1024L; // 5GB |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
43 |
|
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
44 |
Deflater deflater = new Deflater(); |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
45 |
Inflater inflater = new Inflater(); |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
46 |
|
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
47 |
byte[] dataIn = new byte[BUF_SIZE]; |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
48 |
byte[] dataOut = new byte[BUF_SIZE]; |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
49 |
byte[] tmp = new byte[BUF_SIZE]; |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
50 |
|
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
51 |
Random r = new Random(); |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
52 |
r.nextBytes(dataIn); |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
53 |
long bytesReadDef = 0; |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
54 |
long bytesWrittenDef = 0; |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
55 |
long bytesReadInf = 0; |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
56 |
long bytesWrittenInf = 0; |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
57 |
|
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
58 |
deflater.setInput(dataIn, 0, dataIn.length); |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
59 |
while (bytesReadDef < dataSize || bytesWrittenInf < dataSize) { |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
60 |
int len = r.nextInt(BUF_SIZE/2) + BUF_SIZE / 2; |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
61 |
if (deflater.needsInput()) { |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
62 |
bytesReadDef += dataIn.length; |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
63 |
check(bytesReadDef == deflater.getBytesRead()); |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
64 |
deflater.setInput(dataIn, 0, dataIn.length); |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
65 |
} |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
66 |
int n = deflater.deflate(tmp, 0, len); |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
67 |
bytesWrittenDef += n; |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
68 |
check(bytesWrittenDef == deflater.getBytesWritten()); |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
69 |
|
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
70 |
inflater.setInput(tmp, 0, n); |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
71 |
bytesReadInf += n; |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
72 |
while (!inflater.needsInput()) { |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
73 |
bytesWrittenInf += inflater.inflate(dataOut, 0, dataOut.length); |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
74 |
check(bytesWrittenInf == inflater.getBytesWritten()); |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
75 |
} |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
76 |
check(bytesReadInf == inflater.getBytesRead()); |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
77 |
} |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
78 |
} |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
79 |
|
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
80 |
//--------------------- Infrastructure --------------------------- |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
81 |
static volatile int passed = 0, failed = 0; |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
82 |
static void pass() {passed++;} |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
83 |
static void pass(String msg) {System.out.println(msg); passed++;} |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
84 |
static void fail() {failed++; Thread.dumpStack();} |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
85 |
static void fail(String msg) {System.out.println(msg); fail();} |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
86 |
static void unexpected(Throwable t) {failed++; t.printStackTrace();} |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
87 |
static void unexpected(Throwable t, String msg) { |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
88 |
System.out.println(msg); failed++; t.printStackTrace();} |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
89 |
static boolean check(boolean cond) {if (cond) pass(); else fail(); return cond;} |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
90 |
static void equal(Object x, Object y) { |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
91 |
if (x == null ? y == null : x.equals(y)) pass(); |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
92 |
else fail(x + " not equal to " + y);} |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
93 |
public static void main(String[] args) throws Throwable { |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
94 |
try {realMain(args);} catch (Throwable t) {unexpected(t);} |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
95 |
System.out.println("\nPassed = " + passed + " failed = " + failed); |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
96 |
if (failed > 0) throw new AssertionError("Some tests failed");} |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
diff
changeset
|
97 |
} |