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

CannotAccessFieldException reading hidden class #64

Open
MikaelSmith opened this issue Sep 25, 2023 · 6 comments
Open

CannotAccessFieldException reading hidden class #64

MikaelSmith opened this issue Sep 25, 2023 · 6 comments

Comments

@MikaelSmith
Copy link

Using jamm 0.4.0, Apache Impala is running into

java.util.regex.Pattern$CharPredicate$$Lambda$23/0x80000002d cannot be retrieved
	at org.github.jamm.accessors.JpmsAccessor.getFieldValue(JpmsAccessor.java:54)
	at org.github.jamm.MemoryMeter.getFieldValue(MemoryMeter.java:568)
	at org.github.jamm.MemoryMeter.addField(MemoryMeter.java:550)
	at org.github.jamm.MemoryMeter.addDeclaredFields(MemoryMeter.java:537)
	at org.github.jamm.MemoryMeter.addFields(MemoryMeter.java:529)
	at org.github.jamm.MemoryMeter.measureDeep(MemoryMeter.java:507)
	at org.github.jamm.MemoryMeter.measureDeep(MemoryMeter.java:441)
	at org.apache.impala.catalog.local.CatalogdMetaProvider$SizeOfWeigher.weigh(CatalogdMetaProvider.java:2056)
	at com.google.common.cache.LocalCache$Segment.setValue(LocalCache.java:2014)
	at com.google.common.cache.LocalCache$Segment.storeLoadedValue(LocalCache.java:3162)
	at com.google.common.cache.LocalCache$Segment.getAndRecordStats(LocalCache.java:2322)
	at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2283)
	at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2159)
	at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2049)
	at com.google.common.cache.LocalCache.get(LocalCache.java:3966)
	at com.google.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4863)
	at org.apache.impala.catalog.local.CatalogdMetaProvider.loadWithCaching(CatalogdMetaProvider.java:534)
	at org.apache.impala.catalog.local.CatalogdMetaProvider.loadTableList(CatalogdMetaProvider.java:683)
	at org.apache.impala.catalog.local.LocalDb.loadTableNames(LocalDb.java:173)
	at org.apache.impala.catalog.local.LocalDb.getAllTableNames(LocalDb.java:158)
	at org.apache.impala.service.Frontend.getCatalogMetrics(Frontend.java:1058)
	at org.apache.impala.service.JniFrontend.getCatalogMetrics(JniFrontend.java:244)
Caused by: java.lang.UnsupportedOperationException: can't get field offset on a hidden class: private final java.util.regex.Pattern$CharPredicate java.util.regex.Pattern$CharPredicate$$Lambda$23/0x80000002d.arg$1
	at jdk.unsupported/sun.misc.Unsafe.objectFieldOffset(Unsafe.java:645)
	at org.github.jamm.accessors.JpmsAccessor.getFieldValue(JpmsAccessor.java:46)
	... 21 more

That's not the outcome I expected from reading https://github.com/jbellis/jamm#unsafe. I thought it would try to guess the object's size.

@blerer
Copy link
Collaborator

blerer commented Sep 25, 2023

It is because the problem is not with the Unsafe strategy but with the crawling. Jamm is using reflection to visit the object tree but if some objects are not accessible due to the module system it will try to use Unsafe to by pass the module system. Unfortunately, if the class is a hidden one it will not be able to access the field.
There is a way to do it but it is quite hacky so we avoided it until now.
One option is to add an add-open for java.util.regex. I do not know if it is an option for you.

@MikaelSmith
Copy link
Author

MikaelSmith commented Sep 25, 2023

That option works for me. It wasn't immediately clear to me that was how to fix it. Thanks!

@blerer
Copy link
Collaborator

blerer commented Sep 26, 2023

Cool. Can I close this ticket?

@MikaelSmith
Copy link
Author

It still seems a little odd that it doesn't attempt to estimate, similar to how the README describes it. There's no other real option except to add-open for various any class that keeps a reference to a lambda. But I've accepted that workaround for now.

@blerer
Copy link
Collaborator

blerer commented Sep 27, 2023

I can let it open for now and see if I can find a solution.

@ekaterinadimitrova2
Copy link
Collaborator

I can let it open for now and see if I can find a solution.
Until then, I agree we can add a note in the README to prevent further confusion and let people know about the workaround with add-opens, as explained in this thread. I can add the update next week.

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

No branches or pull requests

3 participants