获取JVM上所有引导类的列表? [英] Getting a list of all the bootstrap classes on the JVM?

查看:50
本文介绍了获取JVM上所有引导类的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于ClassLoader,有一个名为 findBootstrapClass 的方法,该方法在引导时返回Class。

There is a method called findBootstrapClass for a ClassLoader that returns a Class if it is bootstrapped. Is there a way to find classes has been loaded?

推荐答案

您可以尝试通过以下方法首先获取引导类加载器:调用

You could try to first get the bootstrap class loader by e.g. calling

ClassLoader bootstrapLoader = ClassLoader.getSystemClassLoader().getParent();

然后按如下说明获取该类加载器的类:如何列出在特定类加载器中加载的所有类

and then get the classes of this class loader as explained here: How can I list all classes loaded in a specific class loader.

但是请注意,获取引导类加载器并不可靠,因为它可能不明确存在。因此 ClassLoader.getSystemClassLoader()。getParent()可能返回null,如 ClassLoader#getParent()

But note, that getting the bootstrap class loader is not reliable, because it may not explicitly exist. So ClassLoader.getSystemClassLoader().getParent() may return null, as explained in the Javadoc of ClassLoader#getParent():


返回父类加载器以进行委派。一些实现
可以使用null来表示引导类加载器。如果此类加载器的父级是引导类加载器
,则在此类实现中此方法
将返回null。

Returns the parent class loader for delegation. Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class loader's parent is the bootstrap class loader.

这篇关于获取JVM上所有引导类的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