test/hotspot/jtreg/runtime/Unsafe/InternalErrorTest.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58312 ce960527ecee
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55490
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
     1
/*
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
     4
 *
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
     8
 *
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    13
 * accompanied this code).
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    14
 *
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    18
 *
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    21
 * questions.
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    22
 */
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    23
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    24
/*
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    25
 * @test
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    26
 * @bug 8191278
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    27
 * @requires os.family != "windows"
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    28
 * @summary Check that SIGBUS errors caused by memory accesses in Unsafe_CopyMemory()
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    29
 * and UnsafeCopySwapMemory() get converted to java.lang.InternalError exceptions.
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    30
 * @modules java.base/jdk.internal.misc
58312
ce960527ecee 8231413: Several test/hotspot/jtreg/runtime tests updates to run with --illegal-access=deny
alanb
parents: 55490
diff changeset
    31
 *          java.base/java.nio:+open
55490
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    32
 *
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    33
 * @library /test/lib
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    34
 * @build sun.hotspot.WhiteBox
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    35
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    36
 *      sun.hotspot.WhiteBox$WhiteBoxPermission
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    37
 *
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    38
 * @run main/othervm -XX:CompileCommand=exclude,*InternalErrorTest.main -XX:CompileCommand=inline,*.get -XX:CompileCommand=inline,*Unsafe.* -Xbootclasspath/a:.  -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI InternalErrorTest
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    39
 */
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    40
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    41
import java.io.File;
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    42
import java.io.IOException;
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    43
import java.io.RandomAccessFile;
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    44
import java.lang.reflect.Field;
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    45
import java.lang.reflect.Method;
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    46
import java.nio.MappedByteBuffer;
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    47
import java.nio.channels.FileChannel;
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    48
import java.nio.file.Files;
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    49
import jdk.internal.misc.Unsafe;
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    50
import sun.hotspot.WhiteBox;
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    51
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    52
// Test that illegal memory access errors in Unsafe_CopyMemory0() and
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    53
// UnsafeCopySwapMemory() that cause SIGBUS errors result in
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    54
// java.lang.InternalError exceptions, not JVM crashes.
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    55
public class InternalErrorTest {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    56
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    57
    private static final Unsafe unsafe = Unsafe.getUnsafe();
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    58
    private static final int pageSize = WhiteBox.getWhiteBox().getVMPageSize();
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    59
    private static final String expectedErrorMsg = "fault occurred in a recent unsafe memory access";
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    60
    private static final String failureMsg1 = "InternalError not thrown";
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    61
    private static final String failureMsg2 = "Wrong InternalError: ";
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    62
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    63
    public static void main(String[] args) throws Throwable {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    64
        Unsafe unsafe = Unsafe.getUnsafe();
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    65
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    66
        String currentDir = System.getProperty("test.classes");
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    67
        File file = new File(currentDir, "tmpFile.txt");
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    68
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    69
        StringBuilder s = new StringBuilder();
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    70
        for (int i = 1; i < pageSize + 1000; i++) {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    71
            s.append("1");
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    72
        }
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    73
        Files.write(file.toPath(), s.toString().getBytes());
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    74
        FileChannel fileChannel = new RandomAccessFile(file, "r").getChannel();
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    75
        MappedByteBuffer buffer =
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    76
            fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    77
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    78
        // Get address of mapped memory.
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    79
        long mapAddr = 0;
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    80
        try {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    81
            Field af = java.nio.Buffer.class.getDeclaredField("address");
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    82
            af.setAccessible(true);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    83
            mapAddr = af.getLong(buffer);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    84
        } catch (Exception f) {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    85
            throw f;
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    86
        }
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    87
        long allocMem = unsafe.allocateMemory(4000);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    88
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    89
        for (int i = 0; i < 3; i++) {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    90
            test(buffer, unsafe, mapAddr, allocMem, i);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    91
        }
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    92
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    93
        Files.write(file.toPath(), "2".getBytes());
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    94
        buffer.position(buffer.position() + pageSize);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    95
        for (int i = 0; i < 3; i++) {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    96
            try {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    97
                test(buffer, unsafe, mapAddr, allocMem, i);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    98
                WhiteBox.getWhiteBox().forceSafepoint();
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
    99
                throw new RuntimeException(failureMsg1);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   100
            } catch (InternalError e) {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   101
                if (!e.getMessage().contains(expectedErrorMsg)) {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   102
                    throw new RuntimeException(failureMsg2 + e.getMessage());
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   103
                }
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   104
            }
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   105
        }
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   106
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   107
        Method m = InternalErrorTest.class.getMethod("test", MappedByteBuffer.class, Unsafe.class, long.class, long.class, int.class);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   108
        WhiteBox.getWhiteBox().enqueueMethodForCompilation(m, 3);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   109
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   110
        for (int i = 0; i < 3; i++) {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   111
            try {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   112
                test(buffer, unsafe, mapAddr, allocMem, i);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   113
                WhiteBox.getWhiteBox().forceSafepoint();
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   114
                throw new RuntimeException(failureMsg1);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   115
            } catch (InternalError e) {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   116
                if (!e.getMessage().contains(expectedErrorMsg)) {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   117
                    throw new RuntimeException(failureMsg2 + e.getMessage());
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   118
                }
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   119
            }
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   120
        }
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   121
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   122
        WhiteBox.getWhiteBox().enqueueMethodForCompilation(m, 4);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   123
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   124
        for (int i = 0; i < 3; i++) {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   125
            try {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   126
                test(buffer, unsafe, mapAddr, allocMem, i);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   127
                WhiteBox.getWhiteBox().forceSafepoint();
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   128
                throw new RuntimeException(failureMsg1);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   129
            } catch (InternalError e) {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   130
                if (!e.getMessage().contains(expectedErrorMsg)) {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   131
                    throw new RuntimeException(failureMsg2 + e.getMessage());
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   132
                }
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   133
            }
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   134
        }
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   135
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   136
        System.out.println("Success");
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   137
    }
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   138
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   139
    public static void test(MappedByteBuffer buffer, Unsafe unsafe, long mapAddr, long allocMem, int type) {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   140
        switch (type) {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   141
            case 0:
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   142
                // testing Unsafe.copyMemory, trying to access a word from next page after truncation.
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   143
                buffer.get(new byte[8]);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   144
                break;
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   145
            case 1:
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   146
                // testing Unsafe.copySwapMemory, trying to access next  page after truncation.
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   147
                unsafe.copySwapMemory(null, mapAddr + pageSize, new byte[4000], 16, 2000, 2);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   148
                break;
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   149
            case 2:
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   150
                // testing Unsafe.copySwapMemory, trying to access next  page after truncation.
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   151
                unsafe.copySwapMemory(null, mapAddr + pageSize, null, allocMem, 2000, 2);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   152
                break;
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   153
        }
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   154
    }
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   155
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
diff changeset
   156
}