Skip to content

Commit cd3ee0e

Browse files
Remove extraneous debug code
1 parent 591ce68 commit cd3ee0e

File tree

2 files changed

+0
-101
lines changed

2 files changed

+0
-101
lines changed

newrelic-agent/src/main/java/com/newrelic/agent/instrumentation/weaver/ClassLoaderClassTransformer.java

-11
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
293293
if (observedClassLoaders.containsKey(superName) ||
294294
classloadersToInclude.contains(reader.getClassName()) || classloadersToInclude.contains(superName)) {
295295
byte[] finalClassBytes = transform(loader, className, classBeingRedefined, protectionDomain, classfileBuffer, null, null);
296-
//WeaveUtils.createReadableClassFileFromByteArray(finalClassBytes, true, className, "ClassLoader", "/Users/katherineanderson/Downloads");
297296
return finalClassBytes;
298297
}
299298
return null;
@@ -325,11 +324,6 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
325324
// we don't need to worry about it possibly using findResource() when we call validate(cache).
326325
ClassCache cache = new ClassCache(new ClassLoaderClassFinder(observedClassLoaders));
327326

328-
//DEBUG TIME: how does the base classloader fare???
329-
if(className.equals("java/lang/ClassLoader")){
330-
WeaveUtils.forceVisitationOfClassFile(classfileBuffer, cache);
331-
}
332-
333327
PackageValidationResult result;
334328
if (className.equals("java/lang/ClassLoader")) {
335329
// For "java.lang.ClassLoader" we only want to instrument one of the loadClass() methods
@@ -381,11 +375,6 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
381375
cache, skipMethods);
382376
// Do the weaving and use our "non-findResource" cache from above
383377
newBytes = packageWeaveResult.getCompositeBytes(cache);
384-
if (className.equals("java/lang/ClassLoader")){
385-
//WeaveUtils.printClassFrames(newBytes);
386-
//WeaveUtils.createReadableClassFileFromByteArray(newBytes, className, "ClassLoader", "/Users/katherineanderson/Downloads");
387-
//VerifierImpl.verify(ClassFile(newBytes), s -> System.out.println(s));
388-
}
389378

390379
if (newBytes != null) {
391380
Agent.LOG.log(Level.FINE, "ClassLoaderClassTransformer patched {0} -- {1}", loader, className);

newrelic-weaver/src/main/java/com/newrelic/weave/utils/WeaveUtils.java

-90
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@
3636
import org.objectweb.asm.tree.MethodInsnNode;
3737
import org.objectweb.asm.tree.MethodNode;
3838
import org.objectweb.asm.tree.TypeInsnNode;
39-
import org.objectweb.asm.tree.analysis.Analyzer;
40-
import org.objectweb.asm.tree.analysis.AnalyzerException;
41-
import org.objectweb.asm.tree.analysis.BasicInterpreter;
42-
import org.objectweb.asm.tree.analysis.BasicValue;
43-
import org.objectweb.asm.tree.analysis.Frame;
4439
import org.objectweb.asm.util.Textifier;
4540
import org.objectweb.asm.util.TraceMethodVisitor;
4641

@@ -550,91 +545,6 @@ public static ClassNode convertToClassNode(byte[] classBytes) {
550545
return result;
551546
}
552547

553-
//make an analyzer
554-
555-
private static void printMethodAnalysis(String owner, MethodNode method) throws AnalyzerException {
556-
System.out.println("Analyzing method: " + method.name);
557-
BasicInterpreter interpreter = new BasicInterpreter();
558-
Analyzer<BasicValue> a = new Analyzer<>(interpreter);
559-
Frame<BasicValue>[] frames = a.analyze(owner, method);
560-
Map<AbstractInsnNode, Integer> rtStacks = new HashMap<>();
561-
for (int j = 0; j < method.instructions.size(); ++j) {
562-
AbstractInsnNode insn = method.instructions.get(j);
563-
Frame<BasicValue> frame = frames[j];
564-
if (frame != null) {
565-
System.out.println("Locals: " + stringLocals(frame) + " stack: " + stringStack(frame) + " " + stringifyInstruction(insn));
566-
}
567-
}
568-
}
569-
570-
private static String stringLocals(Frame<BasicValue> frame) {
571-
StringBuilder sb = new StringBuilder();
572-
for (int i = 0; i < frame.getLocals(); i++) {
573-
BasicValue value = frame.getLocal(i);
574-
sb.append(value);
575-
sb.append(" . ");
576-
}
577-
return sb.toString();
578-
}
579-
580-
private static String stringStack(Frame<BasicValue> frame) {
581-
StringBuilder sb = new StringBuilder();
582-
for (int i = 0; i < frame.getStackSize(); i++) {
583-
BasicValue value = frame.getStack(i);
584-
sb.append(value);
585-
sb.append(" . ");
586-
}
587-
return sb.toString();
588-
}
589-
590-
//print class node
591-
public static void printClassFrames(byte [] classBytes) {
592-
ClassReader reader = new ClassReader(classBytes);
593-
ClassNode cn = new ClassNode();
594-
reader.accept(cn, 0);
595-
for (MethodNode methodNode : cn.methods) {
596-
try {
597-
printMethodAnalysis(cn.name, methodNode);
598-
} catch (AnalyzerException e) {
599-
e.printStackTrace();
600-
}
601-
}
602-
}
603-
604-
//TEMPORARY
605-
606-
public static void forceVisitationOfClassFile(byte[] classBytes, ClassInformationFinder classInfoFinder) {
607-
ClassReader reader = new ClassReader(classBytes);
608-
ClassWriter cw = new PatchedClassWriter(ClassWriter.COMPUTE_FRAMES, classInfoFinder);
609-
reader.accept(cw, ClassReader.EXPAND_FRAMES);
610-
}
611-
612-
public static void getInstructionAtBCI(int bci, byte [] classBytes) {
613-
int bciMargin = 3;
614-
ClassReader reader = new ClassReader(classBytes);
615-
ClassNode cn = new ClassNode();
616-
reader.accept(cn, 0);
617-
for (MethodNode methodNode : cn.methods) {
618-
int currentBytecodeIndex = 0;
619-
for (AbstractInsnNode instruction : methodNode.instructions) {
620-
if (instruction.getType() != AbstractInsnNode.LABEL &&
621-
instruction.getType() != AbstractInsnNode.LINE &&
622-
instruction.getType() != AbstractInsnNode.FRAME) {
623-
624-
if (currentBytecodeIndex > bci - bciMargin || currentBytecodeIndex < bci + bciMargin) {
625-
if (currentBytecodeIndex == bci) {
626-
System.out.print("Target Instruction >>>>>");
627-
}
628-
System.out.println("bci: " + currentBytecodeIndex + " " + stringifyInstruction(instruction));
629-
}
630-
currentBytecodeIndex++;
631-
}
632-
633-
}
634-
System.out.println("Finished instrumenting method: " + methodNode.name);
635-
}
636-
}
637-
638548
public static void createReadableClassFileFromClassNode(ClassNode cn, boolean isNew, String originalName, String targetName, String destDir) {
639549
if (targetName == null || originalName.contains(targetName)) {
640550
System.out.println("Weaved composite ClassLoader");

0 commit comments

Comments
 (0)