hotspot/test/gc/g1/TestStringDeduplicationTools.java
author brutisso
Thu, 10 Dec 2015 14:57:55 +0100
changeset 35061 be6025ebffea
parent 31371 311143309e73
child 40631 ed82623d7831
permissions -rw-r--r--
8145092: Use Unified Logging for the GC logging Summary: JEP-271. VM changes contributed by brutisso, test changes contributed by david. Reviewed-by: sjohanss, david, brutisso Contributed-by: bengt.rutisson@oracle.com, david.lindholm@oralce.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     1
/*
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 26328
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     4
 *
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     7
 * published by the Free Software Foundation.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     8
 *
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    13
 * accompanied this code).
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    14
 *
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    18
 *
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    21
 * questions.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    22
 */
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    23
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    24
/*
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    25
 * Common code for string deduplication tests
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    26
 */
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    27
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    28
import java.lang.management.*;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    29
import java.lang.reflect.*;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    30
import java.security.*;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    31
import java.util.*;
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 26328
diff changeset
    32
import jdk.test.lib.*;
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    33
import sun.misc.*;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    34
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    35
class TestStringDeduplicationTools {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    36
    private static final String YoungGC = "YoungGC";
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    37
    private static final String FullGC  = "FullGC";
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    38
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    39
    private static final int Xmn = 50;  // MB
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    40
    private static final int Xms = 100; // MB
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    41
    private static final int Xmx = 100; // MB
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    42
    private static final int MB = 1024 * 1024;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    43
    private static final int StringLength = 50;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    44
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    45
    private static Field valueField;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    46
    private static Unsafe unsafe;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    47
    private static byte[] dummy;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    48
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    49
    static {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    50
        try {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    51
            Field field = Unsafe.class.getDeclaredField("theUnsafe");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    52
            field.setAccessible(true);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    53
            unsafe = (Unsafe)field.get(null);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    54
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    55
            valueField = String.class.getDeclaredField("value");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    56
            valueField.setAccessible(true);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    57
        } catch (Exception e) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    58
            throw new RuntimeException(e);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    59
        }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    60
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    61
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    62
    private static Object getValue(String string) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    63
        try {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    64
            return valueField.get(string);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    65
        } catch (Exception e) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    66
            throw new RuntimeException(e);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    67
        }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    68
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    69
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    70
    private static void doFullGc(int numberOfTimes) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    71
        for (int i = 0; i < numberOfTimes; i++) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    72
            System.out.println("Begin: Full GC " + (i + 1) + "/" + numberOfTimes);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    73
            System.gc();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    74
            System.out.println("End: Full GC " + (i + 1) + "/" + numberOfTimes);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    75
        }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    76
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    77
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    78
    private static void doYoungGc(int numberOfTimes) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    79
        // Provoke at least numberOfTimes young GCs
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    80
        final int objectSize = 128;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    81
        final int maxObjectInYoung = (Xmn * MB) / objectSize;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    82
        for (int i = 0; i < numberOfTimes; i++) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    83
            System.out.println("Begin: Young GC " + (i + 1) + "/" + numberOfTimes);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    84
            for (int j = 0; j < maxObjectInYoung + 1; j++) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    85
                dummy = new byte[objectSize];
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    86
            }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    87
            System.out.println("End: Young GC " + (i + 1) + "/" + numberOfTimes);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    88
        }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    89
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    90
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    91
    private static void forceDeduplication(int ageThreshold, String gcType) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    92
        // Force deduplication to happen by either causing a FullGC or a YoungGC.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    93
        // We do several collections to also provoke a situation where the the
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    94
        // deduplication thread needs to yield while processing the queue. This
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    95
        // also tests that the references in the deduplication queue are adjusted
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    96
        // accordingly.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    97
        if (gcType.equals(FullGC)) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    98
            doFullGc(3);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    99
        } else {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   100
            doYoungGc(ageThreshold + 3);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   101
        }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   102
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   103
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   104
    private static String generateString(int id) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   105
        StringBuilder builder = new StringBuilder(StringLength);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   106
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   107
        builder.append("DeduplicationTestString:" + id + ":");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   108
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   109
        while (builder.length() < StringLength) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   110
            builder.append('X');
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   111
        }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   112
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   113
        return builder.toString();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   114
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   115
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   116
    private static ArrayList<String> createStrings(int total, int unique) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   117
        System.out.println("Creating strings: total=" + total + ", unique=" + unique);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   118
        if (total % unique != 0) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   119
            throw new RuntimeException("Total must be divisible by unique");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   120
        }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   121
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   122
        ArrayList<String> list = new ArrayList<String>(total);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   123
        for (int j = 0; j < total / unique; j++) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   124
            for (int i = 0; i < unique; i++) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   125
                list.add(generateString(i));
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   126
            }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   127
        }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   128
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   129
        return list;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   130
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   131
26328
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   132
    /**
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   133
     * Verifies that the given list contains expected number of unique strings.
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   134
     * It's possible that deduplication hasn't completed yet, so the method
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   135
     * will perform several attempts to check with a little pause between.
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   136
     * The method throws RuntimeException to signal that verification failed.
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   137
     *
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   138
     * @param list strings to check
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   139
     * @param uniqueExpected expected number of unique strings
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   140
     * @throws RuntimeException if check fails
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   141
     */
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   142
    private static void verifyStrings(ArrayList<String> list, int uniqueExpected) {
26328
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   143
        boolean passed = false;
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   144
        for (int attempts = 0; attempts < 10; attempts++) {
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   145
            // Check number of deduplicated strings
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   146
            ArrayList<Object> unique = new ArrayList<Object>(uniqueExpected);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   147
            for (String string: list) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   148
                Object value = getValue(string);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   149
                boolean uniqueValue = true;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   150
                for (Object obj: unique) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   151
                    if (obj == value) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   152
                        uniqueValue = false;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   153
                        break;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   154
                    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   155
                }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   156
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   157
                if (uniqueValue) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   158
                    unique.add(value);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   159
                }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   160
            }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   161
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   162
            System.out.println("Verifying strings: total=" + list.size() +
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   163
                               ", uniqueFound=" + unique.size() +
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   164
                               ", uniqueExpected=" + uniqueExpected);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   165
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   166
            if (unique.size() == uniqueExpected) {
26328
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   167
                System.out.println("Deduplication completed (as fast as " + attempts + " iterations)");
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   168
                passed = true;
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   169
                break;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   170
            } else {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   171
                System.out.println("Deduplication not completed, waiting...");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   172
                // Give the deduplication thread time to complete
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   173
                try {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   174
                    Thread.sleep(1000);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   175
                } catch (Exception e) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   176
                    throw new RuntimeException(e);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   177
                }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   178
            }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   179
        }
