test/compiler/6837094/Test.java

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/compiler/6837094/Test.java	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,94 @@
     1.4 +/*
     1.5 + * Copyright 2009 Google Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +/**
    1.29 + * @test
    1.30 + * @bug 6837094
    1.31 + * @summary False positive for "meet not symmetric" failure
    1.32 + *
    1.33 + * @run main/othervm -Xbatch -XX:CompileOnly=Test.collectIs,Test$Factory$1.getArray,Test$Factory$2.getArray Test
    1.34 + */
    1.35 +
    1.36 +import java.util.Set;
    1.37 +import java.util.HashSet;
    1.38 +
    1.39 +public class Test {
    1.40 +
    1.41 +  private interface Factory<M extends Interface> {
    1.42 +    Factory<Child0> Zero = new Factory<Child0>() {
    1.43 +      public Child0[] getArray() { return new Child0[1]; }
    1.44 +    };
    1.45 +
    1.46 +    Factory<Child1> One = new Factory<Child1>() {
    1.47 +      public Child1[] getArray() { return new Child1[1]; }
    1.48 +    };
    1.49 +
    1.50 +    M[] getArray();
    1.51 +  }
    1.52 +
    1.53 +  /**
    1.54 +   * C2 asserts when compiling this method. Bimorphic inlining happens at
    1.55 +   * getArray call site. A Phi in the catch block tries to join the meet type
    1.56 +   * from he inline site (Parent[]) with the type expected by CI (Interface[]).
    1.57 +   *
    1.58 +   * C2 throws an assert when it doesn't need to.
    1.59 +   */
    1.60 +  private static <I extends Interface> void collectIs(
    1.61 +      Factory<I> factory, Set<Interface> s) {
    1.62 +    for (I i : factory.getArray()) {
    1.63 +      try {
    1.64 +        s.add(i);
    1.65 +      } catch (Exception e) {
    1.66 +      }
    1.67 +    }
    1.68 +  }
    1.69 +
    1.70 +  static public void main(String argv[]) {
    1.71 +    Set<Interface> s = new HashSet();
    1.72 +
    1.73 +    for (int i = 0; i < 25000; i++) {
    1.74 +      collectIs(Factory.Zero, s);
    1.75 +      collectIs(Factory.One, s);
    1.76 +    }
    1.77 +  }
    1.78 +}
    1.79 +
    1.80 +/**
    1.81 + * Establish necessary class hierarchy
    1.82 + */
    1.83 +
    1.84 +interface Interface {
    1.85 +}
    1.86 +
    1.87 +class Parent {
    1.88 +}
    1.89 +
    1.90 +class Child0 extends Parent implements Interface {
    1.91 +}
    1.92 +
    1.93 +class Child1 extends Parent implements Interface {
    1.94 +}
    1.95 +
    1.96 +class Child2 extends Parent implements Interface {
    1.97 +}

mercurial