test/compiler/unsafe/GetUnsafeObjectG1PreBarrier.java

Thu, 17 Apr 2014 16:09:08 -0700

author
amurillo
date
Thu, 17 Apr 2014 16:09:08 -0700
changeset 6635
49b5160951dd
parent 5490
71526a36ebb4
child 6876
710a3c8b516e
permissions
-rw-r--r--

Added tag hs25.20-b11 for changeset b6a2ba7d3ea7

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

mercurial