Skip to content

Commit

Permalink
DX-88565 Fixed gandiva native library loading option to be global
Browse files Browse the repository at this point in the history
Added jna library which allows more control over native code loading
  • Loading branch information
DenisTarasyuk authored and lriggs committed Apr 25, 2024
1 parent 6dd8729 commit 3199745
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions java/gandiva/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<protobuf.version>3.25.1</protobuf.version>
<jna.version>5.14.0</jna.version>
<checkstyle.failOnViolation>true</checkstyle.failOnViolation>
<arrow.cpp.build.dir>../../../cpp/release-build</arrow.cpp.build.dir>
</properties>
Expand Down Expand Up @@ -66,6 +67,11 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>${jna.version}</version>
</dependency>
</dependencies>
<profiles>
<profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,24 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Collections;
import java.util.Locale;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

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

import com.sun.jna.Library;
import com.sun.jna.NativeLibrary;

/**
* This class handles loading of the jni library, and acts as a bridge for the native functions.
*/
class JniLoader {
private static final String LIBRARY_NAME = "gandiva_jni";

private static final int RTLD_GLOBAL = 0x00100;
private static final int RTLD_LAZY = 0x00001;

private static volatile JniLoader INSTANCE;
private static volatile long defaultConfiguration = 0L;
Expand Down Expand Up @@ -73,6 +80,10 @@ private static void loadGandivaLibraryFromJar(final String tmpDir)
final String libraryToLoad =
LIBRARY_NAME + "/" + getNormalizedArch() + "/" + System.mapLibraryName(LIBRARY_NAME);
final File libraryFile = moveFileFromJarToTemp(tmpDir, libraryToLoad, LIBRARY_NAME);
NativeLibrary.getInstance(
libraryFile.getAbsolutePath(),
Collections.singletonMap(Library.OPTION_OPEN_FLAGS, new Integer(RTLD_LAZY | RTLD_GLOBAL))
);
System.load(libraryFile.getAbsolutePath());
}

Expand Down

0 comments on commit 3199745

Please sign in to comment.