@@ -37,6 +37,7 @@ private DirectBufferAccess()
3737
3838    enum  DirectBufferConstructorType 
3939    {
40+         ARGS_LONG_LONG ,
4041        ARGS_LONG_INT_REF ,
4142        ARGS_LONG_INT ,
4243        ARGS_INT_INT ,
@@ -64,28 +65,35 @@ enum DirectBufferConstructorType
6465            DirectBufferConstructorType  constructorType  = null ;
6566            Method  mbWrap  = null ;
6667            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 ;
7071            }
71-             catch  (NoSuchMethodException  e0 ) {
72+             catch  (NoSuchMethodException  e00 ) {
7273                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 ;
7777                }
78-                 catch  (NoSuchMethodException  e1 ) {
78+                 catch  (NoSuchMethodException  e0 ) {
7979                    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 ;
8284                    }
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+                         }
8997                    }
9098                }
9199            }
@@ -281,6 +289,8 @@ static ByteBuffer newByteBuffer(long address, int index, int length, ByteBuffer
281289        }
282290        try  {
283291            switch  (directBufferConstructorType ) {
292+                 case  ARGS_LONG_LONG :
293+                     return  (ByteBuffer ) byteBufferConstructor .newInstance (address  + index , (long ) length );
284294                case  ARGS_LONG_INT_REF :
285295                    return  (ByteBuffer ) byteBufferConstructor .newInstance (address  + index , length , reference );
286296                case  ARGS_LONG_INT :
0 commit comments