< prev index next >

src/java.base/share/classes/sun/nio/ch/Util.java

Print this page




 398 
 399     private static int pageSize = -1;
 400 
 401     static int pageSize() {
 402         if (pageSize == -1)
 403             pageSize = unsafe().pageSize();
 404         return pageSize;
 405     }
 406 
 407     private static volatile Constructor<?> directByteBufferConstructor;
 408 
 409     private static void initDBBConstructor() {
 410         AccessController.doPrivileged(new PrivilegedAction<Void>() {
 411                 public Void run() {
 412                     try {
 413                         Class<?> cl = Class.forName("java.nio.DirectByteBuffer");
 414                         Constructor<?> ctor = cl.getDeclaredConstructor(
 415                             new Class<?>[] { int.class,
 416                                              long.class,
 417                                              FileDescriptor.class,
 418                                              Runnable.class });

 419                         ctor.setAccessible(true);
 420                         directByteBufferConstructor = ctor;
 421                     } catch (ClassNotFoundException   |
 422                              NoSuchMethodException    |
 423                              IllegalArgumentException |
 424                              ClassCastException x) {
 425                         throw new InternalError(x);
 426                     }
 427                     return null;
 428                 }});
 429     }
 430 
 431     static MappedByteBuffer newMappedByteBuffer(int size, long addr,
 432                                                 FileDescriptor fd,
 433                                                 Runnable unmapper)

 434     {
 435         MappedByteBuffer dbb;
 436         if (directByteBufferConstructor == null)
 437             initDBBConstructor();
 438         try {
 439             dbb = (MappedByteBuffer)directByteBufferConstructor.newInstance(
 440               new Object[] { size,
 441                              addr,
 442                              fd,
 443                              unmapper });

 444         } catch (InstantiationException |
 445                  IllegalAccessException |
 446                  InvocationTargetException e) {
 447             throw new InternalError(e);
 448         }
 449         return dbb;
 450     }
 451 
 452     private static volatile Constructor<?> directByteBufferRConstructor;
 453 
 454     private static void initDBBRConstructor() {
 455         AccessController.doPrivileged(new PrivilegedAction<Void>() {
 456                 public Void run() {
 457                     try {
 458                         Class<?> cl = Class.forName("java.nio.DirectByteBufferR");
 459                         Constructor<?> ctor = cl.getDeclaredConstructor(
 460                             new Class<?>[] { int.class,
 461                                              long.class,
 462                                              FileDescriptor.class,
 463                                              Runnable.class });

 464                         ctor.setAccessible(true);
 465                         directByteBufferRConstructor = ctor;
 466                     } catch (ClassNotFoundException |
 467                              NoSuchMethodException |
 468                              IllegalArgumentException |
 469                              ClassCastException x) {
 470                         throw new InternalError(x);
 471                     }
 472                     return null;
 473                 }});
 474     }
 475 
 476     static MappedByteBuffer newMappedByteBufferR(int size, long addr,
 477                                                  FileDescriptor fd,
 478                                                  Runnable unmapper)

 479     {
 480         MappedByteBuffer dbb;
 481         if (directByteBufferRConstructor == null)
 482             initDBBRConstructor();
 483         try {
 484             dbb = (MappedByteBuffer)directByteBufferRConstructor.newInstance(
 485               new Object[] { size,
 486                              addr,
 487                              fd,
 488                              unmapper });

 489         } catch (InstantiationException |
 490                  IllegalAccessException |
 491                  InvocationTargetException e) {
 492             throw new InternalError(e);
 493         }
 494         return dbb;
 495     }
 496 
 497     static void checkBufferPositionAligned(ByteBuffer bb,
 498                                                      int pos, int alignment)
 499         throws IOException
 500     {
 501         if (bb.alignmentOffset(pos, alignment) != 0) {
 502             throw new IOException("Current location of the bytebuffer ("
 503                 + pos + ") is not a multiple of the block size ("
 504                 + alignment + ")");
 505         }
 506     }
 507 
 508     static void checkRemainingBufferSizeAligned(int rem,




 398 
 399     private static int pageSize = -1;
 400 
 401     static int pageSize() {
 402         if (pageSize == -1)
 403             pageSize = unsafe().pageSize();
 404         return pageSize;
 405     }
 406 
 407     private static volatile Constructor<?> directByteBufferConstructor;
 408 
 409     private static void initDBBConstructor() {
 410         AccessController.doPrivileged(new PrivilegedAction<Void>() {
 411                 public Void run() {
 412                     try {
 413                         Class<?> cl = Class.forName("java.nio.DirectByteBuffer");
 414                         Constructor<?> ctor = cl.getDeclaredConstructor(
 415                             new Class<?>[] { int.class,
 416                                              long.class,
 417                                              FileDescriptor.class,
 418                                              Runnable.class,
 419                                              boolean.class });
 420                         ctor.setAccessible(true);
 421                         directByteBufferConstructor = ctor;
 422                     } catch (ClassNotFoundException   |
 423                              NoSuchMethodException    |
 424                              IllegalArgumentException |
 425                              ClassCastException x) {
 426                         throw new InternalError(x);
 427                     }
 428                     return null;
 429                 }});
 430     }
 431 
 432     static MappedByteBuffer newMappedByteBuffer(int size, long addr,
 433                                                 FileDescriptor fd,
 434                                                 Runnable unmapper,
 435                                                 boolean isPersistent)
 436     {
 437         MappedByteBuffer dbb;
 438         if (directByteBufferConstructor == null)
 439             initDBBConstructor();
 440         try {
 441             dbb = (MappedByteBuffer)directByteBufferConstructor.newInstance(
 442               new Object[] { size,
 443                              addr,
 444                              fd,
 445                              unmapper,
 446                              isPersistent});
 447         } catch (InstantiationException |
 448                  IllegalAccessException |
 449                  InvocationTargetException e) {
 450             throw new InternalError(e);
 451         }
 452         return dbb;
 453     }
 454 
 455     private static volatile Constructor<?> directByteBufferRConstructor;
 456 
 457     private static void initDBBRConstructor() {
 458         AccessController.doPrivileged(new PrivilegedAction<Void>() {
 459                 public Void run() {
 460                     try {
 461                         Class<?> cl = Class.forName("java.nio.DirectByteBufferR");
 462                         Constructor<?> ctor = cl.getDeclaredConstructor(
 463                             new Class<?>[] { int.class,
 464                                              long.class,
 465                                              FileDescriptor.class,
 466                                              Runnable.class,
 467                                              boolean.class });
 468                         ctor.setAccessible(true);
 469                         directByteBufferRConstructor = ctor;
 470                     } catch (ClassNotFoundException |
 471                              NoSuchMethodException |
 472                              IllegalArgumentException |
 473                              ClassCastException x) {
 474                         throw new InternalError(x);
 475                     }
 476                     return null;
 477                 }});
 478     }
 479 
 480     static MappedByteBuffer newMappedByteBufferR(int size, long addr,
 481                                                  FileDescriptor fd,
 482                                                  Runnable unmapper,
 483                                                  boolean isPersistent)
 484     {
 485         MappedByteBuffer dbb;
 486         if (directByteBufferRConstructor == null)
 487             initDBBRConstructor();
 488         try {
 489             dbb = (MappedByteBuffer)directByteBufferRConstructor.newInstance(
 490               new Object[] { size,
 491                              addr,
 492                              fd,
 493                              unmapper,
 494                              isPersistent});
 495         } catch (InstantiationException |
 496                  IllegalAccessException |
 497                  InvocationTargetException e) {
 498             throw new InternalError(e);
 499         }
 500         return dbb;
 501     }
 502 
 503     static void checkBufferPositionAligned(ByteBuffer bb,
 504                                                      int pos, int alignment)
 505         throws IOException
 506     {
 507         if (bb.alignmentOffset(pos, alignment) != 0) {
 508             throw new IOException("Current location of the bytebuffer ("
 509                 + pos + ") is not a multiple of the block size ("
 510                 + alignment + ")");
 511         }
 512     }
 513 
 514     static void checkRemainingBufferSizeAligned(int rem,


< prev index next >