test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/Generator.java
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 49958 cc29d7717e3a
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49958
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     1
/*
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     2
 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     4
 *
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     8
 *
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    14
 *
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    18
 *
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    21
 * questions.
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    22
 */
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    23
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    24
package nsk.monitoring.share;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    25
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    26
import java.util.*;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    27
import java.io.*;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    28
import java.util.ArrayList;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    29
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    30
public class Generator {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    31
        private String patternFileName;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    32
        private String outDir;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    33
        private List<String> lines = new ArrayList<>();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    34
        private String prefix = "LoadableClass";
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    35
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    36
        public Generator(String patternFileName, String outDir) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    37
                this.patternFileName = patternFileName;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    38
                this.outDir = outDir;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    39
        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    40
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    41
        private void load() throws IOException {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    42
                BufferedReader rd = null;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    43
                try {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    44
                        rd = new BufferedReader(new FileReader(patternFileName));
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    45
                        String s = rd.readLine();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    46
                        while (s != null) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    47
                                lines.add(s);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    48
                                s = rd.readLine();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    49
                        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    50
                } finally {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    51
                        if (rd != null) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    52
                                rd.close();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    53
                        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    54
                }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    55
        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    56
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    57
        private void generate(int n) throws IOException {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    58
                PrintStream out = null;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    59
                String tokens = Integer.toString(n);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    60
                if (tokens.length() == 1)
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    61
                        tokens = "00" + tokens;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    62
                else if (tokens.length() == 2)
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    63
                        tokens = "0" + tokens;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    64
                try {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    65
                        out = new PrintStream(new FileOutputStream(new File(outDir, prefix + tokens + ".java")));
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    66
                        for (int i = 0; i < lines.size(); ++i) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    67
                                String line = lines.get(i);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    68
                                out.println(line.replaceAll("XYZ", tokens));
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    69
                        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    70
                } finally {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    71
                        if (out != null) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    72
                                out.close();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    73
                        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    74
                }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    75
        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    76
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    77
        public void run() throws IOException {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    78
                load();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    79
                for (int i = 1; i < 101; ++i)
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    80
                        generate(i);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    81
        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    82
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    83
        private static void usage() {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    84
                System.out.println("Usage: nsk.monitoring.share.Generator <pattern file> <output directory>");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    85
        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    86
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    87
        public static void main(String[] args) throws Exception {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    88
                if (args.length != 2) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    89
                        usage();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    90
                        throw new IllegalArgumentException("Need exactly two arguments.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    91
                }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    92
                new Generator(args[0], args[1]).run();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    93
        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    94
}