author | redestad |
Wed, 17 Apr 2019 00:06:38 +0200 | |
changeset 54550 | 5fa7fbddfe9d |
parent 52804 | 28094715ae71 |
child 54677 | beca9f8524c1 |
permissions | -rw-r--r-- |
37805 | 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 | 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 |
||
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 | 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 |
} |