hotspot/test/gc/stress/TestStressRSetCoarsening.java
author dcubed
Thu, 14 Apr 2016 20:43:16 -0700
changeset 37507 bade77e200d0
parent 37498 c920466a3287
child 38728 3b18de52e85a
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
     1
/*
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
     4
 *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
     8
 *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    13
 * accompanied this code).
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    14
 *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    18
 *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    21
 * questions.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    22
 */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    23
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    24
import java.util.concurrent.TimeoutException;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    25
import sun.hotspot.WhiteBox;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    26
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    27
/*
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    28
 * @test TestStressRSetCoarsening.java
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    29
 * @key stress
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    30
 * @bug 8146984 8147087
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    31
 * @requires vm.gc=="G1" | vm.gc=="null"
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    32
 * @requires os.maxMemory > 3G
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    33
 *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    34
 * @summary Stress G1 Remembered Set by creating a lot of cross region links
37507
dcubed
parents: 37498
diff changeset
    35
 * @modules java.base/jdk.internal.misc
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    36
 * @library /testlibrary /test/lib
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    37
 * @build sun.hotspot.WhiteBox
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    38
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    39
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    40
 * @run main/othervm/timeout=300
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    41
 *     -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    42
 *     -XX:+UseG1GC -Xlog:gc* -XX:MaxGCPauseMillis=1000
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    43
 *     -Xmx500m -XX:G1HeapRegionSize=1m TestStressRSetCoarsening  1  0 300
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    44
 * @run main/othervm/timeout=300
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    45
 *     -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    46
 *     -XX:+UseG1GC -Xlog:gc* -XX:MaxGCPauseMillis=1000
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    47
 *     -Xmx500m -XX:G1HeapRegionSize=8m TestStressRSetCoarsening  1 10 300
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    48
 * @run main/othervm/timeout=300
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    49
 *     -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    50
 *     -XX:+UseG1GC -Xlog:gc* -XX:MaxGCPauseMillis=1000
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    51
 *     -Xmx500m -XX:G1HeapRegionSize=32m TestStressRSetCoarsening 42 10 300
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    52
 * @run main/othervm/timeout=300
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    53
 *     -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    54
 *     -XX:+UseG1GC -Xlog:gc* -XX:MaxGCPauseMillis=1000
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    55
 *     -Xmx500m -XX:G1HeapRegionSize=1m TestStressRSetCoarsening  2 0 300
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    56
 * @run main/othervm/timeout=1800
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    57
 *     -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    58
 *     -XX:+UseG1GC -Xlog:gc* -XX:MaxGCPauseMillis=1000
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    59
 *     -Xmx1G -XX:G1HeapRegionSize=1m TestStressRSetCoarsening 500 0  1800
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    60
 * @run main/othervm/timeout=1800
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    61
 *     -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    62
 *     -XX:+UseG1GC -Xlog:gc* -XX:MaxGCPauseMillis=1000
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    63
 *     -Xmx1G -XX:G1HeapRegionSize=1m TestStressRSetCoarsening 10  10 1800
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    64
 */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    65
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    66
/**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    67
 * What the test does.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    68
 * Preparation stage:
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    69
 *   Fill out ~90% of the heap with objects, each object is an object array.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    70
 *   If we want to allocate K objects per region, we calculate N to meet:
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    71
 *      sizeOf(Object[N]) ~= regionSize / K
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    72
 * Stress stage:
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    73
 *   No more allocation, so no more GC.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    74
 *   We will perform a number of  iterations. On each iteration i,
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    75
 *   for each pair of regions Rx and Ry we will set c[i] references
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    76
 *   from Rx to Ry. If c[i] less than c[i-1] at the end of iteration
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    77
 *   concurrent mark cycle will be initiated (to recalculate remembered sets).
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    78
 *   As the result RSet will be growing up and down, up and down many times.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    79
 *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    80
 * The test expects: no crash and no timeouts.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    81
 *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    82
 * Test Parameters:
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    83
 *   args[0] - number of objects per Heap Region (1 - means humongous)
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    84
 *   args[1] - number of regions to refresh to provoke GC at the end of cycle.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    85
 *             (0 - means no GC, i.e. no reading from RSet)
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    86
 *   args[2] - timeout in seconds (to stop execution to avoid jtreg timeout)
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    87
 */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    88
