Skip to content

Commit

Permalink
8255969: Improve java/io/BufferedInputStream/LargeCopyWithMark.java u…
Browse files Browse the repository at this point in the history
…sing jtreg tags

Reviewed-by: naoto
  • Loading branch information
Brian Burkhalter committed Nov 6, 2020
1 parent 952abea commit 727a69f
Showing 1 changed file with 21 additions and 44 deletions.
65 changes: 21 additions & 44 deletions test/jdk/java/io/BufferedInputStream/LargeCopyWithMark.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,65 +23,42 @@

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

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import static jdk.test.lib.process.ProcessTools.*;


public class LargeCopyWithMark {

public static void main(String[] args) throws Exception {
if (! System.getProperty("os.arch").contains("64")) {
System.out.println("Test runs on 64 bit platforms");
return;
}
ProcessBuilder pb = createJavaProcessBuilder("-Xmx4G",
"-ea:LargeCopyWithMark$Child",
"LargeCopyWithMark$Child");
int res = pb.inheritIO().start().waitFor();
if (res != 0) {
throw new AssertionError("Test failed: exit code = " + res);
}
}
static final int BUFF_SIZE = 8192;
static final int BIS_BUFF_SIZE = Integer.MAX_VALUE / 2 + 100;
static final long BYTES_TO_COPY = 2L * Integer.MAX_VALUE;

public static class Child {
static final int BUFF_SIZE = 8192;
static final int BIS_BUFF_SIZE = Integer.MAX_VALUE / 2 + 100;
static final long BYTES_TO_COPY = 2L * Integer.MAX_VALUE;

static {
assert BIS_BUFF_SIZE * 2 < 0 : "doubling must overflow";
}
static {
assert BIS_BUFF_SIZE * 2 < 0 : "doubling must overflow";
}

public static void main(String[] args) throws Exception {
byte[] buff = new byte[BUFF_SIZE];
public static void main(String[] args) throws Exception {
byte[] buff = new byte[BUFF_SIZE];

try (InputStream myis = new MyInputStream(BYTES_TO_COPY);
InputStream bis = new BufferedInputStream(myis, BIS_BUFF_SIZE);
OutputStream myos = new MyOutputStream()) {
try (InputStream myis = new MyInputStream(BYTES_TO_COPY);
InputStream bis = new BufferedInputStream(myis, BIS_BUFF_SIZE);
OutputStream myos = new MyOutputStream()) {

// will require a buffer bigger than BIS_BUFF_SIZE
bis.mark(BIS_BUFF_SIZE + 100);
// will require a buffer bigger than BIS_BUFF_SIZE
bis.mark(BIS_BUFF_SIZE + 100);

for (;;) {
int count = bis.read(buff, 0, BUFF_SIZE);
if (count == -1)
break;
myos.write(buff, 0, count);
}
} catch (java.lang.NegativeArraySizeException e) {
e.printStackTrace();
System.exit(11);
} catch (Exception e) {
e.printStackTrace();
for (;;) {
int count = bis.read(buff, 0, BUFF_SIZE);
if (count == -1)
break;
myos.write(buff, 0, count);
}
}
}
Expand Down

0 comments on commit 727a69f

Please sign in to comment.