test/compiler/6851282/Test.java

Tue, 31 Aug 2010 17:23:45 -0700

author
trims
date
Tue, 31 Aug 2010 17:23:45 -0700
changeset 2093
0803c0f69b51
parent 1907
c18cbe5936b8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Added tag hs19-b06 for changeset 6c43216df135

kvn@1288 1 /*
trims@1907 2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
kvn@1288 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
kvn@1288 4 *
kvn@1288 5 * This code is free software; you can redistribute it and/or modify it
kvn@1288 6 * under the terms of the GNU General Public License version 2 only, as
kvn@1288 7 * published by the Free Software Foundation.
kvn@1288 8 *
kvn@1288 9 * This code is distributed in the hope that it will be useful, but WITHOUT
kvn@1288 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
kvn@1288 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kvn@1288 12 * version 2 for more details (a copy is included in the LICENSE file that
kvn@1288 13 * accompanied this code).
kvn@1288 14 *
kvn@1288 15 * You should have received a copy of the GNU General Public License version
kvn@1288 16 * 2 along with this work; if not, write to the Free Software Foundation,
kvn@1288 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
kvn@1288 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
kvn@1288 22 *
kvn@1288 23 */
kvn@1288 24
kvn@1288 25 /**
kvn@1288 26 * @test
kvn@1288 27 * @bug 6851282
kvn@1288 28 * @summary JIT miscompilation results in null entry in array when using CompressedOops
kvn@1288 29 *
kvn@1336 30 * @run main/othervm/timeout=600 -Xmx256m -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops Test
kvn@1288 31 */
kvn@1288 32
kvn@1288 33 import java.util.ArrayList;
kvn@1288 34 import java.util.List;
kvn@1288 35
kvn@1288 36 public class Test {
kvn@1288 37 void foo(A a, A[] as) {
kvn@1288 38 for (A a1 : as) {
kvn@1288 39 B[] filtered = a.c(a1);
kvn@1288 40 for (B b : filtered) {
kvn@1288 41 if (b == null) {
kvn@1288 42 System.out.println("bug: b == null");
kvn@1288 43 System.exit(97);
kvn@1288 44 }
kvn@1288 45 }
kvn@1288 46 }
kvn@1288 47 }
kvn@1288 48
kvn@1288 49 public static void main(String[] args) {
kvn@1288 50 List<A> as = new ArrayList<A>();
kvn@1288 51 for (int i = 0; i < 5000; i++) {
kvn@1288 52 List<B> bs = new ArrayList<B>();
kvn@1288 53 for (int j = i; j < i + 1000; j++)
kvn@1288 54 bs.add(new B(j));
kvn@1288 55 as.add(new A(bs.toArray(new B[0])));
kvn@1288 56 }
kvn@1288 57 new Test().foo(as.get(0), as.subList(1, as.size()).toArray(new A[0]));
kvn@1288 58 }
kvn@1288 59 }
kvn@1288 60
kvn@1288 61 class A {
kvn@1288 62 final B[] bs;
kvn@1288 63
kvn@1288 64 public A(B[] bs) {
kvn@1288 65 this.bs = bs;
kvn@1288 66 }
kvn@1288 67
kvn@1288 68 final B[] c(final A a) {
kvn@1288 69 return new BoxedArray<B>(bs).filter(new Function<B, Boolean>() {
kvn@1288 70 public Boolean apply(B arg) {
kvn@1288 71 for (B b : a.bs) {
kvn@1288 72 if (b.d == arg.d)
kvn@1288 73 return true;
kvn@1288 74 }
kvn@1288 75 return false;
kvn@1288 76 }
kvn@1288 77 });
kvn@1288 78 }
kvn@1288 79 }
kvn@1288 80
kvn@1288 81 class BoxedArray<T> {
kvn@1288 82
kvn@1288 83 private final T[] array;
kvn@1288 84
kvn@1288 85 BoxedArray(T[] array) {
kvn@1288 86 this.array = array;
kvn@1288 87 }
kvn@1288 88
kvn@1288 89 public T[] filter(Function<T, Boolean> function) {
kvn@1288 90 boolean[] include = new boolean[array.length];
kvn@1288 91 int len = 0;
kvn@1288 92 int i = 0;
kvn@1288 93 while (i < array.length) {
kvn@1288 94 if (function.apply(array[i])) {
kvn@1288 95 include[i] = true;
kvn@1288 96 len += 1;
kvn@1288 97 }
kvn@1288 98 i += 1;
kvn@1288 99 }
kvn@1288 100 T[] result = (T[]) java.lang.reflect.Array.newInstance(array.getClass().getComponentType(), len);
kvn@1288 101 len = 0;
kvn@1288 102 i = 0;
kvn@1288 103 while (len < result.length) {
kvn@1288 104 if (include[i]) {
kvn@1288 105 result[len] = array[i];
kvn@1288 106 len += 1;
kvn@1288 107 }
kvn@1288 108 i += 1;
kvn@1288 109 }
kvn@1288 110 return result;
kvn@1288 111 }
kvn@1288 112 }
kvn@1288 113
kvn@1288 114 interface Function<T, R> {
kvn@1288 115 R apply(T arg);
kvn@1288 116 }
kvn@1288 117
kvn@1288 118 class B {
kvn@1288 119 final int d;
kvn@1288 120 public B(int d) {
kvn@1288 121 this.d = d;
kvn@1288 122 }
kvn@1288 123 }
kvn@1288 124

mercurial