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

Static memory snapshot: add support for Unsafe, VarHandle, AFU, kotlinx.atomicfu #429

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from

Conversation

dmitrii-artuhov
Copy link
Collaborator

@dmitrii-artuhov dmitrii-artuhov commented Nov 29, 2024

Partly resolves issue #389.

This PR is aimed to add support for lazy tracking fields, that are accessed via:

  • System.arraycopy - right now some tests fail for this functionality. I have an assumption that this could be caused by jit compilation, when the same test (same scenario basically) succeeds for N iterations and fails on N+1th. I am investigating into that. Support for this call will be done via separate PR.
  • Unsafe API
  • VarHandle API
  • java atomic field updaters
  • kotlinx.atomicfu

@dmitrii-artuhov dmitrii-artuhov changed the base branch from develop to trace-debugger-static-memory November 29, 2024 16:28
@dmitrii-artuhov dmitrii-artuhov force-pushed the trace-debugger-system-calls branch from 881a74a to fb813ab Compare December 2, 2024 21:10
@dmitrii-artuhov dmitrii-artuhov changed the title Static memory snapshot: add support for System.arraycopy, Unsafe, VarHandle, AFU, kotlinx.atomicfu, and reflexivity Static memory snapshot: add support for System.arraycopy, Unsafe, VarHandle, AFU, kotlinx.atomicfu Dec 2, 2024
@dmitrii-artuhov dmitrii-artuhov changed the title Static memory snapshot: add support for System.arraycopy, Unsafe, VarHandle, AFU, kotlinx.atomicfu Static memory snapshot: add support for Unsafe, VarHandle, AFU, kotlinx.atomicfu Dec 9, 2024
@dmitrii-artuhov dmitrii-artuhov marked this pull request as ready for review December 12, 2024 11:13
@dmitrii-artuhov dmitrii-artuhov requested a review from eupp December 12, 2024 11:13
Base automatically changed from trace-debugger-static-memory to develop December 12, 2024 11:17
@ndkoval
Copy link
Collaborator

ndkoval commented Dec 12, 2024

Please note that you don't need to have special support for atomicfu -- it compiles to either AFU or VarHandle

@dmitrii-artuhov dmitrii-artuhov force-pushed the trace-debugger-system-calls branch from d95fd4d to 2fd1a05 Compare December 12, 2024 13:32
@@ -25,6 +25,57 @@ import java.util.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*

fun shouldTransformClass(className: String): Boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems the code was moved from somewhere, but I do not see it removed in the original location.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, I would suggest keeping the transformation-related logic in the corresponding package.

@@ -37,11 +37,22 @@ internal object AtomicFieldUpdaterNames {
val offsetField = updater.javaClass.getDeclaredField("offset")
val offset = UNSAFE.getLong(updater, UNSAFE.objectFieldOffset(offsetField))

return findFieldNameByOffsetViaUnsafe(targetType, offset)
return findFieldNameByOffsetViaUnsafe(targetType, offset).let { fieldName ->
if (fieldName != null) AtomicFieldUpdaterDescriptor(targetType, fieldName)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please always add { .. } when the else branch is present.


runInIgnoredSection {
// process method effect on the static memory snapshot
processMethodEffectOnStaticSnapshot(owner, params)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this mean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You mean the name of the method or what it does?
This method checks what kind of function was called (Unsafe API, VarHandle API, Java AFU) and updates static snapshot accordingly

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