test/hotspot/jtreg/gc/stress/TestStressRSetCoarsening.java
author lkorinth
Mon, 28 Jan 2019 15:53:56 +0100
changeset 53523 4c5184c56dc2
parent 48791 6e079ff6c83c
permissions -rw-r--r--
8214799: Add package declaration to each JTREG test case in the gc folder Reviewed-by: lmesnik, tschatzl
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
/*
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 48791
diff changeset
     2
 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
37498
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
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 48791
diff changeset
    24
package gc.stress;
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 48791
diff changeset
    25
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    26
import java.util.concurrent.TimeoutException;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    27
import sun.hotspot.WhiteBox;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    28
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    29
/*
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    30
 * @test TestStressRSetCoarsening.java
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    31
 * @key stress
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    32
 * @bug 8146984 8147087
39414
4adf52148100 8160088: update hotspot tests depending on GC to use @requires vm.gc.X
dfazunen
parents: 38930
diff changeset
    33
 * @requires vm.gc.G1
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    34
 * @requires os.maxMemory > 3G
38930
469cfb0d7eb3 8157954: [TESTBUG] G1 tests fail with defined MaxGCPauseMillis
mchernov
parents: 38728
diff changeset
    35
 * @requires vm.opt.MaxGCPauseMillis == "null"
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    36
 *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    37
 * @summary Stress G1 Remembered Set by creating a lot of cross region links
37507
dcubed
parents: 37498
diff changeset
    38
 * @modules java.base/jdk.internal.misc
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 39414
diff changeset
    39
 * @library /test/lib
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    40
 * @build sun.hotspot.WhiteBox
48791
6e079ff6c83c 8186635: ClassFileInstaller should be run as a driver
iignatyev
parents: 47216
diff changeset
    41
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    42
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    43
 * @run main/othervm/timeout=300
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    44
 *     -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    45
 *     -XX:+UseG1GC -Xlog:gc* -XX:MaxGCPauseMillis=1000
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 48791
diff changeset
    46
 *     -Xmx500m -XX:G1HeapRegionSize=1m gc.stress.TestStressRSetCoarsening  1  0 300
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    47
 * @run main/othervm/timeout=300
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    48
 *     -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    49
 *     -XX:+UseG1GC -Xlog:gc* -XX:MaxGCPauseMillis=1000
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 48791
diff changeset
    50
 *     -Xmx500m -XX:G1HeapRegionSize=8m gc.stress.TestStressRSetCoarsening  1 10 300
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    51
 * @run main/othervm/timeout=300
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    52
 *     -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    53
 *     -XX:+UseG1GC -Xlog:gc* -XX:MaxGCPauseMillis=1000
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 48791
diff changeset
    54
 *     -Xmx500m -XX:G1HeapRegionSize=32m gc.stress.TestStressRSetCoarsening 42 10 300
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    55
 * @run main/othervm/timeout=300
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    56
 *     -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    57
 *     -XX:+UseG1GC -Xlog:gc* -XX:MaxGCPauseMillis=1000
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 48791
diff changeset
    58
 *     -Xmx500m -XX:G1HeapRegionSize=1m gc.stress.TestStressRSetCoarsening  2 0 300
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    59
 * @run main/othervm/timeout=1800
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    60
 *     -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    61
 *     -XX:+UseG1GC -Xlog:gc* -XX:MaxGCPauseMillis=1000
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 48791
diff changeset
    62
 *     -Xmx1G -XX:G1HeapRegionSize=1m gc.stress.TestStressRSetCoarsening 500 0  1800
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    63
 * @run main/othervm/timeout=1800
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    64
 *     -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    65
 *     -XX:+UseG1GC -Xlog:gc* -XX:MaxGCPauseMillis=1000
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 48791
diff changeset
    66
 *     -Xmx1G -XX:G1HeapRegionSize=1m gc.stress.TestStressRSetCoarsening 10  10 1800
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    67
 */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    68
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    69
/**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    70
 * What the test does.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    71
 * Preparation stage:
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    72
 *   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
    73
 *   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
    74
 *      sizeOf(Object[N]) ~= regionSize / K
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    75
 * Stress stage:
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    76
 *   No more allocation, so no more GC.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    77
 *   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
    78
 *   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
    79
 *   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
    80
 *   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
    81
 *   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
    82
 *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    83
 * The test expects: no crash and no timeouts.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    84
 *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    85
 * Test Parameters:
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    86
 *   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
    87
 *   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
    88
 *             (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
    89
 *   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
    90
 */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    91
