hotspot/test/runtime/Unsafe/RangeCheck.java
author mgerdin
Mon, 11 Aug 2014 17:12:41 +0400
changeset 25958 8dc85547d6d6
parent 25368 506eef1dc714
child 29678 dd2f3932c21e
permissions -rw-r--r--
8011397: JTREG needs to copy additional WhiteBox class file to JTwork/scratch/sun/hotspot Reviewed-by: kvn, iignatyev, mgerdin Contributed-by: andrey.x.zakharov@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25336
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
     1
/*
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
     4
 *
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
     8
 *
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    13
 * accompanied this code).
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    14
 *
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    18
 *
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    21
 * questions.
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    22
 */
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    23
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    24
/*
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    25
 * @test
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    26
 * @bug 8001071
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    27
 * @summary Add simple range check into VM implemenation of Unsafe access methods
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    28
 * @library /testlibrary
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    29
 */
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    30
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    31
import com.oracle.java.testlibrary.*;
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    32
import sun.misc.Unsafe;
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    33
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    34
public class RangeCheck {
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    35
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    36
    public static void main(String args[]) throws Exception {
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    37
        if (!Platform.isDebugBuild()) {
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    38
            System.out.println("Testing assert which requires a debug build. Passing silently.");
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    39
            return;
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    40
        }
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    41
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    42
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    43
                true,
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    44
                "-Xmx32m",
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    45
                "-XX:-TransmitErrorReport",
25368
506eef1dc714 8048076: [TESTBUG] runtime/Unsafe/RangeCheck.java fails with -Xcomp
ctornqvi
parents: 25336
diff changeset
    46
                "-XX:-InlineUnsafeOps", // The compiler intrinsics doesn't have the assert
25336
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    47
                DummyClassWithMainRangeCheck.class.getName());
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    48
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    49
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    50
        output.shouldMatch("assert\\(byte_offset < p_size\\) failed: Unsafe access: offset \\d+ > object's size \\d+");
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    51
    }
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    52
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    53
    public static class DummyClassWithMainRangeCheck {
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    54
        public static void main(String args[]) throws Exception {
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    55
            Unsafe unsafe = Utils.getUnsafe();
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    56
            unsafe.getObject(new DummyClassWithMainRangeCheck(), Short.MAX_VALUE);
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    57
        }
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    58
    }
d35d298197f9 8047939: [TESTBUG] Rewrite test/runtime/8001071/Test8001071.sh
ctornqvi
parents:
diff changeset
    59
}