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