001/*
002 * Copyright (c) 2015, 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.bytecode;
024
025import jdk.internal.jvmci.options.*;
026import jdk.internal.jvmci.options.OptionValue.*;
027
028import org.junit.*;
029
030import com.oracle.graal.compiler.phases.*;
031import com.oracle.graal.jtt.*;
032import com.oracle.graal.phases.tiers.*;
033
034/**
035 * Tests the instanceof works, when casting an array of interface.
036 */
037public class BC_instanceof01 extends JTTTest {
038
039    public interface IObject {
040
041    }
042
043    public interface IDerivedObject extends IObject {
044
045    }
046
047    private static class BaseClass {
048
049    }
050
051    private static class TestClass extends BaseClass implements IObject {
052    }
053
054    private static class DerivedTestClass extends BaseClass implements IDerivedObject {
055
056    }
057
058    static TestClass[] a1 = {new TestClass()};
059    static DerivedTestClass[] a2 = {new DerivedTestClass()};
060
061    public static BaseClass[] getBaseClassArray() {
062        return a1;
063    }
064
065    public static BaseClass[] getDerivedBaseClassArray() {
066        return a2;
067    }
068
069    public static boolean test() {
070        return getBaseClassArray() instanceof IObject[];
071    }
072
073    public static int testConditionalElimination() {
074        BaseClass[] result = getDerivedBaseClassArray();
075        if (result instanceof IDerivedObject[]) {
076            if (result instanceof IObject[]) {
077                return 1;
078            } else {
079                return 2;
080            }
081        } else {
082            return 3;
083        }
084    }
085
086    @Test
087    public void run0() throws Throwable {
088        runTest("test");
089    }
090
091    @Override
092    protected Suites getSuites() {
093        try (OverrideScope scope = OptionValue.override(HighTier.Options.Inline, false)) {
094            return super.getSuites();
095        }
096    }
097
098    @Test
099    public void run1() throws Throwable {
100        runTest("testConditionalElimination");
101    }
102}