本文整理汇总了Java中java.lang.instrument.Instrumentation.getAllLoadedClasses方法的典型用法代码示例。如果您正苦于以下问题:Java Instrumentation.getAllLoadedClasses方法的具体用法?Java Instrumentation.getAllLoadedClasses怎么用?Java Instrumentation.getAllLoadedClasses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.instrument.Instrumentation
的用法示例。
在下文中一共展示了Instrumentation.getAllLoadedClasses方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initTransformer
import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
/**
* 初始化类字节码的转换器
*
* @param inst 用于管理字节码转换器
*/
private static void initTransformer(Instrumentation inst) throws UnmodifiableClassException {
LinkedList<Class> retransformClasses = new LinkedList<Class>();
CustomClassTransformer customClassTransformer = new CustomClassTransformer();
inst.addTransformer(customClassTransformer, true);
Class[] loadedClasses = inst.getAllLoadedClasses();
for (Class clazz : loadedClasses) {
for (final AbstractClassHook hook : customClassTransformer.getHooks()) {
if (hook.isClassMatched(clazz.getName().replace(".", "/"))) {
if (inst.isModifiableClass(clazz) && !clazz.getName().startsWith("java.lang.invoke.LambdaForm")) {
retransformClasses.add(clazz);
}
}
}
}
// hook已经加载的类
Class[] classes = new Class[retransformClasses.size()];
retransformClasses.toArray(classes);
if (classes.length > 0) {
inst.retransformClasses(classes);
}
}
示例2: premain
import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
public static void premain(String args, Instrumentation instrumentation) {
if (!instrumentation.isRetransformClassesSupported()) {
System.out.println("Class retransformation is not supported.");
return;
}
System.out.println("Calling lambda to ensure that lambda forms were created");
Agent.lambda.run();
System.out.println("Registering class file transformer");
instrumentation.addTransformer(new Agent());
for (Class c : instrumentation.getAllLoadedClasses()) {
if (c.getName().contains("LambdaForm") &&
instrumentation.isModifiableClass(c)) {
System.out.format("We've found a modifiable lambda form: %s%n", c.getName());
try {
instrumentation.retransformClasses(c);
} catch (UnmodifiableClassException e) {
throw new AssertionError("Modification of modifiable class " +
"caused UnmodifiableClassException", e);
}
}
}
}
示例3: loadedClasses
import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
public static List<String> loadedClasses() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
List<String> rtn = new ArrayList<>();
Instrumentation inst = instrumentation();
Class[] classes = inst.getAllLoadedClasses();
for(Class c:classes){
rtn.add(c.getName());
}
return rtn;
}
示例4: agentmain
import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
public static void agentmain(String arg,Instrumentation inst) throws AttachNotSupportedException, IOException
{
MyAgent.inst=inst;
System.out.println("agent代理程序类[MyAgent]被执行!");
System.out.println("当前代理程序类使用加载器:"+Thread.currentThread().getContextClassLoader().toString());
num.incrementAndGet();
System.out.println(num.longValue());
System.out.println(arg);
Class<?>[] classes = inst.getAllLoadedClasses();
for(Class<?> cls :classes)
{
System.out.println(cls.getName());
}
}
示例5: agentmain
import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
public static void agentmain(@SuppressWarnings("unused") String args, Instrumentation inst) throws Exception {
if (inst.isRedefineClassesSupported() && inst.isRetransformClassesSupported()) {
inst.addTransformer(new Redefiner(), true);
Class<?>[] allClasses = inst.getAllLoadedClasses();
for (int i = 0; i < allClasses.length; i++) {
Class<?> c = allClasses[i];
if (c == Intrinsic.class) {
inst.retransformClasses(new Class<?>[]{c});
}
}
}
}
示例6: agentmain
import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
public static void agentmain(@SuppressWarnings("unused") String args, Instrumentation inst) throws Exception {
if (inst.isRedefineClassesSupported() && inst.isRetransformClassesSupported()) {
inst.addTransformer(new FooTransformer(), true);
Class<?>[] allClasses = inst.getAllLoadedClasses();
for (int i = 0; i < allClasses.length; i++) {
Class<?> c = allClasses[i];
if (c == Foo.class) {
inst.retransformClasses(new Class<?>[]{c});
}
}
}
}
示例7: main
import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Instrumentation inst = Agent.inst;
if (inst == null)
throw new RuntimeException("Agent not loaded");
// check boot class path has been extended
Class<?> helper = Class.forName("AgentHelper");
if (helper.getClassLoader() != null)
throw new RuntimeException("AgentHelper not loaded by boot loader");
// check Instrumentation object can be used
Class<?>[] classes = inst.getAllLoadedClasses();
System.out.println(classes.length + " classes loaded");
}