public class TestStressRSetCoarsening {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    89
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    90
    public static void main(String... args) throws InterruptedException {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    91
        if (args.length != 3) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    92
            throw new IllegalArgumentException("Wrong number of arguments " + args.length);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    93
        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    94
        int objectsPerRegion = Integer.parseInt(args[0]); // 1 means humongous
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    95
        int regsToRefresh = Integer.parseInt(args[1]);  // 0 means no regions to refresh at the end of cycle
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    96
        int timeout = Integer.parseInt(args[2]); // in seconds, test should stop working eariler
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    97
        new TestStressRSetCoarsening(objectsPerRegion, regsToRefresh, timeout).go();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    98
    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    99
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   100
    private static final long KB = 1024;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   101
    private static final long MB = 1024 * KB;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   102
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   103
    private static final WhiteBox WB = WhiteBox.getWhiteBox();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   104
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   105
    public final Object[][] storage;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   106
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   107
    /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   108
     * Number of objects per region. This is a test parameter.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   109
     */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   110
    public final int K;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   111
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   112
    /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   113
     * Length of object array: sizeOf(Object[N]) ~= regionSize / K
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   114
     * N will be calculated as function of K.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   115
     */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   116
    public final int N;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   117
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   118
    /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   119
     * How many regions involved into testing.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   120
     * Will be calculated as heapFractionToAllocate * freeRegionCount.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   121
     */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   122
    public final int regionCount;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   123
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   124
    /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   125
     * How much heap to use.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   126
     */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   127
    public final float heapFractionToAllocate = 0.9f;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   128
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   129
    /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   130
     * How many regions to be refreshed at the end of cycle.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   131
     * This is a test parameter.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   132
     */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   133
    public final int regsToRefresh;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   134
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   135
    /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   136
     * Initial time.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   137
     */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   138
    public final long start;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   139
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   140
    /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   141
     * Time when the test should stop working.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   142
     */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   143
    public final long finishAt;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   144
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   145
    /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   146
     * Does pre-calculation and allocate necessary objects.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   147
     *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   148
     * @param objPerRegions how many objects per G1 heap region
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   149
     */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   150
    TestStressRSetCoarsening(int objPerRegions, int regsToRefresh, int timeout) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   151
        this.K = objPerRegions;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   152
        this.regsToRefresh = regsToRefresh;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   153
        this.start = System.currentTimeMillis();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   154
        this.finishAt = start + timeout * 900; // 10% ahead of jtreg timeout
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   155
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   156
        long regionSize = WB.g1RegionSize();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   157
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   158
        // How many free regions
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   159
        Runtime rt = Runtime.getRuntime();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   160
        long used = rt.totalMemory() - rt.freeMemory();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   161
        long totalFree = rt.maxMemory() - used;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   162
        regionCount = (int) ((totalFree / regionSize) * heapFractionToAllocate);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   163
        long toAllocate = regionCount * regionSize;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   164
        System.out.println("%% Test parameters");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   165
        System.out.println("%%   Objects per region              : " + K);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   166
        System.out.println("%%   Heap fraction to allocate       : " + (int) (heapFractionToAllocate * 100) + "%");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   167
        System.out.println("%%   Regions to refresh to provoke GC: " + regsToRefresh);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   168
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   169
        System.out.println("%% Memory");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   170
        System.out.println("%%   used          :        " + used / MB + "M");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   171
        System.out.println("%%   available     :        " + totalFree / MB + "M");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   172
        System.out.println("%%   to allocate   :        " + toAllocate / MB + "M");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   173
        System.out.println("%%     (in regs)   :        " + regionCount);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   174
        System.out.println("%%   G1 Region Size:        " + regionSize / MB + "M");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   175
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   176
        int refSize = WB.getHeapOopSize();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   177
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   178
        // Calculate N:    K*sizeOf(Object[N]) ~= regionSize
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   179
        //                 sizeOf(Object[N]) ~=  (N+4)*refSize
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   180
        // ==>
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   181
        //                 N = regionSize / K / refSize - 4;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   182
        int n = (int) ((regionSize / K) / refSize) - 5;  // best guess
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   183
        long objSize = WB.getObjectSize(new Object[n]);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   184
        while (K*objSize > regionSize) {   // adjust to avoid OOME
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   185
            n = n - 1;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   186
            objSize = WB.getObjectSize(new Object[n]);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   187
        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   188
        N = n;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   189
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   190
        /*
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   191
         *   --------------
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   192
         *   region0   storage[0]        = new Object[N]
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   193
         *             ...
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   194
         *             storage[K-1]      = new Object[N]
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   195
         *   ---------------
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   196
         *   region1   storage[K]        = new Object[N]
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   197
         *             ...
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   198
         *             storage[2*K - 1]  = new Object[N]
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   199
         *   --------------
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   200
         *   ...
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   201
         *   --------------
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   202
         *   regionX   storage[X*K]         = new Object[N]
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   203
         *             ...
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   204
         *             storage[(X+1)*K -1]  = new Object[N]
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   205
         *    where X = HeapFraction * TotalRegions
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   206
         *   -------------
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   207
         */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   208
        System.out.println("%% Objects");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   209
        System.out.println("%%   N (array length)      : " + N);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   210
        System.out.println("%%   K (objects in regions): " + K);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   211
        System.out.println("%%   Object size           : " + objSize +
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   212
                "  (sizeOf(new Object[" + N + "])");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   213
        System.out.println("%%   Reference size        : " + refSize);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   214
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   215
        storage = new Object[regionCount * K][];
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   216
        for (int i = 0; i < storage.length; i++) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   217
            storage[i] = new Object[N];
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   218
        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   219
    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   220
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   221
    public void go() throws InterruptedException {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   222
        // threshold for sparce -> fine
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   223
        final int FINE = WB.getIntxVMFlag("G1RSetSparseRegionEntries").intValue();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   224
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   225
        // threshold for fine -> coarse
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   226
        final int COARSE = WB.getIntxVMFlag("G1RSetRegionEntries").intValue();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   227
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   228
        // regToRegRefCounts - array of reference counts from region to region
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   229
        // at the the end of iteration.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   230
        // The number of test iterations is array length - 1.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   231
        // If c[i] > c[i-1] then during the iteration i more references will
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   232
        // be created.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   233
        // If c[i] < c[i-1] then some referenes will be cleaned.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   234
        int[] regToRegRefCounts = {0, FINE / 2, 0, FINE, (FINE + COARSE) / 2, 0,
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   235
            COARSE, COARSE + 10, FINE + 1, FINE / 2, 0};
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   236
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   237
        // For progress tracking
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   238
        int[] progress = new int[regToRegRefCounts.length];
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   239
        progress[0] = 0;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   240
        for (int i = 1; i < regToRegRefCounts.length; i++) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   241
            progress[i] = progress[i - 1] + Math.abs(regToRegRefCounts[i] - regToRegRefCounts[i - 1]);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   242
        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   243
        try {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   244
            for (int i = 1; i < regToRegRefCounts.length; i++) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   245
                int pre = regToRegRefCounts[i - 1];
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   246
                int cur = regToRegRefCounts[i];
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   247
                float prog = ((float) progress[i - 1] / progress[progress.length - 1]);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   248
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   249
                System.out.println("%% step " + i
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   250
                        + " out of " + (regToRegRefCounts.length - 1)
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   251
                        + " (~" + (int) (100 * prog) + "% done)");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   252
                System.out.println("%%      " + pre + "  --> " + cur);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   253
                for (int to = 0; to < regionCount; to++) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   254
                    // Select a celebrity object that we will install references to.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   255
                    // The celebrity will be referred from all other regions.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   256
                    // If the number of references after should be less than they
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   257
                    // were before, select NULL.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   258
                    Object celebrity = cur > pre ? storage[to * K] : null;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   259
                    for (int from = 0; from < regionCount; from++) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   260
                        if (to == from) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   261
                            continue; // no need to refer to itself
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   262
                        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   263
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   264
                        int step = cur > pre ? +1 : -1;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   265
                        for (int rn = pre; rn != cur; rn += step) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   266
                            storage[getY(to, from, rn)][getX(to, from, rn)] = celebrity;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   267
                            if (System.currentTimeMillis() > finishAt) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   268
                                throw new TimeoutException();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   269
                            }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   270
                        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   271
                    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   272
                }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   273
                if (pre > cur) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   274
                    // Number of references went down.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   275
                    // Need to provoke recalculation of RSet.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   276
                    WB.g1StartConcMarkCycle();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   277
                    while (WB.g1InConcurrentMark()) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   278
                        Thread.sleep(1);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   279
                    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   280
                }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   281
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   282
                // To force the use of rememebered set entries we need to provoke a GC.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   283
                // To induce some fragmentation, and some mixed GCs, we need
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   284
                // to make a few objects unreachable.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   285
                for (int toClean = i * regsToRefresh; toClean < (i + 1) * regsToRefresh; toClean++) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   286
                    int to = toClean % regionCount;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   287
                    // Need to remove all references from all regions to the region 'to'
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   288
                    for (int from = 0; from < regionCount; from++) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   289
                        if (to == from) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   290
                            continue; // no need to refer to itself
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   291
                        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   292
                        for (int rn = 0; rn <= cur; rn++) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   293
                            storage[getY(to, from, rn)][getX(to, from, rn)] = null;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   294
                        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   295
                    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   296
                    // 'Refresh' storage elements for the region 'to'
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   297
                    // After that loop all 'old' objects in the region 'to'
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   298
                    // should become unreachable.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   299
                    for (int k = 0; k < K; k++) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   300
                        storage[(to * K + k) % storage.length] = new Object[N];
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   301
                    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   302
                }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   303
            }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   304
        } catch (TimeoutException e) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   305
            System.out.println("%% TIMEOUT!!!");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   306
        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   307
        long now = System.currentTimeMillis();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   308
        System.out.println("%% Summary");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   309
        System.out.println("%%   Time spent          : " + ((now - start) / 1000) + " seconds");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   310
        System.out.println("%%   Free memory left    : " + Runtime.getRuntime().freeMemory() / KB + "K");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   311
        System.out.println("%% Test passed");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   312
    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   313
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   314
    /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   315
     * Returns X index in the Storage of the reference #rn from the region
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   316
     * 'from' to the region 'to'.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   317
     *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   318
     * @param to region # to refer to
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   319
     * @param from region # to refer from
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   320
     * @param rn number of reference
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   321
     *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   322
     * @return X index in the range: [0 ... N-1]
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   323
     */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   324
    private int getX(int to, int from, int rn) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   325
        return (rn * regionCount + to) % N;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   326
    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   327
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   328
    /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   329
     * Returns Y index in the Storage of the reference #rn from the region
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   330
     * 'from' to the region 'to'.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   331
     *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   332
     * @param to region # to refer to
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   333
     * @param from region # to refer from
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   334
     * @param rn number of reference
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   335
     *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   336
     * @return Y index in the range: [0 ... K*regionCount -1]
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   337
     */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   338
    private int getY(int to, int from, int rn) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   339
        return ((rn * regionCount + to) / N + from * K) % (regionCount * K);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   340
    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   341
}
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   342