mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
5029431: (bf) Add absolute bulk put and get methods
Reviewed-by: alanb, darcy, chegar, rriggs
This commit is contained in:
parent
2ee61b353b
commit
315b7d0399
12 changed files with 804 additions and 29 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2019, 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
|
||||
|
@ -29,6 +29,7 @@ package java.nio;
|
|||
|
||||
import java.io.FileDescriptor;
|
||||
import java.lang.ref.Reference;
|
||||
import java.util.Objects;
|
||||
import jdk.internal.misc.VM;
|
||||
import jdk.internal.ref.Cleaner;
|
||||
import sun.nio.ch.DirectBuffer;
|
||||
|
@ -325,6 +326,40 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
#end[rw]
|
||||
}
|
||||
|
||||
public $Type$Buffer get(int index, $type$[] dst, int offset, int length) {
|
||||
#if[rw]
|
||||
if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) {
|
||||
Objects.checkFromIndexSize(index, length, limit());
|
||||
Objects.checkFromIndexSize(offset, length, dst.length);
|
||||
|
||||
long dstOffset = ARRAY_BASE_OFFSET + ((long)offset << $LG_BYTES_PER_VALUE$);
|
||||
try {
|
||||
#if[!byte]
|
||||
if (order() != ByteOrder.nativeOrder())
|
||||
UNSAFE.copySwapMemory(null,
|
||||
ix(index),
|
||||
dst,
|
||||
dstOffset,
|
||||
(long)length << $LG_BYTES_PER_VALUE$,
|
||||
(long)1 << $LG_BYTES_PER_VALUE$);
|
||||
else
|
||||
#end[!byte]
|
||||
UNSAFE.copyMemory(null,
|
||||
ix(index),
|
||||
dst,
|
||||
dstOffset,
|
||||
(long)length << $LG_BYTES_PER_VALUE$);
|
||||
} finally {
|
||||
Reference.reachabilityFence(this);
|
||||
}
|
||||
} else {
|
||||
super.get(index, dst, offset, length);
|
||||
}
|
||||
return this;
|
||||
#else[rw]
|
||||
throw new ReadOnlyBufferException();
|
||||
#end[rw]
|
||||
}
|
||||
#end[rw]
|
||||
|
||||
public $Type$Buffer put($type$ x) {
|
||||
|
@ -440,6 +475,42 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
#end[rw]
|
||||
}
|
||||
|
||||
public $Type$Buffer put(int index, $type$[] src, int offset, int length) {
|
||||
#if[rw]
|
||||
if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_FROM_ARRAY_THRESHOLD) {
|
||||
Objects.checkFromIndexSize(index, length, limit());
|
||||
Objects.checkFromIndexSize(offset, length, src.length);
|
||||
|
||||
|
||||
long srcOffset = ARRAY_BASE_OFFSET + ((long)offset << $LG_BYTES_PER_VALUE$);
|
||||
try {
|
||||
#if[!byte]
|
||||
if (order() != ByteOrder.nativeOrder())
|
||||
UNSAFE.copySwapMemory(src,
|
||||
srcOffset,
|
||||
null,
|
||||
ix(index),
|
||||
(long)length << $LG_BYTES_PER_VALUE$,
|
||||
(long)1 << $LG_BYTES_PER_VALUE$);
|
||||
else
|
||||
#end[!byte]
|
||||
UNSAFE.copyMemory(src,
|
||||
srcOffset,
|
||||
null,
|
||||
ix(index),
|
||||
(long)length << $LG_BYTES_PER_VALUE$);
|
||||
} finally {
|
||||
Reference.reachabilityFence(this);
|
||||
}
|
||||
} else {
|
||||
super.put(index, src, offset, length);
|
||||
}
|
||||
return this;
|
||||
#else[rw]
|
||||
throw new ReadOnlyBufferException();
|
||||
#end[rw]
|
||||
}
|
||||
|
||||
public $Type$Buffer compact() {
|
||||
#if[rw]
|
||||
int pos = position();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue