hotspot/test/compiler/unsafe/MixedUnsafeStoreObject.java
changeset 40881 a4955213b573
equal deleted inserted replaced
40880:74222f8c095e 40881:a4955213b573
       
     1 /*
       
     2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /*
       
    25  * @test
       
    26  * @bug 8155635
       
    27  * @modules java.base/jdk.internal.misc
       
    28  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -Xbatch -XX:-TieredCompilation compiler.unsafe.MixedUnsafeStoreObject
       
    29  * @run main/othervm -Xbatch compiler.unsafe.MixedUnsafeStoreObject
       
    30  */
       
    31 
       
    32 package compiler.unsafe;
       
    33 
       
    34 import jdk.internal.misc.Unsafe;
       
    35 
       
    36 public class MixedUnsafeStoreObject {
       
    37     static final Unsafe UNSAFE = Unsafe.getUnsafe();
       
    38 
       
    39     static final long F_OFFSET;
       
    40 
       
    41     static {
       
    42         try {
       
    43             F_OFFSET = UNSAFE.objectFieldOffset(T.class.getDeclaredField("f"));
       
    44         } catch (Exception e) {
       
    45             throw new Error(e);
       
    46         }
       
    47     }
       
    48 
       
    49     static class T {
       
    50         Object f;
       
    51     }
       
    52 
       
    53     public static void testFieldInstanceObject(Object t) {
       
    54         for (int c = 0; c < 20000; c++) { // trigger OSR compilation
       
    55             // java/lang/Object+12 *
       
    56             // _base = InstPtr, _ptr = BotPTR, _field = NULL, mismatched = true
       
    57             UNSAFE.putObject(t, F_OFFSET, "foo");
       
    58         }
       
    59     }
       
    60 
       
    61     public static void testFieldInstanceT(T t) {
       
    62         for (int c = 0; c < 20000; c++) { // trigger OSR compilation
       
    63             // ...$T+12 *
       
    64             // _base = InstPtr, _ptr = BotPTR, _field = T.f, mismatched = false
       
    65             UNSAFE.putObject(t, F_OFFSET, "foo");
       
    66         }
       
    67     }
       
    68     public static void main(String[] args) {
       
    69         testFieldInstanceObject(new T());
       
    70         testFieldInstanceT(new T());
       
    71     }
       
    72 }
       
    73