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