author | alexsch |
Thu, 31 Jul 2014 14:28:10 +0400 | |
changeset 26019 | 10a56d28f48d |
parent 20881 | 9e14db54cb2f |
child 26966 | 580934a3052b |
permissions | -rw-r--r-- |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
1 |
/* |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
4 |
* |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
8 |
* |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
13 |
* accompanied this code). |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
14 |
* |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
18 |
* |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
21 |
* questions. |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
22 |
*/ |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
23 |
|
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
24 |
import com.sun.tools.classfile.*; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
25 |
import com.sun.tools.jdeps.ClassFileReader; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
26 |
import static com.sun.tools.classfile.ConstantPool.*; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
27 |
import java.io.File; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
28 |
import java.io.IOException; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
29 |
import java.nio.file.FileVisitResult; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
30 |
import java.nio.file.Files; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
31 |
import java.nio.file.Path; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
32 |
import java.nio.file.Paths; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
33 |
import java.nio.file.SimpleFileVisitor; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
34 |
import java.nio.file.attribute.BasicFileAttributes; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
35 |
import java.util.ArrayList; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
36 |
import java.util.List; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
37 |
import java.util.Set; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
38 |
import java.util.concurrent.Callable; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
39 |
import java.util.concurrent.ExecutionException; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
40 |
import java.util.concurrent.ExecutorService; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
41 |
import java.util.concurrent.Executors; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
42 |
import java.util.concurrent.FutureTask; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
43 |
|
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
44 |
/* |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
45 |
* @test |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
46 |
* @bug 8010117 |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
47 |
* @summary Verify if CallerSensitive methods are annotated with |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
48 |
* sun.reflect.CallerSensitive annotation |
17204
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
49 |
* @build CallerSensitiveFinder |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
50 |
* @run main/othervm/timeout=900 -mx600m CallerSensitiveFinder |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
51 |
*/ |
17204
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
52 |
public class CallerSensitiveFinder { |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
53 |
private static int numThreads = 3; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
54 |
private static boolean verbose = false; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
55 |
public static void main(String[] args) throws Exception { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
56 |
List<Path> classes = new ArrayList<>(); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
57 |
String testclasses = System.getProperty("test.classes", "."); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
58 |
int i = 0; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
59 |
while (i < args.length) { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
60 |
String arg = args[i++]; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
61 |
if (arg.equals("-v")) { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
62 |
verbose = true; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
63 |
} else { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
64 |
Path p = Paths.get(testclasses, arg); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
65 |
if (!p.toFile().exists()) { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
66 |
throw new IllegalArgumentException(arg + " does not exist"); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
67 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
68 |
classes.add(p); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
69 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
70 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
71 |
if (classes.isEmpty()) { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
72 |
classes.addAll(PlatformClassPath.getJREClasses()); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
73 |
} |
17204
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
74 |
CallerSensitiveFinder csfinder = new CallerSensitiveFinder(); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
75 |
|
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
76 |
List<String> errors = csfinder.run(classes); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
77 |
if (!errors.isEmpty()) { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
78 |
throw new RuntimeException(errors.size() + |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
79 |
" caller-sensitive methods are missing @CallerSensitive annotation"); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
80 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
81 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
82 |
|
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
83 |
private final List<String> csMethodsMissingAnnotation = new ArrayList<>(); |
17204
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
84 |
private final ReferenceFinder finder; |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
85 |
public CallerSensitiveFinder() { |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
86 |
this.finder = new ReferenceFinder(getFilter(), getVisitor()); |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
87 |
} |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
88 |
|
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
89 |
private ReferenceFinder.Filter getFilter() { |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
90 |
final String classname = "sun/reflect/Reflection"; |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
91 |
final String method = "getCallerClass"; |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
92 |
return new ReferenceFinder.Filter() { |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
93 |
public boolean accept(ConstantPool cpool, CPRefInfo cpref) { |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
94 |
try { |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
95 |
CONSTANT_NameAndType_info nat = cpref.getNameAndTypeInfo(); |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
96 |
return cpref.getClassName().equals(classname) && nat.getName().equals(method); |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
97 |
} catch (ConstantPoolException ex) { |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
98 |
throw new RuntimeException(ex); |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
99 |
} |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
100 |
} |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
101 |
}; |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
102 |
} |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
103 |
|
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
104 |
private ReferenceFinder.Visitor getVisitor() { |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
105 |
return new ReferenceFinder.Visitor() { |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
106 |
public void visit(ClassFile cf, Method m, List<CPRefInfo> refs) { |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
107 |
try { |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
108 |
String name = String.format("%s#%s %s", cf.getName(), |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
109 |
m.getName(cf.constant_pool), |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
110 |
m.descriptor.getValue(cf.constant_pool)); |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
111 |
if (!CallerSensitiveFinder.isCallerSensitive(m, cf.constant_pool)) { |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
112 |
csMethodsMissingAnnotation.add(name); |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
113 |
System.err.println("Missing @CallerSensitive: " + name); |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
114 |
} else { |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
115 |
if (verbose) { |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
116 |
System.out.format("@CS %s%n", name); |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
117 |
} |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
118 |
} |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
119 |
} catch (ConstantPoolException ex) { |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
120 |
throw new RuntimeException(ex); |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
121 |
} |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
122 |
} |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
123 |
}; |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
124 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
125 |
|
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
126 |
public List<String> run(List<Path> classes) throws IOException, InterruptedException, |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
127 |
ExecutionException, ConstantPoolException |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
128 |
{ |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
129 |
ExecutorService pool = Executors.newFixedThreadPool(numThreads); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
130 |
for (Path path : classes) { |
20881
9e14db54cb2f
8015912: jdeps support to output in dot file format
mchung
parents:
17204
diff
changeset
|
131 |
ClassFileReader reader = ClassFileReader.newInstance(path); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
132 |
for (ClassFile cf : reader.getClassFiles()) { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
133 |
String classFileName = cf.getName(); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
134 |
// for each ClassFile |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
135 |
// parse constant pool to find matching method refs |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
136 |
// parse each method (caller) |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
137 |
// - visit and find method references matching the given method name |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
138 |
pool.submit(getTask(cf)); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
139 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
140 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
141 |
waitForCompletion(); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
142 |
pool.shutdown(); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
143 |
return csMethodsMissingAnnotation; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
144 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
145 |
|
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
146 |
private static final String CALLER_SENSITIVE_ANNOTATION = "Lsun/reflect/CallerSensitive;"; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
147 |
private static boolean isCallerSensitive(Method m, ConstantPool cp) |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
148 |
throws ConstantPoolException |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
149 |
{ |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
150 |
RuntimeAnnotations_attribute attr = |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
151 |
(RuntimeAnnotations_attribute)m.attributes.get(Attribute.RuntimeVisibleAnnotations); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
152 |
int index = 0; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
153 |
if (attr != null) { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
154 |
for (int i = 0; i < attr.annotations.length; i++) { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
155 |
Annotation ann = attr.annotations[i]; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
156 |
String annType = cp.getUTF8Value(ann.type_index); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
157 |
if (CALLER_SENSITIVE_ANNOTATION.equals(annType)) { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
158 |
return true; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
159 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
160 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
161 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
162 |
return false; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
163 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
164 |
|
17204
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
165 |
private final List<FutureTask<Void>> tasks = new ArrayList<FutureTask<Void>>(); |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
166 |
private FutureTask<Void> getTask(final ClassFile cf) { |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
167 |
FutureTask<Void> task = new FutureTask<Void>(new Callable<Void>() { |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
168 |
public Void call() throws Exception { |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
169 |
finder.parse(cf); |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
170 |
return null; |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
171 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
172 |
}); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
173 |
tasks.add(task); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
174 |
return task; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
175 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
176 |
|
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
177 |
private void waitForCompletion() throws InterruptedException, ExecutionException { |
17204
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
178 |
for (FutureTask<Void> t : tasks) { |
d0540971275f
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
16906
diff
changeset
|
179 |
t.get(); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
180 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
181 |
System.out.println("Parsed " + tasks.size() + " classfiles"); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
182 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
183 |
|
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
184 |
static class PlatformClassPath { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
185 |
static List<Path> getJREClasses() throws IOException { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
186 |
List<Path> result = new ArrayList<Path>(); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
187 |
Path home = Paths.get(System.getProperty("java.home")); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
188 |
|
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
189 |
if (home.endsWith("jre")) { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
190 |
// jar files in <javahome>/jre/lib |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
191 |
// skip <javahome>/lib |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
192 |
result.addAll(addJarFiles(home.resolve("lib"))); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
193 |
} else if (home.resolve("lib").toFile().exists()) { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
194 |
// either a JRE or a jdk build image |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
195 |
File classes = home.resolve("classes").toFile(); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
196 |
if (classes.exists() && classes.isDirectory()) { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
197 |
// jdk build outputdir |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
198 |
result.add(classes.toPath()); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
199 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
200 |
// add other JAR files |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
201 |
result.addAll(addJarFiles(home.resolve("lib"))); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
202 |
} else { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
203 |
throw new RuntimeException("\"" + home + "\" not a JDK home"); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
204 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
205 |
return result; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
206 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
207 |
|
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
208 |
static List<Path> addJarFiles(final Path root) throws IOException { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
209 |
final List<Path> result = new ArrayList<Path>(); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
210 |
final Path ext = root.resolve("ext"); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
211 |
Files.walkFileTree(root, new SimpleFileVisitor<Path>() { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
212 |
@Override |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
213 |
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
214 |
throws IOException { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
215 |
if (dir.equals(root) || dir.equals(ext)) { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
216 |
return FileVisitResult.CONTINUE; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
217 |
} else { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
218 |
// skip other cobundled JAR files |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
219 |
return FileVisitResult.SKIP_SUBTREE; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
220 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
221 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
222 |
|
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
223 |
@Override |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
224 |
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
225 |
throws IOException { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
226 |
File f = file.toFile(); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
227 |
String fn = f.getName(); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
228 |
// parse alt-rt.jar as well |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
229 |
if (fn.endsWith(".jar") && !fn.equals("jfxrt.jar")) { |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
230 |
result.add(file); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
231 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
232 |
return FileVisitResult.CONTINUE; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
233 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
234 |
}); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
235 |
return result; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
236 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
237 |
} |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
diff
changeset
|
238 |
} |