make/jdk/src/classes/build/tools/classlist/HelloClasslist.java
author redestad
Wed, 17 Apr 2019 00:06:38 +0200
changeset 54550 5fa7fbddfe9d
parent 52804 28094715ae71
child 54677 beca9f8524c1
permissions -rw-r--r--
8222484: Specialize generation of simple String concatenation expressions Reviewed-by: jrose, jlaskey
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37805
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
     1
/*
54550
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
     2
 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
37805
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
     4
 *
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    10
 *
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    15
 * accompanied this code).
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    16
 *
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    20
 *
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    23
 * questions.
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    24
 */
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    25
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    26
/**
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    27
 * This application is meant to be run to create a classlist file representing
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    28
 * common use.
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    29
 *
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    30
 * The classlist is produced by adding -XX:DumpLoadedClassList=classlist
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    31
 */
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    32
package build.tools.classlist;
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    33
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    34
import java.net.InetAddress;
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    35
import java.time.LocalDateTime;
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    36
import java.time.ZoneId;
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    37
import java.time.format.DateTimeFormatter;
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    38
import java.util.stream.Stream;
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    39
import java.util.logging.*;
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    40
import java.util.Arrays;
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    41
import java.util.Date;
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    42
import java.util.List;
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    43
import java.util.Locale;
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    44
import java.text.DateFormat;
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    45
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    46
import static java.util.stream.Collectors.*;
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    47
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    48
/**
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    49
 * This class is used to generate a classlist during build. Intent
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    50
 * is to touch a reasonable amount of JDK classes that are commonly
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    51
 * loaded and used early.
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    52
 */
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    53
public class HelloClasslist {
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    54
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    55
    private static final Logger LOGGER = Logger.getLogger("Hello");
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    56
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    57
    public static void main(String ... args) {
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    58
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    59
        List<String> strings = Arrays.asList("Hello", "World!", "From: ",
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    60
              InetAddress.getLoopbackAddress().toString());
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    61
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    62
        String helloWorld = strings.parallelStream()
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    63
              .map(s -> s.toLowerCase(Locale.ROOT))
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    64
              .collect(joining(","));
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    65
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    66
        Stream.of(helloWorld.split(","))
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    67
              .forEach(System.out::println);
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    68
52177
430e6421d503 8212597: Optimize String concatenation setup when using primitive operands
redestad
parents: 47216
diff changeset
    69
        // Common concatenation patterns
54550
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
    70
        String SS     = String.valueOf(args.length) + String.valueOf(args.length);
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
    71
        String CS     = "string" + String.valueOf(args.length);
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
    72
        String SC     = String.valueOf(args.length) + "string";
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
    73
        String SCS    = String.valueOf(args.length) + "string" + String.valueOf(args.length);
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
    74
        String CSS    = "string" + String.valueOf(args.length) + String.valueOf(args.length);
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
    75
        String CSCS   = "string" + String.valueOf(args.length) + "string" + String.valueOf(args.length);
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
    76
        String SCSC   = String.valueOf(args.length) + "string" + String.valueOf(args.length) + "string";
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
    77
        String CSCSC  = "string" + String.valueOf(args.length) + "string" + String.valueOf(args.length) + "string";
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
    78
        String SCSCS  = String.valueOf(args.length) + "string" + String.valueOf(args.length) + "string" + String.valueOf(args.length);
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
    79
        String CI     = "string" + args.length;
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
    80
        String IC     = args.length + "string";
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
    81
        String CIC    = "string" + args.length + "string";
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
    82
        String CICI   = "string" + args.length + "string" + args.length;
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
    83
        String CJ     = "string" + System.currentTimeMillis();
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
    84
        String JC     = System.currentTimeMillis() + "string";
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
    85
        String CJC    = "string" + System.currentTimeMillis() + "string";
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
    86
        String CJCJ   = "string" + System.currentTimeMillis() + "string" + System.currentTimeMillis();
5fa7fbddfe9d 8222484: Specialize generation of simple String concatenation expressions
redestad
parents: 52804
diff changeset
    87
        String CJCJC  = "string" + System.currentTimeMillis() + "string" + System.currentTimeMillis() + "string";
52177
430e6421d503 8212597: Optimize String concatenation setup when using primitive operands
redestad
parents: 47216
diff changeset
    88
37805
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    89
        String newDate = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    90
                LocalDateTime.now(ZoneId.of("GMT")));
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    91
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    92
        String oldDate = String.format("%s%n",
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    93
                DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.ROOT)
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    94
                        .format(new Date()));
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    95
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    96
        LOGGER.log(Level.INFO, "New Date: " + newDate + " - old: " + oldDate);
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    97
    }
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    98
62e458968aad 8150044: Generate classlists at build-time
redestad
parents:
diff changeset
    99
}