-
Notifications
You must be signed in to change notification settings - Fork 293
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
Fix var hoisting issue when no previous store #8122
Merged
+33
−14
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import static com.datadog.debugger.instrumentation.ASMHelper.invokeVirtual; | ||
import static com.datadog.debugger.instrumentation.ASMHelper.isFinalField; | ||
import static com.datadog.debugger.instrumentation.ASMHelper.isStaticField; | ||
import static com.datadog.debugger.instrumentation.ASMHelper.isStore; | ||
import static com.datadog.debugger.instrumentation.ASMHelper.ldc; | ||
import static com.datadog.debugger.instrumentation.ASMHelper.newInstance; | ||
import static com.datadog.debugger.instrumentation.Types.CAPTURED_CONTEXT_TYPE; | ||
|
@@ -68,7 +69,7 @@ | |
import org.slf4j.LoggerFactory; | ||
|
||
public class CapturedContextInstrumentor extends Instrumentor { | ||
private static final Logger log = LoggerFactory.getLogger(CapturedContextInstrumentor.class); | ||
private static final Logger LOGGER = LoggerFactory.getLogger(CapturedContextInstrumentor.class); | ||
private final boolean captureSnapshot; | ||
private final Limits limits; | ||
private final LabelNode contextInitLabel = new LabelNode(); | ||
|
@@ -639,8 +640,8 @@ private void rewriteLocalVarInsn(LocalVariableNode localVar, int oldSlot, int ne | |
// 10: astore_1 | ||
// 11: aload_1 | ||
// range for slot 1 starts at 11 | ||
// javac always starts the range right after the init of the local var, so we can just look for | ||
// the previous instruction | ||
// javac often starts the range right after the init of the local var, so we can just look for | ||
// the previous instruction. But not always, and we put an arbitrary limit to 10 instructions | ||
// for kotlinc, many instructions can separate the init and the range start | ||
// ex: | ||
// LocalVariableTable: | ||
|
@@ -656,18 +657,26 @@ private void rewriteLocalVarInsn(LocalVariableNode localVar, int oldSlot, int ne | |
private static void rewritePreviousStoreInsn( | ||
LocalVariableNode localVar, int oldSlot, int newSlot) { | ||
AbstractInsnNode previous = localVar.start.getPrevious(); | ||
while (previous != null | ||
&& (!(previous instanceof VarInsnNode) || ((VarInsnNode) previous).var != oldSlot)) { | ||
int processed = 0; | ||
// arbitrary fixing limit to 10 previous instructions to look at | ||
while (previous != null && !isVarStoreForSlot(previous, oldSlot) && processed < 10) { | ||
previous = previous.getPrevious(); | ||
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. what happen if getPrevious return null? 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. ah right I missed one test in the while. it's working for isVarStoreForLost method |
||
processed++; | ||
} | ||
if (previous != null) { | ||
if (isVarStoreForSlot(previous, oldSlot)) { | ||
VarInsnNode varInsnNode = (VarInsnNode) previous; | ||
if (varInsnNode.var == oldSlot) { | ||
varInsnNode.var = newSlot; | ||
} | ||
} | ||
} | ||
|
||
private static boolean isVarStoreForSlot(AbstractInsnNode node, int slotIdx) { | ||
return node instanceof VarInsnNode | ||
&& isStore(node.getOpcode()) | ||
&& ((VarInsnNode) node).var == slotIdx; | ||
} | ||
|
||
private void createInProbeFinallyHandler(LabelNode inProbeStartLabel, LabelNode inProbeEndLabel) { | ||
LabelNode handlerLabel = new LabelNode(); | ||
InsnList handler = new InsnList(); | ||
|
@@ -1234,7 +1243,7 @@ private static void addInheritedStaticFields( | |
FieldNode fieldNode = | ||
new FieldNode(field.getModifiers(), field.getName(), desc, null, field); | ||
results.add(fieldNode); | ||
log.debug("Adding static inherited field {}", fieldNode.name); | ||
LOGGER.debug("Adding static inherited field {}", fieldNode.name); | ||
fieldCount++; | ||
if (fieldCount > limits.maxFieldCount) { | ||
return; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+10.5 KB
...a-agent/agent-debugger/src/test/resources/classfiles/ByteSourceJsonBootstrapper.classfile
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
might need to update the comment above
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.
done