|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
23 | 23 |
|
24 | 24 | /* @test
|
25 | 25 | * @bug 7129312
|
| 26 | + * @requires (sun.arch.data.model == "64" & os.maxMemory > 4g) |
26 | 27 | * @summary BufferedInputStream calculates negative array size with large
|
27 | 28 | * streams and mark
|
28 |
| - * @library /test/lib |
29 |
| - * @run main/othervm LargeCopyWithMark |
| 29 | + * @run main/othervm -Xmx4G LargeCopyWithMark |
30 | 30 | */
|
31 | 31 |
|
32 | 32 | import java.io.BufferedInputStream;
|
33 | 33 | import java.io.IOException;
|
34 | 34 | import java.io.InputStream;
|
35 | 35 | import java.io.OutputStream;
|
36 |
| -import static jdk.test.lib.process.ProcessTools.*; |
37 |
| - |
38 | 36 |
|
39 | 37 | public class LargeCopyWithMark {
|
40 | 38 |
|
41 |
| - public static void main(String[] args) throws Exception { |
42 |
| - if (! System.getProperty("os.arch").contains("64")) { |
43 |
| - System.out.println("Test runs on 64 bit platforms"); |
44 |
| - return; |
45 |
| - } |
46 |
| - ProcessBuilder pb = createJavaProcessBuilder("-Xmx4G", |
47 |
| - "-ea:LargeCopyWithMark$Child", |
48 |
| - "LargeCopyWithMark$Child"); |
49 |
| - int res = pb.inheritIO().start().waitFor(); |
50 |
| - if (res != 0) { |
51 |
| - throw new AssertionError("Test failed: exit code = " + res); |
52 |
| - } |
53 |
| - } |
| 39 | + static final int BUFF_SIZE = 8192; |
| 40 | + static final int BIS_BUFF_SIZE = Integer.MAX_VALUE / 2 + 100; |
| 41 | + static final long BYTES_TO_COPY = 2L * Integer.MAX_VALUE; |
54 | 42 |
|
55 |
| - public static class Child { |
56 |
| - static final int BUFF_SIZE = 8192; |
57 |
| - static final int BIS_BUFF_SIZE = Integer.MAX_VALUE / 2 + 100; |
58 |
| - static final long BYTES_TO_COPY = 2L * Integer.MAX_VALUE; |
59 |
| - |
60 |
| - static { |
61 |
| - assert BIS_BUFF_SIZE * 2 < 0 : "doubling must overflow"; |
62 |
| - } |
| 43 | + static { |
| 44 | + assert BIS_BUFF_SIZE * 2 < 0 : "doubling must overflow"; |
| 45 | + } |
63 | 46 |
|
64 |
| - public static void main(String[] args) throws Exception { |
65 |
| - byte[] buff = new byte[BUFF_SIZE]; |
| 47 | + public static void main(String[] args) throws Exception { |
| 48 | + byte[] buff = new byte[BUFF_SIZE]; |
66 | 49 |
|
67 |
| - try (InputStream myis = new MyInputStream(BYTES_TO_COPY); |
68 |
| - InputStream bis = new BufferedInputStream(myis, BIS_BUFF_SIZE); |
69 |
| - OutputStream myos = new MyOutputStream()) { |
| 50 | + try (InputStream myis = new MyInputStream(BYTES_TO_COPY); |
| 51 | + InputStream bis = new BufferedInputStream(myis, BIS_BUFF_SIZE); |
| 52 | + OutputStream myos = new MyOutputStream()) { |
70 | 53 |
|
71 |
| - // will require a buffer bigger than BIS_BUFF_SIZE |
72 |
| - bis.mark(BIS_BUFF_SIZE + 100); |
| 54 | + // will require a buffer bigger than BIS_BUFF_SIZE |
| 55 | + bis.mark(BIS_BUFF_SIZE + 100); |
73 | 56 |
|
74 |
| - for (;;) { |
75 |
| - int count = bis.read(buff, 0, BUFF_SIZE); |
76 |
| - if (count == -1) |
77 |
| - break; |
78 |
| - myos.write(buff, 0, count); |
79 |
| - } |
80 |
| - } catch (java.lang.NegativeArraySizeException e) { |
81 |
| - e.printStackTrace(); |
82 |
| - System.exit(11); |
83 |
| - } catch (Exception e) { |
84 |
| - e.printStackTrace(); |
| 57 | + for (;;) { |
| 58 | + int count = bis.read(buff, 0, BUFF_SIZE); |
| 59 | + if (count == -1) |
| 60 | + break; |
| 61 | + myos.write(buff, 0, count); |
85 | 62 | }
|
86 | 63 | }
|
87 | 64 | }
|
|
0 commit comments