test/jdk/java/nio/Buffer/ByteBufferViews.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 40195 jdk/test/java/nio/Buffer/ByteBufferViews.java@a13e4945de1d
child 53959 1542e63eb537
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
     1
/*
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
     4
 *
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
     8
 *
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    13
 * accompanied this code).
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    14
 *
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    18
 *
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    21
 * questions.
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    22
 */
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    23
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    24
/* @test
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    25
 * @summary Binary data and view tests for byte buffers
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    26
 * @bug 8159257
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    27
 * @run testng ByteBufferViews
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    28
 */
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    29
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    30
import org.testng.annotations.DataProvider;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    31
import org.testng.annotations.Test;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    32
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    33
import java.nio.Buffer;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    34
import java.nio.ByteBuffer;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    35
import java.nio.ByteOrder;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    36
import java.nio.CharBuffer;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    37
import java.nio.DoubleBuffer;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    38
import java.nio.FloatBuffer;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    39
import java.nio.IntBuffer;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    40
import java.nio.LongBuffer;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    41
import java.nio.ShortBuffer;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    42
import java.util.List;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    43
import java.util.Map;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    44
import java.util.function.Function;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    45
import java.util.function.IntFunction;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    46
import java.util.function.IntUnaryOperator;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    47
import java.util.function.UnaryOperator;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    48
import java.util.stream.Collectors;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    49
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    50
import static org.testng.Assert.*;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    51
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    52
public class ByteBufferViews {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    53
    static final int SIZE = 32;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    54
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    55
    // List of buffer allocator functions
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    56
    static final List<Map.Entry<String, IntFunction<ByteBuffer>>> BYTE_BUFFER_ALLOCATE_FUNCTIONS = List.of(
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    57
            // Heap
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    58
            Map.entry("ByteBuffer.allocate(ba)",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    59
                      size -> ByteBuffer.allocate(size)),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    60
            // Aligned
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    61
            Map.entry("ByteBuffer.allocate(size).position(8)",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    62
                      size -> ByteBuffer.allocate(size).position(8)),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    63
            Map.entry("ByteBuffer.allocate(size).position(8).slice()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    64
                      size -> ByteBuffer.allocate(size).position(8).slice()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    65
            Map.entry("ByteBuffer.allocate(size).position(8).slice().duplicate()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    66
                      size -> ByteBuffer.allocate(size).position(8).slice().duplicate()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    67
            // Unaligned
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    68
            Map.entry("ByteBuffer.allocate(size).position(1)",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    69
                      size -> ByteBuffer.allocate(size).position(1)),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    70
            Map.entry("ByteBuffer.allocate(size).position(1).slice()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    71
                      size -> ByteBuffer.allocate(size).position(1).slice()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    72
            Map.entry("ByteBuffer.allocate(size).position(1).slice().duplicate()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    73
                      size -> ByteBuffer.allocate(size).position(1).slice().duplicate()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    74
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    75
            // Off-heap
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    76
            Map.entry("ByteBuffer.allocateDirect(size)",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    77
                      size -> ByteBuffer.allocateDirect(size)),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    78
            // Aligned
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    79
            Map.entry("ByteBuffer.allocateDirect(size).position(8)",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    80
                      size -> ByteBuffer.allocateDirect(size).position(8)),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    81
            Map.entry("ByteBuffer.allocateDirect(size).position(8).slice()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    82
                      size -> ByteBuffer.allocateDirect(size).position(8).slice()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    83
            Map.entry("ByteBuffer.allocateDirect(size).position(8).slice().duplicate()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    84
                      size -> ByteBuffer.allocateDirect(size).position(8).slice().duplicate()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    85
            // Unaligned
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    86
            Map.entry("ByteBuffer.allocateDirect(size).position(1)",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    87
                      size -> ByteBuffer.allocateDirect(size).position(1)),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    88
            Map.entry("ByteBuffer.allocateDirect(size).position(1).slice()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    89
                      size -> ByteBuffer.allocateDirect(size).position(1).slice()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    90
            Map.entry("ByteBuffer.allocateDirect(size).position(1).slice().duplicate()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    91
                      size -> ByteBuffer.allocateDirect(size).position(1).slice().duplicate())
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    92
    );
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    93
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    94
    // List of buffer byte order functions
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    95
    static final List<Map.Entry<String, UnaryOperator<ByteBuffer>>> BYTE_BUFFER_ORDER_FUNCTIONS = List.of(
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    96
            Map.entry("order(ByteOrder.BIG_ENDIAN)",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    97
                      (ByteBuffer bb) -> bb.order(ByteOrder.BIG_ENDIAN)),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    98
            Map.entry("order(ByteOrder.LITTLE_ENDIAN)",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
    99
                      (ByteBuffer bb) -> bb.order(ByteOrder.LITTLE_ENDIAN))
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   100
    );
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   101
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   102
    // Produce a composition of allocation and byte order buffer functions
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   103
    static List<Map.Entry<String, IntFunction<ByteBuffer>>> composeBufferFunctions(
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   104
            List<Map.Entry<String, IntFunction<ByteBuffer>>> af,
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   105
            List<Map.Entry<String, UnaryOperator<ByteBuffer>>> of) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   106
        return af.stream().flatMap(afe -> of.stream().
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   107
                map(ofe -> {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   108
                    String s = afe.getKey() + "." + ofe.getKey();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   109
                    IntFunction<ByteBuffer> f = size -> ofe.getValue().
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   110
                            apply(afe.getValue().apply(size));
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   111
                    return Map.entry(s, f);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   112
                })
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   113
        ).collect(Collectors.toList());
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   114
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   115
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   116
    // List of buffer allocator functions to test
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   117
    static final List<Map.Entry<String, IntFunction<ByteBuffer>>> BYTE_BUFFER_FUNCTIONS =
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   118
            composeBufferFunctions(BYTE_BUFFER_ALLOCATE_FUNCTIONS, BYTE_BUFFER_ORDER_FUNCTIONS);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   119
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   120
    // Creates a cross product of test arguments for
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   121
    // buffer allocator functions and buffer view functions
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   122
    static Object[][] product(List<? extends Map.Entry<String, ?>> la,
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   123
                              List<? extends Map.Entry<String, ?>> lb) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   124
        return la.stream().flatMap(lae -> lb.stream().
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   125
                map(lbe -> List.of(
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   126
                        lae.getKey() + " -> " + lbe.getKey(),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   127
                        lae.getValue(),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   128
                        lbe.getValue()).toArray()
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   129
                )).toArray(Object[][]::new);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   130
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   131
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   132
    static void assertValues(int i, Object bValue, Object bbValue, ByteBuffer bb) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   133
        if (!bValue.equals(bbValue)) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   134
            fail(String.format("Values %s and %s differ at index %d for %s",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   135
                               bValue, bbValue, i, bb));
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   136
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   137
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   138
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   139
    static void assertValues(int i, Object bbValue, Object bvValue, ByteBuffer bb, Buffer bv) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   140
        if (!bbValue.equals(bvValue)) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   141
            fail(String.format("Values %s and %s differ at index %d for %s and %s",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   142
                               bbValue, bvValue, i, bb, bv));
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   143
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   144
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   145
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   146
    static ByteBuffer allocate(IntFunction<ByteBuffer> f) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   147
        return allocate(f, i -> i);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   148
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   149
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   150
    static ByteBuffer allocate(IntFunction<ByteBuffer> f, IntUnaryOperator o) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   151
        return fill(f.apply(SIZE), o);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   152
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   153
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   154
    static ByteBuffer fill(ByteBuffer bb, IntUnaryOperator o) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   155
        for (int i = 0; i < bb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   156
            bb.put(i, (byte) o.applyAsInt(i));
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   157
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   158
        return bb;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   159
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   160
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   161
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   162
    @DataProvider
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   163
    public static Object[][] shortViewProvider() {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   164
        List<Map.Entry<String, Function<ByteBuffer, ShortBuffer>>> bfs = List.of(
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   165
                Map.entry("bb.asShortBuffer()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   166
                          bb -> bb.asShortBuffer()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   167
                Map.entry("bb.asShortBuffer().slice()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   168
                          bb -> bb.asShortBuffer().slice()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   169
                Map.entry("bb.asShortBuffer().slice().duplicate()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   170
                          bb -> bb.asShortBuffer().slice().duplicate())
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   171
        );
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   172
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   173
        return product(BYTE_BUFFER_FUNCTIONS, bfs);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   174
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   175
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   176
    @Test(dataProvider = "shortViewProvider")
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   177
    public void testShortGet(String desc, IntFunction<ByteBuffer> fbb,
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   178
                             Function<ByteBuffer, ShortBuffer> fbi) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   179
        ByteBuffer bb = allocate(fbb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   180
        ShortBuffer vb = fbi.apply(bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   181
        int o = bb.position();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   182
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   183
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   184
            short fromBytes = getShortFromBytes(bb, o + i * 2);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   185
            short fromMethodView = bb.getShort(o + i * 2);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   186
            assertValues(i, fromBytes, fromMethodView, bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   187
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   188
            short fromBufferView = vb.get(i);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   189
            assertValues(i, fromMethodView, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   190
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   191
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   192
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   193
            short v = getShortFromBytes(bb, o + i * 2);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   194
            short a = bb.getShort();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   195
            assertValues(i, v, a, bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   196
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   197
            short b = vb.get();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   198
            assertValues(i, a, b, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   199
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   200
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   201
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   202
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   203
    @Test(dataProvider = "shortViewProvider")
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   204
    public void testShortPut(String desc, IntFunction<ByteBuffer> fbb,
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   205
                             Function<ByteBuffer, ShortBuffer> fbi) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   206
        ByteBuffer bbfilled = allocate(fbb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   207
        ByteBuffer bb = allocate(fbb, i -> 0);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   208
        ShortBuffer vb = fbi.apply(bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   209
        int o = bb.position();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   210
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   211
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   212
            short fromFilled = bbfilled.getShort(o + i * 2);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   213
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   214
            vb.put(i, fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   215
            short fromMethodView = bb.getShort(o + i * 2);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   216
            assertValues(i, fromFilled, fromMethodView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   217
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   218
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   219
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   220
            short fromFilled = bbfilled.getShort(o + i * 2);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   221
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   222
            vb.put(fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   223
            short fromMethodView = bb.getShort();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   224
            assertValues(i, fromFilled, fromMethodView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   225
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   226
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   227
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   228
        fill(bb, i -> 0);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   229
        bb.clear().position(o);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   230
        vb.clear();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   231
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   232
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   233
            short fromFilled = bbfilled.getShort(o + i * 2);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   234
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   235
            bb.putShort(o + i * 2, fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   236
            short fromBufferView = vb.get(i);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   237
            assertValues(i, fromFilled, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   238
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   239
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   240
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   241
            short fromFilled = bbfilled.getShort(o + i * 2);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   242
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   243
            bb.putShort(fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   244
            short fromBufferView = vb.get();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   245
            assertValues(i, fromFilled, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   246
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   247
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   248
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   249
    static short getShortFromBytes(ByteBuffer bb, int i) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   250
        int a = bb.get(i) & 0xFF;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   251
        int b = bb.get(i + 1) & 0xFF;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   252
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   253
        if (bb.order() == ByteOrder.BIG_ENDIAN) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   254
            return (short) ((a << 8) | b);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   255
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   256
        else {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   257
            return (short) ((b << 8) | a);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   258
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   259
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   260
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   261
    @DataProvider
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   262
    public static Object[][] charViewProvider() {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   263
        List<Map.Entry<String, Function<ByteBuffer, CharBuffer>>> bfs = List.of(
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   264
                Map.entry("bb.asCharBuffer()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   265
                          bb -> bb.asCharBuffer()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   266
                Map.entry("bb.asCharBuffer().slice()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   267
                          bb -> bb.asCharBuffer().slice()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   268
                Map.entry("bb.asCharBuffer().slice().duplicate()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   269
                          bb -> bb.asCharBuffer().slice().duplicate())
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   270
        );
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   271
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   272
        return product(BYTE_BUFFER_FUNCTIONS, bfs);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   273
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   274
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   275
    @Test(dataProvider = "charViewProvider")
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   276
    public void testCharGet(String desc, IntFunction<ByteBuffer> fbb,
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   277
                            Function<ByteBuffer, CharBuffer> fbi) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   278
        ByteBuffer bb = allocate(fbb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   279
        CharBuffer vb = fbi.apply(bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   280
        int o = bb.position();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   281
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   282
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   283
            char fromBytes = getCharFromBytes(bb, o + i * 2);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   284
            char fromMethodView = bb.getChar(o + i * 2);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   285
            assertValues(i, fromBytes, fromMethodView, bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   286
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   287
            char fromBufferView = vb.get(i);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   288
            assertValues(i, fromMethodView, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   289
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   290
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   291
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   292
            char fromBytes = getCharFromBytes(bb, o + i * 2);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   293
            char fromMethodView = bb.getChar();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   294
            assertValues(i, fromBytes, fromMethodView, bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   295
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   296
            char fromBufferView = vb.get();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   297
            assertValues(i, fromMethodView, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   298
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   299
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   300
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   301
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   302
    @Test(dataProvider = "charViewProvider")
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   303
    public void testCharPut(String desc, IntFunction<ByteBuffer> fbb,
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   304
                            Function<ByteBuffer, CharBuffer> fbi) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   305
        ByteBuffer bbfilled = allocate(fbb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   306
        ByteBuffer bb = allocate(fbb, i -> 0);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   307
        CharBuffer vb = fbi.apply(bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   308
        int o = bb.position();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   309
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   310
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   311
            char fromFilled = bbfilled.getChar(o + i * 2);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   312
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   313
            vb.put(i, fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   314
            char fromMethodView = bb.getChar(o + i * 2);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   315
            assertValues(i, fromFilled, fromMethodView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   316
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   317
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   318
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   319
            char fromFilled = bbfilled.getChar(o + i * 2);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   320
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   321
            vb.put(fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   322
            char fromMethodView = bb.getChar();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   323
            assertValues(i, fromFilled, fromMethodView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   324
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   325
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   326
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   327
        fill(bb, i -> 0);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   328
        bb.clear().position(o);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   329
        vb.clear();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   330
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   331
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   332
            char fromFilled = bbfilled.getChar(o + i * 2);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   333
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   334
            bb.putChar(o + i * 2, fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   335
            char fromBufferView = vb.get(i);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   336
            assertValues(i, fromFilled, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   337
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   338
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   339
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   340
            char fromFilled = bbfilled.getChar(o + i * 2);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   341
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   342
            bb.putChar(fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   343
            char fromBufferView = vb.get();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   344
            assertValues(i, fromFilled, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   345
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   346
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   347
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   348
    static char getCharFromBytes(ByteBuffer bb, int i) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   349
        return (char) getShortFromBytes(bb, i);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   350
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   351
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   352
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   353
    @DataProvider
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   354
    public static Object[][] intViewProvider() {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   355
        List<Map.Entry<String, Function<ByteBuffer, IntBuffer>>> bfs = List.of(
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   356
                Map.entry("bb.asIntBuffer()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   357
                          bb -> bb.asIntBuffer()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   358
                Map.entry("bb.asIntBuffer().slice()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   359
                          bb -> bb.asIntBuffer().slice()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   360
                Map.entry("bb.asIntBuffer().slice().duplicate()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   361
                          bb -> bb.asIntBuffer().slice().duplicate())
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   362
        );
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   363
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   364
        return product(BYTE_BUFFER_FUNCTIONS, bfs);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   365
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   366
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   367
    @Test(dataProvider = "intViewProvider")
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   368
    public void testIntGet(String desc, IntFunction<ByteBuffer> fbb,
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   369
                           Function<ByteBuffer, IntBuffer> fbi) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   370
        ByteBuffer bb = allocate(fbb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   371
        IntBuffer vb = fbi.apply(bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   372
        int o = bb.position();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   373
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   374
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   375
            int fromBytes = getIntFromBytes(bb, o + i * 4);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   376
            int fromMethodView = bb.getInt(o + i * 4);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   377
            assertValues(i, fromBytes, fromMethodView, bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   378
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   379
            int fromBufferView = vb.get(i);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   380
            assertValues(i, fromMethodView, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   381
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   382
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   383
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   384
            int v = getIntFromBytes(bb, o + i * 4);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   385
            int a = bb.getInt();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   386
            assertValues(i, v, a, bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   387
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   388
            int b = vb.get();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   389
            assertValues(i, a, b, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   390
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   391
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   392
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   393
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   394
    @Test(dataProvider = "intViewProvider")
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   395
    public void testIntPut(String desc, IntFunction<ByteBuffer> fbb,
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   396
                           Function<ByteBuffer, IntBuffer> fbi) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   397
        ByteBuffer bbfilled = allocate(fbb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   398
        ByteBuffer bb = allocate(fbb, i -> 0);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   399
        IntBuffer vb = fbi.apply(bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   400
        int o = bb.position();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   401
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   402
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   403
            int fromFilled = bbfilled.getInt(o + i * 4);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   404
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   405
            vb.put(i, fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   406
            int fromMethodView = bb.getInt(o + i * 4);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   407
            assertValues(i, fromFilled, fromMethodView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   408
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   409
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   410
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   411
            int fromFilled = bbfilled.getInt(o + i * 4);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   412
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   413
            vb.put(fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   414
            int fromMethodView = bb.getInt();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   415
            assertValues(i, fromFilled, fromMethodView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   416
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   417
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   418
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   419
        fill(bb, i -> 0);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   420
        bb.clear().position(o);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   421
        vb.clear();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   422
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   423
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   424
            int fromFilled = bbfilled.getInt(o + i * 4);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   425
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   426
            bb.putInt(o + i * 4, fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   427
            int fromBufferView = vb.get(i);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   428
            assertValues(i, fromFilled, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   429
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   430
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   431
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   432
            int fromFilled = bbfilled.getInt(o + i * 4);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   433
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   434
            bb.putInt(fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   435
            int fromBufferView = vb.get();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   436
            assertValues(i, fromFilled, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   437
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   438
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   439
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   440
    static int getIntFromBytes(ByteBuffer bb, int i) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   441
        int a = bb.get(i) & 0xFF;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   442
        int b = bb.get(i + 1) & 0xFF;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   443
        int c = bb.get(i + 2) & 0xFF;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   444
        int d = bb.get(i + 3) & 0xFF;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   445
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   446
        if (bb.order() == ByteOrder.BIG_ENDIAN) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   447
            return ((a << 24) | (b << 16) | (c << 8) | d);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   448
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   449
        else {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   450
            return ((d << 24) | (c << 16) | (b << 8) | a);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   451
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   452
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   453
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   454
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   455
    @DataProvider
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   456
    public static Object[][] longViewProvider() {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   457
        List<Map.Entry<String, Function<ByteBuffer, LongBuffer>>> bfs = List.of(
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   458
                Map.entry("bb.asLongBuffer()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   459
                          bb -> bb.asLongBuffer()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   460
                Map.entry("bb.asLongBuffer().slice()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   461
                          bb -> bb.asLongBuffer().slice()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   462
                Map.entry("bb.asLongBuffer().slice().duplicate()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   463
                          bb -> bb.asLongBuffer().slice().duplicate())
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   464
        );
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   465
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   466
        return product(BYTE_BUFFER_FUNCTIONS, bfs);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   467
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   468
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   469
    @Test(dataProvider = "longViewProvider")
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   470
    public void testLongGet(String desc, IntFunction<ByteBuffer> fbb,
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   471
                            Function<ByteBuffer, LongBuffer> fbi) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   472
        ByteBuffer bb = allocate(fbb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   473
        LongBuffer vb = fbi.apply(bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   474
        int o = bb.position();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   475
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   476
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   477
            long fromBytes = getLongFromBytes(bb, o + i * 8);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   478
            long fromMethodView = bb.getLong(o + i * 8);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   479
            assertValues(i, fromBytes, fromMethodView, bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   480
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   481
            long fromBufferView = vb.get(i);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   482
            assertValues(i, fromMethodView, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   483
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   484
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   485
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   486
            long v = getLongFromBytes(bb, o + i * 8);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   487
            long a = bb.getLong();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   488
            assertValues(i, v, a, bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   489
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   490
            long b = vb.get();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   491
            assertValues(i, a, b, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   492
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   493
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   494
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   495
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   496
    @Test(dataProvider = "longViewProvider")
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   497
    public void testLongPut(String desc, IntFunction<ByteBuffer> fbb,
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   498
                            Function<ByteBuffer, LongBuffer> fbi) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   499
        ByteBuffer bbfilled = allocate(fbb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   500
        ByteBuffer bb = allocate(fbb, i -> 0);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   501
        LongBuffer vb = fbi.apply(bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   502
        int o = bb.position();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   503
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   504
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   505
            long fromFilled = bbfilled.getLong(o + i * 8);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   506
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   507
            vb.put(i, fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   508
            long fromMethodView = bb.getLong(o + i * 8);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   509
            assertValues(i, fromFilled, fromMethodView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   510
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   511
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   512
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   513
            long fromFilled = bbfilled.getLong(o + i * 8);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   514
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   515
            vb.put(fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   516
            long fromMethodView = bb.getLong();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   517
            assertValues(i, fromFilled, fromMethodView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   518
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   519
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   520
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   521
        fill(bb, i -> 0);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   522
        bb.clear().position(o);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   523
        vb.clear();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   524
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   525
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   526
            long fromFilled = bbfilled.getLong(o + i * 8);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   527
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   528
            bb.putLong(o + i * 8, fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   529
            long fromBufferView = vb.get(i);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   530
            assertValues(i, fromFilled, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   531
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   532
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   533
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   534
            long fromFilled = bbfilled.getLong(o + i * 8);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   535
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   536
            bb.putLong(fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   537
            long fromBufferView = vb.get();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   538
            assertValues(i, fromFilled, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   539
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   540
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   541
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   542
    static long getLongFromBytes(ByteBuffer bb, int i) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   543
        long a = bb.get(i) & 0xFF;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   544
        long b = bb.get(i + 1) & 0xFF;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   545
        long c = bb.get(i + 2) & 0xFF;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   546
        long d = bb.get(i + 3) & 0xFF;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   547
        long e = bb.get(i + 4) & 0xFF;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   548
        long f = bb.get(i + 5) & 0xFF;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   549
        long g = bb.get(i + 6) & 0xFF;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   550
        long h = bb.get(i + 7) & 0xFF;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   551
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   552
        if (bb.order() == ByteOrder.BIG_ENDIAN) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   553
            return ((a << 56) | (b << 48) | (c << 40) | (d << 32) |
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   554
                    (e << 24) | (f << 16) | (g << 8) | h);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   555
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   556
        else {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   557
            return ((h << 56) | (g << 48) | (f << 40) | (e << 32) |
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   558
                    (d << 24) | (c << 16) | (b << 8) | a);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   559
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   560
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   561
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   562
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   563
    @DataProvider
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   564
    public static Object[][] floatViewProvider() {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   565
        List<Map.Entry<String, Function<ByteBuffer, FloatBuffer>>> bfs = List.of(
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   566
                Map.entry("bb.asFloatBuffer()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   567
                          bb -> bb.asFloatBuffer()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   568
                Map.entry("bb.asFloatBuffer().slice()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   569
                          bb -> bb.asFloatBuffer().slice()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   570
                Map.entry("bb.asFloatBuffer().slice().duplicate()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   571
                          bb -> bb.asFloatBuffer().slice().duplicate())
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   572
        );
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   573
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   574
        return product(BYTE_BUFFER_FUNCTIONS, bfs);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   575
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   576
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   577
    @Test(dataProvider = "floatViewProvider")
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   578
    public void testFloatGet(String desc, IntFunction<ByteBuffer> fbb,
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   579
                             Function<ByteBuffer, FloatBuffer> fbi) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   580
        ByteBuffer bb = allocate(fbb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   581
        FloatBuffer vb = fbi.apply(bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   582
        int o = bb.position();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   583
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   584
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   585
            float fromBytes = getFloatFromBytes(bb, o + i * 4);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   586
            float fromMethodView = bb.getFloat(o + i * 4);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   587
            assertValues(i, fromBytes, fromMethodView, bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   588
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   589
            float fromBufferView = vb.get(i);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   590
            assertValues(i, fromMethodView, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   591
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   592
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   593
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   594
            float v = getFloatFromBytes(bb, o + i * 4);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   595
            float a = bb.getFloat();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   596
            assertValues(i, v, a, bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   597
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   598
            float b = vb.get();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   599
            assertValues(i, a, b, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   600
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   601
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   602
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   603
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   604
    @Test(dataProvider = "floatViewProvider")
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   605
    public void testFloatPut(String desc, IntFunction<ByteBuffer> fbb,
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   606
                             Function<ByteBuffer, FloatBuffer> fbi) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   607
        ByteBuffer bbfilled = allocate(fbb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   608
        ByteBuffer bb = allocate(fbb, i -> 0);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   609
        FloatBuffer vb = fbi.apply(bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   610
        int o = bb.position();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   611
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   612
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   613
            float fromFilled = bbfilled.getFloat(o + i * 4);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   614
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   615
            vb.put(i, fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   616
            float fromMethodView = bb.getFloat(o + i * 4);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   617
            assertValues(i, fromFilled, fromMethodView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   618
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   619
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   620
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   621
            float fromFilled = bbfilled.getFloat(o + i * 4);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   622
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   623
            vb.put(fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   624
            float fromMethodView = bb.getFloat();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   625
            assertValues(i, fromFilled, fromMethodView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   626
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   627
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   628
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   629
        fill(bb, i -> 0);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   630
        bb.clear().position(o);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   631
        vb.clear();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   632
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   633
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   634
            float fromFilled = bbfilled.getFloat(o + i * 4);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   635
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   636
            bb.putFloat(o + i * 4, fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   637
            float fromBufferView = vb.get(i);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   638
            assertValues(i, fromFilled, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   639
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   640
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   641
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   642
            float fromFilled = bbfilled.getFloat(o + i * 4);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   643
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   644
            bb.putFloat(fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   645
            float fromBufferView = vb.get();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   646
            assertValues(i, fromFilled, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   647
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   648
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   649
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   650
    static float getFloatFromBytes(ByteBuffer bb, int i) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   651
        return Float.intBitsToFloat(getIntFromBytes(bb, i));
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   652
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   653
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   654
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   655
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   656
    @DataProvider
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   657
    public static Object[][] doubleViewProvider() {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   658
        List<Map.Entry<String, Function<ByteBuffer, DoubleBuffer>>> bfs = List.of(
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   659
                Map.entry("bb.asDoubleBuffer()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   660
                          bb -> bb.asDoubleBuffer()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   661
                Map.entry("bb.asDoubleBuffer().slice()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   662
                          bb -> bb.asDoubleBuffer().slice()),
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   663
                Map.entry("bb.asDoubleBuffer().slice().duplicate()",
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   664
                          bb -> bb.asDoubleBuffer().slice().duplicate())
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   665
        );
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   666
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   667
        return product(BYTE_BUFFER_FUNCTIONS, bfs);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   668
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   669
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   670
    @Test(dataProvider = "doubleViewProvider")
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   671
    public void testDoubleGet(String desc, IntFunction<ByteBuffer> fbb,
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   672
                              Function<ByteBuffer, DoubleBuffer> fbi) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   673
        ByteBuffer bb = allocate(fbb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   674
        DoubleBuffer vb = fbi.apply(bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   675
        int o = bb.position();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   676
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   677
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   678
            double fromBytes = getDoubleFromBytes(bb, o + i * 8);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   679
            double fromMethodView = bb.getDouble(o + i * 8);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   680
            assertValues(i, fromBytes, fromMethodView, bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   681
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   682
            double fromBufferView = vb.get(i);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   683
            assertValues(i, fromMethodView, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   684
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   685
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   686
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   687
            double v = getDoubleFromBytes(bb, o + i * 8);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   688
            double a = bb.getDouble();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   689
            assertValues(i, v, a, bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   690
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   691
            double b = vb.get();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   692
            assertValues(i, a, b, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   693
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   694
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   695
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   696
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   697
    @Test(dataProvider = "doubleViewProvider")
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   698
    public void testDoublePut(String desc, IntFunction<ByteBuffer> fbb,
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   699
                              Function<ByteBuffer, DoubleBuffer> fbi) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   700
        ByteBuffer bbfilled = allocate(fbb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   701
        ByteBuffer bb = allocate(fbb, i -> 0);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   702
        DoubleBuffer vb = fbi.apply(bb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   703
        int o = bb.position();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   704
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   705
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   706
            double fromFilled = bbfilled.getDouble(o + i * 8);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   707
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   708
            vb.put(i, fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   709
            double fromMethodView = bb.getDouble(o + i * 8);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   710
            assertValues(i, fromFilled, fromMethodView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   711
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   712
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   713
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   714
            double fromFilled = bbfilled.getDouble(o + i * 8);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   715
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   716
            vb.put(fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   717
            double fromMethodView = bb.getDouble();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   718
            assertValues(i, fromFilled, fromMethodView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   719
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   720
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   721
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   722
        fill(bb, i -> 0);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   723
        bb.clear().position(o);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   724
        vb.clear();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   725
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   726
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   727
            double fromFilled = bbfilled.getDouble(o + i * 8);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   728
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   729
            bb.putDouble(o + i * 8, fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   730
            double fromBufferView = vb.get(i);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   731
            assertValues(i, fromFilled, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   732
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   733
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   734
        for (int i = 0; i < vb.limit(); i++) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   735
            double fromFilled = bbfilled.getDouble(o + i * 8);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   736
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   737
            bb.putDouble(fromFilled);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   738
            double fromBufferView = vb.get();
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   739
            assertValues(i, fromFilled, fromBufferView, bb, vb);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   740
        }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   741
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   742
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   743
    static double getDoubleFromBytes(ByteBuffer bb, int i) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   744
        return Double.longBitsToDouble(getLongFromBytes(bb, i));
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   745
    }
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents:
diff changeset
   746
}