public class TestStressRSetCoarsening {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    92
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    93
    public static void main(String... args) throws InterruptedException {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    94
        if (args.length != 3) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    95
            throw new IllegalArgumentException("Wrong number of arguments " + args.length);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    96
        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    97
        int objectsPerRegion = Integer.parseInt(args[0]); // 1 means humongous
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    98
        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
    99
        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
   100
        new TestStressRSetCoarsening(objectsPerRegion, regsToRefresh, timeout).go();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   101
    }
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 long KB = 1024;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   104
    private static final long MB = 1024 * KB;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   105
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   106
    private static final WhiteBox WB = WhiteBox.getWhiteBox();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   107
38728
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   108
    public final ObjStorage storage;
37498
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
    /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   111
     * 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
   112
     */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   113
    public final int K;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   114
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
     * Length of object array: sizeOf(Object[N]) ~= regionSize / K
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   117
     * N will be calculated as function of K.
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
    public final int N;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   120
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
     * How many regions involved into testing.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   123
     * Will be calculated as heapFractionToAllocate * freeRegionCount.
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
    public final int regionCount;
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
    /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   128
     * How much heap to use.
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
    public final float heapFractionToAllocate = 0.9f;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   131
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
     * 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
   134
     * This is a test parameter.
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
    public final int regsToRefresh;
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
    /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   139
     * Initial time.
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
    public final long start;
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
    /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   144
     * Time when the test should stop working.
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
    public final long finishAt;
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
    /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   149
     * Does pre-calculation and allocate necessary objects.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   150
     *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   151
     * @param objPerRegions how many objects per G1 heap region
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   152
     */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   153
    TestStressRSetCoarsening(int objPerRegions, int regsToRefresh, int timeout) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   154
        this.K = objPerRegions;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   155
        this.regsToRefresh = regsToRefresh;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   156
        this.start = System.currentTimeMillis();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   157
        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
   158
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   159
        long regionSize = WB.g1RegionSize();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   160
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   161
        // How many free regions
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   162
        Runtime rt = Runtime.getRuntime();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   163
        long used = rt.totalMemory() - rt.freeMemory();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   164
        long totalFree = rt.maxMemory() - used;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   165
        regionCount = (int) ((totalFree / regionSize) * heapFractionToAllocate);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   166
        long toAllocate = regionCount * regionSize;
38728
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   167
        long freeMemoryLimit = totalFree - toAllocate;
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   168
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   169
        System.out.println("%% Test parameters");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   170
        System.out.println("%%   Objects per region              : " + K);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   171
        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
   172
        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
   173
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   174
        System.out.println("%% Memory");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   175
        System.out.println("%%   used          :        " + used / MB + "M");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   176
        System.out.println("%%   available     :        " + totalFree / MB + "M");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   177
        System.out.println("%%   to allocate   :        " + toAllocate / MB + "M");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   178
        System.out.println("%%     (in regs)   :        " + regionCount);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   179
        System.out.println("%%   G1 Region Size:        " + regionSize / MB + "M");
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
        int refSize = WB.getHeapOopSize();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   182
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   183
        // Calculate N:    K*sizeOf(Object[N]) ~= regionSize
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   184
        //                 sizeOf(Object[N]) ~=  (N+4)*refSize
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   185
        // ==>
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   186
        //                 N = regionSize / K / refSize - 4;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   187
        int n = (int) ((regionSize / K) / refSize) - 5;  // best guess
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   188
        long objSize = WB.getObjectSize(new Object[n]);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   189
        while (K*objSize > regionSize) {   // adjust to avoid OOME
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   190
            n = n - 1;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   191
            objSize = WB.getObjectSize(new Object[n]);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   192
        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   193
        N = n;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   194
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
         *   --------------
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   197
         *   region0   storage[0]        = new Object[N]
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   198
         *             ...
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   199
         *             storage[K-1]      = new Object[N]
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
         *   region1   storage[K]        = new Object[N]
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   202
         *             ...
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   203
         *             storage[2*K - 1]  = new Object[N]
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   204
         *   --------------
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   205
         *   ...
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
         *   regionX   storage[X*K]         = new Object[N]
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   208
         *             ...
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   209
         *             storage[(X+1)*K -1]  = new Object[N]
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   210
         *    where X = HeapFraction * TotalRegions
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   211
         *   -------------
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   212
         */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   213
        System.out.println("%% Objects");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   214
        System.out.println("%%   N (array length)      : " + N);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   215
        System.out.println("%%   K (objects in regions): " + K);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   216
        System.out.println("%%   Object size           : " + objSize +
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   217
                "  (sizeOf(new Object[" + N + "])");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   218
        System.out.println("%%   Reference size        : " + refSize);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   219
38728
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   220
        // Maximum number of objects to allocate is regionCount * K.
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   221
        storage = new ObjStorage(regionCount * K);
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   222
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   223
        // Add objects as long as there is space in the storage
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   224
        // and we haven't used more memory than planned.
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   225
        while (!storage.isFull() && (rt.maxMemory() - used) > freeMemoryLimit) {
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   226
            storage.addArray(new Object[N]);
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   227
            // Update used memory
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   228
            used = rt.totalMemory() - rt.freeMemory();
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   229
        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   230
    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   231
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   232
    public void go() throws InterruptedException {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   233
        // threshold for sparce -> fine
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   234
        final int FINE = WB.getIntxVMFlag("G1RSetSparseRegionEntries").intValue();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   235
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   236
        // threshold for fine -> coarse
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   237
        final int COARSE = WB.getIntxVMFlag("G1RSetRegionEntries").intValue();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   238
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   239
        // regToRegRefCounts - array of reference counts from region to region
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   240
        // at the the end of iteration.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   241
        // The number of test iterations is array length - 1.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   242
        // 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
   243
        // be created.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   244
        // 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
   245
        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
   246
            COARSE, COARSE + 10, FINE + 1, FINE / 2, 0};
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   247
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   248
        // For progress tracking
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   249
        int[] progress = new int[regToRegRefCounts.length];
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   250
        progress[0] = 0;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   251
        for (int i = 1; i < regToRegRefCounts.length; i++) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   252
            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
   253
        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   254
        try {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   255
            for (int i = 1; i < regToRegRefCounts.length; i++) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   256
                int pre = regToRegRefCounts[i - 1];
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   257
                int cur = regToRegRefCounts[i];
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   258
                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
   259
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   260
                System.out.println("%% step " + i
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   261
                        + " out of " + (regToRegRefCounts.length - 1)
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   262
                        + " (~" + (int) (100 * prog) + "% done)");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   263
                System.out.println("%%      " + pre + "  --> " + cur);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   264
                for (int to = 0; to < regionCount; to++) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   265
                    // 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
   266
                    // The celebrity will be referred from all other regions.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   267
                    // 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
   268
                    // were before, select NULL.
38728
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   269
                    Object celebrity = cur > pre ? storage.getArrayAt(to * K) : null;
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   270
                    for (int from = 0; from < regionCount; from++) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   271
                        if (to == from) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   272
                            continue; // no need to refer to itself
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   273
                        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   274
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   275
                        int step = cur > pre ? +1 : -1;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   276
                        for (int rn = pre; rn != cur; rn += step) {
38728
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   277
                            Object[] rnArray = storage.getArrayAt(getY(to, from, rn));
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   278
                            rnArray[getX(to, from, rn)] = celebrity;
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   279
                            if (System.currentTimeMillis() > finishAt) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   280
                                throw new TimeoutException();
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
                        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   283
                    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   284
                }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   285
                if (pre > cur) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   286
                    // Number of references went down.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   287
                    // Need to provoke recalculation of RSet.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   288
                    WB.g1StartConcMarkCycle();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   289
                    while (WB.g1InConcurrentMark()) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   290
                        Thread.sleep(1);
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
                }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   293
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   294
                // 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
   295
                // 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
   296
                // to make a few objects unreachable.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   297
                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
   298
                    int to = toClean % regionCount;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   299
                    // 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
   300
                    for (int from = 0; from < regionCount; from++) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   301
                        if (to == from) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   302
                            continue; // no need to refer to itself
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
                        for (int rn = 0; rn <= cur; rn++) {
38728
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   305
                            Object[] rnArray = storage.getArrayAt(getY(to, from, rn));
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   306
                            rnArray[getX(to, from, rn)] = null;
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   307
                        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   308
                    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   309
                    // 'Refresh' storage elements for the region 'to'
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   310
                    // 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
   311
                    // should become unreachable.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   312
                    for (int k = 0; k < K; k++) {
38728
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   313
                        storage.setArrayAt(to * K + k, new Object[N]);
37498
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
                }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   316
            }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   317
        } catch (TimeoutException e) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   318
            System.out.println("%% TIMEOUT!!!");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   319
        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   320
        long now = System.currentTimeMillis();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   321
        System.out.println("%% Summary");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   322
        System.out.println("%%   Time spent          : " + ((now - start) / 1000) + " seconds");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   323
        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
   324
        System.out.println("%% Test passed");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   325
    }
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
     * 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
   329
     * 'from' to the region 'to'.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   330
     *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   331
     * @param to region # to refer to
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   332
     * @param from region # to refer from
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   333
     * @param rn number of reference
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   334
     *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   335
     * @return X index in the range: [0 ... N-1]
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   336
     */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   337
    private int getX(int to, int from, int rn) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   338
        return (rn * regionCount + to) % N;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   339
    }
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
     * 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
   343
     * 'from' to the region 'to'.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   344
     *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   345
     * @param to region # to refer to
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   346
     * @param from region # to refer from
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   347
     * @param rn number of reference
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   348
     *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   349
     * @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
   350
     */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   351
    private int getY(int to, int from, int rn) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   352
        return ((rn * regionCount + to) / N + from * K) % (regionCount * K);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   353
    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   354
}
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   355
38728
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   356
//Helper class to encapsulate the object array storage.
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   357
class ObjStorage {
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   358
    public final Object[][] storage;
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   359
    public int usedCount;
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   360
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   361
    ObjStorage(int size) {
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   362
        storage  = new Object[size][];
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   363
        usedCount = 0;
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   364
    }
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   365
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   366
    public boolean isFull() {
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   367
        return usedCount >= storage.length;
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   368
    }
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   369
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   370
    public void addArray(Object[] objects) {
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   371
        if (isFull()) {
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   372
            throw new IllegalStateException("Storage full maximum number of allowed elements: " + usedCount);
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   373
        }
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   374
        storage[usedCount++] = objects;
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   375
    }
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   376
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   377
    // Limit by usedCount since memory limits can cause the storage
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   378
    // to have unused slots in the end.
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   379
    public void setArrayAt(int i, Object[] objects) {
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   380
        storage[i % usedCount] = objects;
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   381
    }
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   382
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   383
    // Limit by usedCount since memory limits can cause the storage
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   384
    // to have unused slots in the end.
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   385
    public Object[] getArrayAt(int i) {
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   386
        return storage[i % usedCount];
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   387
    }
3b18de52e85a 8157153: TestStressRSetCoarsening fails with OOM
sjohanss
parents: 37507
diff changeset
   388
}