0N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation.
0N/A *
2362N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2362N/A *
2362N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 6851282
1053N/A * @summary JIT miscompilation results in null entry in array when using CompressedOops
0N/A *
0N/A * @run main/othervm/timeout=600 -Xmx256m -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops Test
0N/A */
0N/A
0N/Aimport java.util.ArrayList;
0N/Aimport java.util.List;
0N/A
0N/Apublic class Test {
0N/A void foo(A a, A[] as) {
0N/A for (A a1 : as) {
0N/A B[] filtered = a.c(a1);
0N/A for (B b : filtered) {
0N/A if (b == null) {
0N/A System.out.println("bug: b == null");
0N/A System.exit(97);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A public static void main(String[] args) {
0N/A List<A> as = new ArrayList<A>();
0N/A for (int i = 0; i < 5000; i++) {
0N/A List<B> bs = new ArrayList<B>();
0N/A for (int j = i; j < i + 1000; j++)
0N/A bs.add(new B(j));
0N/A as.add(new A(bs.toArray(new B[0])));
0N/A }
0N/A new Test().foo(as.get(0), as.subList(1, as.size()).toArray(new A[0]));
0N/A }
0N/A}
0N/A
0N/Aclass A {
0N/A final B[] bs;
0N/A
0N/A public A(B[] bs) {
0N/A this.bs = bs;
0N/A }
0N/A
0N/A final B[] c(final A a) {
1053N/A return new BoxedArray<B>(bs).filter(new Function<B, Boolean>() {
1053N/A public Boolean apply(B arg) {
1053N/A for (B b : a.bs) {
1053N/A if (b.d == arg.d)
1053N/A return true;
2862N/A }
2862N/A return false;
2862N/A }
2862N/A });
2862N/A }
2862N/A}
1053N/A
0N/Aclass BoxedArray<T> {
0N/A
0N/A private final T[] array;
0N/A
0N/A BoxedArray(T[] array) {
0N/A this.array = array;
0N/A }
0N/A
0N/A public T[] filter(Function<T, Boolean> function) {
0N/A boolean[] include = new boolean[array.length];
0N/A int len = 0;
0N/A int i = 0;
0N/A while (i < array.length) {
0N/A if (function.apply(array[i])) {
0N/A include[i] = true;
0N/A len += 1;
0N/A }
0N/A i += 1;
0N/A }
0N/A T[] result = (T[]) java.lang.reflect.Array.newInstance(array.getClass().getComponentType(), len);
0N/A len = 0;
0N/A i = 0;
0N/A while (len < result.length) {
0N/A if (include[i]) {
0N/A result[len] = array[i];
0N/A len += 1;
0N/A }
0N/A i += 1;
0N/A }
0N/A return result;
0N/A }
0N/A}
0N/A
0N/Ainterface Function<T, R> {
0N/A R apply(T arg);
0N/A}
0N/A
0N/Aclass B {
0N/A final int d;
0N/A public B(int d) {
0N/A this.d = d;
0N/A }
0N/A}
0N/A
0N/A