hotspot/test/gc/logging/TestUnifiedLoggingSwitchStress.java
author jmasa
Fri, 13 May 2016 12:36:03 -0700
changeset 38311 9f2555351233
parent 38275 38582fe9500f
child 39965 5955109add86
permissions -rw-r--r--
8156867: Simplify/reduce testing in ParallelCompact_test Reviewed-by: jwilhelm, jprovino
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
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    46
 * @library /testlibrary /test/lib /
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    47
 * @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
    48
 *
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    49
 * @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
    50
 *                   gc.logging.TestUnifiedLoggingSwitchStress 60
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    51
 */
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
class MemoryStresser implements Runnable {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    54
    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
    55
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    56
    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
    57
    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
    58
    private int maxSimpleAllocationMemory = 0;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    59
    private int usedMemory = 0;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    60
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
     * 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
    63
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    64
    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
    65
    /**
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    66
     * 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
    67
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    68
    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
    69
    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
    70
    /**
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    71
     * 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
    72
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    73
    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
    74
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
     * 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
    77
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    78
    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
    79
    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
    80
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
     * @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
    83
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    84
    public MemoryStresser(int maxMemory) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    85
        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
    86
    }
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
    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
    89
            // Huge allocation
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    90
            () -> {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    91
                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
    92
                    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
    93
                            * 0.9));
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    94
                    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
    95
                }
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
            // Huge deallocation
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
    99
            () -> {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   100
                if (liveHObjects.size() > 0) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   101
                    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
   102
                    liveHObjects.remove(elementNum);
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   103
                }
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
            // Simple allocation
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   107
            () -> {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   108
                if (maxSimpleAllocationMemory - usedMemory != 0) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   109
                    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
   110
                            MAX_SIMPLE_ALLOCATION_SIZE));
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   111
                    if (arraySize != 0) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   112
                        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
   113
                        usedMemory += arraySize;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   114
                    }
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
            // Simple deallocation
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   119
            () -> {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   120
                if (liveObjects.size() != 0) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   121
                    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
   122
                    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
   123
                    liveObjects.remove(elementNum);
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   124
                    usedMemory -= shouldFree;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   125
                }
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
            // Dead object allocation
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   129
            () -> {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   130
                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
   131
                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
   132
            }
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
    @Override
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   136
    public void run() {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   137
        while (!shouldStop) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   138
            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
   139
            Thread.yield();
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   140
        }
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
        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
   143
    }
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
class LogLevelSwitcher implements Runnable {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   147
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   148
    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
   149
    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
   150
    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
   151
    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
   152
    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
   153
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
     * @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
   156
     * @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
   157
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   158
    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
   159
        this.logCount = logCount;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   160
        this.logFilePrefix = logFilePrefix;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   161
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
    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
   165
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   166
    @Override
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   167
    public void run() {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   168
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   169
        while (!shouldStop) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   170
            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
   171
            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
   172
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   173
            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
   174
            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
   175
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   176
            try {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   177
                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
   178
                                        "vmLog",
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   179
                                        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
   180
                                        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
   181
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   182
                if (!out.toString().isEmpty()) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   183
                    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
   184
                                    + " output %s\n",
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   185
                            outputCommand, logLevelCommand, out);
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   186
                }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   187
            } 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
   188
                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
   189
                e.printStackTrace();
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   190
                throw new Error(e);
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   191
            }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   192
            Thread.yield();
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   193
        }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   194
        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
   195
    }
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
public class TestUnifiedLoggingSwitchStress {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   200
    /**
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   201
     * 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
   202
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   203
    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
   204
    /**
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   205
     * 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
   206
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   207
    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
   208
    /**
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   209
     * 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
   210
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   211
    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
   212
    /**
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   213
     * 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
   214
     */
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   215
    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
   216
            / 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
   217
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   218
    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
   219
        if (args.length != 1) {
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   220
            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
   221
        }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   222
        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
   223
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   224
        long startTime = System.currentTimeMillis();
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   225
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   226
        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
   227
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   228
        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
   229
            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
   230
        }
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
        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
   233
            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
   234
        }
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
        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
   237
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   238
        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
   239
            Thread.yield();
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   240
        }
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
        MemoryStresser.shouldStop = true;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   243
        LogLevelSwitcher.shouldStop = true;
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   244
    }
38582fe9500f 8150865: SQE test: GC unified logging: check that dynamic log level doesn't break anything
kzhaldyb
parents:
diff changeset
   245
}