Test.java 928 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
/*
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */

/*
 * @test
 * @bug 6659207
 * @summary access violation in CompilerThread0
 */

public class Test {
    static int[] array = new int[12];

    static int index(int i) {
        if (i == 0) return 0;
        for (int n = 0; n < array.length; n++)
            if (i < array[n]) return n;
        return -1;
    }

    static int test(int i) {
        int result = 0;
        i = index(i);
        if (i >= 0)
            if (array[i] != 0)
                result++;

        if (i != -1)
            array[i]++;

        return result;
    }

    public static void main(String[] args) {
        int total = 0;
        for (int i = 0; i < 100000; i++) {
            total += test(10);
        }
        System.out.println(total);
    }
}