Skip to content

Switch to static MethodHandle - #2893

Closed
otbutz wants to merge 3 commits into
graphhopper:masterfrom
otbutz:method_handle
Closed

otbutz wants to merge 3 commits into
graphhopper:masterfrom
otbutz:method_handle

Conversation

@otbutz

@otbutz otbutz commented Oct 19, 2023

Copy link
Copy Markdown
Contributor

Avoids the reflection overhead on each call.

# Conflicts:
#	core/src/main/java/com/graphhopper/storage/MMapDataAccess.java
@karussell

Copy link
Copy Markdown
Member

The cleaner method is rarely called. Can you ensure that if it is called that it works as expected?

@otbutz

otbutz commented Nov 16, 2023

Copy link
Copy Markdown
Contributor Author

I can throw in a dedicated unit test if you prefer.

@otbutz

otbutz commented Nov 20, 2023

Copy link
Copy Markdown
Contributor Author

@karussell done 😉

@karussell

Copy link
Copy Markdown
Member

I meant the cleanMappedByteBuffer. Is it still doing the work it was previously doing?

@otbutz

otbutz commented Dec 1, 2023

Copy link
Copy Markdown
Contributor Author

The only purpose of cleanMappedByteBuffer is to invoke Unsafe.invokeCleaner(ByteBuffer) for the given ByteBuffer. And that's what the unittest checks by triggering the IllegalArgumentException:

https://github.com/openjdk/jdk/blob/dfacda488bfbe2e11e8d607a6d08527710286982/src/jdk.unsupported/share/classes/sun/misc/Unsafe.java#L1256-L1261

@otbutz

otbutz commented Jan 12, 2024

Copy link
Copy Markdown
Contributor Author

This may also benefit GraalVM compilation. Static method handles are supported.

@karussell

karussell commented Feb 2, 2024 •

Copy link
Copy Markdown
Member

As the cleaner is only called when closing a GraphHopper instance there is no real measurable overhead in production. And in general we should get rid of the Unsafe usage as it is marked for removal. So I will close here.

I have a branch that uses foreign memory API (java.lang.foreign.MemorySegment instead of MappedByteBuffer) and then one can just call java.lang.foreign.Arena::close() in close and no Unsafe is required. Of course many other things (incl. performance) are unclear and need to be tested.

@karussell karussell closed this Feb 2, 2024
@karussell

karussell commented Feb 2, 2024 •

Copy link
Copy Markdown
Member

This may also benefit GraalVM compilation. Static method handles are supported.

I doubt this will easily work with the dynamic nature of our custom models (janino). I.e. to support AOT compilation a few manual tweaks would be still required (like initially creating the Java classes from the custom models).

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