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

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

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

Instrumentation.isRetransformClassesSupported介绍

暂无

代码示例

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

@Override
public int reweave(String agentId) throws Exception {
  if (instrumentation == null) {
    // this method is called from GlowrootAgentInit.resetConfigForTests() when
    // instrumentation is null
    return 0;
  }
  // this command is filtered out of the UI when retransform classes is not supported
  checkState(instrumentation.isRetransformClassesSupported(),
      "Retransform classes is not supported");
  return reweaveInternal();
}

代码示例来源: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: glowroot/glowroot

WeavingClassFileTransformer transformer =
    new WeavingClassFileTransformer(weaver, instrumentation);
if (instrumentation.isRetransformClassesSupported()) {
  instrumentation.addTransformer(transformer, true);
  jvmRetransformClassesSupported = true;

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

@Override
protected boolean isRetransforming(Instrumentation instrumentation) {
  if (!instrumentation.isRetransformClassesSupported()) {
    throw new IllegalArgumentException("Cannot retransform classes: " + instrumentation);
  }
  return true;
}

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

@Override
protected void check(Instrumentation instrumentation) {
  if (!instrumentation.isRetransformClassesSupported()) {
    throw new IllegalStateException("Cannot apply redefinition on " + instrumentation);
  }
}

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

@Override
protected Strategy validate(Instrumentation instrumentation) {
  if (!instrumentation.isRetransformClassesSupported()) {
    throw new IllegalArgumentException("Does not support retransformation: " + instrumentation);
  }
  return this;
}

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

@Override
protected Strategy validate(Instrumentation instrumentation) {
  if (!instrumentation.isRetransformClassesSupported()) {
    throw new IllegalArgumentException("Does not support retransformation: " + instrumentation);
  }
  return this;
}

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

/**
 * Creates an agent-based class file locator.
 *
 * @param instrumentation      The instrumentation to be used.
 * @param classLoadingDelegate The delegate responsible for class loading.
 */
public AgentBased(Instrumentation instrumentation, ClassLoadingDelegate classLoadingDelegate) {
  if (!instrumentation.isRetransformClassesSupported()) {
    throw new IllegalArgumentException(instrumentation + " does not support retransformation");
  }
  this.instrumentation = instrumentation;
  this.classLoadingDelegate = classLoadingDelegate;
}

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

/**
 * Creates an agent-based class file locator.
 *
 * @param instrumentation      The instrumentation to be used.
 * @param classLoadingDelegate The delegate responsible for class loading.
 */
public AgentBased(Instrumentation instrumentation, ClassLoadingDelegate classLoadingDelegate) {
  if (!instrumentation.isRetransformClassesSupported()) {
    throw new IllegalArgumentException(instrumentation + " does not support retransformation");
  }
  this.instrumentation = instrumentation;
  this.classLoadingDelegate = classLoadingDelegate;
}

代码示例来源:origin: stackoverflow.com

class JavaAgent {
  private JavaAgent() {}

  public static void premain(String agentArgs, Instrumentation inst) {
    System.out.println("Agent Premain Start");
    Transformer.instrumentation = inst;
    inst.addTransformer(new Transformer(), inst.isRetransformClassesSupported());
  }    
}

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

/**
 * Creates a class reloading strategy for the given instrumentation. The given instrumentation must either
 * support {@link java.lang.instrument.Instrumentation#isRedefineClassesSupported()} or
 * {@link java.lang.instrument.Instrumentation#isRetransformClassesSupported()}. If both modes are supported,
 * classes will be transformed using a class retransformation.
 *
 * @param instrumentation The instrumentation to be used by this reloading strategy.
 * @return A suitable class reloading strategy.
 */
public static ClassReloadingStrategy of(Instrumentation instrumentation) {
  Strategy strategy;
  if (instrumentation.isRedefineClassesSupported()) {
    strategy = Strategy.REDEFINITION;
  } else if (instrumentation.isRetransformClassesSupported()) {
    strategy = Strategy.RETRANSFORMATION;
  } else {
    throw new IllegalArgumentException("Instrumentation does not support manipulation of loaded classes: " + instrumentation);
  }
  return new ClassReloadingStrategy(instrumentation, strategy);
}

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

/**
 * Creates a class reloading strategy for the given instrumentation. The given instrumentation must either
 * support {@link java.lang.instrument.Instrumentation#isRedefineClassesSupported()} or
 * {@link java.lang.instrument.Instrumentation#isRetransformClassesSupported()}. If both modes are supported,
 * classes will be transformed using a class retransformation.
 *
 * @param instrumentation The instrumentation to be used by this reloading strategy.
 * @return A suitable class reloading strategy.
 */
public static ClassReloadingStrategy of(Instrumentation instrumentation) {
  Strategy strategy;
  if (instrumentation.isRedefineClassesSupported()) {
    strategy = Strategy.REDEFINITION;
  } else if (instrumentation.isRetransformClassesSupported()) {
    strategy = Strategy.RETRANSFORMATION;
  } else {
    throw new IllegalArgumentException("Instrumentation does not support manipulation of loaded classes: " + instrumentation);
  }
  return new ClassReloadingStrategy(instrumentation, strategy);
}

代码示例来源:origin: stackoverflow.com

inst.addTransformer(new CheckAgent(), inst.isRetransformClassesSupported());
inst.addTransformer(new CheckAgent(), inst.isRetransformClassesSupported());

代码示例来源:origin: foursquare/heapaudit

private static void instrument(HeapAudit agent,
                String args,
                Instrumentation instrumentation) throws FileNotFoundException, UnmodifiableClassException {
  if (!instrumentation.isRetransformClassesSupported()) {
    throw new UnmodifiableClassException();
  }
  instrumentation.addTransformer(agent,
                  true);
  ArrayList<Class<?>> classes = new ArrayList<Class<?>>();
  for (Class<?> c: instrumentation.getAllLoadedClasses()) {
    if (instrumentation.isModifiableClass(c)) {
      classes.add(c);
    }
  }
  instrumentation.retransformClasses(classes.toArray(new Class<?>[classes.size()]));
}

代码示例来源:origin: com.github.fommil/java-allocation-instrumenter

private static void bootstrap(Instrumentation inst) {
  inst.addTransformer(new AllocationInstrumenter(),
      inst.isRetransformClassesSupported());
  if (!canRewriteBootstrap) {
    return;
  }
  // Get the set of already loaded classes that can be rewritten.
  Class<?>[] classes = inst.getAllLoadedClasses();
  ArrayList<Class<?>> classList = new ArrayList<Class<?>>();
  for (int i = 0; i < classes.length; i++) {
    if (inst.isModifiableClass(classes[i])) {
      classList.add(classes[i]);
    }
  }
  // Reload classes, if possible.
  Class<?>[] workaround = new Class<?>[classList.size()];
  try {
    inst.retransformClasses(classList.toArray(workaround));
  } catch (UnmodifiableClassException e) {
    System.err.println("AllocationInstrumenter was unable to "
        + "retransform early loaded classes.");
  }
}

代码示例来源:origin: yushijinhun/authlib-injector

public static synchronized void bootstrap(Instrumentation instrumentation) throws InjectorInitializationException {
  if (booted) {
    Logging.LAUNCH.info("Already started, skipping");
    return;
  }
  booted = true;
  AuthlibInjector.instrumentation = instrumentation;
  retransformSupported = instrumentation.isRetransformClassesSupported();
  if (!retransformSupported) {
    Logging.LAUNCH.warning("Retransform is not supported");
  }
  Logging.LAUNCH.info("Version: " + getVersion());
  Optional<YggdrasilConfiguration> optionalConfig = configure();
  if (optionalConfig.isPresent()) {
    classTransformer = createTransformer(optionalConfig.get());
    instrumentation.addTransformer(classTransformer, retransformSupported);
    MC52974Workaround.init();
    MC52974_1710Workaround.init();
  } else {
    Logging.LAUNCH.severe("No config available");
    throw new InjectorInitializationException();
  }
}

代码示例来源:origin: jboss-fuse/fabric8

private void instrumentApplication() throws FileNotFoundException, UnmodifiableClassException {
  if (!instrumentation.isRetransformClassesSupported()) {
    throw new UnmodifiableClassException();
  }
  instrumentation.addTransformer(this, true);
  for (Class<?> c : instrumentation.getAllLoadedClasses()) {
    if (isInstrumentClass(c)) {
      if (configuration.isAsyncTransformation()) {
        try {
          blockingQueue.put(c);
        } catch (InterruptedException e) {
          Thread.currentThread().interrupt();
          break;
        }
      } else {
        try {
          instrumentation.retransformClasses(new Class[]{c});
        } catch (Throwable e) {
          LOG.error("Could not transform " + c.getName(), e);
        }
      }
    }
  }
  if (configuration.isAsyncTransformation() && !blockingQueue.isEmpty()) {
    startTransformThread();
  }
}

代码示例来源:origin: edu.berkeley.cs.jqf/jqf-instrument

public static void premain(String agentArgs, Instrumentation inst) throws ClassNotFoundException {
 preloadClasses();
 inst.addTransformer(new SnoopInstructionTransformer(), true);
 if (inst.isRetransformClassesSupported()) {
  for (Class clazz : inst.getAllLoadedClasses()) {
   try {
    String cname = clazz.getName().replace(".","/");
    if (shouldExclude(cname) == false) {
     if (inst.isModifiableClass(clazz)) {
      inst.retransformClasses(clazz);
     } else {
      println("[JANALA] Could not instrument " + clazz + " :-(");
     }
    }
   } catch (Exception e){
    if (verbose) {
     println("[JANALA] Could not instrument " + clazz + " :-(");
     e.printStackTrace();
    }
   }
  }
 }
}

代码示例来源:origin: rohanpadhye/jqf

public static void premain(String agentArgs, Instrumentation inst) throws ClassNotFoundException {
 preloadClasses();
 inst.addTransformer(new SnoopInstructionTransformer(), true);
 if (inst.isRetransformClassesSupported()) {
  for (Class clazz : inst.getAllLoadedClasses()) {
   try {
    String cname = clazz.getName().replace(".","/");
    if (shouldExclude(cname) == false) {
     if (inst.isModifiableClass(clazz)) {
      inst.retransformClasses(clazz);
     } else {
      println("[JANALA] Could not instrument " + clazz + " :-(");
     }
    }
   } catch (Exception e){
    if (verbose) {
     println("[JANALA] Could not instrument " + clazz + " :-(");
     e.printStackTrace();
    }
   }
  }
 }
}

代码示例来源:origin: EvoSuite/evosuite

@Test
public void checkRetransformIsSupported(){
  Assert.assertTrue(InstrumentingAgent.getInstrumentation().isRetransformClassesSupported());
}

相关文章