Skip to content

Commit 58cfafa

Browse files
committed
DX-88565 Fixed gandiva native library loading option to be global
Added jna library which allows more control over native code loading
1 parent 21c87a3 commit 58cfafa

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

java/gandiva/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<maven.compiler.source>1.8</maven.compiler.source>
2727
<maven.compiler.target>1.8</maven.compiler.target>
2828
<protobuf.version>3.25.1</protobuf.version>
29+
<jna.version>5.14.0</jna.version>
2930
<checkstyle.failOnViolation>true</checkstyle.failOnViolation>
3031
<arrow.cpp.build.dir>../../../cpp/release-build</arrow.cpp.build.dir>
3132
</properties>
@@ -62,6 +63,11 @@
6263
<groupId>org.slf4j</groupId>
6364
<artifactId>slf4j-api</artifactId>
6465
</dependency>
66+
<dependency>
67+
<groupId>net.java.dev.jna</groupId>
68+
<artifactId>jna</artifactId>
69+
<version>${jna.version}</version>
70+
</dependency>
6571
</dependencies>
6672
<profiles>
6773
<profile>

java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/JniLoader.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,24 @@
2424
import java.io.InputStream;
2525
import java.nio.file.Files;
2626
import java.nio.file.StandardCopyOption;
27+
import java.util.Collections;
2728
import java.util.Locale;
2829
import java.util.concurrent.ConcurrentHashMap;
2930
import java.util.concurrent.ConcurrentMap;
3031

3132
import org.apache.arrow.gandiva.exceptions.GandivaException;
3233

34+
import com.sun.jna.Library;
35+
import com.sun.jna.NativeLibrary;
36+
3337
/**
3438
* This class handles loading of the jni library, and acts as a bridge for the native functions.
3539
*/
3640
class JniLoader {
3741
private static final String LIBRARY_NAME = "gandiva_jni";
42+
43+
private static final int RTLD_GLOBAL = 0x00100;
44+
private static final int RTLD_LAZY = 0x00001;
3845

3946
private static volatile JniLoader INSTANCE;
4047
private static volatile long defaultConfiguration = 0L;
@@ -73,6 +80,10 @@ private static void loadGandivaLibraryFromJar(final String tmpDir)
7380
final String libraryToLoad =
7481
getNormalizedArch() + "/" + System.mapLibraryName(LIBRARY_NAME);
7582
final File libraryFile = moveFileFromJarToTemp(tmpDir, libraryToLoad, LIBRARY_NAME);
83+
NativeLibrary.getInstance(
84+
libraryFile.getAbsolutePath(),
85+
Collections.singletonMap(Library.OPTION_OPEN_FLAGS, new Integer(RTLD_LAZY | RTLD_GLOBAL))
86+
);
7687
System.load(libraryFile.getAbsolutePath());
7788
}
7889

0 commit comments

Comments
 (0)