Skip to content

Instantly share code, notes, and snippets.

@thomasdarimont
Last active April 15, 2021 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasdarimont/0d96961bbb15033f0cdef79b78c0415e to your computer and use it in GitHub Desktop.
Save thomasdarimont/0d96961bbb15033f0cdef79b78c0415e to your computer and use it in GitHub Desktop.
MainMethodFinder is a simple CLI Tool to find runnable main Methods in JDK Libraries.
package wb.java17;
import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.ClassVisitor;
import jdk.internal.org.objectweb.asm.MethodVisitor;
import jdk.internal.org.objectweb.asm.Opcodes;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Comparator;
import java.util.Optional;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.RecursiveAction;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
/**
* Compile:
* <pre>javac --add-exports java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED -d target/classes src/main/java/wb/java17/MainMethodFinder.java </pre>
* <p>
* Run:
* <pre>java --add-exports java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED -cp target/classes wb.java17.MainMethodFinder</pre>
* <p>
* Run with different Java Home:
* <pre>java --add-exports java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED -cp target/classes wb.java17.MainMethodFinder ~/.sdkman/candidates/java/8.0.282.hs-adpt</pre>
* <p>
* Compile with GraalVM Native Image:
* <pre>native-image -cp target/classes wb.java17.MainMethodFinder MainMethodFinder</pre>
* <p>
* Run GraalVM Native Image
* <pre>./MainMethodFinder ~/.sdkman/candidates/java/8.0.282.hs-adpt</pre>
* <pre>./MainMethodFinder ~/.sdkman/candidates/java/11.0.10.hs-adpt</pre>
*/
public class MainMethodFinder {
public static void main(String[] args) throws IOException {
long time = System.nanoTime();
try {
// System.out.printf("Java Version: %s%n", Runtime.version());
var jdkHomePath = args.length > 0
? Path.of(args[0])
: detectCurrentJdkPath();
System.out.printf("Scanning Java Installation: %s%n", jdkHomePath);
var mainMethods = new CopyOnWriteArrayList<MainMethod>();
MainMethodReportingVisitor visitor = new MainMethodReportingVisitor(mainMethods::add);
Files.walkFileTree(jdkHomePath, visitor);
visitor.join();
mainMethods.sort(Comparator.comparing((MainMethod left) -> left.library.getName()).thenComparing((MainMethod left) -> left.className));
mainMethods.forEach(m -> System.out.printf("Found main in %s: %s %n", m.library.getName(), m.className));
} finally {
time = System.nanoTime() - time;
System.out.printf("time = %dms%n", TimeUnit.NANOSECONDS.toMillis(time));
// System.out.printf("ForkJoin Pool Stats: %s%n", ForkJoinPool.commonPool());
}
}
private static Path detectCurrentJdkPath() {
return Paths.get(ProcessHandle.current().info().command().orElseThrow()).resolve("../..").normalize();
}
static class MainMethodReportingVisitor extends SimpleFileVisitor<Path> {
private final Consumer<MainMethod> consumer;
private final Queue<RecursiveAction> outstanding = new ConcurrentLinkedQueue<>();
public MainMethodReportingVisitor(Consumer<MainMethod> consumer) {
this.consumer = consumer;
}
@Override
public FileVisitResult visitFile(Path filePath, BasicFileAttributes attrs) {
var maybeJdkLibrary = filePath.toFile();
if (isJdkLibrary(maybeJdkLibrary.getName())) {
var action = new RecursiveAction() {
protected void compute() {
scanLibraryForMainClasses(maybeJdkLibrary);
}
};
action.fork();
outstanding.add(action);
}
return FileVisitResult.CONTINUE;
}
public void join() {
for (RecursiveAction action; (action = outstanding.poll()) != null; ) {
action.join();
}
}
private boolean isJdkLibrary(String maybeJdkLibraryName) {
return maybeJdkLibraryName.endsWith(".jar") || maybeJdkLibraryName.endsWith(".jmod");
}
private void scanLibraryForMainClasses(File library) {
// Using FileSystems.newFileSystem(library.toPath(), (ClassLoader)null) for Java 11 compatibility
try (var fileSystem = FileSystems.newFileSystem(library.toPath(), (ClassLoader) null)) {
var root = fileSystem.getRootDirectories().iterator().next();
var visitor = new MainMethodVisitor(library, consumer, fileSystem);
Files.walk(root).parallel().filter(this::isClassFile).forEach(visitor::scanClassForMainMethod);
} catch (IOException e) {
e.printStackTrace();
}
}
private boolean isClassFile(Path nestedFilePath) {
return nestedFilePath.toString().endsWith(".class");
}
}
static class MainMethod {
File library;
String className;
public MainMethod(File library, String className) {
this.library = library;
this.className = className;
}
}
static class MainMethodVisitor extends ClassVisitor {
// Adapted from Opcodes.ASM*
private static final int ASM6 = 6 << 16;
private static final int ASM7 = 7 << 16;
private static final int ASM8 = 8 << 16;
private static final int ASM_API_VERSION =
// Opcodes.ASM8 // not using this constant to support running on Java11-17
System.getProperty("java.version").startsWith("11.")
? ASM6
: System.getProperty("java.version").startsWith("15.")
? ASM7
: ASM8;
private final ThreadLocal<String> currentInternalClassName = new ThreadLocal<>();
private final File library;
private final Consumer<MainMethod> mainMethodConsumer;
private final FileSystem fileSystem;
public MainMethodVisitor(File library, Consumer<MainMethod> mainMethodConsumer, FileSystem fileSystem) {
super(ASM_API_VERSION);
this.library = library;
this.mainMethodConsumer = mainMethodConsumer;
this.fileSystem = fileSystem;
}
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
currentInternalClassName.set(name);
super.visit(version, access, name, signature, superName, interfaces);
}
@Override
public void visitEnd() {
super.visitEnd();
currentInternalClassName.remove();
}
@Override
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
if (isRunnableMainMethod(access, name, descriptor)) {
mainMethodConsumer.accept(new MainMethod(library, currentInternalClassName.get().replace('/', '.')));
}
return super.visitMethod(access, name, descriptor, signature, exceptions);
}
private boolean isRunnableMainMethod(int access, String name, String descriptor) {
return "main".equals(name)
&& (access & Opcodes.ACC_STATIC) != 0
&& "([Ljava/lang/String;)V".equals(descriptor);
}
private void scanClassForMainMethod(Path pathToLibraryClass) {
tryGetClassBytes(pathToLibraryClass, fileSystem).ifPresent(this::visitClassBytes);
}
private void visitClassBytes(byte[] classBytes) {
new ClassReader(classBytes).accept(this, 0);
}
private Optional<byte[]> tryGetClassBytes(Path nestedFilePath, FileSystem fileSystem) {
try (var is = new BufferedInputStream(fileSystem.provider().newInputStream(nestedFilePath))) {
return Optional.of(is.readAllBytes());
} catch (IOException e) {
e.printStackTrace();
}
return Optional.empty();
}
}
}
$ java --add-exports java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED -cp target/classes wb.java17.MainMethodFinder
Scanning Java Installation: /home/tom/.sdkman/candidates/java/16.0.0.hs-adpt
Found main in java.rmi.jmod: sun.rmi.registry.RegistryImpl
Found main in java.rmi.jmod: sun.rmi.server.Activation
Found main in java.scripting.jmod: com.sun.tools.script.shell.Main
Found main in java.rmi.jmod: sun.rmi.server.ActivationGroupInit
Found main in jdk.javadoc.jmod: jdk.javadoc.internal.tool.Main
Found main in jdk.jdeps.jmod: com.sun.tools.javap.Main
Found main in jdk.jpackage.jmod: jdk.jpackage.main.Main
Found main in jdk.javadoc.jmod: jdk.javadoc.internal.doclint.DocLint
Found main in jdk.jstatd.jmod: sun.tools.jstatd.Jstatd
Found main in jdk.jconsole.jmod: sun.tools.jconsole.JConsole
Found main in java.prefs.jmod: java.util.prefs.Base64
Found main in jdk.jdeps.jmod: com.sun.tools.jdeps.Main
Found main in jdk.jdi.jmod: com.sun.tools.example.debug.expr.ExpressionParser
Found main in jdk.jdeps.jmod: com.sun.tools.jdeps.Profile
Found main in jdk.jdi.jmod: com.sun.tools.example.debug.tty.TTY
Found main in jdk.jdeps.jmod: com.sun.tools.jdeprscan.Main
Found main in jdk.security.auth.jmod: com.sun.security.auth.module.Crypt
Found main in jdk.jcmd.jmod: sun.tools.jps.Jps
Found main in jdk.jcmd.jmod: sun.tools.jmap.JMap
Found main in jdk.jcmd.jmod: sun.tools.jstat.Jstat
Found main in jdk.jcmd.jmod: sun.tools.jcmd.JCmd
Found main in jdk.jcmd.jmod: sun.tools.jstack.JStack
Found main in jdk.zipfs.jmod: jdk.nio.zipfs.ZipInfo
Found main in jdk.jcmd.jmod: sun.tools.jinfo.JInfo
Found main in jdk.jartool.jmod: sun.security.tools.jarsigner.Main
Found main in jdk.jartool.jmod: sun.tools.jar.Main
Found main in jdk.jlink.jmod: jdk.tools.jlink.internal.Main
Found main in jdk.jlink.jmod: jdk.tools.jimage.Main
Found main in jdk.jlink.jmod: jdk.tools.jmod.Main
Found main in java.xml.jmod: com.sun.org.apache.xerces.internal.impl.Constants
Found main in java.xml.jmod: com.sun.org.apache.xerces.internal.impl.xpath.XPath
Found main in java.xml.jmod: com.sun.org.apache.xerces.internal.impl.xpath.regex.REUtil
Found main in jdk.aot.jmod: jdk.tools.jaotc.Main
Found main in jdk.compiler.jmod: com.sun.tools.javac.Main
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.win32.coff.TestDebugInfo
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.win32.coff.DumpExports
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.linux.LinuxAddress
Found main in java.xml.jmod: com.sun.org.apache.bcel.internal.util.BCELifier
Found main in java.xml.jmod: com.sun.org.apache.bcel.internal.util.Class2HTML
Found main in java.xml.crypto.jmod: com.sun.org.apache.xml.internal.security.keys.storage.implementations.CertsInFilesystemDirectoryResolver
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.SALauncher
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.DebugServer
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.ObjectHistogram
Found main in jdk.jfr.jmod: jdk.jfr.internal.tool.Main
Found main in java.base.jmod: sun.launcher.LauncherHelper$FXHelper
Found main in jdk.compiler.jmod: sun.tools.serialver.SerialVer
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.jcore.ClassDump
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.JInfo
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.JSnap
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.StackTrace
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.JMap
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.SysPropsDumper
Found main in jdk.compiler.jmod: com.sun.tools.sjavac.Main
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.PStack
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.HeapDumper
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.PMap
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.HeapSummary
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.JStack
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.FinalizerInfo
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.FlagDumper
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.ClassLoaderStats
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.ui.HighPrecisionJScrollBar
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.ui.AnnotatedMemoryPanel
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.ui.ObjectHistogramPanel
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.ui.CommandProcessorPanel
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.ui.DebuggerConsolePanel
Found main in java.xml.jmod: com.sun.org.apache.xalan.internal.xsltc.ProcessorVersion
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.CLHSDB
Found main in jdk.jshell.jmod: jdk.jshell.execution.RemoteExecutionControl
Found main in jdk.jshell.jmod: jdk.internal.jshell.tool.JShellToolProvider
Found main in java.base.jmod: sun.security.provider.PolicyParser
Found main in java.base.jmod: sun.security.tools.keytool.Main
Found main in jdk.hotspot.agent.jmod: com.sun.java.swing.ui.WizardDlg
Found main in jdk.hotspot.agent.jmod: com.sun.java.swing.ui.TabsDlg
Found main in jdk.compiler.jmod: com.sun.tools.javac.launcher.Main
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.ObjectHistogram
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.utilities.PlatformInfo
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.utilities.RBTree
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.HSDB
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.StackTrace
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.HelloWorld
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.bsd.BsdAddress
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.posix.elf.ELFFileParser
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.remote.RemoteAddress
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.proc.ProcAddress
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.windbg.WindbgAddress
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.dummy.DummyAddress
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.win32.coff.TestParser
Found main in java.base.jmod: jdk.internal.org.objectweb.asm.util.Textifier
Found main in java.base.jmod: jdk.internal.org.objectweb.asm.util.ASMifier
Found main in java.base.jmod: jdk.internal.org.objectweb.asm.util.CheckClassAdapter
Found main in java.desktop.jmod: sun.java2d.loops.GraphicsPrimitiveMgr
Found main in jdk.internal.vm.compiler.jmod: org.graalvm.compiler.hotspot.JVMCIVersionCheck
Found main in java.base.jmod: java.util.regex.PrintPattern
time = 771ms
$ java --add-exports java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED -cp target/classes wb.java17.MainMethodFinder
Scanning Java Installation: /home/tom/.sdkman/candidates/java/17.ea.11-open
Found main in java.scripting.jmod: com.sun.tools.script.shell.Main
Found main in jdk.javadoc.jmod: jdk.javadoc.internal.tool.Main
Found main in jdk.javadoc.jmod: jdk.javadoc.internal.doclint.DocLint
Found main in java.rmi.jmod: sun.rmi.server.ActivationGroupInit
Found main in java.rmi.jmod: sun.rmi.server.Activation
Found main in jdk.jdi.jmod: com.sun.tools.example.debug.tty.TTY
Found main in jdk.jdi.jmod: com.sun.tools.example.debug.expr.ExpressionParser
Found main in java.rmi.jmod: sun.rmi.registry.RegistryImpl
Found main in jdk.jpackage.jmod: jdk.jpackage.main.Main
Found main in jdk.jdeps.jmod: com.sun.tools.jdeprscan.Main
Found main in jdk.jdeps.jmod: com.sun.tools.javap.Main
Found main in jdk.jconsole.jmod: sun.tools.jconsole.JConsole
Found main in jdk.jdeps.jmod: com.sun.tools.jdeps.Main
Found main in java.prefs.jmod: java.util.prefs.Base64
Found main in jdk.jdeps.jmod: com.sun.tools.jdeps.Profile
Found main in jdk.jstatd.jmod: sun.tools.jstatd.Jstatd
Found main in jdk.security.auth.jmod: com.sun.security.auth.module.Crypt
Found main in jdk.jcmd.jmod: sun.tools.jstack.JStack
Found main in jdk.jcmd.jmod: sun.tools.jps.Jps
Found main in jdk.jcmd.jmod: sun.tools.jmap.JMap
Found main in jdk.jcmd.jmod: sun.tools.jinfo.JInfo
Found main in jdk.jcmd.jmod: sun.tools.jcmd.JCmd
Found main in jdk.jcmd.jmod: sun.tools.jstat.Jstat
Found main in jdk.zipfs.jmod: jdk.nio.zipfs.ZipInfo
Found main in jdk.jlink.jmod: jdk.tools.jmod.Main
Found main in jdk.jartool.jmod: sun.security.tools.jarsigner.Main
Found main in jdk.jartool.jmod: sun.tools.jar.Main
Found main in jdk.jlink.jmod: jdk.tools.jlink.internal.Main
Found main in jdk.jlink.jmod: jdk.tools.jimage.Main
Found main in java.xml.jmod: com.sun.org.apache.xerces.internal.impl.Constants
Found main in java.xml.jmod: com.sun.org.apache.bcel.internal.util.Class2HTML
Found main in java.xml.jmod: com.sun.org.apache.bcel.internal.util.BCELifier
Found main in java.xml.jmod: com.sun.org.apache.xerces.internal.impl.xpath.XPath
Found main in java.xml.jmod: com.sun.org.apache.xerces.internal.impl.xpath.regex.REUtil
Found main in java.xml.crypto.jmod: com.sun.org.apache.xml.internal.security.keys.storage.implementations.CertsInFilesystemDirectoryResolver
Found main in java.base.jmod: sun.launcher.LauncherHelper$FXHelper
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.jcore.ClassDump
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.CLHSDB
Found main in jdk.jfr.jmod: jdk.jfr.internal.tool.Main
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.windbg.WindbgAddress
Found main in java.base.jmod: sun.security.tools.keytool.Main
Found main in java.xml.jmod: com.sun.org.apache.xalan.internal.xsltc.ProcessorVersion
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.win32.coff.TestParser
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.win32.coff.TestDebugInfo
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.win32.coff.DumpExports
Found main in jdk.jshell.jmod: jdk.jshell.execution.RemoteExecutionControl
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.remote.RemoteAddress
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.proc.ProcAddress
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.linux.LinuxAddress
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.dummy.DummyAddress
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.posix.elf.ELFFileParser
Found main in jdk.compiler.jmod: sun.tools.serialver.SerialVer
Found main in jdk.jshell.jmod: jdk.internal.jshell.tool.JShellToolProvider
Found main in jdk.compiler.jmod: com.sun.tools.sjavac.Main
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.debugger.bsd.BsdAddress
Found main in java.base.jmod: sun.security.provider.PolicyParser
Found main in jdk.compiler.jmod: com.sun.tools.javac.launcher.Main
Found main in jdk.compiler.jmod: com.sun.tools.javac.Main
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.ui.DebuggerConsolePanel
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.ui.CommandProcessorPanel
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.ui.HighPrecisionJScrollBar
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.ui.AnnotatedMemoryPanel
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.ui.ObjectHistogramPanel
Found main in jdk.hotspot.agent.jmod: com.sun.java.swing.ui.WizardDlg
Found main in jdk.hotspot.agent.jmod: com.sun.java.swing.ui.TabsDlg
Found main in java.desktop.jmod: sun.java2d.loops.GraphicsPrimitiveMgr
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.StackTrace
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.SALauncher
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.ObjectHistogram
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.HelloWorld
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.HSDB
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.DebugServer
Found main in java.base.jmod: jdk.internal.org.objectweb.asm.util.Textifier
Found main in java.base.jmod: jdk.internal.org.objectweb.asm.util.CheckClassAdapter
Found main in java.base.jmod: jdk.internal.org.objectweb.asm.util.ASMifier
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.utilities.PlatformInfo
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.utilities.RBTree
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.SysPropsDumper
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.StackTrace
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.PStack
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.PMap
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.ObjectHistogram
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.JStack
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.JSnap
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.JMap
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.JInfo
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.HeapSummary
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.HeapDumper
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.FlagDumper
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.FinalizerInfo
Found main in jdk.hotspot.agent.jmod: sun.jvm.hotspot.tools.ClassLoaderStats
Found main in java.base.jmod: java.util.regex.PrintPattern
time = 680ms
$ java --add-exports java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED -cp target/classes wb.java17.MainMethodFinder ~/.sdkman/candidates/java/8.0.282.hs-adpt
Scanning Java Installation: /home/tom/.sdkman/candidates/java/8.0.282.hs-adpt
Found main in jconsole.jar: sun.tools.jconsole.JConsole
Found main in zipfs.jar: com.sun.nio.zipfs.ZipInfo
Found main in tools.jar: com.sun.tools.internal.xjc.Driver
Found main in tools.jar: com.sun.tools.internal.xjc.util.MimeTypeRange
Found main in sa-jdi.jar: sun.jvm.hotspot.HelloWorld
Found main in sa-jdi.jar: sun.jvm.hotspot.DebugServer
Found main in nashorn.jar: jdk.nashorn.tools.Shell
Found main in sa-jdi.jar: sun.jvm.hotspot.ObjectHistogram
Found main in sa-jdi.jar: sun.jvm.hotspot.StackTrace
Found main in tools.jar: com.sun.tools.internal.ws.WsImport
Found main in tools.jar: com.sun.tools.internal.ws.WsGen
Found main in tools.jar: com.sun.tools.extcheck.Main
Found main in sa-jdi.jar: sun.jvm.hotspot.jdi.SADebugServer
Found main in tools.jar: com.sun.tools.corba.se.idl.Compile
Found main in tools.jar: com.sun.tools.corba.se.idl.toJavaPortable.Compile
Found main in rt.jar: sun.rmi.transport.proxy.CGIHandler
Found main in rt.jar: sun.rmi.server.ActivationGroupInit
Found main in rt.jar: sun.rmi.server.Activation
Found main in rt.jar: sun.rmi.registry.RegistryImpl
Found main in sa-jdi.jar: sun.jvm.hotspot.HSDB
Found main in sa-jdi.jar: sun.jvm.hotspot.ui.AnnotatedMemoryPanel
Found main in tools.jar: com.sun.tools.doclint.DocLint
Found main in tools.jar: com.sun.tools.hat.Main
Found main in sa-jdi.jar: sun.jvm.hotspot.ui.ObjectHistogramPanel
Found main in sa-jdi.jar: sun.jvm.hotspot.ui.HighPrecisionJScrollBar
Found main in sa-jdi.jar: sun.jvm.hotspot.ui.CommandProcessorPanel
Found main in jfr.jar: jdk.jfr.internal.tool.Main
Found main in sa-jdi.jar: sun.jvm.hotspot.ui.DebuggerConsolePanel
Found main in tools.jar: com.sun.tools.example.debug.expr.ExpressionParser
Found main in sa-jdi.jar: com.sun.java.swing.ui.TabsDlg
Found main in sa-jdi.jar: com.sun.java.swing.ui.WizardDlg
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.dummy.DummyAddress
Found main in tools.jar: com.sun.tools.example.debug.tty.TTY
Found main in tools.jar: com.sun.tools.javah.Main
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.win32.coff.DumpExports
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.win32.coff.TestDebugInfo
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.win32.coff.TestParser
Found main in tools.jar: com.sun.tools.javap.Main
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.linux.LinuxAddress
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.posix.elf.ELFFileParser
Found main in tools.jar: com.sun.tools.jdeps.Profile
Found main in tools.jar: com.sun.tools.jdeps.Main
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.bsd.BsdAddress
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.remote.RemoteAddress
Found main in tools.jar: com.sun.tools.javadoc.Main
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.proc.ProcAddress
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.windbg.WindbgAddress
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.jcore.ClassDump
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.PMap
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.HeapSummary
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.ClassLoaderStats
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.PStack
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.FinalizerInfo
Found main in tools.jar: com.sun.tools.script.shell.Main
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.JSnap
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.soql.JSDB
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.soql.SOQL
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.ObjectHistogram
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.FlagDumper
Found main in tools.jar: com.sun.tools.internal.jxc.SchemaGenerator
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.JMap
Found main in tools.jar: com.sun.tools.internal.jxc.SchemaGeneratorFacade
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.StackTrace
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.JInfo
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.HeapDumper
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.SysPropsDumper
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.JStack
Found main in tools.jar: com.sun.tools.internal.xjc.reader.xmlschema.parser.SchemaConstraintChecker
Found main in rt.jar: sun.tools.jar.Main
Found main in sa-jdi.jar: sun.jvm.hotspot.CLHSDB
Found main in sa-jdi.jar: sun.jvm.hotspot.utilities.RBTree
Found main in tools.jar: com.sun.tools.javac.sym.CreateSymbols
Found main in tools.jar: com.sun.tools.javac.sym.Profiles
Found main in tools.jar: com.sun.tools.javac.util.Bits
Found main in rt.jar: sun.net.NetworkServer
Found main in sa-jdi.jar: sun.jvm.hotspot.utilities.PlatformInfo
Found main in tools.jar: com.sun.tools.internal.xjc.XJCFacade
Found main in rt.jar: sun.java2d.loops.GraphicsPrimitiveMgr
Found main in rt.jar: sun.launcher.LauncherHelper$FXHelper
Found main in tools.jar: com.sun.tools.javac.Main
Found main in rt.jar: sun.security.tools.policytool.PolicyTool
Found main in rt.jar: sun.security.tools.keytool.Main
Found main in tools.jar: com.sun.xml.internal.rngom.digested.Main
Found main in tools.jar: com.sun.xml.internal.rngom.digested.DXMLPrinter
Found main in rt.jar: sun.security.provider.PolicyParser
Found main in tools.jar: com.sun.xml.internal.rngom.xml.util.EncodingMap
Found main in tools.jar: sun.tools.jcmd.JCmd
Found main in tools.jar: sun.tools.jmap.JMap
Found main in tools.jar: sun.tools.jstatd.Jstatd
Found main in tools.jar: sun.tools.jar.Main
Found main in tools.jar: sun.tools.native2ascii.Main
Found main in tools.jar: sun.tools.jinfo.JInfo
Found main in rt.jar: com.sun.security.auth.module.Crypt
Found main in tools.jar: sun.tools.jstack.JStack
Found main in tools.jar: sun.tools.serialver.SerialVer
Found main in tools.jar: sun.tools.jstat.Jstat
Found main in tools.jar: sun.tools.jps.Jps
Found main in tools.jar: sun.tools.javac.Main
Found main in tools.jar: sun.security.tools.jarsigner.Main
Found main in tools.jar: sun.applet.AppletViewer
Found main in tools.jar: sun.applet.Main
Found main in tools.jar: sun.rmi.rmic.Main
Found main in tools.jar: sun.rmi.rmic.iiop.StaticStringsHash
Found main in tools.jar: sun.rmi.rmic.newrmic.Main
Found main in rt.jar: sun.applet.Main
Found main in rt.jar: sun.applet.AppletViewer
Found main in rt.jar: com.sun.org.apache.xml.internal.security.keys.storage.implementations.CertsInFilesystemDirectoryResolver
Found main in rt.jar: jdk.internal.org.objectweb.asm.util.Textifier
Found main in rt.jar: jdk.internal.org.objectweb.asm.util.CheckClassAdapter
Found main in rt.jar: jdk.internal.org.objectweb.asm.util.ASMifier
Found main in rt.jar: com.sun.org.apache.xerces.internal.impl.xpath.regex.REUtil
Found main in rt.jar: com.sun.org.apache.xerces.internal.impl.xpath.XPath
Found main in rt.jar: com.sun.org.apache.xerces.internal.impl.Version
Found main in rt.jar: com.sun.org.apache.xerces.internal.impl.Constants
Found main in rt.jar: com.sun.org.apache.xalan.internal.xsltc.cmdline.Transform
Found main in rt.jar: com.sun.org.apache.xalan.internal.xsltc.cmdline.Compile
Found main in rt.jar: com.sun.org.apache.xalan.internal.xsltc.ProcessorVersion
Found main in rt.jar: com.sun.org.apache.xalan.internal.xslt.EnvironmentCheck
Found main in rt.jar: java.util.prefs.Base64
Found main in rt.jar: com.sun.java.util.jar.pack.Driver
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.XML_SAX_StAX_FI
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.XML_SAX_FI
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.XML_DOM_SAX_FI
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.XML_DOM_FI
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.PrintTable
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.FI_StAX_SAX_Or_XML_SAX_SAXEvent
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.FI_SAX_XML
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.FI_SAX_Or_XML_SAX_SAXEvent
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.FI_SAX_Or_XML_SAX_DOM_SAX_SAXEvent
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.FI_DOM_Or_XML_DOM_SAX_SAXEvent
Found main in rt.jar: com.sun.corba.se.spi.orbutil.fsm.FSMTest
Found main in rt.jar: com.sun.corba.se.internal.CosNaming.BootstrapServer
Found main in rt.jar: com.sun.corba.se.impl.util.Version
Found main in rt.jar: com.sun.corba.se.impl.util.ORBProperties
Found main in rt.jar: com.sun.corba.se.impl.util.JDKBridge
Found main in rt.jar: com.sun.corba.se.impl.naming.pcosnaming.NameServer
Found main in rt.jar: com.sun.corba.se.impl.naming.cosnaming.TransientNameServer
Found main in rt.jar: com.sun.corba.se.impl.activation.ServerTool
Found main in rt.jar: com.sun.corba.se.impl.activation.ServerMain
Found main in rt.jar: com.sun.corba.se.impl.activation.RepositoryImpl
Found main in rt.jar: com.sun.corba.se.impl.activation.ORBD
time = 669ms
$ ./MainMethodFinder ~/.sdkman/candidates/java/8.0.282.hs-adpt
Scanning Java Installation: /home/tom/.sdkman/candidates/java/8.0.282.hs-adpt
Found main in jconsole.jar: sun.tools.jconsole.JConsole
Found main in zipfs.jar: com.sun.nio.zipfs.ZipInfo
Found main in tools.jar: com.sun.tools.internal.xjc.Driver
Found main in tools.jar: com.sun.tools.internal.xjc.util.MimeTypeRange
Found main in sa-jdi.jar: sun.jvm.hotspot.HelloWorld
Found main in sa-jdi.jar: sun.jvm.hotspot.DebugServer
Found main in nashorn.jar: jdk.nashorn.tools.Shell
Found main in sa-jdi.jar: sun.jvm.hotspot.ObjectHistogram
Found main in tools.jar: com.sun.tools.internal.ws.WsImport
Found main in tools.jar: com.sun.tools.internal.ws.WsGen
Found main in sa-jdi.jar: sun.jvm.hotspot.StackTrace
Found main in tools.jar: com.sun.tools.extcheck.Main
Found main in tools.jar: com.sun.tools.corba.se.idl.Compile
Found main in tools.jar: com.sun.tools.corba.se.idl.toJavaPortable.Compile
Found main in sa-jdi.jar: sun.jvm.hotspot.jdi.SADebugServer
Found main in tools.jar: com.sun.tools.doclint.DocLint
Found main in tools.jar: com.sun.tools.hat.Main
Found main in tools.jar: com.sun.tools.example.debug.expr.ExpressionParser
Found main in sa-jdi.jar: sun.jvm.hotspot.HSDB
Found main in tools.jar: com.sun.tools.example.debug.tty.TTY
Found main in rt.jar: sun.rmi.transport.proxy.CGIHandler
Found main in tools.jar: com.sun.tools.javah.Main
Found main in sa-jdi.jar: sun.jvm.hotspot.ui.AnnotatedMemoryPanel
Found main in rt.jar: sun.rmi.server.ActivationGroupInit
Found main in rt.jar: sun.rmi.server.Activation
Found main in rt.jar: sun.rmi.registry.RegistryImpl
Found main in jfr.jar: jdk.jfr.internal.tool.Main
Found main in sa-jdi.jar: sun.jvm.hotspot.ui.ObjectHistogramPanel
Found main in sa-jdi.jar: sun.jvm.hotspot.ui.HighPrecisionJScrollBar
Found main in sa-jdi.jar: sun.jvm.hotspot.ui.CommandProcessorPanel
Found main in sa-jdi.jar: sun.jvm.hotspot.ui.DebuggerConsolePanel
Found main in sa-jdi.jar: com.sun.java.swing.ui.TabsDlg
Found main in sa-jdi.jar: com.sun.java.swing.ui.WizardDlg
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.dummy.DummyAddress
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.win32.coff.DumpExports
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.win32.coff.TestDebugInfo
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.win32.coff.TestParser
Found main in tools.jar: com.sun.tools.javap.Main
Found main in rt.jar: sun.tools.jar.Main
Found main in tools.jar: com.sun.tools.jdeps.Profile
Found main in tools.jar: com.sun.tools.jdeps.Main
Found main in rt.jar: sun.net.NetworkServer
Found main in tools.jar: com.sun.tools.javadoc.Main
Found main in tools.jar: com.sun.tools.javac.Main
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.linux.LinuxAddress
Found main in tools.jar: com.sun.tools.script.shell.Main
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.posix.elf.ELFFileParser
Found main in tools.jar: com.sun.tools.internal.jxc.SchemaGenerator
Found main in tools.jar: com.sun.tools.internal.jxc.SchemaGeneratorFacade
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.bsd.BsdAddress
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.remote.RemoteAddress
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.proc.ProcAddress
Found main in tools.jar: com.sun.tools.internal.xjc.reader.xmlschema.parser.SchemaConstraintChecker
Found main in sa-jdi.jar: sun.jvm.hotspot.debugger.windbg.WindbgAddress
Found main in rt.jar: sun.launcher.LauncherHelper$FXHelper
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.jcore.ClassDump
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.PMap
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.HeapSummary
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.ClassLoaderStats
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.PStack
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.FinalizerInfo
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.JSnap
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.soql.JSDB
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.soql.SOQL
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.ObjectHistogram
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.FlagDumper
Found main in rt.jar: sun.security.tools.policytool.PolicyTool
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.JMap
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.StackTrace
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.JInfo
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.HeapDumper
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.SysPropsDumper
Found main in sa-jdi.jar: sun.jvm.hotspot.tools.JStack
Found main in rt.jar: sun.security.tools.keytool.Main
Found main in tools.jar: com.sun.tools.internal.xjc.XJCFacade
Found main in rt.jar: sun.java2d.loops.GraphicsPrimitiveMgr
Found main in sa-jdi.jar: sun.jvm.hotspot.CLHSDB
Found main in tools.jar: com.sun.tools.javac.sym.CreateSymbols
Found main in tools.jar: com.sun.tools.javac.sym.Profiles
Found main in tools.jar: com.sun.tools.javac.util.Bits
Found main in rt.jar: sun.security.provider.PolicyParser
Found main in sa-jdi.jar: sun.jvm.hotspot.utilities.RBTree
Found main in sa-jdi.jar: sun.jvm.hotspot.utilities.PlatformInfo
Found main in tools.jar: com.sun.xml.internal.rngom.digested.Main
Found main in tools.jar: com.sun.xml.internal.rngom.digested.DXMLPrinter
Found main in tools.jar: com.sun.xml.internal.rngom.xml.util.EncodingMap
Found main in tools.jar: sun.tools.jcmd.JCmd
Found main in tools.jar: sun.tools.jmap.JMap
Found main in tools.jar: sun.tools.jstatd.Jstatd
Found main in tools.jar: sun.tools.jar.Main
Found main in tools.jar: sun.tools.native2ascii.Main
Found main in tools.jar: sun.tools.jinfo.JInfo
Found main in tools.jar: sun.tools.jstack.JStack
Found main in tools.jar: sun.tools.serialver.SerialVer
Found main in tools.jar: sun.tools.jstat.Jstat
Found main in tools.jar: sun.tools.jps.Jps
Found main in tools.jar: sun.tools.javac.Main
Found main in tools.jar: sun.security.tools.jarsigner.Main
Found main in tools.jar: sun.applet.AppletViewer
Found main in tools.jar: sun.applet.Main
Found main in tools.jar: sun.rmi.rmic.Main
Found main in tools.jar: sun.rmi.rmic.iiop.StaticStringsHash
Found main in tools.jar: sun.rmi.rmic.newrmic.Main
Found main in rt.jar: com.sun.security.auth.module.Crypt
Found main in rt.jar: sun.applet.Main
Found main in rt.jar: sun.applet.AppletViewer
Found main in rt.jar: com.sun.org.apache.xml.internal.security.keys.storage.implementations.CertsInFilesystemDirectoryResolver
Found main in rt.jar: jdk.internal.org.objectweb.asm.util.Textifier
Found main in rt.jar: jdk.internal.org.objectweb.asm.util.CheckClassAdapter
Found main in rt.jar: jdk.internal.org.objectweb.asm.util.ASMifier
Found main in rt.jar: com.sun.org.apache.xerces.internal.impl.xpath.regex.REUtil
Found main in rt.jar: com.sun.org.apache.xerces.internal.impl.xpath.XPath
Found main in rt.jar: com.sun.org.apache.xerces.internal.impl.Version
Found main in rt.jar: com.sun.org.apache.xerces.internal.impl.Constants
Found main in rt.jar: com.sun.org.apache.xalan.internal.xsltc.cmdline.Transform
Found main in rt.jar: com.sun.org.apache.xalan.internal.xsltc.cmdline.Compile
Found main in rt.jar: com.sun.org.apache.xalan.internal.xsltc.ProcessorVersion
Found main in rt.jar: com.sun.org.apache.xalan.internal.xslt.EnvironmentCheck
Found main in rt.jar: java.util.prefs.Base64
Found main in rt.jar: com.sun.java.util.jar.pack.Driver
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.XML_SAX_StAX_FI
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.XML_SAX_FI
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.XML_DOM_SAX_FI
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.XML_DOM_FI
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.PrintTable
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.FI_StAX_SAX_Or_XML_SAX_SAXEvent
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.FI_SAX_XML
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.FI_SAX_Or_XML_SAX_SAXEvent
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.FI_SAX_Or_XML_SAX_DOM_SAX_SAXEvent
Found main in rt.jar: com.sun.xml.internal.fastinfoset.tools.FI_DOM_Or_XML_DOM_SAX_SAXEvent
Found main in rt.jar: com.sun.corba.se.spi.orbutil.fsm.FSMTest
Found main in rt.jar: com.sun.corba.se.internal.CosNaming.BootstrapServer
Found main in rt.jar: com.sun.corba.se.impl.util.Version
Found main in rt.jar: com.sun.corba.se.impl.util.ORBProperties
Found main in rt.jar: com.sun.corba.se.impl.util.JDKBridge
Found main in rt.jar: com.sun.corba.se.impl.naming.pcosnaming.NameServer
Found main in rt.jar: com.sun.corba.se.impl.naming.cosnaming.TransientNameServer
Found main in rt.jar: com.sun.corba.se.impl.activation.ServerTool
Found main in rt.jar: com.sun.corba.se.impl.activation.ServerMain
Found main in rt.jar: com.sun.corba.se.impl.activation.RepositoryImpl
Found main in rt.jar: com.sun.corba.se.impl.activation.ORBD
time = 277ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment