1 /*
   2  * Copyright (c) 2012, 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 8002069
  28  * @summary Assert failed in C2: assert(field->edge_count() > 0) failed: sanity
  29  *
  30  * @run main/othervm -Xmx32m -XX:+IgnoreUnrecognizedVMOptions -Xbatch
  31  *      -XX:CompileCommand=exclude,compiler.c2.Test8002069::dummy
  32  *      compiler.c2.Test8002069
  33  */
  34 
  35 package compiler.c2;
  36 
  37 public class Test8002069 {
  38     static abstract class O {
  39         int f;
  40 
  41         public O() {
  42             f = 5;
  43         }
  44 
  45         abstract void put(int i);
  46 
  47         public int foo(int i) {
  48             put(i);
  49             return i;
  50         }
  51     }
  52 
  53     static class A extends O {
  54         int[] a;
  55 
  56         public A(int s) {
  57             a = new int[s];
  58         }
  59 
  60         public void put(int i) {
  61             a[i % a.length] = i;
  62         }
  63     }
  64 
  65     static class B extends O {
  66         int sz;
  67         int[] a;
  68 
  69         public B(int s) {
  70             sz = s;
  71             a = new int[s];
  72         }
  73 
  74         public void put(int i) {
  75             a[i % sz] = i;
  76         }
  77     }
  78 
  79     public static void main(String args[]) {
  80         int sum = 0;
  81         for (int i = 0; i < 8000; i++) {
  82             sum += test1(i);
  83         }
  84         for (int i = 0; i < 100000; i++) {
  85             sum += test2(i);
  86         }
  87         System.out.println("PASSED. sum = " + sum);
  88     }
  89 
  90     private O o;
  91 
  92     private int foo(int i) {
  93         return o.foo(i);
  94     }
  95 
  96     static int test1(int i) {
  97         Test8002069 t = new Test8002069();
  98         t.o = new A(5);
  99         return t.foo(i);
 100     }
 101 
 102     static int test2(int i) {
 103         Test8002069 t = new Test8002069();
 104         t.o = new B(5);
 105         dummy(i);
 106         return t.foo(i);
 107     }
 108 
 109     static int dummy(int i) {
 110         return i * 2;
 111     }
 112 }
 113