-
Notifications
You must be signed in to change notification settings - Fork 184
[Review][Java] Add detailed error message for libcuvs load failure to UnsupportedProvider/UnsupportedOperationExceptions
#1316
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
Merged
rapids-bot
merged 7 commits into
rapidsai:branch-25.10
from
ldematte:java/improve-error-messages-3
Sep 15, 2025
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
09c5ee4
Add reason to UnsupportedProvider/UnsupportedOperationExceptions
ldematte b6810e3
Add cuvs version check to JDKProvider
ldematte 5656107
Add cuvs library load check to JDKProvider
ldematte 4ebb1f2
Merge remote-tracking branch 'upstream/branch-25.10' into java/improv…
ldematte fc84042
Extend NativeDependencyLoader to use different strategies for fat-jar…
ldematte b8157a7
Merge remote-tracking branch 'upstream/branch-25.10' into java/improv…
ldematte 9efc1ea
Use ProviderInitializationException for loadLibrary failures
ldematte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
java/cuvs-java/src/main/java/com/nvidia/cuvs/spi/ProviderInitializationException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Copyright (c) 2025, NVIDIA CORPORATION. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.nvidia.cuvs.spi; | ||
|
|
||
| class ProviderInitializationException extends Exception { | ||
| ProviderInitializationException(String message, Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
|
|
||
| public ProviderInitializationException(String message) { | ||
| super(message); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
java/cuvs-java/src/main/java22/com/nvidia/cuvs/internal/common/NativeLibraryUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright (c) 2025, NVIDIA CORPORATION. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.nvidia.cuvs.internal.common; | ||
|
|
||
| import java.lang.foreign.*; | ||
| import java.lang.invoke.MethodHandle; | ||
|
|
||
| public class NativeLibraryUtils { | ||
|
|
||
| private NativeLibraryUtils() {} | ||
|
|
||
| private static final SymbolLookup LOOKUP = | ||
| SymbolLookup.libraryLookup(System.mapLibraryName("jvm"), Arena.ofAuto()) | ||
| .or(SymbolLookup.loaderLookup()) | ||
| .or(Linker.nativeLinker().defaultLookup()); | ||
|
|
||
| // void * JVM_LoadLibrary(const char *name, jboolean throwException); | ||
| public static MethodHandle JVM_LoadLibrary$mh = | ||
| Linker.nativeLinker() | ||
| .downcallHandle( | ||
| LOOKUP.find("JVM_LoadLibrary").orElseThrow(), | ||
| FunctionDescriptor.of( | ||
| ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_BOOLEAN)); | ||
| // void JVM_UnloadLibrary(void * handle); | ||
| public static MethodHandle JVM_UnloadLibrary$mh = | ||
| Linker.nativeLinker() | ||
| .downcallHandle( | ||
| LOOKUP.find("JVM_UnloadLibrary").orElseThrow(), | ||
| FunctionDescriptor.ofVoid(ValueLayout.ADDRESS)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@ldematte nice sleuthing. Let's try to use System.localLibrary earlier so that we can get similar improved error messages.
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 like the idea! Less reflection :)
A first test seems to indicate that
System.loadLibrarygives a different and less precise message. I'll dig into that.In any case, trying to load the library before seems best.