hotspot/test/compiler/unsafe/GetUnsafeObjectG1PreBarrier.java
author dsamersoff
Sun, 01 May 2016 12:47:00 +0300
changeset 38152 80e5da81fb2c
parent 36851 03e2f4d0a421
child 40059 c2304140ed64
permissions -rw-r--r--
8154258: [TESTBUG] Various serviceability tests fail compilation Summary: Replace sun.misc.Unsafe with jdk.internal.misc.Unsafe Reviewed-by: chegar, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19156
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
     1
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 19160
diff changeset
     2
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
19156
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
     4
 *
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
     7
 * published by the Free Software Foundation.
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
     8
 *
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    13
 * accompanied this code).
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    14
 *
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    18
 *
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    21
 * questions.
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    22
 */
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    23
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    24
/*
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    25
 * @test
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    26
 * @bug 8016474
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    27
 * @summary The bug only happens with C1 and G1 using a different ObjectAlignmentInBytes than KlassAlignmentInBytes (which is 8)
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 29678
diff changeset
    28
 * @modules java.base/jdk.internal.misc
19160
6731e700c220 8022029: GetUnsafeObjectG1PreBarrier fails on 32-bit with: Unrecognized VM option 'ObjectAlignmentInBytes=32'
twisti
parents: 19156
diff changeset
    29
 * @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=32 GetUnsafeObjectG1PreBarrier
19156
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    30
 */
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    31
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    32
import java.lang.reflect.Field;
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    33
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 36851
diff changeset
    34
import jdk.internal.misc.Unsafe;
19156
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    35
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    36
public class GetUnsafeObjectG1PreBarrier {
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    37
    private static final Unsafe unsafe;
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    38
    private static final int N = 100_000;
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    39
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    40
    static {
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    41
        try {
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    42
            Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    43
            theUnsafe.setAccessible(true);
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    44
            unsafe = (Unsafe) theUnsafe.get(null);
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    45
        } catch (NoSuchFieldException | IllegalAccessException e) {
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    46
            throw new IllegalStateException(e);
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    47
        }
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    48
    }
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    49
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    50
    public Object a;
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    51
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    52
    public static void main(String[] args) throws Throwable {
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    53
        new GetUnsafeObjectG1PreBarrier();
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    54
    }
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    55
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    56
    public GetUnsafeObjectG1PreBarrier() throws Throwable {
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    57
        doit();
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    58
    }
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    59
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    60
    private void doit() throws Throwable {
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    61
        Field field = GetUnsafeObjectG1PreBarrier.class.getField("a");
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    62
        long fieldOffset = unsafe.objectFieldOffset(field);
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    63
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    64
        for (int i = 0; i < N; i++) {
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    65
            readField(this, fieldOffset);
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    66
        }
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    67
    }
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    68
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    69
    private void readField(Object o, long fieldOffset) {
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    70
        unsafe.getObject(o, fieldOffset);
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    71
    }
96abb5953450 8016474: Crash in sun.reflect.UnsafeObjectFieldAccessorImpl.get
twisti
parents:
diff changeset
    72
}