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