本文整理了Java中java.lang.instrument.Instrumentation.redefineClasses()
方法的一些代码示例,展示了Instrumentation.redefineClasses()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instrumentation.redefineClasses()
方法的具体详情如下:
包路径:java.lang.instrument.Instrumentation
类名称:Instrumentation
方法名:redefineClasses
暂无
代码示例来源:origin: redisson/redisson
@Override
protected void apply(Instrumentation instrumentation, Map<Class<?>, ClassDefinition> classDefinitions)
throws UnmodifiableClassException, ClassNotFoundException {
instrumentation.redefineClasses(classDefinitions.values().toArray(new ClassDefinition[classDefinitions.size()]));
}
代码示例来源:origin: dcevm/dcevm
public void redefineClasses(Map<Class<?>, byte[]> classes) throws ClassNotFoundException, UnmodifiableClassException {
Instrumentation instrumentation = InstrumentationAgent.INSTRUMENTATION;
if (instrumentation == null) {
throw new IllegalStateException("Instrumentation agent is not properly installed!");
}
ClassDefinition[] definitions = new ClassDefinition[classes.size()];
int i = 0;
for (Map.Entry<Class<?>, byte[]> entry : classes.entrySet()) {
definitions[i++] = new ClassDefinition(entry.getKey(), entry.getValue());
}
instrumentation.redefineClasses(definitions);
}
代码示例来源:origin: scouter-project/scouter
private void hooking(Hook m) {
// Never use dynamic hooking on AIX with JDK1.5
if (SystemUtil.IS_AIX && SystemUtil.IS_JAVA_1_5) {
return;
}
try {
Class cls = Class.forName(m.classname, false, m.loader);
ClassDefinition[] cd = new ClassDefinition[1];
cd[0] = new ClassDefinition(cls, m.body);
JavaAgent.getInstrumentation().redefineClasses(cd);
} catch (Throwable t) {
Logger.println("A149", "async hook fail:" + m.classname + " " + t);
}
}
}
代码示例来源:origin: scouter-project/scouter
private void hooking(Hook m) {
// Never use dynamic hooking on AIX with JDK1.5
if (SystemUtil.IS_AIX && SystemUtil.IS_JAVA_1_5) {
return;
}
try {
Class cls = Class.forName(m.classname, false, m.loader);
ClassDefinition[] cd = new ClassDefinition[1];
cd[0] = new ClassDefinition(cls, m.body);
JavaAgent.getInstrumentation().redefineClasses(cd);
} catch (Throwable t) {
Logger.println("A149", "async hook fail:" + m.classname + " " + t);
}
}
}
代码示例来源:origin: HotswapProjects/HotswapAgent
@Override
public void run() {
try {
instrumentation.redefineClasses(new ClassDefinition(transformer.getClassBeingRedefined(), transformer
.getClassfileBuffer()));
} catch (Throwable t) {
transformer.removeClassState();
throw new RuntimeException(t);
}
}
代码示例来源:origin: redisson/redisson
circularityLock.release();
try {
instrumentation.redefineClasses(classDefinitions.toArray(new ClassDefinition[classDefinitions.size()]));
} finally {
circularityLock.acquire();
代码示例来源:origin: scouter-project/scouter
private void redefine(StringSet clazzes) {
Class[] loadedClasses = JavaAgent.getInstrumentation().getAllLoadedClasses();
ArrayList<ClassDefinition> definitionList = new ArrayList<ClassDefinition>();
boolean allSuccess = true;
for (int i = 0; i < loadedClasses.length; i++) {
if (clazzes.hasKey(loadedClasses[i].getName())) {
try {
byte[] buff = ClassUtil.getByteCode(loadedClasses[i]);
if (buff == null) {
continue;
}
definitionList.add(new ClassDefinition(loadedClasses[i], buff));
} catch (Exception e) {
allSuccess = false;
break;
}
}
}
if (definitionList.size() > 0 && allSuccess) {
try {
JavaAgent.getInstrumentation().redefineClasses(definitionList.toArray(new ClassDefinition[definitionList.size()]));
} catch (Throwable th) {
Logger.println("A183", "redefine error : " + loadedClasses);
}
}
}
代码示例来源:origin: scouter-project/scouter
private void redefine(StringSet clazzes) {
Class[] loadedClasses = JavaAgent.getInstrumentation().getAllLoadedClasses();
ArrayList<ClassDefinition> definitionList = new ArrayList<ClassDefinition>();
boolean allSuccess = true;
for (int i = 0; i < loadedClasses.length; i++) {
if (clazzes.hasKey(loadedClasses[i].getName())) {
try {
byte[] buff = ClassUtil.getByteCode(loadedClasses[i]);
if (buff == null) {
continue;
}
definitionList.add(new ClassDefinition(loadedClasses[i], buff));
} catch (Exception e) {
allSuccess = false;
break;
}
}
}
if (definitionList.size() > 0 && allSuccess) {
try {
JavaAgent.getInstrumentation().redefineClasses(definitionList.toArray(new ClassDefinition[definitionList.size()]));
} catch (Throwable th) {
Logger.println("A183", "redefine error : " + loadedClasses);
}
}
}
代码示例来源:origin: org.javassist/javassist
/**
* Redefines classes.
*/
public static void redefine(Class<?>[] oldClasses, CtClass[] newClasses)
throws NotFoundException, IOException, CannotCompileException
{
startAgent();
ClassDefinition[] defs = new ClassDefinition[oldClasses.length];
for (int i = 0; i < oldClasses.length; i++)
defs[i] = new ClassDefinition(oldClasses[i], newClasses[i].toBytecode());
try {
instrumentation.redefineClasses(defs);
}
catch (ClassNotFoundException e) {
throw new NotFoundException(e.getMessage(), e);
}
catch (UnmodifiableClassException e) {
throw new CannotCompileException(e.getMessage(), e);
}
}
代码示例来源:origin: scouter-project/scouter
JavaAgent.getInstrumentation().redefineClasses(definitionList.toArray(new ClassDefinition[definitionList.size()]));
p.put("success", new BooleanValue(true));
} catch (Throwable th) {
代码示例来源:origin: scouter-project/scouter
JavaAgent.getInstrumentation().redefineClasses(definitionList.toArray(new ClassDefinition[definitionList.size()]));
p.put("success", new BooleanValue(true));
} catch (Throwable th) {
代码示例来源:origin: scouter-project/scouter
JavaAgent.getInstrumentation().redefineClasses(definitionList.toArray(new ClassDefinition[definitionList.size()]));
p.put("success", new BooleanValue(true));
} catch (Throwable th) {
代码示例来源:origin: scouter-project/scouter
/**
* Redefines classes.
*/
public static void redefine(Class<?>[] oldClasses, CtClass[] newClasses)
throws NotFoundException, IOException, CannotCompileException
{
startAgent();
ClassDefinition[] defs = new ClassDefinition[oldClasses.length];
for (int i = 0; i < oldClasses.length; i++)
defs[i] = new ClassDefinition(oldClasses[i], newClasses[i].toBytecode());
try {
instrumentation.redefineClasses(defs);
}
catch (ClassNotFoundException e) {
throw new NotFoundException(e.getMessage(), e);
}
catch (UnmodifiableClassException e) {
throw new CannotCompileException(e.getMessage(), e);
}
}
代码示例来源:origin: hcoles/pitest
public static boolean hotSwap(final Class<?> mutateMe, final byte[] bytes) { // NO_UCD
final ClassDefinition[] definitions = { new ClassDefinition(mutateMe, bytes) };
try {
instrumentation.redefineClasses(definitions);
return true;
} catch (final ClassNotFoundException e) {
// swallow
} catch (final UnmodifiableClassException e) {
// swallow
} catch (final java.lang.VerifyError e) {
// swallow
} catch (final java.lang.InternalError e) {
// swallow
}
return false;
}
代码示例来源:origin: com.google.code.maven-play-plugin.org.playframework/play
public static void reload(ClassDefinition... definitions) throws UnmodifiableClassException, ClassNotFoundException {
instrumentation.redefineClasses(definitions);
}
}
代码示例来源:origin: org.testifyproject.external/external-bytebuddy
@Override
protected void apply(Instrumentation instrumentation, Map<Class<?>, ClassDefinition> classDefinitions)
throws UnmodifiableClassException, ClassNotFoundException {
instrumentation.redefineClasses(classDefinitions.values().toArray(new ClassDefinition[classDefinitions.size()]));
}
代码示例来源:origin: co.paralleluniverse/quasar-core
public static void redefine(Collection<ClassDefinition> classDefinitions) {
try {
instrumentation.redefineClasses(classDefinitions.toArray(new ClassDefinition[0]));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.fitbur.external/external-bytebuddy
@Override
protected void apply(Instrumentation instrumentation, Map<Class<?>, ClassDefinition> classDefinitions)
throws UnmodifiableClassException, ClassNotFoundException {
instrumentation.redefineClasses(classDefinitions.values().toArray(new ClassDefinition[classDefinitions.size()]));
}
代码示例来源:origin: jmockit/jmockit1
private static void redefineClassForCoverage(@Nonnull Class<?> loadedClass, @Nonnull byte[] modifiedClassfile) {
ClassDefinition[] classDefs = {new ClassDefinition(loadedClass, modifiedClassfile)};
try {
Startup.instrumentation().redefineClasses(classDefs);
}
catch (ClassNotFoundException | UnmodifiableClassException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.jmockit/jmockit-coverage
private static void redefineClassForCoverage(@Nonnull Class<?> loadedClass, @Nonnull byte[] modifiedClassfile)
{
ClassDefinition[] classDefs = {new ClassDefinition(loadedClass, modifiedClassfile)};
try {
Startup.instrumentation().redefineClasses(classDefs);
}
catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
catch (UnmodifiableClassException e) {
throw new RuntimeException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!