26328
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   180
        if (!passed) {
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   181
            throw new RuntimeException("String verification failed");
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   182
        }
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   183
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   184
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   185
    private static OutputAnalyzer runTest(String... extraArgs) throws Exception {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   186
        String[] defaultArgs = new String[] {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   187
            "-Xmn" + Xmn + "m",
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   188
            "-Xms" + Xms + "m",
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   189
            "-Xmx" + Xmx + "m",
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   190
            "-XX:+UseG1GC",
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   191
            "-XX:+UnlockDiagnosticVMOptions",
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   192
            "-XX:+VerifyAfterGC" // Always verify after GC
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   193
        };
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   194
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   195
        ArrayList<String> args = new ArrayList<String>();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   196
        args.addAll(Arrays.asList(defaultArgs));
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   197
        args.addAll(Arrays.asList(extraArgs));
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   198
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   199
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args.toArray(new String[args.size()]));
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   200
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   201
        System.err.println(output.getStderr());
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   202
        System.out.println(output.getStdout());
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   203
        return output;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   204
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   205
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   206
    private static class DeduplicationTest {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   207
        public static void main(String[] args) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   208
            System.out.println("Begin: DeduplicationTest");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   209
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   210
            final int numberOfStrings = Integer.parseUnsignedInt(args[0]);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   211
            final int numberOfUniqueStrings = Integer.parseUnsignedInt(args[1]);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   212
            final int ageThreshold = Integer.parseUnsignedInt(args[2]);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   213
            final String gcType = args[3];
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   214
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   215
            ArrayList<String> list = createStrings(numberOfStrings, numberOfUniqueStrings);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   216
            forceDeduplication(ageThreshold, gcType);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   217
            verifyStrings(list, numberOfUniqueStrings);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   218
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   219
            System.out.println("End: DeduplicationTest");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   220
        }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   221
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   222
        public static OutputAnalyzer run(int numberOfStrings, int ageThreshold, String gcType, String... extraArgs) throws Exception {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   223
            String[] defaultArgs = new String[] {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   224
                "-XX:+UseStringDeduplication",
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   225
                "-XX:StringDeduplicationAgeThreshold=" + ageThreshold,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   226
                DeduplicationTest.class.getName(),
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   227
                "" + numberOfStrings,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   228
                "" + numberOfStrings / 2,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   229
                "" + ageThreshold,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   230
                gcType
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   231
            };
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   232
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   233
            ArrayList<String> args = new ArrayList<String>();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   234
            args.addAll(Arrays.asList(extraArgs));
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   235
            args.addAll(Arrays.asList(defaultArgs));
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   236
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   237
            return runTest(args.toArray(new String[args.size()]));
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   238
        }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   239
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   240
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   241
    private static class InternedTest {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   242
        public static void main(String[] args) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   243
            // This test verifies that interned strings are always
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   244
            // deduplicated when being interned, and never after
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   245
            // being interned.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   246
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   247
            System.out.println("Begin: InternedTest");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   248
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   249
            final int ageThreshold = Integer.parseUnsignedInt(args[0]);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   250
            final String baseString = "DeduplicationTestString:" + InternedTest.class.getName();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   251
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   252
            // Create duplicate of baseString
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   253
            StringBuilder sb1 = new StringBuilder(baseString);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   254
            String dupString1 = sb1.toString();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   255
            if (getValue(dupString1) == getValue(baseString)) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   256
                throw new RuntimeException("Values should not match");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   257
            }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   258
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   259
            // Force baseString to be inspected for deduplication
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   260
            // and be inserted into the deduplication hashtable.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   261
            forceDeduplication(ageThreshold, FullGC);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   262
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   263
            // Wait for deduplication to occur
