src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template
changeset 53855 7c362992527a
parent 51318 60f9b6b5ad86
child 53959 1542e63eb537
equal deleted inserted replaced
53854:792c8a5fbb29 53855:7c362992527a
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    27 
    27 
    28 package java.nio;
    28 package java.nio;
    29 
    29 
    30 import java.io.FileDescriptor;
    30 import java.io.FileDescriptor;
    31 import java.lang.ref.Reference;
    31 import java.lang.ref.Reference;
       
    32 import java.util.Objects;
    32 import jdk.internal.misc.VM;
    33 import jdk.internal.misc.VM;
    33 import jdk.internal.ref.Cleaner;
    34 import jdk.internal.ref.Cleaner;
    34 import sun.nio.ch.DirectBuffer;
    35 import sun.nio.ch.DirectBuffer;
    35 
    36 
    36 
    37 
   323 #else[rw]
   324 #else[rw]
   324         throw new ReadOnlyBufferException();
   325         throw new ReadOnlyBufferException();
   325 #end[rw]
   326 #end[rw]
   326     }
   327     }
   327 
   328 
       
   329     public $Type$Buffer get(int index, $type$[] dst, int offset, int length) {
       
   330 #if[rw]
       
   331         if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) {
       
   332             Objects.checkFromIndexSize(index, length, limit());
       
   333             Objects.checkFromIndexSize(offset, length, dst.length);
       
   334 
       
   335             long dstOffset = ARRAY_BASE_OFFSET + ((long)offset << $LG_BYTES_PER_VALUE$);
       
   336             try {
       
   337 #if[!byte]
       
   338                 if (order() != ByteOrder.nativeOrder())
       
   339                     UNSAFE.copySwapMemory(null,
       
   340                                           ix(index),
       
   341                                           dst,
       
   342                                           dstOffset,
       
   343                                           (long)length << $LG_BYTES_PER_VALUE$,
       
   344                                           (long)1 << $LG_BYTES_PER_VALUE$);
       
   345                 else
       
   346 #end[!byte]
       
   347                     UNSAFE.copyMemory(null,
       
   348                                       ix(index),
       
   349                                       dst,
       
   350                                       dstOffset,
       
   351                                       (long)length << $LG_BYTES_PER_VALUE$);
       
   352             } finally {
       
   353                 Reference.reachabilityFence(this);
       
   354             }
       
   355         } else {
       
   356             super.get(index, dst, offset, length);
       
   357         }
       
   358         return this;
       
   359 #else[rw]
       
   360         throw new ReadOnlyBufferException();
       
   361 #end[rw]
       
   362     }
   328 #end[rw]
   363 #end[rw]
   329 
   364 
   330     public $Type$Buffer put($type$ x) {
   365     public $Type$Buffer put($type$ x) {
   331 #if[rw]
   366 #if[rw]
   332         try {
   367         try {
   438 #else[rw]
   473 #else[rw]
   439         throw new ReadOnlyBufferException();
   474         throw new ReadOnlyBufferException();
   440 #end[rw]
   475 #end[rw]
   441     }
   476     }
   442 
   477 
       
   478     public $Type$Buffer put(int index, $type$[] src, int offset, int length) {
       
   479 #if[rw]
       
   480         if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_FROM_ARRAY_THRESHOLD) {
       
   481             Objects.checkFromIndexSize(index, length, limit());
       
   482             Objects.checkFromIndexSize(offset, length, src.length);
       
   483 
       
   484 
       
   485             long srcOffset = ARRAY_BASE_OFFSET + ((long)offset << $LG_BYTES_PER_VALUE$);
       
   486             try {
       
   487 #if[!byte]
       
   488                 if (order() != ByteOrder.nativeOrder())
       
   489                     UNSAFE.copySwapMemory(src,
       
   490                                           srcOffset,
       
   491                                           null,
       
   492                                           ix(index),
       
   493                                           (long)length << $LG_BYTES_PER_VALUE$,
       
   494                                           (long)1 << $LG_BYTES_PER_VALUE$);
       
   495                 else
       
   496 #end[!byte]
       
   497                     UNSAFE.copyMemory(src,
       
   498                                       srcOffset,
       
   499                                       null,
       
   500                                       ix(index),
       
   501                                       (long)length << $LG_BYTES_PER_VALUE$);
       
   502             } finally {
       
   503                 Reference.reachabilityFence(this);
       
   504             }
       
   505         } else {
       
   506             super.put(index, src, offset, length);
       
   507         }
       
   508         return this;
       
   509 #else[rw]
       
   510         throw new ReadOnlyBufferException();
       
   511 #end[rw]
       
   512     }
       
   513 
   443     public $Type$Buffer compact() {
   514     public $Type$Buffer compact() {
   444 #if[rw]
   515 #if[rw]
   445         int pos = position();
   516         int pos = position();
   446         int lim = limit();
   517         int lim = limit();
   447         assert (pos <= lim);
   518         assert (pos <= lim);