001/* 002 * Copyright (c) 2013, 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.replacements.test; 024 025import java.lang.reflect.*; 026 027import jdk.internal.jvmci.meta.*; 028 029import org.junit.*; 030 031import com.oracle.graal.compiler.test.*; 032 033/** 034 * Tests the implementation of Array.createInstance. 035 */ 036public class DynamicNewArrayTest extends GraalCompilerTest { 037 038 private class Element { 039 } 040 041 @Test 042 public void test1() { 043 test("test1snippet"); 044 } 045 046 @Test 047 public void test2() { 048 test("test2snippet"); 049 } 050 051 @Test 052 public void test3() { 053 test("dynamic", Long.class, 7); 054 } 055 056 @Test 057 public void test4() { 058 test("dynamic", Boolean.class, -7); 059 test("dynamicSynchronized", Boolean.class, -7); 060 } 061 062 @Test 063 public void test5() { 064 test("dynamic", byte.class, 7); 065 } 066 067 @Test 068 public void test6() { 069 test("dynamic", null, 5); 070 } 071 072 @Test 073 public void test7() { 074 test("dynamic", void.class, 5); 075 } 076 077 @Test 078 public void testStub() { 079 ResolvedJavaMethod method = getResolvedJavaMethod("dynamic"); 080 // this will use the stub call because Element[] is not loaded 081 Result actual1 = executeActual(method, null, Element.class, 7); 082 // this call will use the fast path 083 Result actual2 = executeActual(method, null, Element.class, 7); 084 Result expected = executeExpected(method, null, Element.class, 7); 085 assertEquals(actual1, expected); 086 assertEquals(actual2, expected); 087 } 088 089 public static Object test1snippet() { 090 return Array.newInstance(Integer.class, 7); 091 } 092 093 public static Object test2snippet() { 094 return Array.newInstance(char.class, 7); 095 } 096 097 public static Object dynamic(Class<?> elementType, int length) { 098 return Array.newInstance(elementType, length); 099 } 100 101 public static synchronized Object dynamicSynchronized(Class<?> elementType, int length) { 102 return Array.newInstance(elementType, length); 103 } 104}