author | mchung |
Thu, 17 Oct 2013 13:19:48 -0700 | |
changeset 21046 | ebf16a1a6328 |
parent 16550 | langtools/src/share/classes/com/sun/tools/jdeps/Profiles.java@f20e2521f3df |
child 21503 | 45fc62482cae |
permissions | -rw-r--r-- |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
1 |
/* |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
4 |
* |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
10 |
* |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
15 |
* accompanied this code). |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
16 |
* |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
20 |
* |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
23 |
* questions. |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
24 |
*/ |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
25 |
package com.sun.tools.jdeps; |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
26 |
|
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
27 |
import com.sun.tools.classfile.Annotation; |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
28 |
import com.sun.tools.classfile.Annotation.*; |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
29 |
import com.sun.tools.classfile.Attribute; |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
30 |
import com.sun.tools.classfile.ClassFile; |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
31 |
import com.sun.tools.classfile.ConstantPool.*; |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
32 |
import com.sun.tools.classfile.ConstantPoolException; |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
33 |
import com.sun.tools.classfile.RuntimeAnnotations_attribute; |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
34 |
import java.io.FileReader; |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
35 |
import java.io.IOException; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
36 |
import java.nio.file.Files; |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
37 |
import java.nio.file.Path; |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
38 |
import java.nio.file.Paths; |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
39 |
import java.util.*; |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
40 |
import java.util.jar.JarFile; |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
41 |
|
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
42 |
/** |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
43 |
* Build the profile information from ct.sym if exists. |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
44 |
*/ |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
45 |
enum Profile { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
46 |
|
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
47 |
COMPACT1("compact1", 1), |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
48 |
COMPACT2("compact2", 2), |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
49 |
COMPACT3("compact3", 3), |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
50 |
FULL_JRE("Full JRE", 4); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
51 |
|
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
52 |
final String name; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
53 |
final int profile; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
54 |
final Set<String> packages; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
55 |
final Set<String> proprietaryPkgs; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
56 |
|
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
57 |
Profile(String name, int profile) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
58 |
this.name = name; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
59 |
this.profile = profile; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
60 |
this.packages = new HashSet<>(); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
61 |
this.proprietaryPkgs = new HashSet<>(); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
62 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
63 |
|
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
64 |
@Override |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
65 |
public String toString() { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
66 |
return name; |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
67 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
68 |
|
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
69 |
public static int getProfileCount() { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
70 |
return PackageToProfile.map.values().size(); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
71 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
72 |
|
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
73 |
/** |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
74 |
* Returns the Profile for the given package name. It returns an empty |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
75 |
* string if the given package is not in any profile. |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
76 |
*/ |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
77 |
public static Profile getProfile(String pn) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
78 |
Profile profile = PackageToProfile.map.get(pn); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
79 |
return (profile != null && profile.packages.contains(pn)) |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
80 |
? profile : null; |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
81 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
82 |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
83 |
static class PackageToProfile { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
84 |
static Map<String, Profile> map = initProfiles(); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
85 |
|
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
86 |
private static Map<String, Profile> initProfiles() { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
87 |
try { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
88 |
String profilesProps = System.getProperty("jdeps.profiles"); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
89 |
if (profilesProps != null) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
90 |
// for testing for JDK development build where ct.sym doesn't exist |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
91 |
initProfilesFromProperties(profilesProps); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
92 |
} else { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
93 |
Path home = Paths.get(System.getProperty("java.home")); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
94 |
if (home.endsWith("jre")) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
95 |
home = home.getParent(); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
96 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
97 |
Path ctsym = home.resolve("lib").resolve("ct.sym"); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
98 |
if (Files.exists(ctsym)) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
99 |
// parse ct.sym and load information about profiles |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
100 |
try (JarFile jf = new JarFile(ctsym.toFile())) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
101 |
ClassFileReader reader = ClassFileReader.newInstance(ctsym, jf); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
102 |
for (ClassFile cf : reader.getClassFiles()) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
103 |
findProfile(cf); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
104 |
} |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
105 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
106 |
} |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
107 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
108 |
} catch (IOException | ConstantPoolException e) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
109 |
throw new Error(e); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
110 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
111 |
HashMap<String,Profile> map = new HashMap<>(); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
112 |
for (Profile profile : Profile.values()) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
113 |
for (String pn : profile.packages) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
114 |
if (!map.containsKey(pn)) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
115 |
// split packages in the JRE: use the smaller compact |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
116 |
map.put(pn, profile); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
117 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
118 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
119 |
for (String pn : profile.proprietaryPkgs) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
120 |
if (!map.containsKey(pn)) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
121 |
map.put(pn, profile); |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
122 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
123 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
124 |
} |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
125 |
return map; |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
126 |
} |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
127 |
private static final String PROFILE_ANNOTATION = "Ljdk/Profile+Annotation;"; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
128 |
private static final String PROPRIETARY_ANNOTATION = "Lsun/Proprietary+Annotation;"; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
129 |
private static Profile findProfile(ClassFile cf) throws ConstantPoolException { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
130 |
RuntimeAnnotations_attribute attr = (RuntimeAnnotations_attribute) |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
131 |
cf.attributes.get(Attribute.RuntimeInvisibleAnnotations); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
132 |
int index = 0; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
133 |
boolean proprietary = false; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
134 |
if (attr != null) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
135 |
for (int i = 0; i < attr.annotations.length; i++) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
136 |
Annotation ann = attr.annotations[i]; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
137 |
String annType = cf.constant_pool.getUTF8Value(ann.type_index); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
138 |
if (PROFILE_ANNOTATION.equals(annType)) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
139 |
for (int j = 0; j < ann.num_element_value_pairs; j++) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
140 |
Annotation.element_value_pair pair = ann.element_value_pairs[j]; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
141 |
Primitive_element_value ev = (Primitive_element_value) pair.value; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
142 |
CONSTANT_Integer_info info = (CONSTANT_Integer_info) |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
143 |
cf.constant_pool.get(ev.const_value_index); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
144 |
index = info.value; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
145 |
break; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
146 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
147 |
} else if (PROPRIETARY_ANNOTATION.equals(annType)) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
148 |
proprietary = true; |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
149 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
150 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
151 |
} |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
152 |
|
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
153 |
Profile p = null; // default |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
154 |
switch (index) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
155 |
case 1: |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
156 |
p = Profile.COMPACT1; break; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
157 |
case 2: |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
158 |
p = Profile.COMPACT2; break; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
159 |
case 3: |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
160 |
p = Profile.COMPACT3; break; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
161 |
case 4: |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
162 |
p = Profile.FULL_JRE; break; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
163 |
default: |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
164 |
// skip classes with profile=0 |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
165 |
// Inner classes are not annotated with the profile annotation |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
166 |
return null; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
167 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
168 |
|
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
169 |
String name = cf.getName(); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
170 |
int i = name.lastIndexOf('/'); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
171 |
name = (i > 0) ? name.substring(0, i).replace('/', '.') : ""; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
172 |
if (proprietary) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
173 |
p.proprietaryPkgs.add(name); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
174 |
} else { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
175 |
p.packages.add(name); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
176 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
177 |
return p; |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
178 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
179 |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
180 |
private static void initProfilesFromProperties(String path) throws IOException { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
181 |
Properties props = new Properties(); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
182 |
try (FileReader reader = new FileReader(path)) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
183 |
props.load(reader); |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
184 |
} |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
185 |
for (Profile prof : Profile.values()) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
186 |
int i = prof.profile; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
187 |
String key = props.getProperty("profile." + i + ".name"); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
188 |
if (key == null) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
189 |
throw new RuntimeException(key + " missing in " + path); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
190 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
191 |
String n = props.getProperty("profile." + i + ".packages"); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
192 |
String[] pkgs = n.split("\\s+"); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
193 |
for (String p : pkgs) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
194 |
if (p.isEmpty()) continue; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
195 |
prof.packages.add(p); |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
196 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
197 |
} |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
198 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
199 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
200 |
|
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
201 |
// for debugging |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
202 |
public static void main(String[] args) { |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
203 |
if (args.length == 0) { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
204 |
if (Profile.getProfileCount() == 0) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
205 |
System.err.println("No profile is present in this JDK"); |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
206 |
} |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
207 |
for (Profile p : Profile.values()) { |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
208 |
String profileName = p.name; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
209 |
SortedSet<String> set = new TreeSet<>(p.packages); |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
210 |
for (String s : set) { |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
211 |
// filter out the inner classes that are not annotated with |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
212 |
// the profile annotation |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
213 |
if (PackageToProfile.map.get(s) == p) { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
214 |
System.out.format("%2d: %-10s %s%n", p.profile, profileName, s); |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
215 |
profileName = ""; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
216 |
} else { |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
217 |
System.err.format("Split package: %s in %s and %s %n", |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
218 |
s, PackageToProfile.map.get(s).name, p.name); |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
219 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
220 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
221 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
222 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
223 |
for (String pn : args) { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
224 |
System.out.format("%s in %s%n", pn, getProfile(pn)); |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
225 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
226 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
227 |
} |