Skip to content

Commit 727a69f

Browse files
author
Brian Burkhalter
committed
8255969: Improve java/io/BufferedInputStream/LargeCopyWithMark.java using jtreg tags
Reviewed-by: naoto
1 parent 952abea commit 727a69f

File tree

1 file changed

+21
-44
lines changed

1 file changed

+21
-44
lines changed

test/jdk/java/io/BufferedInputStream/LargeCopyWithMark.java

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,65 +23,42 @@
2323

2424
/* @test
2525
* @bug 7129312
26+
* @requires (sun.arch.data.model == "64" & os.maxMemory > 4g)
2627
* @summary BufferedInputStream calculates negative array size with large
2728
* streams and mark
28-
* @library /test/lib
29-
* @run main/othervm LargeCopyWithMark
29+
* @run main/othervm -Xmx4G LargeCopyWithMark
3030
*/
3131

3232
import java.io.BufferedInputStream;
3333
import java.io.IOException;
3434
import java.io.InputStream;
3535
import java.io.OutputStream;
36-
import static jdk.test.lib.process.ProcessTools.*;
37-
3836

3937
public class LargeCopyWithMark {
4038

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;
5442

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+
}
6346

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];
6649

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()) {
7053

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);
7356

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);
8562
}
8663
}
8764
}

0 commit comments

Comments
 (0)