-
Notifications
You must be signed in to change notification settings - Fork 344
Fix instrumenting metric probes for Kotlin #11890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,7 @@ | |
| import java.lang.reflect.Field; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
| import org.objectweb.asm.Opcodes; | ||
| import org.objectweb.asm.Type; | ||
|
|
@@ -71,6 +72,8 @@ | |
| import org.objectweb.asm.tree.TryCatchBlockNode; | ||
| import org.objectweb.asm.tree.TypeInsnNode; | ||
| import org.objectweb.asm.tree.VarInsnNode; | ||
| import org.objectweb.asm.tree.analysis.BasicValue; | ||
| import org.objectweb.asm.tree.analysis.Frame; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
|
|
@@ -158,15 +161,18 @@ private InsnList wrapTryCatch(InsnList insnList) { | |
| } | ||
|
|
||
| @Override | ||
| protected InsnList getBeforeReturnInsnList(AbstractInsnNode node) { | ||
| protected InsnList getBeforeReturnInsnList( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure this is limited to metric probes?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Until contrary proven, yes because this is specific to the code inserted for metric probe instrumentation. |
||
| AbstractInsnNode node, Map<AbstractInsnNode, Frame<BasicValue>> frames) { | ||
| int size = 1; | ||
| int storeOpCode = 0; | ||
| int loadOpCode = 0; | ||
| Type returnType = null; | ||
| switch (node.getOpcode()) { | ||
| case Opcodes.RET: | ||
| case Opcodes.RETURN: | ||
| return wrapTryCatch(callMetric(metricProbe, node)); | ||
| InsnList insnList = wrapTryCatch(callMetric(metricProbe, node)); | ||
| insnList.insert(stackCleanupInsnList(node, 0, frames)); // void return: nothing to keep | ||
| return insnList; | ||
| case Opcodes.LRETURN: | ||
| storeOpCode = Opcodes.LSTORE; | ||
| loadOpCode = Opcodes.LLOAD; | ||
|
|
@@ -202,7 +208,10 @@ protected InsnList getBeforeReturnInsnList(AbstractInsnNode node) { | |
| wrapTryCatch( | ||
| callMetric(metricProbe, node, new ReturnContext(tmpIdx, loadOpCode, returnType))); | ||
| // store return value from the stack to local before wrapped call | ||
| insnList.insert(new VarInsnNode(storeOpCode, tmpIdx)); | ||
| InsnList prefixInsns = new InsnList(); | ||
| prefixInsns.add(new VarInsnNode(storeOpCode, tmpIdx)); | ||
| prefixInsns.add(stackCleanupInsnList(node, 1, frames)); // keep 1 value (the one we just stored) | ||
| insnList.insert(prefixInsns); | ||
| // restore return value to the stack after wrapped call | ||
| insnList.add(new VarInsnNode(loadOpCode, tmpIdx)); | ||
| return insnList; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this produce a half-finished map? Would that be an issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No because the specific exception is thrown only by ASM's
Analyzer.analyzemethod so when the exception is thrown, the map is untouchly empty