本文整理匯總了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");
}