Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ public InstrumentationResult.Status instrument() {
installFinallyBlocks();
return InstrumentationResult.Status.INSTALLED;
}
Map<AbstractInsnNode, Frame<BasicValue>> frames = computeFrames(classNode.name, methodNode);
instrumentMethodEnter();
instrumentTryCatchHandlers();
processInstructions();
processInstructions(frames);
addFinallyHandler(contextInitLabel, returnHandlerLabel);
installFinallyBlocks();
return InstrumentationResult.Status.INSTALLED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public ExceptionInstrumenter(

@Override
public InstrumentationResult.Status instrument() {
processInstructions(); // fill returnHandlerLabel
Map<AbstractInsnNode, Frame<BasicValue>> frames = computeFrames(classNode.name, methodNode);
processInstructions(frames); // fill returnHandlerLabel
addFinallyHandler(methodEnterLabel, returnHandlerLabel);
installFinallyBlocks();
return InstrumentationResult.Status.INSTALLED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ private AbstractInsnNode findFirstInsnForConstructor(AbstractInsnNode first) {
return lastInvokeSpecial;
}

protected void processInstructions() {
Map<AbstractInsnNode, Frame<BasicValue>> frames = new IdentityHashMap<>();
computeFrames(classNode.name, methodNode, frames);
protected void processInstructions(Map<AbstractInsnNode, Frame<BasicValue>> frames) {
AbstractInsnNode node = methodNode.instructions.getFirst();
LabelNode sentinelNode = new LabelNode();
methodNode.instructions.add(sentinelNode);
Expand Down Expand Up @@ -195,8 +193,9 @@ protected InsnList stackCleanupInsnList(
return result;
}

private static void computeFrames(
String owner, MethodNode methodNode, Map<AbstractInsnNode, Frame<BasicValue>> frames) {
protected static Map<AbstractInsnNode, Frame<BasicValue>> computeFrames(
String owner, MethodNode methodNode) {
Comment on lines +196 to +197

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a problem.

Map<AbstractInsnNode, Frame<BasicValue>> frames = new IdentityHashMap<>();
try {
Frame<BasicValue>[] frameArray =
new Analyzer<>(new BasicInterpreter()).analyze(owner, methodNode);
Expand All @@ -207,8 +206,14 @@ private static void computeFrames(
current = current.getNext();
}
} catch (AnalyzerException ex) {
LOGGER.debug("Failed to analyze method[{}::{}] instructions", owner, methodNode.name, ex);
LOGGER.debug(
"Failed to analyze method[{}::{}{}] instructions",
owner,
methodNode.name,
methodNode.desc,
ex);
}
return frames;
}

protected AbstractInsnNode processInstruction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ public InstrumentationResult.Status instrument() {
}
case EXIT:
{
processInstructions();
Map<AbstractInsnNode, Frame<BasicValue>> frames =
computeFrames(classNode.name, methodNode);
processInstructions(frames);
addFinallyHandler(returnHandlerLabel);
installFinallyBlocks();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
import com.datadog.debugger.probe.Where;
import com.datadog.debugger.util.ClassFileLines;
import java.util.List;
import java.util.Map;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.TryCatchBlockNode;
import org.objectweb.asm.tree.VarInsnNode;
import org.objectweb.asm.tree.analysis.BasicValue;
import org.objectweb.asm.tree.analysis.Frame;

public class SpanInstrumenter extends Instrumenter {
private int spanVar;
Expand All @@ -38,7 +42,8 @@ public InstrumentationResult.Status instrument() {
return addRangeSpan(classFileLines);
}
spanVar = newVar(DEBUGGER_SPAN_TYPE);
processInstructions();
Map<AbstractInsnNode, Frame<BasicValue>> frames = computeFrames(classNode.name, methodNode);
processInstructions(frames);
LabelNode initSpanLabel = new LabelNode();
InsnList insnList = createSpan(initSpanLabel);
LabelNode endLabel = new LabelNode();
Expand Down
Loading