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


Java Instrumentation.retransformClasses方法代碼示例

本文整理匯總了Java中java.lang.instrument.Instrumentation.retransformClasses方法的典型用法代碼示例。如果您正苦於以下問題:Java Instrumentation.retransformClasses方法的具體用法?Java Instrumentation.retransformClasses怎麽用?Java Instrumentation.retransformClasses使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.instrument.Instrumentation的用法示例。


在下文中一共展示了Instrumentation.retransformClasses方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: reloadClass

import java.lang.instrument.Instrumentation; //導入方法依賴的package包/類
private static void reloadClass(Class seleClass) throws Exception {
    if (!isLoaded) {
        startUp();
    }
    Instrumentation inst = instrumentation();

    inst.retransformClasses(seleClass);
}
 
開發者ID:ctripcorp,項目名稱:cornerstone,代碼行數:9,代碼來源:AgentTool.java

示例4: removeMetricsClass

import java.lang.instrument.Instrumentation; //導入方法依賴的package包/類
public synchronized static void removeMetricsClass(String name) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, UnmodifiableClassException {
    Class seleClass = Class.forName(name.replace('/', '.'));
    needRecoverClasses.put(name, needMetricsClasses.remove(name));
    Instrumentation inst = instrumentation();
    inst.retransformClasses(seleClass);
    MetricsCollector.getCollector().removeClassMetrics(name);
}
 
開發者ID:ctripcorp,項目名稱:cornerstone,代碼行數:8,代碼來源:AgentTool.java

示例5: removeDebugClassByTraceId

import java.lang.instrument.Instrumentation; //導入方法依賴的package包/類
public synchronized static Map<String, Object> removeDebugClassByTraceId(String traceId,boolean isForce) throws NotFoundException {
    String className = null;
    logger.debug("ready remove "+traceId);
    Map<String, Object> rtn = DebugTool.removeTraceInfo(traceId);

    for (Map.Entry<String, DebugInfo> entry : debugClassInfos.entrySet()) {
        if (traceId.equals(entry.getValue().getTraceId())) {
            className = entry.getKey();
            break;
        }
    }
    if (className == null) {
        throw  new NotFoundException("no debug class found by traceid "+traceId);
    }

    if(rtn != null || isForce) {
        try {

            Class seleClass = Class.forName(className.replace('/', '.'));
            debugClassInfos.remove(className);
            needRecoverClasses.put(className, needDebugClasses.remove(className));
            Instrumentation inst = instrumentation();
            inst.retransformClasses(seleClass);
        } catch (Throwable e) {
            logger.error("recover debug class failed!", e);
        }
    }
    return rtn;

}
 
開發者ID:ctripcorp,項目名稱:cornerstone,代碼行數:31,代碼來源:AgentTool.java

示例6: rewriteIfPossible

import java.lang.instrument.Instrumentation; //導入方法依賴的package包/類
@Override
public void rewriteIfPossible(Class<?> declaringClass) throws IllegalStateException {
  Instrumentation instrumentation = checkInstrumentation();
  
  /*
  byte[] bytecode;
  ClassLoader loader = declaringClass.getClassLoader();
  try(InputStream input = loader.getResourceAsStream(declaringClass.getName().replace('.', '/') + ".class")) {
    if (input == null) {
      throw new IllegalStateException("no input");
    }

    Function<String, Optional<InputStream>> classFileFinder = internalName -> Optional.ofNullable(loader.getResourceAsStream(internalName + ".class"));
    bytecode = Rewriter.rewrite(input, classFileFinder);
  } catch (IOException e) {
    throw new IllegalStateException(e);
  }
  
  try {
    instrumentation.redefineClasses(new ClassDefinition(declaringClass, bytecode));
  } catch (ClassNotFoundException | UnmodifiableClassException e) {
    throw new IllegalStateException(e);
  }*/
  
  try {
    instrumentation.retransformClasses(declaringClass);
  } catch (UnmodifiableClassException e) {
    throw new IllegalStateException(e);
  }
}
 
開發者ID:forax,項目名稱:mjolnir,代碼行數:31,代碼來源:AgentFacadeImpl.java

示例7: 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

示例8: premain

import java.lang.instrument.Instrumentation; //導入方法依賴的package包/類
public static void premain(String agentArgs, Instrumentation inst) throws Exception {
    LoggingTransformer t = new LoggingTransformer();
    inst.addTransformer(t, true);
    {
        Class demoClass = Class.forName("RedefineLeak$Tester");

        for (int i = 0; i < 10000; i++) {
           inst.retransformClasses(demoClass);
        }
    }
    System.gc();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:RedefineLeak.java

示例9: redefine

import java.lang.instrument.Instrumentation; //導入方法依賴的package包/類
public static void redefine(String agentArgs, Instrumentation instrumentation, Class to_redefine) {

        try {
            instrumentation.retransformClasses(to_redefine);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:Agent.java

示例10: 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


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