GetUnsafeObjectG1PreBarrier.java revision 11707:ad7af1afda7a
1269603Sngie/* 2269603Sngie * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. 3279430Srstone * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4336345Skevans * 5279430Srstone * This code is free software; you can redistribute it and/or modify it 6286796Soshogbo * under the terms of the GNU General Public License version 2 only, as 7279430Srstone * published by the Free Software Foundation. 8279424Srstone * 9269603Sngie * This code is distributed in the hope that it will be useful, but WITHOUT 10269603Sngie * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11269603Sngie * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12269603Sngie * version 2 for more details (a copy is included in the LICENSE file that 13269603Sngie * accompanied this code). 14269603Sngie * 15269603Sngie * You should have received a copy of the GNU General Public License version 16275024Sbapt * 2 along with this work; if not, write to the Free Software Foundation, 17269603Sngie * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18279424Srstone * 19269603Sngie * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20269603Sngie * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 * @test 26 * @bug 8016474 27 * @summary The bug only happens with C1 and G1 using a different ObjectAlignmentInBytes than KlassAlignmentInBytes (which is 8) 28 * 29 * @modules java.base/jdk.internal.misc 30 * @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=32 31 * compiler.unsafe.GetUnsafeObjectG1PreBarrier 32 */ 33 34package compiler.unsafe; 35 36import jdk.internal.misc.Unsafe; 37 38import java.lang.reflect.Field; 39 40public class GetUnsafeObjectG1PreBarrier { 41 private static final Unsafe unsafe; 42 private static final int N = 100_000; 43 44 static { 45 try { 46 Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); 47 theUnsafe.setAccessible(true); 48 unsafe = (Unsafe) theUnsafe.get(null); 49 } catch (NoSuchFieldException | IllegalAccessException e) { 50 throw new IllegalStateException(e); 51 } 52 } 53 54 public Object a; 55 56 public static void main(String[] args) throws Throwable { 57 new GetUnsafeObjectG1PreBarrier(); 58 } 59 60 public GetUnsafeObjectG1PreBarrier() throws Throwable { 61 doit(); 62 } 63 64 private void doit() throws Throwable { 65 Field field = GetUnsafeObjectG1PreBarrier.class.getField("a"); 66 long fieldOffset = unsafe.objectFieldOffset(field); 67 68 for (int i = 0; i < N; i++) { 69 readField(this, fieldOffset); 70 } 71 } 72 73 private void readField(Object o, long fieldOffset) { 74 unsafe.getObject(o, fieldOffset); 75 } 76} 77