MCPcopy Create free account
hub / github.com/VowpalWabbit/vowpal_wabbit / Native

Class Native

java/src/main/java/common/Native.java:9–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7import java.util.*;
8
9public class Native {
10 private static final String PLATFORM_DIR = getPlatformDir();
11 private static final String LIB_NAME = getLibraryName();
12
13 /**
14 * Detects the current platform and returns the appropriate natives directory name.
15 * Supported platforms: linux_64, linux_arm64, macos_x64, macos_arm64, windows_64
16 */
17 private static String getPlatformDir() {
18 String os = System.getProperty("os.name", "").toLowerCase();
19 String arch = System.getProperty("os.arch", "").toLowerCase();
20
21 String osDir;
22 if (os.contains("linux")) {
23 osDir = "linux";
24 } else if (os.contains("mac") || os.contains("darwin")) {
25 osDir = "macos";
26 } else if (os.contains("win")) {
27 osDir = "windows";
28 } else {
29 throw new UnsupportedOperationException("Unsupported operating system: " + os);
30 }
31
32 String archDir;
33 if (arch.equals("amd64") || arch.equals("x86_64")) {
34 archDir = osDir.equals("linux") ? "64" : "x64";
35 } else if (arch.equals("aarch64") || arch.equals("arm64")) {
36 archDir = "arm64";
37 } else {
38 throw new UnsupportedOperationException("Unsupported architecture: " + arch);
39 }
40
41 return osDir + "_" + archDir;
42 }
43
44 /**
45 * Returns the platform-specific library file name.
46 */
47 private static String getLibraryName() {
48 String os = System.getProperty("os.name", "").toLowerCase();
49 if (os.contains("win")) {
50 return "vw_jni.dll";
51 } else if (os.contains("mac") || os.contains("darwin")) {
52 return "libvw_jni.dylib";
53 } else {
54 return "libvw_jni.so";
55 }
56 }
57
58 private static void try_load_from_path() {
59 System.loadLibrary("vw_jni");
60 }
61
62 private static void try_load_from_jar() throws IOException {
63 String nativesPrefix = "natives/" + PLATFORM_DIR + "/";
64
65 // create temp directory
66 Path tempDirectory = Files.createTempDirectory("tmplibvw");

Callers

nothing calls this directly

Calls 4

getPlatformDirMethod · 0.95
getLibraryNameMethod · 0.95
try_load_from_pathMethod · 0.95
try_load_from_jarMethod · 0.95

Tested by

no test coverage detected