Path: blob/master/test/hotspot/jtreg/compiler/c2/Test6851282.java
41149 views
/*1* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 685128226* @summary JIT miscompilation results in null entry in array when using CompressedOops27*28* @run main/othervm/timeout=600 -Xmx256m -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops29* compiler.c2.Test685128230*/3132package compiler.c2;3334import java.util.ArrayList;35import java.util.List;3637public class Test6851282 {38void foo(A a, A[] as) {39for (A a1 : as) {40B[] filtered = a.c(a1);41for (B b : filtered) {42if (b == null) {43System.out.println("bug: b == null");44System.exit(97);45}46}47}48}4950public static void main(String[] args) {51List<A> as = new ArrayList<A>();52for (int i = 0; i < 5000; i++) {53List<B> bs = new ArrayList<B>();54for (int j = i; j < i + 1000; j++)55bs.add(new B(j));56as.add(new A(bs.toArray(new B[0])));57}58new Test6851282().foo(as.get(0), as.subList(1, as.size()).toArray(new A[0]));59}6061static class A {62final B[] bs;6364public A(B[] bs) {65this.bs = bs;66}6768final B[] c(final A a) {69return new BoxedArray<B>(bs).filter(new Function<B, Boolean>() {70public Boolean apply(B arg) {71for (B b : a.bs) {72if (b.d == arg.d)73return true;74}75return false;76}77});78}79}8081static class BoxedArray<T> {8283private final T[] array;8485BoxedArray(T[] array) {86this.array = array;87}8889public T[] filter(Function<T, Boolean> function) {90boolean[] include = new boolean[array.length];91int len = 0;92int i = 0;93while (i < array.length) {94if (function.apply(array[i])) {95include[i] = true;96len += 1;97}98i += 1;99}100T[] result = (T[]) java.lang.reflect.Array.newInstance(array.getClass().getComponentType(), len);101len = 0;102i = 0;103while (len < result.length) {104if (include[i]) {105result[len] = array[i];106len += 1;107}108i += 1;109}110return result;111}112}113114static interface Function<T, R> {115R apply(T arg);116}117118static class B {119final int d;120121public B(int d) {122this.d = d;123}124}125}126127128129