001/*
002 * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.jtt.jdk;
024
025import java.lang.reflect.*;
026import java.util.*;
027
028import org.junit.*;
029
030import sun.misc.*;
031
032import com.oracle.graal.jtt.*;
033
034/*
035 */
036public class UnsafeAllocateInstance01 extends JTTTest {
037
038    int field01 = 42;
039
040    public static int testInstance() throws SecurityException, InstantiationException {
041        final Unsafe unsafe = getUnsafe();
042        UnsafeAllocateInstance01 newObject = (UnsafeAllocateInstance01) unsafe.allocateInstance(UnsafeAllocateInstance01.class);
043        return newObject.field01;
044    }
045
046    public static void testClassForException(Class<?> clazz) throws SecurityException, InstantiationException {
047        final Unsafe unsafe = getUnsafe();
048        unsafe.allocateInstance(clazz);
049    }
050
051    static Unsafe getUnsafe() {
052        try {
053            final Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
054            unsafeField.setAccessible(true);
055            return (Unsafe) unsafeField.get(null);
056        } catch (Exception e) {
057            throw new Error(e);
058        }
059    }
060
061    @Test
062    public void run0() throws Throwable {
063        runTest("testInstance");
064    }
065
066    @Test
067    public void run1() throws Throwable {
068        runTest("testClassForException", UnsafeAllocateInstance01[].class);
069    }
070
071    @Test
072    public void run7() throws Throwable {
073        runTest("testClassForException", UnsafeAllocateInstance01.class);
074    }
075
076    @Test
077    public void run2() throws Throwable {
078        runTest("testClassForException", AbstractList.class);
079    }
080
081    @Test
082    public void run3() throws Throwable {
083        runTest("testClassForException", List.class);
084    }
085
086    @Test
087    public void run4() throws Throwable {
088        runTest("testClassForException", Class.class);
089    }
090
091    @Ignore("Currently crashes hotspot")
092    @Test
093    public void run5() throws Throwable {
094        runTest("testClassForException", void.class);
095    }
096
097    @Ignore("Currently crashes hotspot")
098    @Test
099    public void run6() throws Throwable {
100        runTest("testClassForException", int.class);
101    }
102}