Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javah/compareTest/FindNativeFiles.java
38813 views
1
/*
2
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.io.IOException;
25
import java.io.InputStream;
26
import java.util.Enumeration;
27
import java.util.jar.JarEntry;
28
import java.util.jar.JarFile;
29
30
import com.sun.tools.classfile.AccessFlags;
31
import com.sun.tools.classfile.ClassFile;
32
import com.sun.tools.classfile.ConstantPoolException;
33
import com.sun.tools.classfile.Method;
34
import java.util.Comparator;
35
import java.util.Set;
36
import java.util.TreeSet;
37
38
public class FindNativeFiles {
39
public static void main(String[] args) throws IOException, ConstantPoolException {
40
new FindNativeFiles().run(args);
41
}
42
43
public void run(String[] args) throws IOException, ConstantPoolException {
44
JarFile jar = new JarFile(args[0]);
45
Set<JarEntry> entries = getNativeClasses(jar);
46
for (JarEntry e: entries) {
47
String name = e.getName();
48
String className = name.substring(0, name.length() - 6).replace("/", ".");
49
System.out.println(className);
50
}
51
}
52
53
Set<JarEntry> getNativeClasses(JarFile jar) throws IOException, ConstantPoolException {
54
Set<JarEntry> results = new TreeSet<JarEntry>(new Comparator<JarEntry>() {
55
public int compare(JarEntry o1, JarEntry o2) {
56
return o1.getName().compareTo(o2.getName());
57
}
58
});
59
Enumeration<JarEntry> e = jar.entries();
60
while (e.hasMoreElements()) {
61
JarEntry je = e.nextElement();
62
if (isNativeClass(jar, je))
63
results.add(je);
64
}
65
return results;
66
}
67
68
boolean isNativeClass(JarFile jar, JarEntry entry) throws IOException, ConstantPoolException {
69
String name = entry.getName();
70
if (name.startsWith("META-INF") || !name.endsWith(".class"))
71
return false;
72
//String className = name.substring(0, name.length() - 6).replace("/", ".");
73
//System.err.println("check " + className);
74
InputStream in = jar.getInputStream(entry);
75
ClassFile cf = ClassFile.read(in);
76
in.close();
77
for (int i = 0; i < cf.methods.length; i++) {
78
Method m = cf.methods[i];
79
if (m.access_flags.is(AccessFlags.ACC_NATIVE)) {
80
// System.err.println(className);
81
return true;
82
}
83
}
84
return false;
85
}
86
}
87
88