26328
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   264
            for (int attempts = 0; attempts < 10; attempts++) {
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   265
                if (getValue(dupString1) == getValue(baseString)) {
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   266
                    break;
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   267
                }
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   268
                System.out.println("Waiting...");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   269
                try {
26328
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   270
                    Thread.sleep(1000);
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   271
                } catch (Exception e) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   272
                    throw new RuntimeException(e);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   273
                }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   274
            }
26328
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   275
            if (getValue(dupString1) != getValue(baseString)) {
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   276
                throw new RuntimeException("Deduplication has not occurred");
8a3e0337bbb5 8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
dfazunen
parents: 24842
diff changeset
   277
            }
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   278
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   279
            // Create a new duplicate of baseString
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   280
            StringBuilder sb2 = new StringBuilder(baseString);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   281
            String dupString2 = sb2.toString();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   282
            if (getValue(dupString2) == getValue(baseString)) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   283
                throw new RuntimeException("Values should not match");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   284
            }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   285
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   286
            // Intern the new duplicate
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   287
            Object beforeInternedValue = getValue(dupString2);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   288
            String internedString = dupString2.intern();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   289
            if (internedString != dupString2) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   290
                throw new RuntimeException("String should match");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   291
            }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   292
            if (getValue(internedString) != getValue(baseString)) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   293
                throw new RuntimeException("Values should match");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   294
            }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   295
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   296
            // Check original value of interned string, to make sure
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   297
            // deduplication happened on the interned string and not
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   298
            // on the base string
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   299
            if (beforeInternedValue == getValue(baseString)) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   300
                throw new RuntimeException("Values should not match");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   301
            }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   302
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   303
            System.out.println("End: InternedTest");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   304
        }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   305
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   306
        public static OutputAnalyzer run() throws Exception {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   307
            return runTest("-Xlog:gc=debug,gc+stringdedup=trace",
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   308
                           "-XX:+UseStringDeduplication",
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   309
                           "-XX:StringDeduplicationAgeThreshold=" + DefaultAgeThreshold,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   310
                           InternedTest.class.getName(),
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   311
                           "" + DefaultAgeThreshold);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   312
        }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   313
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   314
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   315
    /*
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   316
     * Tests
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   317
     */
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   318
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   319
    private static final int LargeNumberOfStrings = 10000;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   320
    private static final int SmallNumberOfStrings = 10;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   321
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   322
    private static final int MaxAgeThreshold      = 15;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   323
    private static final int DefaultAgeThreshold  = 3;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   324
    private static final int MinAgeThreshold      = 1;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   325
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   326
    private static final int TooLowAgeThreshold   = MinAgeThreshold - 1;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   327
    private static final int TooHighAgeThreshold  = MaxAgeThreshold + 1;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   328
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   329
    public static void testYoungGC() throws Exception {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   330
        // Do young GC to age strings to provoke deduplication
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   331
        OutputAnalyzer output = DeduplicationTest.run(LargeNumberOfStrings,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   332
                                                      DefaultAgeThreshold,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   333
                                                      YoungGC,
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   334
                                                      "-Xlog:gc,gc+stringdedup=trace");
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   335
        output.shouldNotContain("Full GC");
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   336
        output.shouldContain("Pause Young (G1 Evacuation Pause)");
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   337
        output.shouldContain("Concurrent String Deduplication");
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   338
        output.shouldContain("Deduplicated:");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   339
        output.shouldHaveExitValue(0);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   340
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   341
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   342
    public static void testFullGC() throws Exception {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   343
        // Do full GC to age strings to provoke deduplication
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   344
        OutputAnalyzer output = DeduplicationTest.run(LargeNumberOfStrings,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   345
                                                      DefaultAgeThreshold,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   346
                                                      FullGC,
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   347
                                                      "-Xlog:gc,gc+stringdedup=trace");
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   348
        output.shouldNotContain("Pause Young (G1 Evacuation Pause)");
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   349
        output.shouldContain("Full GC");
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   350
        output.shouldContain("Concurrent String Deduplication");
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   351
        output.shouldContain("Deduplicated:");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   352
        output.shouldHaveExitValue(0);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   353
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   354
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   355
    public static void testTableResize() throws Exception {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   356
        // Test with StringDeduplicationResizeALot
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   357
        OutputAnalyzer output = DeduplicationTest.run(LargeNumberOfStrings,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   358
                                                      DefaultAgeThreshold,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   359
                                                      YoungGC,
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   360
                                                      "-Xlog:gc,gc+stringdedup=trace",
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   361
                                                      "-XX:+StringDeduplicationResizeALot");
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   362
        output.shouldContain("Concurrent String Deduplication");
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   363
        output.shouldContain("Deduplicated:");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   364
        output.shouldNotContain("Resize Count: 0");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   365
        output.shouldHaveExitValue(0);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   366
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   367
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   368
    public static void testTableRehash() throws Exception {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   369
        // Test with StringDeduplicationRehashALot
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   370
        OutputAnalyzer output = DeduplicationTest.run(LargeNumberOfStrings,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   371
                                                      DefaultAgeThreshold,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   372
                                                      YoungGC,
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   373
                                                      "-Xlog:gc,gc+stringdedup=trace",
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   374
                                                      "-XX:+StringDeduplicationRehashALot");
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   375
        output.shouldContain("Concurrent String Deduplication");
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   376
        output.shouldContain("Deduplicated:");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   377
        output.shouldNotContain("Rehash Count: 0");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   378
        output.shouldNotContain("Hash Seed: 0x0");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   379
        output.shouldHaveExitValue(0);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   380
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   381
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   382
    public static void testAgeThreshold() throws Exception {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   383
        OutputAnalyzer output;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   384
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   385
        // Test with max age theshold
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   386
        output = DeduplicationTest.run(SmallNumberOfStrings,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   387
                                       MaxAgeThreshold,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   388
                                       YoungGC,
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   389
                                       "-Xlog:gc,gc+stringdedup=trace");
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   390
        output.shouldContain("Concurrent String Deduplication");
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   391
        output.shouldContain("Deduplicated:");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   392
        output.shouldHaveExitValue(0);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   393
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   394
        // Test with min age theshold
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   395
        output = DeduplicationTest.run(SmallNumberOfStrings,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   396
                                       MinAgeThreshold,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   397
                                       YoungGC,
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   398
                                       "-Xlog:gc,gc+stringdedup=trace");
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   399
        output.shouldContain("Concurrent String Deduplication");
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   400
        output.shouldContain("Deduplicated:");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   401
        output.shouldHaveExitValue(0);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   402
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   403
        // Test with too low age threshold
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   404
        output = DeduplicationTest.run(SmallNumberOfStrings,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   405
                                       TooLowAgeThreshold,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   406
                                       YoungGC);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
   407
        output.shouldContain("outside the allowed range");
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   408
        output.shouldHaveExitValue(1);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   409
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   410
        // Test with too high age threshold
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   411
        output = DeduplicationTest.run(SmallNumberOfStrings,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   412
                                       TooHighAgeThreshold,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   413
                                       YoungGC);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
   414
        output.shouldContain("outside the allowed range");
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   415
        output.shouldHaveExitValue(1);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   416
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   417
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   418
    public static void testPrintOptions() throws Exception {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   419
        OutputAnalyzer output;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   420
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   421
        // Test without -Xlog:gc
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   422
        output = DeduplicationTest.run(SmallNumberOfStrings,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   423
                                       DefaultAgeThreshold,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   424
                                       YoungGC);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   425
        output.shouldNotContain("Concurrent String Deduplication");
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   426
        output.shouldNotContain("Deduplicated:");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   427
        output.shouldHaveExitValue(0);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   428
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   429
        // Test with -Xlog:gc+stringdedup
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   430
        output = DeduplicationTest.run(SmallNumberOfStrings,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   431
                                       DefaultAgeThreshold,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   432
                                       YoungGC,
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   433
                                       "-Xlog:gc+stringdedup");
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 31371
diff changeset
   434
        output.shouldContain("Concurrent String Deduplication");
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   435
        output.shouldNotContain("Deduplicated:");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   436
        output.shouldHaveExitValue(0);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   437
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   438
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   439
    public static void testInterned() throws Exception {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   440
        // Test that interned strings are deduplicated before being interned
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   441
        OutputAnalyzer output = InternedTest.run();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   442
        output.shouldHaveExitValue(0);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   443
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   444
}