Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
8258955: (bf) slice(int, int) on view buffers fails to adjust index a…
…ccording to primitive size

Reviewed-by: alanb
  • Loading branch information
ChrisHegarty committed Jan 2, 2021
1 parent 881bceb commit 73f5415
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2021, 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 Down Expand Up @@ -237,7 +237,8 @@ class Direct$Type$Buffer$RW$$BO$
0,
length,
length,
index, segment);
index << $LG_BYTES_PER_VALUE$,
segment);
}

public $Type$Buffer duplicate() {
Expand Down
34 changes: 32 additions & 2 deletions test/jdk/java/nio/Buffer/ByteBufferViews.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, 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,7 +23,7 @@

/* @test
* @summary Binary data and view tests for byte buffers
* @bug 8159257
* @bug 8159257 8258955
* @run testng ByteBufferViews
*/

Expand Down Expand Up @@ -174,6 +174,11 @@ public static Object[][] shortViewProvider() {
bb -> bb.asShortBuffer()),
Map.entry("bb.asShortBuffer().slice()",
bb -> bb.asShortBuffer().slice()),
Map.entry("bb.asShortBuffer().slice(index,length)",
bb -> { var sb = bb.asShortBuffer();
sb = sb.slice(1, sb.limit() - 1);
bb.position(bb.position() + 2);
return sb; }),
Map.entry("bb.asShortBuffer().slice().duplicate()",
bb -> bb.asShortBuffer().slice().duplicate())
);
Expand Down Expand Up @@ -273,6 +278,11 @@ public static Object[][] charViewProvider() {
bb -> bb.asCharBuffer()),
Map.entry("bb.asCharBuffer().slice()",
bb -> bb.asCharBuffer().slice()),
Map.entry("bb.asCharBuffer().slice(index,length)",
bb -> { var cb = bb.asCharBuffer();
cb = cb.slice(1, cb.limit() - 1);
bb.position(bb.position() + 2);
return cb; }),
Map.entry("bb.asCharBuffer().slice().duplicate()",
bb -> bb.asCharBuffer().slice().duplicate())
);
Expand Down Expand Up @@ -365,6 +375,11 @@ public static Object[][] intViewProvider() {
bb -> bb.asIntBuffer()),
Map.entry("bb.asIntBuffer().slice()",
bb -> bb.asIntBuffer().slice()),
Map.entry("bb.asIntBuffer().slice(index,length)",
bb -> { var ib = bb.asIntBuffer();
ib = ib.slice(1, ib.limit() - 1);
bb.position(bb.position() + 4);
return ib; }),
Map.entry("bb.asIntBuffer().slice().duplicate()",
bb -> bb.asIntBuffer().slice().duplicate())
);
Expand Down Expand Up @@ -467,6 +482,11 @@ public static Object[][] longViewProvider() {
bb -> bb.asLongBuffer()),
Map.entry("bb.asLongBuffer().slice()",
bb -> bb.asLongBuffer().slice()),
Map.entry("bb.asLongBuffer().slice(index,length)",
bb -> { var lb = bb.asLongBuffer();
lb = lb.slice(1, lb.limit() - 1);
bb.position(bb.position() + 8);
return lb; }),
Map.entry("bb.asLongBuffer().slice().duplicate()",
bb -> bb.asLongBuffer().slice().duplicate())
);
Expand Down Expand Up @@ -575,6 +595,11 @@ public static Object[][] floatViewProvider() {
bb -> bb.asFloatBuffer()),
Map.entry("bb.asFloatBuffer().slice()",
bb -> bb.asFloatBuffer().slice()),
Map.entry("bb.asFloatBuffer().slice(index,length)",
bb -> { var fb = bb.asFloatBuffer();
fb = fb.slice(1, fb.limit() - 1);
bb.position(bb.position() + 4);
return fb; }),
Map.entry("bb.asFloatBuffer().slice().duplicate()",
bb -> bb.asFloatBuffer().slice().duplicate())
);
Expand Down Expand Up @@ -668,6 +693,11 @@ public static Object[][] doubleViewProvider() {
bb -> bb.asDoubleBuffer()),
Map.entry("bb.asDoubleBuffer().slice()",
bb -> bb.asDoubleBuffer().slice()),
Map.entry("bb.asDoubleBuffer().slice(index,length)",
bb -> { var db = bb.asDoubleBuffer();
db = db.slice(1, db.limit() - 1);
bb.position(bb.position() + 8);
return db; }),
Map.entry("bb.asDoubleBuffer().slice().duplicate()",
bb -> bb.asDoubleBuffer().slice().duplicate())
);
Expand Down

1 comment on commit 73f5415

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.