Skip to content

Return as soon as the instrumentation decision is known - #831

Open
markro49 wants to merge 1 commit into
codespecs:masterfrom
markro49:handleinvoke-early-return
Open

Return as soon as the instrumentation decision is known#831
markro49 wants to merge 1 commit into
codespecs:masterfrom
markro49:handleinvoke-early-return

Conversation

@markro49

Copy link
Copy Markdown
Contributor

Suggested by Michael Ernst in review of PR #685. Independent of #828 and #830.

isTargetInstrumented (BCEL) and its counterpart in DCInstrument24 decide whether an invoke's target is instrumented. Several paths set targetInstrumented = false and broke out of the search only to fall through to the return. They now return directly.

Why the two halves of this change belong together

The early returns are only safe because the INVOKESPECIAL handling moved to the top of the method. That block records that a super(...) or this(...) call has left the receiver initialized:

if (methodName.equals("<init>")
    && (classname.equals(classGen.getSuperclassName())
        || classname.equals(classGen.getClassName()))) {
  this.constructor_is_initialized = true;
}

Left at the end, every new early-return path would silently skip it. That is not hypothetical: the same flag going unset is what produced a comparability regression in Hanoi during the Java 24 port, where a delegating constructor's field write emitted discard_tag instead of the field's set_tag accessor, moving the field out of the parameter's comparability set.

Moving it is safe because nothing between the old and new positions reads the flag. Its only reader is tag_fields_ok, reached from load_store_field -- a different method, applied to field-access instructions later in the walk. So a field read before the super() call still sees the flag unset, and one after still sees it set.

Note on test coverage

The DCInstrument24 half is covered: removing the flag assignment makes delegatingConstructorInitializesReceiver fail.

The DCInstrument half is not. AllTestsSuite contains no DCInstrument tests, so removing the same assignment there leaves the whole suite green. That half rests on compilation and on symmetry with the verified sibling. Flagging it because this change is specifically about preserving a side effect, and because the original Hanoi regression was caught only by the system tests.

Testing

make compile, make JAVA24=1 junit (105 + 13), make check-format, javadoc -Xdoclint:all, and all six typecheck-part1 checkers against the bundled Checker Framework are clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01A1De2wQi77Zz4pnapvnFJz

(Suggested by Michael Ernst in review of PR 685)

Several paths set targetInstrumented to false and broke out of the search
only to reach the return.  They now return directly.

That requires moving the INVOKESPECIAL handling to the top of the method:
it records that a super(...) or this(...) call has left the receiver
initialized, and left at the end it would be skipped by the new early
returns.  Nothing between the two positions reads the flag; its only
reader is tag_fields_ok, reached from load_store_field.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A1De2wQi77Zz4pnapvnFJz
@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 7c607198-831e-4be8-a776-e64efed32b3e

📥 Commits

Reviewing files that changed from the base of the PR and between d8d1f18 and afed5e7.

📒 Files selected for processing (2)
  • java/daikon/dcomp/DCInstrument.java
  • java/daikon/dcomp/DCInstrument24.java

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

isTargetInstrumented in both instrumentation implementations now updates constructor initialization before target classification. The methods return false immediately for invokedynamic, Object methods, unavailable classes or interfaces, and unsuccessful superclass searches. Deferred constructor-state updates and loop-break handling were removed.

Suggested reviewers: mernstdaikon

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: ⚪ Minimal · up to afed5

The instrumentation changes preserve constructor initialization before early exits, with no current merge-blocking risk identified.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant