hotspot/test/gc/stress/TestStressIHOPMultiThread.java
author lana
Thu, 12 May 2016 15:15:02 +0000
changeset 37915 be4ff50b6cb6
parent 37498 c920466a3287
child 39414 4adf52148100
permissions -rw-r--r--
Added tag jdk-9+118 for changeset cc643de7cb06
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37498
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
     1
/*
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
     4
 *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
     8
 *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    13
 * accompanied this code).
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    14
 *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    18
 *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    21
 * questions.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    22
 */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    23
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    24
 /*
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    25
 * @test TestStressIHOPMultiThread
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    26
 * @bug 8148397
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    27
 * @key stress
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    28
 * @summary Stress test for IHOP
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    29
 * @requires vm.gc=="G1" | vm.gc=="null"
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    30
 * @run main/othervm/timeout=200 -Xmx128m -XX:G1HeapWastePercent=0 -XX:G1MixedGCCountTarget=1
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    31
 *              -XX:+UseG1GC -XX:G1HeapRegionSize=1m -XX:+G1UseAdaptiveIHOP
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    32
 *              -Xlog:gc+ihop=debug,gc+ihop+ergo=debug,gc+ergo=debug:TestStressIHOPMultiThread1.log
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    33
 *              -Dtimeout=2 -DheapUsageMinBound=30 -DheapUsageMaxBound=80
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    34
 *              -Dthreads=2 TestStressIHOPMultiThread
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    35
 * @run main/othervm/timeout=200 -Xmx256m -XX:G1HeapWastePercent=0 -XX:G1MixedGCCountTarget=1
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    36
 *              -XX:+UseG1GC -XX:G1HeapRegionSize=2m -XX:+G1UseAdaptiveIHOP
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    37
 *              -Xlog:gc+ihop=debug,gc+ihop+ergo=debug,gc+ergo=debug:TestStressIHOPMultiThread2.log
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    38
 *              -Dtimeout=2 -DheapUsageMinBound=60 -DheapUsageMaxBound=90
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    39
 *              -Dthreads=3 TestStressIHOPMultiThread
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    40
 * @run main/othervm/timeout=200 -Xmx256m -XX:G1HeapWastePercent=0 -XX:G1MixedGCCountTarget=1
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    41
 *              -XX:+UseG1GC -XX:G1HeapRegionSize=4m -XX:-G1UseAdaptiveIHOP
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    42
 *              -Xlog:gc+ihop=debug,gc+ihop+ergo=debug,gc+ergo=debug:TestStressIHOPMultiThread3.log
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    43
 *              -Dtimeout=2 -DheapUsageMinBound=40 -DheapUsageMaxBound=90
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    44
 *              -Dthreads=5 TestStressIHOPMultiThread
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    45
 * @run main/othervm/timeout=200 -Xmx128m -XX:G1HeapWastePercent=0 -XX:G1MixedGCCountTarget=1
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    46
 *              -XX:+UseG1GC -XX:G1HeapRegionSize=8m -XX:+G1UseAdaptiveIHOP
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    47
 *              -Xlog:gc+ihop=debug,gc+ihop+ergo=debug,gc+ergo=debug:TestStressIHOPMultiThread4.log
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    48
 *              -Dtimeout=2 -DheapUsageMinBound=20 -DheapUsageMaxBound=90
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    49
 *              -Dthreads=10 TestStressIHOPMultiThread
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    50
 * @run main/othervm/timeout=200 -Xmx512m -XX:G1HeapWastePercent=0 -XX:G1MixedGCCountTarget=1
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    51
 *              -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:+G1UseAdaptiveIHOP
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    52
 *              -Xlog:gc+ihop=debug,gc+ihop+ergo=debug,gc+ergo=debug:TestStressIHOPMultiThread5.log
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    53
 *              -Dtimeout=2 -DheapUsageMinBound=20 -DheapUsageMaxBound=90
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    54
 *              -Dthreads=17 TestStressIHOPMultiThread
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    55
 */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    56
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    57
import java.util.ArrayList;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    58
import java.util.LinkedList;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    59
import java.util.List;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    60
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    61
/**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    62
 * Stress test for Adaptive IHOP. Starts a number of threads that fill and free
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    63
 * specified amount of memory. Tests work with enabled IHOP logging.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    64
 *
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    65
 */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    66
public class TestStressIHOPMultiThread {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    67
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    68
    public final static List<Object> GARBAGE = new LinkedList<>();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    69
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    70
    private final long HEAP_SIZE;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    71
    // Amount of memory to be allocated before iterations start
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    72
    private final long HEAP_PREALLOC_SIZE;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    73
    // Amount of memory to be allocated and freed during iterations
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    74
    private final long HEAP_ALLOC_SIZE;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    75
    private final int CHUNK_SIZE = 100000;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    76
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    77
    private final int TIMEOUT;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    78
    private final int THREADS;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    79
    private final int HEAP_LOW_BOUND;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    80
    private final int HEAP_HIGH_BOUND;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    81
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    82
    private volatile boolean running = true;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    83
    private final List<AllocationThread> threads;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    84
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    85
    public static void main(String[] args) throws InterruptedException {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    86
        new TestStressIHOPMultiThread().start();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    87
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    88
    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    89
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    90
    TestStressIHOPMultiThread() {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    91
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    92
        TIMEOUT = Integer.getInteger("timeout") * 60;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    93
        THREADS = Integer.getInteger("threads");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    94
        HEAP_LOW_BOUND = Integer.getInteger("heapUsageMinBound");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    95
        HEAP_HIGH_BOUND = Integer.getInteger("heapUsageMaxBound");
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    96
        HEAP_SIZE = Runtime.getRuntime().maxMemory();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    97
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    98
        HEAP_PREALLOC_SIZE = HEAP_SIZE * HEAP_LOW_BOUND / 100;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
    99
        HEAP_ALLOC_SIZE = HEAP_SIZE * (HEAP_HIGH_BOUND - HEAP_LOW_BOUND) / 100;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   100
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   101
        threads = new ArrayList<>(THREADS);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   102
    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   103
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   104
    public void start() throws InterruptedException {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   105
        fill();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   106
        createThreads();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   107
        waitForStress();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   108
        stressDone();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   109
        waitForFinish();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   110
    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   111
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   112
    /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   113
     * Fills HEAP_PREALLOC_SIZE bytes of garbage.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   114
     */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   115
    private void fill() {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   116
        long allocated = 0;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   117
        while (allocated < HEAP_PREALLOC_SIZE) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   118
            GARBAGE.add(new byte[CHUNK_SIZE]);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   119
            allocated += CHUNK_SIZE;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   120
        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   121
    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   122
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   123
    /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   124
     * Creates a number of threads which will fill and free amount of memory.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   125
     */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   126
    private void createThreads() {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   127
        for (int i = 0; i < THREADS; ++i) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   128
            System.out.println("Create thread " + i);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   129
            AllocationThread thread =new TestStressIHOPMultiThread.AllocationThread(i, HEAP_ALLOC_SIZE / THREADS);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   130
            // Put reference to thread garbage into common garbage for avoiding possible optimization.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   131
            GARBAGE.add(thread.getList());
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   132
            threads.add(thread);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   133
        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   134
        threads.forEach(t -> t.start());
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   135
    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   136
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   137
    /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   138
     * Wait each thread for finishing
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   139
     */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   140
    private void waitForFinish() {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   141
        threads.forEach(thread -> {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   142
            thread.silentJoin();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   143
        });
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   144
    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   145
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   146
    private boolean isRunning() {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   147
        return running;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   148
    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   149
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   150
    private void stressDone() {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   151
        running = false;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   152
    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   153
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   154
    private void waitForStress() throws InterruptedException {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   155
        Thread.sleep(TIMEOUT * 1000);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   156
    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   157
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   158
    private class AllocationThread extends Thread {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   159
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   160
        private final List<Object> garbage;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   161
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   162
        private final long amountOfGarbage;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   163
        private final int threadId;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   164
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   165
        public AllocationThread(int id, long amount) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   166
            super("Thread " + id);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   167
            threadId = id;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   168
            amountOfGarbage = amount;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   169
            garbage = new LinkedList<>();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   170
        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   171
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   172
        /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   173
         * Returns list of garbage.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   174
         * @return List with thread garbage.
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   175
         */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   176
        public List<Object> getList(){
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   177
            return garbage;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   178
        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   179
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   180
        @Override
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   181
        public void run() {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   182
            System.out.println("Start the thread " + threadId);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   183
            while (TestStressIHOPMultiThread.this.isRunning()) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   184
                allocate(amountOfGarbage);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   185
                free();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   186
            }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   187
        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   188
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   189
        private void silentJoin() {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   190
            System.out.println("Join the thread " + threadId);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   191
            try {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   192
                join();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   193
            } catch (InterruptedException ie) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   194
                throw new RuntimeException(ie);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   195
            }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   196
        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   197
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   198
        /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   199
         * Allocates thread local garbage
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   200
         */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   201
        private void allocate(long amount) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   202
            long allocated = 0;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   203
            while (allocated < amount && TestStressIHOPMultiThread.this.isRunning()) {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   204
                garbage.add(new byte[CHUNK_SIZE]);
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   205
                allocated += CHUNK_SIZE;
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   206
            }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   207
        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   208
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   209
        /**
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   210
         * Frees thread local garbage
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   211
         */
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   212
        private void free() {
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   213
            garbage.clear();
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   214
        }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   215
    }
c920466a3287 8153222: [TESTBUG] Move tests in stress/gc to gc/stress
mchernov
parents:
diff changeset
   216
}