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

WeakHashMap enhancement and expand #2632

Merged
merged 4 commits into from Mar 26, 2024

Conversation

EpicDima
Copy link
Contributor

@EpicDima EpicDima commented Feb 11, 2024

#2463 solution

I updated the PR, but the CI check has failed, it works locally, even with JDK 17 Zulu, which is used on CI. Maybe it's the wrong implementation again, if so, then it's probably possible to close the PR, since now I don't have the competence to make the right solution.

@CLAassistant
Copy link

CLAassistant commented Feb 11, 2024

CLA assistant check
All committers have signed the CLA.

import shark.LeakTraceObject.ObjectType.INSTANCE

class AndroidObjectInspectorsTest {

// TODO: There is another trace with the extended WeakHashMap.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trace before image
Trace after image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

This is happening because this change changed the expected behavior for weak keys, making them look like strong keys. That won't work.

}
assertThat(recomposerNode.originObject.leakingStatus == NOT_LEAKING)
assertThat(recomposerNode.originObject.leakingStatusReason == "Recomposer is in state PendingWork")
assertThat(recomposerNode.originObject.leakingStatus).isEqualTo(UNKNOWN)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was not executed, I also fixed it


val hashMapClassId = weakHashMapClass.objectId

return InternalSharedHashMapReferenceReader(
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately, we need more tweaking than this. WeakHashMap has weak keys. We need to reconnect this with how we define which references to follow or not.

@EpicDima EpicDima force-pushed the epicdima/WeakHashMap_enhancement branch from 7370563 to f9be8b9 Compare February 18, 2024 21:07
@EpicDima EpicDima force-pushed the epicdima/WeakHashMap_enhancement branch from f9be8b9 to 963d25a Compare February 18, 2024 21:14
assertThat(refPath).hasSize(3)

with(refPath[0]) {
assertThat(owningClassName).isEqualTo(WeakHashMap::class.qualifiedName)
Copy link
Member

@pyricau pyricau Mar 26, 2024

Choose a reason for hiding this comment

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

This is failing in CI

shark.OpenJdkInstanceRefReadersTest > WeakHashMap expanded FAILED
    org.junit.ComparisonFailure: expected:<"java.[util.WeakHashMap]"> but was:<"java.[lang.ref.Reference]">
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
        at shark.OpenJdkInstanceRefReadersTest.WeakHashMap expanded(OpenJdkInstanceRefReadersTest.kt:432)

@pyricau
Copy link
Member

pyricau commented Mar 26, 2024

Thanks, I do want to take a closer look, check out the branch locally, figure out why it's failing etc.

@pyricau
Copy link
Member

pyricau commented Mar 26, 2024

The failure has to do with the dynamic nature of WeakHashMap: the tests are adding a non retained key the map, so depending on how much work the GC is doing, sometimes the entry will still be in the map and sometimes not.

- Change tests to leverage a retained key rather than a weakly reachable one, which created flakiness and wasn't testing the intended behavior (a cleared weak key sees the entry added to the reference queue but we don't want to find objects there anyway)
- Removed tests that didn't seem ended (we're mostly interested in the expander case, and I didn't get what the singleton case is supposed to be about)
@pyricau
Copy link
Member

pyricau commented Mar 26, 2024

Updated the branch with cleanups and fixes.

@pyricau pyricau merged commit f54c5a4 into square:main Mar 26, 2024
9 checks passed
@EpicDima EpicDima deleted the epicdima/WeakHashMap_enhancement branch March 31, 2024 16:10
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.

None yet

3 participants