當前位置: 首頁>>代碼示例>>Java>>正文


Java Instrumentation.getAllLoadedClasses方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:baidu,項目名稱:openrasp,代碼行數:27,代碼來源:Agent.java

示例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);
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:TestLambdaFormRetransformation.java

示例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;
}
 
開發者ID:ctripcorp,項目名稱:cornerstone,代碼行數:11,代碼來源:AgentTool.java

示例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());
       }
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:15,代碼來源:MyAgent.java

示例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});
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:RedefineIntrinsicTest.java

示例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});
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:RedefineClassTest.java

示例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");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:Main.java


注:本文中的java.lang.instrument.Instrumentation.getAllLoadedClasses方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。