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

Add a Java agent for Trace Debugger #464

Merged
merged 13 commits into from
Feb 4, 2025
Merged

Add a Java agent for Trace Debugger #464

merged 13 commits into from
Feb 4, 2025

Conversation

dmitrii-artuhov
Copy link
Collaborator

@dmitrii-artuhov dmitrii-artuhov commented Jan 31, 2025

This PR adds a static agent for trace debugger plugin (though, lincheck's agent is left dynamic, yet). The pair-PR for the plugin could be found here.

This PR is based on #460

@dmitrii-artuhov dmitrii-artuhov changed the base branch from trace-debugger-flag-1 to develop January 31, 2025 19:06
@dmitrii-artuhov dmitrii-artuhov changed the base branch from develop to trace-debugger-flag-1 January 31, 2025 21:37
@zhelenskiy zhelenskiy force-pushed the trace-debugger-flag-1 branch 2 times, most recently from 3d1f0b1 to 6ba67b5 Compare February 1, 2025 02:28
Base automatically changed from trace-debugger-flag-1 to develop February 2, 2025 20:55
@ndkoval
Copy link
Collaborator

ndkoval commented Feb 2, 2025

@dmitrii-artuhov please rebase the PR onto develop

@ndkoval
Copy link
Collaborator

ndkoval commented Feb 2, 2025

@dmitrii-artuhov, please also add a test to check that the agent works as expected.

I suggest adding an additional system property to run the agent without the plugin but printing the execution trace to a specified file, thus providing a testing framework similar to representation tests in Lincheck. Then, you can create a simple project and check that running Java's main, Kotlin's main, and a Junit test works as expected. Please do not try to check complex programs here; we just need to check that the agent generally works.
UPD: will address this in a separate PR

@ndkoval ndkoval changed the title Add trace debugger agent Add a Java agen for Trace Debugger Feb 3, 2025
@dmitrii-artuhov dmitrii-artuhov changed the title Add a Java agen for Trace Debugger Add a Java agent for Trace Debugger Feb 3, 2025
/**
* This method is called from the trace-debugger evaluation.
*/
private fun visualizeTrace(): Array<Any>? = runCatching {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@eupp should we have a similar fix for the general-purpose model checker? What is the current status of its integration with the plugin?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, we would need a similar fix.
Let's maybe keep visualizeTrace name for a while, because I guess it is also used on the trace-debugger plugin side.

Then once we refactor visualize for general-purpose mc, we would be able to re-use it here:

private fun visualizeTrace(): Array<Any>? = visualize()

or remove it completely.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we provide thread names through visualizeTrace?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also tagging @avpotapov00


internal class TraceDebuggerStaticMethodWrapper {
fun callStaticMethod(clazz: Class<*>, method: Method) {
ensureClassHierarchyIsTransformed(clazz.name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the trace debugger mode, let's transform ALL classes, never calling ensureClassHierarchyIsTransformed(..) and the reflection calls that preceed it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Too much classes are transformed I guess. I wasn't able to wait until the trace would be collected and shown by the plugin, it was endlessly spinning with IDEA background task "Collecting trace..."

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, wow. OK, let's postpone this change then.

@@ -139,6 +139,19 @@ private fun visualize(strategyObject: Any) = runCatching {
visualizeInstance(testObject, objectToNumberMap, continuationToLincheckThreadIdMap, threadToLincheckThreadIdMap)
}

/**
* This method is called from the trace-debugger evaluation.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please indicate when the plugin calls this method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have no idea when it happens)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please investigate and leave a comment

@@ -229,30 +229,30 @@ internal class ModelCheckingStrategy(
}

if (representation.isNotEmpty()) {
representations.add("$type;${node.iThread};${node.callDepth};${node.shouldBeExpanded(false)};${eventId};${representation}")
representations.add("$type;${node.iThread};${node.callDepth};${node.shouldBeExpanded(false)};${eventId};${representation};null")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you need this null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is a stack trace element according to plugin, I don't know if it is used aywhere

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm afraid, this change might break the Lincheck plugin and is unnecessary for the Trace Debugger one.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@avpotapov00 do you know how this argument is used in the trace debugger plugin?

Copy link
Collaborator

@ndkoval ndkoval left a comment

Choose a reason for hiding this comment

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

I've left minor comments, please address them, and the PR is ready to go 🚀

@ndkoval
Copy link
Collaborator

ndkoval commented Feb 3, 2025

@dmitrii-artuhov Please also check that the Lincheck plugin works with this change.

@ndkoval ndkoval merged commit cf59a47 into develop Feb 4, 2025
20 checks passed
@ndkoval ndkoval deleted the trace-debugger-agent branch February 4, 2025 17:08
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.

4 participants