java.lang.instrument.Instrumentation.retransformClasses()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(180)

本文整理了Java中java.lang.instrument.Instrumentation.retransformClasses()方法的一些代码示例,展示了Instrumentation.retransformClasses()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instrumentation.retransformClasses()方法的具体详情如下:
包路径:java.lang.instrument.Instrumentation
类名称:Instrumentation
方法名:retransformClasses

Instrumentation.retransformClasses介绍

暂无

代码示例

代码示例来源:origin: btraceio/btrace

public static void retransform(String runtimeName, Class<?> clazz) {
  try {
    BTraceRuntime rt = runtimes.get(runtimeName);
    if (rt != null && rt.instrumentation.isModifiableClass(clazz)) {
      rt.instrumentation.retransformClasses(clazz);
    }
  } catch (Throwable e) {
    warning(e);
  }
}

代码示例来源:origin: org.mockito/mockito-core

try {
  assureCanReadMockito(types);
  instrumentation.retransformClasses(types.toArray(new Class<?>[types.size()]));
  Throwable throwable = lastException;
  if (throwable != null) {

代码示例来源:origin: oldmanpushcart/greys-anatomy

inst.retransformClasses(classArray);

代码示例来源:origin: oldmanpushcart/greys-anatomy

arraycopy(enhanceMap.keySet().toArray(), 0, classArray, 0, size);
if (classArray.length > 0) {
  inst.retransformClasses(classArray);
for (Class<?> clazz : enhanceMap.keySet()) {
  try {
    inst.retransformClasses(clazz);
  } catch (Throwable t) {
    logger.warn("reTransform {} failed.", clazz, t);

代码示例来源:origin: oldmanpushcart/greys-anatomy

final Class<?>[] classArray = new Class<?>[size];
  arraycopy(classes.toArray(), 0, classArray, 0, size);
  inst.retransformClasses(classArray);
} finally {
  inst.removeTransformer(getClassByteArrayFileTransformer);

代码示例来源:origin: alibaba/jvm-sandbox

if (null == progress) {
  try {
    inst.retransformClasses(waitingReTransformClasses.toArray(new Class[waitingReTransformClasses.size()]));
    logger.info("module[id:{}] watch[id:{}] batch reTransform classes[count:{}] success.",
        coreModule.getUniqueId(), watchId, waitingReTransformClasses.size());
      inst.retransformClasses(waitingReTransformClass);
      logger.info("module[id:{}] watch[id:{}] single reTransform class:{} success, at index:{},total:{};",
          coreModule.getUniqueId(), watchId, waitingReTransformClass,

代码示例来源:origin: btraceio/btrace

try {
    debugPrint("Attempting to retransform class: " + c.getName());
    inst.retransformClasses(c);
  } catch (VerifyError e) {
    debugPrint("verification error: " + c.getName());
inst.retransformClasses(classes);

代码示例来源:origin: glowroot/glowroot

public static void initialReweave(Set<PointcutClassName> pointcutClassNames,
    Class<?>[] initialLoadedClasses, Instrumentation instrumentation) {
  if (!instrumentation.isRetransformClassesSupported()) {
    return;
  }
  Set<Class<?>> classes = getExistingModifiableSubClasses(pointcutClassNames,
      initialLoadedClasses, instrumentation);
  for (Class<?> clazz : classes) {
    if (clazz.isInterface()) {
      continue;
    }
    try {
      instrumentation.retransformClasses(clazz);
    } catch (UnmodifiableClassException e) {
      // IBM JDK 6 throws UnmodifiableClassException even though call to
      // isModifiableClass() in getExistingModifiableSubClasses() returns true
      logger.debug(e.getMessage(), e);
    }
  }
}

代码示例来源:origin: electronicarts/ea-async

public static void agentmain(String agentArgs, Instrumentation inst)
  {
    Transformer transformer = new Transformer();
    inst.addTransformer(transformer, true);
    f1:
    for (Class<?> clazz : inst.getAllLoadedClasses())
    {
      if (inst.isModifiableClass(clazz)
          && !clazz.getName().startsWith("java.")
          && !clazz.getName().startsWith("javax.")
          && !clazz.getName().startsWith("sun."))
      {
        try
        {
          if (transformer.needsInstrumentation(clazz))
          {
            inst.retransformClasses(clazz);
          }
        }
        catch (Exception | Error e)
        {
          e.printStackTrace();
        }
      }
    }
    System.setProperty(Transformer.EA_ASYNC_RUNNING, "true");
  }
}

代码示例来源:origin: glowroot/glowroot

return 0;
instrumentation.retransformClasses(Iterables.toArray(classes, Class.class));
List<Class<?>> updatedReweavableClasses =
    analyzedWorld.getClassesWithReweavableAdvice(false);

代码示例来源:origin: glowroot/glowroot

instrumentation.addTransformer(transformer, true);
instrumentation
    .retransformClasses(Class.forName("sun.misc.Launcher$AppClassLoader"));
instrumentation.removeTransformer(transformer);

代码示例来源:origin: jmockit/jmockit1

@SuppressWarnings("ConstantConditions")
public static void retransformClass(@Nonnull Class<?> aClass) {
 try { instrumentation.retransformClasses(aClass); } catch (UnmodifiableClassException ignore) {}
}

代码示例来源:origin: jbachorik/btrace2

public static void retransform(String runtimeName, Class<?> clazz) {
  try {
    BTraceRuntime rt = runtimes.get(runtimeName);
    if (rt != null && rt.instrumentation.isModifiableClass(clazz)) {
      rt.instrumentation.retransformClasses(clazz);
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: com.fitbur.external/external-bytebuddy

@Override
  public void reset(Instrumentation instrumentation, ClassFileLocator classFileLocator, List<Class<?>> types) throws IOException, UnmodifiableClassException, ClassNotFoundException {
    instrumentation.addTransformer(ClassResettingTransformer.INSTANCE, true);
    try {
      instrumentation.retransformClasses(types.toArray(new Class<?>[types.size()]));
    } finally {
      instrumentation.removeTransformer(ClassResettingTransformer.INSTANCE);
    }
  }
};

代码示例来源:origin: org.gridkit.3rd.btrace/runtime

public static void retransform(String runtimeName, Class<?> clazz) {
  try {
    BTraceRuntime rt = runtimes.get(runtimeName);
    if (rt != null && rt.instrumentation.isModifiableClass(clazz)) {
      rt.instrumentation.retransformClasses(clazz);
    }
  } catch (Exception e) {
    BTraceLogger.debugPrint(e);
  }
}

代码示例来源:origin: ctripcorp/vi

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);
}

代码示例来源:origin: ctripcorp/vi

private static void reloadClass(Class seleClass) throws Exception {
  if (!isLoaded) {
    startUp();
  }
  Instrumentation inst = instrumentation();
  inst.retransformClasses(seleClass);
}

代码示例来源:origin: org.testifyproject.external/external-bytebuddy

@Override
protected void apply(Instrumentation instrumentation, Map<Class<?>, ClassDefinition> classDefinitions) throws UnmodifiableClassException {
  ClassRedefinitionTransformer classRedefinitionTransformer = new ClassRedefinitionTransformer(classDefinitions);
  synchronized (this) {
    instrumentation.addTransformer(classRedefinitionTransformer, REDEFINE_CLASSES);
    try {
      instrumentation.retransformClasses(classDefinitions.keySet().toArray(new Class<?>[classDefinitions.size()]));
    } finally {
      instrumentation.removeTransformer(classRedefinitionTransformer);
    }
  }
  classRedefinitionTransformer.assertTransformation();
}

代码示例来源:origin: com.fitbur.external/external-bytebuddy

@Override
protected void apply(Instrumentation instrumentation, Map<Class<?>, ClassDefinition> classDefinitions) throws UnmodifiableClassException {
  ClassRedefinitionTransformer classRedefinitionTransformer = new ClassRedefinitionTransformer(classDefinitions);
  synchronized (this) {
    instrumentation.addTransformer(classRedefinitionTransformer, REDEFINE_CLASSES);
    try {
      instrumentation.retransformClasses(classDefinitions.keySet().toArray(new Class<?>[classDefinitions.size()]));
    } finally {
      instrumentation.removeTransformer(classRedefinitionTransformer);
    }
  }
  classRedefinitionTransformer.assertTransformation();
}

代码示例来源:origin: net.orfjackal.retrolambda/retrolambda

public static void premain(String agentArgs, Instrumentation inst) throws Exception {
  // Append the agent JAR to the bootstrap search path so that the instrumented InnerClassLambdaMetaFactory
  // could refer to Agent.
  inst.appendToBootstrapClassLoaderSearch(new JarFile(getAgentJarFile()));
  inst.addTransformer(new InnerClassLambdaMetafactoryTransformer(), true);
  inst.retransformClasses(Class.forName("java.lang.invoke.InnerClassLambdaMetafactory"));
}

相关文章