Skip to content
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

[Java21] Fix failing debugger for java 21 #43448

Open
wants to merge 10 commits into
base: java21
Choose a base branch
from

Conversation

HindujaB
Copy link
Contributor

@HindujaB HindujaB commented Oct 4, 2024

Purpose

$subject
Fixes #43430

Approach

Describe how you are implementing the solutions along with the design details.

Samples

Provide high-level details about the samples related to this feature.

Remarks

List any other known issues, related PRs, TODO items, or any other notes related to the PR.

Check List

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • Added necessary tests
    • Unit Tests
    • Spec Conformance Tests
    • Integration Tests
    • Ballerina By Example Tests
  • Increased Test Coverage
  • Added necessary documentation
    • API documentation
    • Module documentation in Module.md files
    • Ballerina By Examples


// variables outside worker should not be visible
Assert.assertFalse(localVariables.containsKey("a"));
if (debugHitInfo.getKey().getLine() == 23) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fix is added because with new virtual thread implementation, the order of execution for workers is not consistent. Therefore, we can't rely on the debug point hitting order. I modified the assertions depending on which debug point hits first.
@warunalakshitha Is this expected?

@@ -83,7 +83,7 @@ public void stackFrameDebugTest() throws BallerinaTestException {
// Stack frame representation test for strand creation with 'start' keyword.
// Results of the strand is not assigned to any variable. In this case frame name is assigned to 'anonymous'.
debugTestRunner.assertCallStack(frames[0], "sayHello", 45, "main.bal");
debugTestRunner.assertCallStack(frames[1], "start:anonymous", 10, "main.bal");
debugTestRunner.assertCallStack(frames[1], "start:anon", 10, "main.bal");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here, the default strand name is changed to anon if the future value name is not provided.

Comment on lines 1110 to 1111
ClassPrepareRequest classPrepareRequest = erm.createClassPrepareRequest();
classPrepareRequest.enable();
Copy link
Contributor

@NipunaRanasinghe NipunaRanasinghe Oct 4, 2024

Choose a reason for hiding this comment

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

Just to make it consistent with L1112 and L1113

Suggested change
ClassPrepareRequest classPrepareRequest = erm.createClassPrepareRequest();
classPrepareRequest.enable();
ClassPrepareRequest classPrepareRequest = erm.createClassPrepareRequest().enable();

Comment on lines 62 to +63
private static final Logger LOGGER = LoggerFactory.getLogger(JDIEventProcessor.class);
private static final List<ThreadReference> virtualThreads = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private static final Logger LOGGER = LoggerFactory.getLogger(JDIEventProcessor.class);
private static final List<ThreadReference> virtualThreads = new ArrayList<>();
private static final Logger LOGGER = LoggerFactory.getLogger(JDIEventProcessor.class);
private static final List<ThreadReference> virtualThreads = new ArrayList<>();
Suggested change
private static final Logger LOGGER = LoggerFactory.getLogger(JDIEventProcessor.class);
private static final List<ThreadReference> virtualThreads = new ArrayList<>();
private static final List<ThreadReference> virtualThreads = new ArrayList<>();
private static final Logger LOGGER = LoggerFactory.getLogger(JDIEventProcessor.class);

Comment on lines +132 to +145
} else if (event instanceof ThreadStartEvent threadStartEvent) {
ThreadReference thread = threadStartEvent.thread();
if (thread.isVirtual()) {
synchronized (virtualThreads) {
virtualThreads.add(thread);
}
}
eventSet.resume();
} else if (event instanceof ThreadDeathEvent threadDeathEvent) {
ThreadReference thread = threadDeathEvent.thread();
synchronized (virtualThreads) {
virtualThreads.remove(thread);
}
eventSet.resume();
Copy link
Contributor

Choose a reason for hiding this comment

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

For the virtualThreads variable, using a ConcurrentLinkedQueue or CopyOnWriteArrayList (concurrent data structures) is generally better than using an ArrayList with explicit synchronization blocks.

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.

2 participants