hotspot/test/gc/logging/TestUnifiedLoggingSwitchStress.java
author mchernov
Tue, 12 Jul 2016 15:06:18 +0300
changeset 39965 5955109add86
parent 38275 38582fe9500f
child 40631 ed82623d7831
permissions -rw-r--r--
8158508: gc/logging/TestUnifiedLoggingSwitchStress.java timeout Reviewed-by: jmasa, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38275
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
     1
/*
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
     4
 *
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
     8
 *
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    13
 * accompanied this code).
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    14
 *
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    18
 *
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    21
 * questions.
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    22
 *
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    23
 */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    24
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    25
package gc.logging;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    26
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    27
import jdk.test.lib.Utils;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    28
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    29
import javax.management.InstanceNotFoundException;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    30
import javax.management.MBeanException;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    31
import javax.management.MBeanServer;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    32
import javax.management.MalformedObjectNameException;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    33
import javax.management.ObjectName;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    34
import javax.management.ReflectionException;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    35
import java.lang.management.ManagementFactory;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    36
import java.util.LinkedList;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    37
import java.util.List;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    38
import java.util.Random;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    39
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    40
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    41
/**
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    42
 * @test TestUnifiedLoggingSwitchStress
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    43
 * @summary Switches gc log level on fly while stressing memory/gc
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    44
 * @key gc
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    45
 * @key stress
39965
5955109add86 8158508: gc/logging/TestUnifiedLoggingSwitchStress.java timeout
mchernov
parents: 38275
diff changeset
    46
 * @requires !vm.flightRecorder
38275
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    47
 * @library /testlibrary /test/lib /
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    48
 * @modules java.management java.base/jdk.internal.misc
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    49
 *
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    50
 * @run main/othervm -Xmx256M -Xms256M
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    51
 *                   gc.logging.TestUnifiedLoggingSwitchStress 60
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    52
 */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    53
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    54
class MemoryStresser implements Runnable {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    55
    public static volatile boolean shouldStop = false;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    56
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    57
    private final List<byte[]> liveObjects = new LinkedList<>();
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    58
    private final List<byte[]> liveHObjects = new LinkedList<>();
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    59
    private int maxSimpleAllocationMemory = 0;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    60
    private int usedMemory = 0;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    61
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    62
    /**
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    63
     * Maximum amount of huge allocations
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    64
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    65
    private static int H_ALLOCATION_MAX_COUNT = 4;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    66
    /**
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    67
     * Maximum regions in one huge allocation
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    68
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    69
    private static int H_ALLOCATION_REGION_SIZE = 2;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    70
    private static final int G1_REGION_SIZE = 1024 * 1024;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    71
    /**
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    72
     * Maximum size of simple allocation
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    73
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    74
    private static final int MAX_SIMPLE_ALLOCATION_SIZE = (int) (G1_REGION_SIZE / 2 * 0.9);
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    75
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    76
    /**
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    77
     * Maximum size of dead (i.e. one which is made unreachable right after allocation) object
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    78
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    79
    private static final int DEAD_OBJECT_MAX_SIZE = G1_REGION_SIZE / 10;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    80
    private static final Random RND = Utils.getRandomInstance();
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    81
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    82
    /**
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    83
     * @param maxMemory maximum memory that could be allocated
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    84
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    85
    public MemoryStresser(int maxMemory) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    86
        maxSimpleAllocationMemory = maxMemory - G1_REGION_SIZE * H_ALLOCATION_MAX_COUNT * H_ALLOCATION_REGION_SIZE;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    87
    }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    88
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    89
    public final Runnable[] actions = new Runnable[]{
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    90
            // Huge allocation
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    91
            () -> {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    92
                if (liveHObjects.size() < H_ALLOCATION_MAX_COUNT) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    93
                    int allocationSize = RND.nextInt((int) (G1_REGION_SIZE * (H_ALLOCATION_REGION_SIZE - 0.5)
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    94
                            * 0.9));
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    95
                    liveHObjects.add(new byte[allocationSize + G1_REGION_SIZE / 2]);
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    96
                }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    97
            },
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    98
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    99
            // Huge deallocation
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   100
            () -> {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   101
                if (liveHObjects.size() > 0) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   102
                    int elementNum = RND.nextInt(liveHObjects.size());
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   103
                    liveHObjects.remove(elementNum);
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   104
                }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   105
            },
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   106
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   107
            // Simple allocation
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   108
            () -> {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   109
                if (maxSimpleAllocationMemory - usedMemory != 0) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   110
                    int arraySize = RND.nextInt(Math.min(maxSimpleAllocationMemory - usedMemory,
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   111
                            MAX_SIMPLE_ALLOCATION_SIZE));
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   112
                    if (arraySize != 0) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   113
                        liveObjects.add(new byte[arraySize]);
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   114
                        usedMemory += arraySize;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   115
                    }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   116
                }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   117
            },
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   118
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   119
            // Simple deallocation
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   120
            () -> {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   121
                if (liveObjects.size() != 0) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   122
                    int elementNum = RND.nextInt(liveObjects.size());
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   123
                    int shouldFree = liveObjects.get(elementNum).length;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   124
                    liveObjects.remove(elementNum);
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   125
                    usedMemory -= shouldFree;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   126
                }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   127
            },
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   128
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   129
            // Dead object allocation
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   130
            () -> {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   131
                int size = RND.nextInt(DEAD_OBJECT_MAX_SIZE);
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   132
                byte[] deadObject = new byte[size];
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   133
            }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   134
    };
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   135
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   136
    @Override
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   137
    public void run() {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   138
        while (!shouldStop) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   139
            actions[RND.nextInt(actions.length)].run();
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   140
            Thread.yield();
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   141
        }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   142
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   143
        System.out.println("Memory Stresser finished");
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   144
    }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   145
}
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   146
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   147
class LogLevelSwitcher implements Runnable {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   148
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   149
    public static volatile boolean shouldStop = false;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   150
    private final int logCount; // how many various log files will be used
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   151
    private final String logFilePrefix; // name of log file will be logFilePrefix + index
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   152
    private final Random RND = Utils.getRandomInstance();
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   153
    private final MBeanServer MBS = ManagementFactory.getPlatformMBeanServer();
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   154
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   155
    /**
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   156
     * @param logFilePrefix prefix for log files
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   157
     * @param logCount     amount of log files
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   158
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   159
    public LogLevelSwitcher(String logFilePrefix, int logCount) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   160
        this.logCount = logCount;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   161
        this.logFilePrefix = logFilePrefix;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   162
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   163
    }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   164
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   165
    private static final String[] LOG_LEVELS = {"error", "warning", "info", "debug", "trace"};
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   166
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   167
    @Override
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   168
    public void run() {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   169
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   170
        while (!shouldStop) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   171
            int fileNum = RND.nextInt(logCount);
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   172
            int logLevel = RND.nextInt(LOG_LEVELS.length);
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   173
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   174
            String outputCommand = String.format("output=%s_%d.log", logFilePrefix, fileNum);
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   175
            String logLevelCommand = "what='gc*=" + LOG_LEVELS[logLevel] + "'";
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   176
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   177
            try {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   178
                Object out = MBS.invoke(new ObjectName("com.sun.management:type=DiagnosticCommand"),
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   179
                                        "vmLog",
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   180
                                        new Object[]{new String[]{outputCommand, logLevelCommand}},
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   181
                                        new String[]{String[].class.getName()});
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   182
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   183
                if (!out.toString().isEmpty()) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   184
                    System.out.format("WARNING: Diagnostic command vmLog with arguments %s,%s returned not empty"
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   185
                                    + " output %s\n",
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   186
                            outputCommand, logLevelCommand, out);
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   187
                }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   188
            } catch (InstanceNotFoundException | MBeanException | ReflectionException | MalformedObjectNameException e) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   189
                System.out.println("Got exception trying to change log level:" + e);
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   190
                e.printStackTrace();
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   191
                throw new Error(e);
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   192
            }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   193
            Thread.yield();
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   194
        }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   195
        System.out.println("Log Switcher finished");
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   196
    }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   197
}
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   198
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   199
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   200
public class TestUnifiedLoggingSwitchStress {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   201
    /**
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   202
     * Count of memory stressing threads
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   203
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   204
    private static final int MEMORY_STRESSERS_COUNT = 3;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   205
    /**
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   206
     * Count of log switching threads
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   207
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   208
    private static final int LOG_LEVEL_SWITCHERS_COUNT = 2;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   209
    /**
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   210
     * Count of log files created by each log switching thread
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   211
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   212
    private static final int LOG_FILES_COUNT = 2;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   213
    /**
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   214
     * Maximum amount memory allocated by each stressing thread
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   215
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   216
    private static final int MAX_MEMORY_PER_STRESSER = (int) (Runtime.getRuntime().freeMemory()
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   217
            / MEMORY_STRESSERS_COUNT * 0.7);
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   218
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   219
    public static void main(String[] args) throws InterruptedException {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   220
        if (args.length != 1) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   221
            throw new Error("Test Bug: Expected duration (in seconds) wasn't provided as command line argument");
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   222
        }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   223
        long duration = Integer.parseInt(args[0]) * 1000;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   224
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   225
        long startTime = System.currentTimeMillis();
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   226
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   227
        List<Thread> threads = new LinkedList<>();
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   228
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   229
        for (int i = 0; i < LOG_LEVEL_SWITCHERS_COUNT; i++) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   230
            threads.add(new Thread(new LogLevelSwitcher("Output_" + i, LOG_FILES_COUNT)));
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   231
        }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   232
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   233
        for (int i = 0; i < MEMORY_STRESSERS_COUNT; i++) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   234
            threads.add(new Thread(new MemoryStresser(MAX_MEMORY_PER_STRESSER)));
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   235
        }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   236
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   237
        threads.stream().forEach(Thread::start);
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   238
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   239
        while (System.currentTimeMillis() - startTime < duration) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   240
            Thread.yield();
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   241
        }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   242
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   243
        MemoryStresser.shouldStop = true;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   244
        LogLevelSwitcher.shouldStop = true;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   245
    }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   246
}