@@ -37,6 +37,7 @@ private DirectBufferAccess()
37
37
38
38
enum DirectBufferConstructorType
39
39
{
40
+ ARGS_LONG_LONG ,
40
41
ARGS_LONG_INT_REF ,
41
42
ARGS_LONG_INT ,
42
43
ARGS_INT_INT ,
@@ -64,28 +65,35 @@ enum DirectBufferConstructorType
64
65
DirectBufferConstructorType constructorType = null ;
65
66
Method mbWrap = null ;
66
67
try {
67
- // TODO We should use MethodHandle for Java7, which can avoid the cost of boxing with JIT optimization
68
- directByteBufferConstructor = directByteBufferClass .getDeclaredConstructor (long .class , int . class , Object .class );
69
- constructorType = DirectBufferConstructorType .ARGS_LONG_INT_REF ;
68
+ // JDK21 DirectByteBuffer(long, long)
69
+ directByteBufferConstructor = directByteBufferClass .getDeclaredConstructor (long .class , long .class );
70
+ constructorType = DirectBufferConstructorType .ARGS_LONG_LONG ;
70
71
}
71
- catch (NoSuchMethodException e0 ) {
72
+ catch (NoSuchMethodException e00 ) {
72
73
try {
73
- // https://android.googlesource.com/platform/libcore/+/master/luni/src/main/java/java/nio/DirectByteBuffer.java
74
- // DirectByteBuffer(long address, int capacity)
75
- directByteBufferConstructor = directByteBufferClass .getDeclaredConstructor (long .class , int .class );
76
- constructorType = DirectBufferConstructorType .ARGS_LONG_INT ;
74
+ // TODO We should use MethodHandle for Java7, which can avoid the cost of boxing with JIT optimization
75
+ directByteBufferConstructor = directByteBufferClass .getDeclaredConstructor (long .class , int .class , Object .class );
76
+ constructorType = DirectBufferConstructorType .ARGS_LONG_INT_REF ;
77
77
}
78
- catch (NoSuchMethodException e1 ) {
78
+ catch (NoSuchMethodException e0 ) {
79
79
try {
80
- directByteBufferConstructor = directByteBufferClass .getDeclaredConstructor (int .class , int .class );
81
- constructorType = DirectBufferConstructorType .ARGS_INT_INT ;
80
+ // https://android.googlesource.com/platform/libcore/+/master/luni/src/main/java/java/nio/DirectByteBuffer.java
81
+ // DirectByteBuffer(long address, int capacity)
82
+ directByteBufferConstructor = directByteBufferClass .getDeclaredConstructor (long .class , int .class );
83
+ constructorType = DirectBufferConstructorType .ARGS_LONG_INT ;
82
84
}
83
- catch (NoSuchMethodException e2 ) {
84
- Class <?> aClass = Class .forName ("java.nio.MemoryBlock" );
85
- mbWrap = aClass .getDeclaredMethod ("wrapFromJni" , int .class , long .class );
86
- mbWrap .setAccessible (true );
87
- directByteBufferConstructor = directByteBufferClass .getDeclaredConstructor (aClass , int .class , int .class );
88
- constructorType = DirectBufferConstructorType .ARGS_MB_INT_INT ;
85
+ catch (NoSuchMethodException e1 ) {
86
+ try {
87
+ directByteBufferConstructor = directByteBufferClass .getDeclaredConstructor (int .class , int .class );
88
+ constructorType = DirectBufferConstructorType .ARGS_INT_INT ;
89
+ }
90
+ catch (NoSuchMethodException e2 ) {
91
+ Class <?> aClass = Class .forName ("java.nio.MemoryBlock" );
92
+ mbWrap = aClass .getDeclaredMethod ("wrapFromJni" , int .class , long .class );
93
+ mbWrap .setAccessible (true );
94
+ directByteBufferConstructor = directByteBufferClass .getDeclaredConstructor (aClass , int .class , int .class );
95
+ constructorType = DirectBufferConstructorType .ARGS_MB_INT_INT ;
96
+ }
89
97
}
90
98
}
91
99
}
@@ -281,6 +289,8 @@ static ByteBuffer newByteBuffer(long address, int index, int length, ByteBuffer
281
289
}
282
290
try {
283
291
switch (directBufferConstructorType ) {
292
+ case ARGS_LONG_LONG :
293
+ return (ByteBuffer ) byteBufferConstructor .newInstance (address + index , (long ) length );
284
294
case ARGS_LONG_INT_REF :
285
295
return (ByteBuffer ) byteBufferConstructor .newInstance (address + index , length , reference );
286
296
case ARGS_LONG_INT :
0 commit comments