-
Notifications
You must be signed in to change notification settings - Fork 10
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
fix: Fix incorrect Javadoc #24
Conversation
For loading a `Language` cannot use `Arena.ofConfined()` because that will directly unload the library again and then seems to crash the JVM afterwards, at least on Windows. And `SymbolLookup#libraryLookup` does not consider `java.library.path`, see https://bugs.openjdk.org/browse/JDK-8311090.
* language = Language.load(symbols, "tree_sitter_java"); | ||
* } | ||
* String library = System.mapLibraryName("tree-sitter-java"); | ||
* SymbolLookup symbols = SymbolLookup.libraryLookup(library, Arena.ofAuto()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope Arena.ofAuto()
is actually safe here and jtreesitter always holds a strong reference to the Language
. Otherwise this could crash the JVM as well in case the Arena
is not reachable anymore and is garbage collected (?).
Arena.ofAuto()
is currently also used in the TreeSitterJava
binding (here in the tests and in tree-sitter/tree-sitter-java#182; but there at least the TreeSitterJava
class has a strong reference to the Arena
.
The language pointer is copied into the library arena anyway, so the initial arena shouldn't affect it.
But |
The issues should be fixed in v0.23.1. |
Thanks! This only applies to the Java parser bindings though, not to the Library loading for Regarding the Language language;
try (Arena arena = Arena.ofConfined()) {
SymbolLookup symbols = SymbolLookup.libraryLookup(Path.of("libtree-sitter-java.so"), arena);
language = Language.load(symbols, "tree_sitter_java");
}
try (var parser = new Parser(language)) {
try (var tree = parser.parse(source).get()) {
var rootNode = tree.getRootNode();
}
}
Do you mean this code in the java-tree-sitter/src/main/java/io/github/treesitter/jtreesitter/Language.java Lines 42 to 43 in 364154c
The documentation of
So maybe this is not actually performing a copy, and therefore after the library was unloaded still refers to that (now unloaded) memory area? |
Why can't Java ever do anything right… |
Thanks for adjusting the documentation! Are some the Maybe also the If I understand it correctly, the main problem here is that you cannot perform a 'real' copy because the actual size, at least for the But for the other structs I think the actual size is known (through the jextract generated code), so you could implement copying there? (not sure how well this would work for pointers though)
Yes some parts of |
They are needed for the cleanup functions, not for actually copying the data.
The Arena used there will only be closed when the singleton instance gets garbage collected. |
Ah ok, thanks for the explanation. But for So would it make sense to remove the |
For loading a
Language
cannot useArena.ofConfined()
because that will directly unload the library again and then seems to crash the JVM afterwards, at least on Windows.And
SymbolLookup#libraryLookup
does not considerjava.library.path
, see https://bugs.openjdk.org/browse/JDK-8311090 and my comment on tree-sitter/tree-sitter-java#182 (comment).