hotspot/test/stress/gc/TestMultiThreadStressRSet.java
author erikj
Thu, 14 Apr 2016 15:13:42 +0200
changeset 37299 db3b0d4c3bda
parent 37062 5a26bcf87c57
permissions -rw-r--r--
8149777: Enable enhanced failure handler for "make test" Reviewed-by: ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37062
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
     1
/*
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
     4
 *
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
     8
 *
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    13
 * accompanied this code).
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    14
 *
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    18
 *
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    21
 * questions.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    22
 */
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    23
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    24
import java.io.PrintStream;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    25
import java.util.ArrayList;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    26
import java.util.List;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    27
import java.util.Map;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    28
import java.util.Random;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    29
import sun.hotspot.WhiteBox;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    30
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    31
/*
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    32
 * @test TestMultiThreadStressRSet.java
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    33
 * @key stress
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    34
 * @requires vm.gc=="G1" | vm.gc=="null"
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    35
 * @requires os.maxMemory > 2G
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    36
 *
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    37
 * @summary Stress G1 Remembered Set using multiple threads
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    38
 * @library /test/lib /testlibrary
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    39
 * @build sun.hotspot.WhiteBox
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    40
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    41
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    42
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    43
 *   -XX:+UseG1GC -XX:G1SummarizeRSetStatsPeriod=1 -Xlog:gc
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    44
 *   -Xmx500m -XX:G1HeapRegionSize=1m -XX:MaxGCPauseMillis=1000 TestMultiThreadStressRSet 10 4
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    45
 *
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    46
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    47
 *   -XX:+UseG1GC -XX:G1SummarizeRSetStatsPeriod=100 -Xlog:gc
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    48
 *   -Xmx1G -XX:G1HeapRegionSize=8m -XX:MaxGCPauseMillis=1000 TestMultiThreadStressRSet 60 16
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    49
 *
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    50
 * @run main/othervm/timeout=700 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    51
 *   -XX:+UseG1GC -XX:G1SummarizeRSetStatsPeriod=100 -Xlog:gc
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    52
 *   -Xmx500m -XX:G1HeapRegionSize=1m -XX:MaxGCPauseMillis=1000 TestMultiThreadStressRSet 600 32
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    53
 */
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    54
public class TestMultiThreadStressRSet {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    55
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    56
    private static final Random RND = new Random(2015 * 2016);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    57
    private static final WhiteBox WB = WhiteBox.getWhiteBox();
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    58
    private static final int REF_SIZE = WB.getHeapOopSize();
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    59
    private static final int REGION_SIZE = WB.g1RegionSize();
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    60
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    61
    // How many regions to use for the storage
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    62
    private static final int STORAGE_REGIONS = 20;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    63
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    64
    // Size a single obj in the storage
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    65
    private static final int OBJ_SIZE = 1024;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    66
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    67
    // How many regions of young/old gen to use in the BUFFER
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    68
    private static final int BUFFER_YOUNG_REGIONS = 60;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    69
    private static final int BUFFER_OLD_REGIONS = 40;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    70
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    71
    // Total number of objects in the storage.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    72
    private final int N;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    73
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    74
    // The storage of byte[]
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    75
    private final List<Object> STORAGE;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    76
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    77
    // Where references to the Storage will be stored
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    78
    private final List<Object[]> BUFFER;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    79
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    80
    // The length of a buffer element.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    81
    // RSet deals with "cards" (areas of 512 bytes), not with single refs
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    82
    // So, to affect the RSet the BUFFER refs should be allocated in different
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    83
    // memory cards.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    84
    private final int BUF_ARR_LEN = 100 * (512 / REF_SIZE);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    85
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    86
    // Total number of objects in the young/old buffers
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    87
    private final int YOUNG;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    88
    private final int OLD;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    89
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    90
    // To cause Remembered Sets change their coarse level the test uses a window
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    91
    // within STORAGE. All the BUFFER elements refer to only STORAGE objects
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    92
    // from the current window. The window is defined by a range.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    93
    // The first element has got the index: 'windowStart',
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    94
    // the last one: 'windowStart + windowSize - 1'
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    95
    // The window is shifting periodically.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    96
    private int windowStart;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    97
    private final int windowSize;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    98
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
    99
    // Counter of created worker threads
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   100
    private int counter = 0;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   101
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   102
    private volatile String errorMessage = null;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   103
    private volatile boolean isEnough = false;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   104
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   105
    public static void main(String args[]) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   106
        if (args.length != 2) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   107
            throw new IllegalArgumentException("TEST BUG: wrong arg count " + args.length);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   108
        }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   109
        long time = Long.parseLong(args[0]);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   110
        int threads = Integer.parseInt(args[1]);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   111
        new TestMultiThreadStressRSet().test(time * 1000, threads);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   112
    }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   113
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   114
    /**
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   115
     * Initiates test parameters, fills out the STORAGE and BUFFER.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   116
     */
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   117
    public TestMultiThreadStressRSet() {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   118
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   119
        N = (REGION_SIZE - 1) * STORAGE_REGIONS / OBJ_SIZE + 1;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   120
        STORAGE = new ArrayList<>(N);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   121
        int bytes = OBJ_SIZE - 20;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   122
        for (int i = 0; i < N - 1; i++) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   123
            STORAGE.add(new byte[bytes]);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   124
        }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   125
        STORAGE.add(new byte[REGION_SIZE / 2 + 100]); // humongous
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   126
        windowStart = 0;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   127
        windowSize = REGION_SIZE / OBJ_SIZE;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   128
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   129
        BUFFER = new ArrayList<>();
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   130
        int sizeOfBufferObject = 20 + REF_SIZE * BUF_ARR_LEN;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   131
        OLD = REGION_SIZE * BUFFER_OLD_REGIONS / sizeOfBufferObject;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   132
        YOUNG = REGION_SIZE * BUFFER_YOUNG_REGIONS / sizeOfBufferObject;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   133
        for (int i = 0; i < OLD + YOUNG; i++) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   134
            BUFFER.add(new Object[BUF_ARR_LEN]);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   135
        }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   136
    }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   137
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   138
    /**
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   139
     * Does the testing. Steps:
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   140
     * <ul>
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   141
     * <li> starts the Shifter thread
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   142
     * <li> during the given time starts new Worker threads, keeping the number
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   143
     * of live thread under limit.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   144
     * <li> stops the Shifter thread
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   145
     * </ul>
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   146
     *
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   147
     * @param timeInMillis how long to stress
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   148
     * @param maxThreads the maximum number of Worker thread working together.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   149
     */
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   150
    public void test(long timeInMillis, int maxThreads) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   151
        if (timeInMillis <= 0 || maxThreads <= 0) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   152
            throw new IllegalArgumentException("TEST BUG: be positive!");
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   153
        }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   154
        System.out.println("%% Time to work: " + timeInMillis / 1000 + "s");
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   155
        System.out.println("%% Number of threads: " + maxThreads);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   156
        long finish = System.currentTimeMillis() + timeInMillis;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   157
        Shifter shift = new Shifter(this, 1000, (int) (windowSize * 0.9));
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   158
        shift.start();
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   159
        for (int i = 0; i < maxThreads; i++) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   160
            new Worker(this, 100).start();
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   161
        }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   162
        try {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   163
            while (System.currentTimeMillis() < finish && errorMessage == null) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   164
                Thread.sleep(100);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   165
            }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   166
        } catch (Throwable t) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   167
            printAllStackTraces(System.err);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   168
            t.printStackTrace(System.err);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   169
            this.errorMessage = t.getMessage();
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   170
        } finally {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   171
            isEnough = true;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   172
        }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   173
        System.out.println("%% Total work cycles: " + counter);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   174
        if (errorMessage != null) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   175
            throw new RuntimeException(errorMessage);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   176
        }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   177
    }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   178
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   179
    /**
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   180
     * Returns an element from from the BUFFER (an object array) to keep
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   181
     * references to the storage.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   182
     *
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   183
     * @return an Object[] from buffer.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   184
     */
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   185
    private Object[] getFromBuffer() {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   186
        int index = counter % (OLD + YOUNG);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   187
        synchronized (BUFFER) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   188
            if (index < OLD) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   189
                if (counter % 100 == (counter / 100) % 100) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   190
                    // need to generate garbage in the old gen to provoke mixed GC
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   191
                    return replaceInBuffer(index);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   192
                } else {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   193
                    return BUFFER.get(index);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   194
                }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   195
            } else {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   196
                return replaceInBuffer(index);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   197
            }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   198
        }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   199
    }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   200
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   201
    private Object[] replaceInBuffer(int index) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   202
        Object[] objs = new Object[BUF_ARR_LEN];
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   203
        BUFFER.set(index, objs);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   204
        return objs;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   205
    }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   206
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   207
    /**
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   208
     * Returns a random object from the current window within the storage.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   209
     * A storage element with index from windowStart to windowStart+windowSize.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   210
     *
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   211
     * @return a random element from the current window within the storage.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   212
     */
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   213
    private Object getRandomObject() {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   214
        int index = (windowStart + RND.nextInt(windowSize)) % N;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   215
        return STORAGE.get(index);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   216
    }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   217
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   218
    private static void printAllStackTraces(PrintStream ps) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   219
        Map<Thread, StackTraceElement[]> traces = Thread.getAllStackTraces();
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   220
        for (Thread t : traces.keySet()) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   221
            ps.println(t.toString() + " " + t.getState());
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   222
            for (StackTraceElement traceElement : traces.get(t)) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   223
                ps.println("\tat " + traceElement);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   224
            }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   225
        }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   226
    }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   227
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   228
    /**
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   229
     * Thread to create a number of references from BUFFER to STORAGE.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   230
     */
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   231
    private static class Worker extends Thread {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   232
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   233
        final TestMultiThreadStressRSet boss;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   234
        final int refs; // number of refs to OldGen
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   235
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   236
        /**
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   237
         * @param boss the tests
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   238
         * @param refsToOldGen how many references to the OldGen to create
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   239
         */
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   240
        Worker(TestMultiThreadStressRSet boss, int refsToOldGen) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   241
            this.boss = boss;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   242
            this.refs = refsToOldGen;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   243
        }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   244
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   245
        @Override
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   246
        public void run() {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   247
            try {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   248
                while (!boss.isEnough) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   249
                    Object[] objs = boss.getFromBuffer();
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   250
                    int step = objs.length / refs;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   251
                    for (int i = 0; i < refs; i += step) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   252
                        objs[i] = boss.getRandomObject();
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   253
                    }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   254
                    boss.counter++;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   255
                }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   256
            } catch (Throwable t) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   257
                t.printStackTrace(System.out);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   258
                boss.errorMessage = t.getMessage();
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   259
            }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   260
        }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   261
    }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   262
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   263
    /**
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   264
     * Periodically shifts the current STORAGE window, removing references
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   265
     * in BUFFER that refer to objects outside the window.
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   266
     */
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   267
    private static class Shifter extends Thread {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   268
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   269
        final TestMultiThreadStressRSet boss;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   270
        final int sleepTime;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   271
        final int shift;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   272
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   273
        Shifter(TestMultiThreadStressRSet boss, int sleepTime, int shift) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   274
            this.boss = boss;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   275
            this.sleepTime = sleepTime;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   276
            this.shift = shift;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   277
        }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   278
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   279
        @Override
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   280
        public void run() {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   281
            try {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   282
                while (!boss.isEnough) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   283
                    Thread.sleep(sleepTime);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   284
                    boss.windowStart += shift;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   285
                    for (int i = 0; i < boss.OLD; i++) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   286
                        Object[] objs = boss.BUFFER.get(i);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   287
                        for (int j = 0; j < objs.length; j++) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   288
                            objs[j] = null;
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   289
                        }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   290
                    }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   291
                    if (!WB.g1InConcurrentMark()) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   292
                        System.out.println("%% start CMC");
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   293
                        WB.g1StartConcMarkCycle();
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   294
                    } else {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   295
                        System.out.println("%% CMC is already in progress");
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   296
                    }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   297
                }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   298
            } catch (Throwable t) {
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   299
                t.printStackTrace(System.out);
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   300
                boss.errorMessage = t.getMessage();
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   301
            }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   302
        }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   303
    }
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   304
}
5a26bcf87c57 8145908: [Newtest] Multi-threading stress test for G1 Remembered Sets
dfazunen
parents:
diff changeset
   305