4837564: (bf) Please make DirectByteBuffer performance enhancements
Reviewed-by: chegar
This commit is contained in:
parent
444dc7067b
commit
7ed3e0a896
@ -29,6 +29,7 @@ package java.nio;
|
||||
|
||||
import sun.misc.Cleaner;
|
||||
import sun.misc.Unsafe;
|
||||
import sun.misc.VM;
|
||||
import sun.nio.ch.DirectBuffer;
|
||||
|
||||
|
||||
@ -114,8 +115,9 @@ class Direct$Type$Buffer$RW$$BO$
|
||||
Direct$Type$Buffer$RW$(int cap) { // package-private
|
||||
#if[rw]
|
||||
super(-1, 0, cap, cap, false);
|
||||
boolean pa = VM.isDirectMemoryPageAligned();
|
||||
int ps = Bits.pageSize();
|
||||
int size = cap + ps;
|
||||
long size = Math.max(1L, (long)cap + (pa ? ps : 0));
|
||||
Bits.reserveMemory(size, cap);
|
||||
|
||||
long base = 0;
|
||||
@ -126,7 +128,7 @@ class Direct$Type$Buffer$RW$$BO$
|
||||
throw x;
|
||||
}
|
||||
unsafe.setMemory(base, size, (byte) 0);
|
||||
if (base % ps != 0) {
|
||||
if (pa && (base % ps != 0)) {
|
||||
// Round up to page boundary
|
||||
address = base + ps - (base & (ps - 1));
|
||||
} else {
|
||||
|
@ -178,6 +178,17 @@ public class VM {
|
||||
return directMemory;
|
||||
}
|
||||
|
||||
// User-controllable flag that determines if direct buffers should be page
|
||||
// aligned. The "-XX:+PageAlignDirectMemory" option can be used to force
|
||||
// buffers, allocated by ByteBuffer.allocateDirect, to be page aligned.
|
||||
private static boolean pageAlignDirectMemory;
|
||||
|
||||
// Returns {@code true} if the direct buffers should be page aligned. This
|
||||
// variable is initialized by saveAndRemoveProperties.
|
||||
public static boolean isDirectMemoryPageAligned() {
|
||||
return pageAlignDirectMemory;
|
||||
}
|
||||
|
||||
// A user-settable boolean to determine whether ClassLoader.loadClass should
|
||||
// accept array syntax. This value may be changed during VM initialization
|
||||
// via the system property "sun.lang.ClassLoader.allowArraySyntax".
|
||||
@ -252,6 +263,11 @@ public class VM {
|
||||
}
|
||||
}
|
||||
|
||||
// Check if direct buffers should be page aligned
|
||||
s = (String)props.remove("sun.nio.PageAlignDirectMemory");
|
||||
if ("true".equals(s))
|
||||
pageAlignDirectMemory = true;
|
||||
|
||||
// Set a boolean to determine whether ClassLoader.loadClass accepts
|
||||
// array syntax. This value is controlled by the system property
|
||||
// "sun.lang.ClassLoader.allowArraySyntax".
|
||||
|
@ -30,18 +30,7 @@
|
||||
# @build LimitDirectMemory
|
||||
# @run shell LimitDirectMemory.sh
|
||||
|
||||
# set platform-dependent variable
|
||||
OS=`uname -s`
|
||||
case "$OS" in
|
||||
SunOS | Linux ) TMP=/tmp ;;
|
||||
Windows* ) TMP="c:/temp" ;;
|
||||
* )
|
||||
echo "Unrecognized system!"
|
||||
exit 1;
|
||||
;;
|
||||
esac
|
||||
|
||||
TMP1=${TMP}/tmp1_$$
|
||||
TMP1=tmp_$$
|
||||
|
||||
runTest() {
|
||||
echo "Testing: $*"
|
||||
@ -82,18 +71,21 @@ runTest -XX:MaxDirectMemorySize=65M -cp ${TESTCLASSES} \
|
||||
|
||||
# Exactly the default amount of memory is available.
|
||||
runTest -cp ${TESTCLASSES} LimitDirectMemory false 10 1
|
||||
runTest -cp ${TESTCLASSES} LimitDirectMemory false 0 DEFAULT
|
||||
runTest -cp ${TESTCLASSES} LimitDirectMemory true 0 DEFAULT+1
|
||||
runTest -Xmx64m -cp ${TESTCLASSES} LimitDirectMemory false 0 DEFAULT
|
||||
runTest -Xmx64m -cp ${TESTCLASSES} LimitDirectMemory true 0 DEFAULT+1
|
||||
|
||||
# We should be able to eliminate direct memory allocation entirely.
|
||||
runTest -XX:MaxDirectMemorySize=0 -cp ${TESTCLASSES} LimitDirectMemory true 0 1
|
||||
|
||||
# Setting the system property should not work so we should be able to allocate
|
||||
# the default amount.
|
||||
runTest -Dsun.nio.MaxDirectMemorySize=1K -cp ${TESTCLASSES} \
|
||||
runTest -Dsun.nio.MaxDirectMemorySize=1K -Xmx64m -cp ${TESTCLASSES} \
|
||||
LimitDirectMemory false DEFAULT-1 DEFAULT/2
|
||||
|
||||
# Various bad values fail to launch the VM.
|
||||
launchFail foo
|
||||
launchFail 10kmt
|
||||
launchFail -1
|
||||
|
||||
# Clean-up
|
||||
rm ${TMP1}
|
||||
|
Loading…
x
Reference in New Issue
Block a user