author | prr |
Fri, 25 May 2018 12:12:24 -0700 | |
changeset 50347 | b2f046ae8eb6 |
parent 47753 | a2008587c13f |
child 57939 | e8ba7e4f4190 |
permissions | -rw-r--r-- |
36757
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
1 |
/* |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
4 |
* |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
8 |
* |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
13 |
* accompanied this code). |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
14 |
* |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
18 |
* |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
21 |
* questions. |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
22 |
*/ |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
23 |
|
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
24 |
import java.nio.charset.Charset; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
25 |
import java.nio.file.Files; |
36757
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
26 |
import java.nio.file.Path; |
40681
87d3f0e6a51f
8164858: Enable build-time use of java.lang.invoke resolve tracing
redestad
parents:
40562
diff
changeset
|
27 |
import java.util.Collection; |
36757
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
28 |
import java.util.List; |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
29 |
import java.util.stream.Collectors; |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
30 |
|
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
31 |
import jdk.tools.jlink.internal.plugins.GenerateJLIClassesPlugin; |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
32 |
|
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
33 |
import tests.Helper; |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
34 |
import tests.JImageGenerator; |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
35 |
import tests.JImageValidator; |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
36 |
import tests.Result; |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
37 |
|
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
38 |
/* |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
39 |
* @test |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
40 |
* @library ../../lib |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
41 |
* @summary Test --generate-jli-classes plugin |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
42 |
* @modules java.base/jdk.internal.jimage |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
43 |
* jdk.jdeps/com.sun.tools.classfile |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
44 |
* jdk.jlink/jdk.tools.jlink.internal |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
45 |
* jdk.jlink/jdk.tools.jlink.internal.plugins |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
46 |
* jdk.jlink/jdk.tools.jmod |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
47 |
* jdk.jlink/jdk.tools.jimage |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
48 |
* @build tests.* |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
49 |
* @run main/othervm GenerateJLIClassesPluginTest |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
50 |
*/ |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
51 |
public class GenerateJLIClassesPluginTest { |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
52 |
|
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
53 |
private static Helper helper; |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
54 |
|
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
55 |
public static void main(String[] args) throws Exception { |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
56 |
helper = Helper.newHelper(); |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
57 |
if (helper == null) { |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
58 |
System.err.println("Test not run"); |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
59 |
return; |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
60 |
} |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
61 |
|
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
62 |
helper.generateDefaultModules(); |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
63 |
|
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
64 |
|
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
65 |
// Test that generate-jli is enabled by default |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
66 |
Result result = JImageGenerator.getJLinkTask() |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
67 |
.modulePath(helper.defaultModulePath()) |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
68 |
.output(helper.createNewImageDir("generate-jli")) |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
69 |
.addMods("java.base") |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
70 |
.call(); |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
71 |
|
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
72 |
Path image = result.assertSuccess(); |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
73 |
|
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
74 |
JImageValidator.validate( |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
75 |
image.resolve("lib").resolve("modules"), |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
76 |
classFilesForSpecies(GenerateJLIClassesPlugin.defaultSpecies()), |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
77 |
List.of()); |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
78 |
|
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
79 |
// Check that --generate-jli-classes=@file works as intended |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
80 |
Path baseFile = Files.createTempFile("base", "trace"); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
81 |
String species = "LLLLLLLLLLLLLLLLLLL"; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
82 |
String fileString = "[SPECIES_RESOLVE] java.lang.invoke.BoundMethodHandle$Species_" + species + " (salvaged)\n"; |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
83 |
Files.write(baseFile, fileString.getBytes(Charset.defaultCharset())); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
84 |
result = JImageGenerator.getJLinkTask() |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
85 |
.modulePath(helper.defaultModulePath()) |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
86 |
.output(helper.createNewImageDir("generate-jli-file")) |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
87 |
.option("--generate-jli-classes=@" + baseFile.toString()) |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
88 |
.addMods("java.base") |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
89 |
.call(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
90 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
91 |
image = result.assertSuccess(); |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
92 |
|
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
93 |
JImageValidator.validate( |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
94 |
image.resolve("lib").resolve("modules"), |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
95 |
classFilesForSpecies(List.of(species)), // species should be in the image |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
96 |
classFilesForSpecies(List.of(species.substring(1)))); // but not it's immediate parent |
36757
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
97 |
} |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
98 |
|
40681
87d3f0e6a51f
8164858: Enable build-time use of java.lang.invoke resolve tracing
redestad
parents:
40562
diff
changeset
|
99 |
private static List<String> classFilesForSpecies(Collection<String> species) { |
36757
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
100 |
return species.stream() |
47753
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
101 |
.map(s -> "/java.base/java/lang/invoke/BoundMethodHandle$Species_" |
a2008587c13f
8184777: Factor out species generation logic from BoundMethodHandle
redestad
parents:
47216
diff
changeset
|
102 |
+ GenerateJLIClassesPlugin.expandSignature(s) + ".class") |
36757
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
103 |
.collect(Collectors.toList()); |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
104 |
} |
c859c6feee56
8152641: Plugin to generate BMH$Species classes ahead-of-time
redestad
parents:
diff
changeset
|
105 |
} |