hotspot/test/compiler/intrinsics/unsafe/TestUnsafeMismatchedArrayFieldAccess.java
author chegar
Tue, 22 Mar 2016 15:26:07 +0000
changeset 36694 182a5e7a519e
parent 34189 d5a8eb423f77
child 38152 80e5da81fb2c
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34189
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
     1
/*
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
     4
 *
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
     8
 *
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    13
 * accompanied this code).
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    14
 *
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    18
 *
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    21
 * questions.
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    22
 *
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    23
 */
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    24
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    25
/**
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    26
 * @test
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    27
 * @bug 8142386
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    28
 * @library /testlibrary /test/lib
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    29
 * @summary Unsafe access to an array is wrongly marked as mismatched
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    30
 * @run main/othervm -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -XX:-TieredCompilation TestUnsafeMismatchedArrayFieldAccess
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    31
 *
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    32
 */
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    33
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    34
import java.lang.reflect.*;
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    35
import jdk.test.lib.Utils;
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    36
import sun.misc.Unsafe;
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    37
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    38
public class TestUnsafeMismatchedArrayFieldAccess {
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    39
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    40
    private static final Unsafe UNSAFE = Utils.getUnsafe();
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    41
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    42
    static {
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    43
        try {
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    44
            array_offset = UNSAFE.objectFieldOffset(TestUnsafeMismatchedArrayFieldAccess.class.getDeclaredField("array"));
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    45
        }
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    46
        catch (Exception e) {
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    47
            throw new AssertionError(e);
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    48
        }
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    49
    }
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    50
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    51
    int[] array;
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    52
    static final long array_offset;
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    53
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    54
    void m() {
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    55
        UNSAFE.getObject(this, array_offset);
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    56
    }
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    57
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    58
    static public void main(String[] args) {
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    59
        TestUnsafeMismatchedArrayFieldAccess test = new TestUnsafeMismatchedArrayFieldAccess();
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    60
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    61
        for (int i = 0; i < 20000; i++) {
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    62
            test.m();
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    63
        }
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    64
    }
d5a8eb423f77 8142386: Octane crashes with assert(is_Load())
roland
parents:
diff changeset
    65
}