1 /*
   2  * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 /*
  26  * @test
  27  * @bug 6832293
  28  * @summary JIT compiler got wrong result in type checking with -server
  29  * @run main/othervm  -Xcomp -XX:CompileOnly=Test.run Test
  30  */
  31 
  32 import java.io.PrintStream;
  33 
  34 interface SomeInterface {
  35     int SEVENS = 777;
  36 }
  37 
  38 interface AnotherInterface {
  39     int THIRDS = 33;
  40 }
  41 
  42 class SomeClass implements SomeInterface {
  43     int i;
  44 
  45     SomeClass(int i) {
  46         this.i = i;
  47     }
  48 }
  49 
  50 class ImmediateSubclass extends SomeClass implements SomeInterface {
  51     float f;
  52 
  53     ImmediateSubclass(int i, float f) {
  54         super(i);
  55         this.f = f;
  56     }
  57 }
  58 
  59 final class FinalSubclass extends ImmediateSubclass implements AnotherInterface {
  60     double d;
  61 
  62      FinalSubclass(int i, float f, double d) {
  63         super(i, f);
  64         this.d = d;
  65     }
  66 }
  67 
  68 public class Test {
  69 
  70     public static void main(String args[]) throws Exception{
  71         /* try to pre initialize */
  72         SomeClass[] a=new SomeClass[10];
  73         Class.forName("ImmediateSubclass");
  74         Class.forName("FinalSubclass");
  75         System.exit(run(args, System.out) + 95/*STATUS_TEMP*/);
  76     }
  77 
  78     static int errorStatus = 0/*STATUS_PASSED*/;
  79 
  80     static void errorAlert(PrintStream out, int errorLevel) {
  81         out.println("Test: failure #" + errorLevel);
  82         errorStatus = 2/*STATUS_FAILED*/;
  83     }
  84 
  85     static SomeClass[] v2 = new FinalSubclass[4];
  86 
  87     public static int run(String args[],PrintStream out) {
  88         int i [], j [];
  89         SomeInterface u [], v[] [];
  90         AnotherInterface w [];
  91         SomeClass x [] [];
  92 
  93         i = new int [10];
  94         i[0] = 777;
  95         j = (int []) i;
  96         if (j != i)
  97             errorAlert(out, 2);
  98         else if (j.length != 10)
  99             errorAlert(out, 3);
 100         else if (j[0] != 777)
 101             errorAlert(out, 4);
 102 
 103         v = new SomeClass [3] [];
 104         x = (SomeClass [] []) v;
 105         if (! (x instanceof SomeInterface [] []))
 106             errorAlert(out, 5);
 107         else if (! (x instanceof SomeClass [] []))
 108             errorAlert(out, 6);
 109         else if (x != v)
 110             errorAlert(out, 7);
 111 
 112         x[0] = (SomeClass []) new ImmediateSubclass [4];
 113         if (! (x[0] instanceof ImmediateSubclass []))
 114             errorAlert(out, 8);
 115         else if (x[0].length != 4)
 116             errorAlert(out, 9);
 117 
 118         x[1] = (SomeClass []) v2;
 119         if (! (x[1] instanceof FinalSubclass []))
 120             errorAlert(out, 10);
 121         else if (x[1].length != 4)
 122             errorAlert(out, 11);
 123 
 124         w = (AnotherInterface []) x[1];
 125         if (! (w instanceof FinalSubclass []))
 126             errorAlert(out, 12);
 127         else if (w != x[1])
 128             errorAlert(out, 13);
 129         else if (w.length != 4)
 130             errorAlert(out, 14);
 131 
 132         return errorStatus;
 133     }
 134 }
 135