243 lines
8.2 KiB
Diff
243 lines
8.2 KiB
Diff
diff --git a/hadoop-common-project/hadoop-common/src/CMakeLists.txt b/hadoop-common-project/hadoop-common/src/CMakeLists.txt
|
|
index dec63c4..de21bab 100644
|
|
--- a/hadoop-common-project/hadoop-common/src/CMakeLists.txt
|
|
+++ b/hadoop-common-project/hadoop-common/src/CMakeLists.txt
|
|
@@ -205,7 +205,6 @@ ENDIF()
|
|
|
|
target_link_dual_libraries(hadoop
|
|
${LIB_DL}
|
|
- ${JAVA_JVM_LIBRARY}
|
|
)
|
|
SET(LIBHADOOP_VERSION "1.0.0")
|
|
SET_TARGET_PROPERTIES(hadoop PROPERTIES
|
|
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/CMakeLists.txt b/hadoop-hdfs-project/hadoop-hdfs/src/CMakeLists.txt
|
|
index 82d1a32..2151bb8 100644
|
|
--- a/hadoop-hdfs-project/hadoop-hdfs/src/CMakeLists.txt
|
|
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/CMakeLists.txt
|
|
@@ -147,7 +147,6 @@ if (NEED_LINK_DL)
|
|
endif(NEED_LINK_DL)
|
|
|
|
target_link_dual_libraries(hdfs
|
|
- ${JAVA_JVM_LIBRARY}
|
|
${LIB_DL}
|
|
${OS_LINK_LIBRARIES}
|
|
)
|
|
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/CMakeLists.txt b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/CMakeLists.txt
|
|
index dd3f1e6..68ba422 100644
|
|
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/CMakeLists.txt
|
|
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/fuse-dfs/CMakeLists.txt
|
|
@@ -68,7 +68,6 @@ IF(FUSE_FOUND)
|
|
)
|
|
target_link_libraries(fuse_dfs
|
|
${FUSE_LIBRARIES}
|
|
- ${JAVA_JVM_LIBRARY}
|
|
hdfs
|
|
m
|
|
pthread
|
|
@@ -77,16 +77,6 @@ IF(FUSE_FOUND)
|
|
pthread
|
|
rt
|
|
)
|
|
- add_executable(test_fuse_dfs
|
|
- test/test_fuse_dfs.c
|
|
- test/fuse_workload.c
|
|
- )
|
|
- target_link_libraries(test_fuse_dfs
|
|
- ${FUSE_LIBRARIES}
|
|
- native_mini_dfs
|
|
- posix_util
|
|
- pthread
|
|
- )
|
|
ELSE(FUSE_FOUND)
|
|
IF(REQUIRE_FUSE)
|
|
MESSAGE(FATAL_ERROR "Required component fuse_dfs could not be built.")
|
|
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/libhdfs/jni_helper.c b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/libhdfs/jni_helper.c
|
|
index 878289f..62686b3 100644
|
|
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/libhdfs/jni_helper.c
|
|
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/libhdfs/jni_helper.c
|
|
@@ -24,6 +24,7 @@
|
|
#include "os/mutexes.h"
|
|
#include "os/thread_local_storage.h"
|
|
|
|
+#include <dlfcn.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
@@ -373,6 +374,12 @@ static JNIEnv* getGlobalJNIEnv(void)
|
|
jint rv = 0;
|
|
jint noVMs = 0;
|
|
jthrowable jthr;
|
|
+ void *jvmHandle = NULL;
|
|
+ jint JNICALL (*getCreatedJavaJVMsPtr)(JavaVM **, jsize, jsize *);
|
|
+ getCreatedJavaJVMsPtr = NULL;
|
|
+ jint JNICALL (*createJavaVMPtr)(JavaVM **, void **, void *);
|
|
+ createJavaVMPtr = NULL;
|
|
+ char *dlsym_error = NULL;
|
|
char *hadoopClassPath;
|
|
const char *hadoopClassPathVMArg = "-Djava.class.path=";
|
|
size_t optHadoopClassPathLen;
|
|
@@ -384,10 +391,75 @@ static JNIEnv* getGlobalJNIEnv(void)
|
|
JavaVMInitArgs vm_args;
|
|
JavaVM *vm;
|
|
JavaVMOption *options;
|
|
+ //Get JAVA_HOME to use appropriate libjvm
|
|
+ char *javaHome = getenv("JAVA_HOME");
|
|
+ if (javaHome == NULL) {
|
|
+ javaHome = "/usr/lib/jvm";
|
|
+ }
|
|
+
|
|
+#if defined(__x86_64__) && defined (__LP64__)
|
|
+ const char *arch="amd64";
|
|
+#elif defined(__x86_64__) && defined (__ILP32__)
|
|
+ const char *arch="x32";
|
|
+#elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__)
|
|
+ const char *arch="ppc64le";
|
|
+#elif defined(__powerpc64__)
|
|
+ const char *arch="ppc64";
|
|
+#elif defined(__powerpc__)
|
|
+ const char *arch="ppc";
|
|
+#elif defined(__i386__)
|
|
+ const char *arch="i386";
|
|
+#elif defined(__ia64__)
|
|
+ const char *arch="ia64";
|
|
+#elif defined(__s390x__)
|
|
+ const char *arch="s390x";
|
|
+#elif defined(__s390__)
|
|
+ const char *arch="s390";
|
|
+#elif defined(__armel__)
|
|
+ const char *arch="arm";
|
|
+#elif defined(__arm__)
|
|
+ const char *arch="arm";
|
|
+#elif defined(__aarch64__)
|
|
+ const char *arch="aarch64";
|
|
+#elif defined(__sparc__) && defined(__arch64__)
|
|
+ const char *arch="sparcv9";
|
|
+#elif defined(__sparc__)
|
|
+ const char *arch="sparc";
|
|
+#elif defined(__alpha__)
|
|
+ const char *arch="alpha";
|
|
+#elif defined(__mips__) && defined(__MIPSEL__) && _MIPS_SIM==_ABIO32
|
|
+ const char *arch="mipsel";
|
|
+#elif defined(__mips__) && defined(__MIPSEL__)
|
|
+ const char *arch="mips64el";
|
|
+#elif defined(__mips__) && _MIPS_SIM==_ABIO32
|
|
+ const char *arch="mips";
|
|
+#elif defined(__mips__)
|
|
+ const char *arch="mips64";
|
|
+#else
|
|
+#error Unknown JVM architecture
|
|
+#endif
|
|
+
|
|
+ //Load the appropriate libjvm
|
|
+ char libjvmPath[strlen(javaHome)+35];
|
|
+ snprintf(libjvmPath, sizeof(libjvmPath), "%s/jre/lib/%s/server/libjvm.so", javaHome, arch);
|
|
+ jvmHandle = dlopen(libjvmPath, RTLD_NOW|RTLD_LOCAL);
|
|
+ if (jvmHandle == NULL) {
|
|
+ fprintf(stderr, "Failed to load libjvm.so!\n");
|
|
+ return NULL;
|
|
+ }
|
|
|
|
- rv = JNI_GetCreatedJavaVMs(&(vmBuf[0]), VM_BUF_LENGTH, &noVMs);
|
|
+ //Load the JNI_GetCreatedJavaVMs function from the libjvm library
|
|
+ getCreatedJavaJVMsPtr = (jint JNICALL (*)(JavaVM **, jsize, jsize *)) dlsym(jvmHandle, "JNI_GetCreatedJavaVMs");
|
|
+ dlsym_error = dlerror();
|
|
+ if (dlsym_error) {
|
|
+ fprintf(stderr, "Can not load symbol JNI_GetCreatedJavaVMs: %s\n", dlsym_error);
|
|
+ dlclose(jvmHandle);
|
|
+ return NULL;
|
|
+ }
|
|
+ rv = (*getCreatedJavaJVMsPtr)(&(vmBuf[0]), VM_BUF_LENGTH, &noVMs);
|
|
if (rv != 0) {
|
|
fprintf(stderr, "JNI_GetCreatedJavaVMs failed with error: %d\n", rv);
|
|
+ dlclose(jvmHandle);
|
|
return NULL;
|
|
}
|
|
|
|
@@ -396,6 +468,7 @@ static JNIEnv* getGlobalJNIEnv(void)
|
|
hadoopClassPath = getenv("CLASSPATH");
|
|
if (hadoopClassPath == NULL) {
|
|
fprintf(stderr, "Environment variable CLASSPATH not set!\n");
|
|
+ dlclose(jvmHandle);
|
|
return NULL;
|
|
}
|
|
optHadoopClassPathLen = strlen(hadoopClassPath) +
|
|
@@ -502,7 +576,15 @@ static JNIEnv* getGlobalJNIEnv(void)
|
|
vm_args.nOptions = noArgs;
|
|
vm_args.ignoreUnrecognized = 1;
|
|
|
|
- rv = JNI_CreateJavaVM(&vm, (void*)&env, &vm_args);
|
|
+ //Load the JNI_CreateJavaVM function from the libjvm library
|
|
+ createJavaVMPtr = (jint JNICALL (*)(JavaVM **, void **, void *)) dlsym(jvmHandle, "JNI_CreateJavaVM");
|
|
+ dlsym_error = dlerror();
|
|
+ if (dlsym_error) {
|
|
+ fprintf(stderr, "Can not load symbol JNI_CreateJavaVM: %s\n", dlsym_error);
|
|
+ dlclose(jvmHandle);
|
|
+ return NULL;
|
|
+ }
|
|
+ rv = (*createJavaVMPtr)(&vm, (void*)&env, &vm_args);
|
|
|
|
if (hadoopJvmArgs != NULL) {
|
|
free(hadoopJvmArgs);
|
|
@@ -512,6 +594,7 @@ static JNIEnv* getGlobalJNIEnv(void)
|
|
if (rv != 0) {
|
|
fprintf(stderr, "Call to JNI_CreateJavaVM failed "
|
|
"with error: %d\n", rv);
|
|
+ dlclose(jvmHandle);
|
|
return NULL;
|
|
}
|
|
jthr = invokeMethod(env, NULL, STATIC, NULL,
|
|
@@ -470,6 +552,7 @@ static JNIEnv* getGlobalJNIEnv(void)
|
|
if (rv != 0) {
|
|
fprintf(stderr, "Call to AttachCurrentThread "
|
|
"failed with error: %d\n", rv);
|
|
+ dlclose(jvmHandle);
|
|
return NULL;
|
|
}
|
|
}
|
|
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/CMakeLists.txt b/hadoop-hdfs-project/hadoop-hdfs/src/CMakeLists.txt
|
|
index 74f20dd..255d4ab 100644
|
|
--- a/hadoop-hdfs-project/hadoop-hdfs/src/CMakeLists.txt
|
|
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/CMakeLists.txt
|
|
@@ -161,7 +161,6 @@ add_executable(test_libhdfs_ops
|
|
)
|
|
target_link_libraries(test_libhdfs_ops
|
|
hdfs_static
|
|
- ${JAVA_JVM_LIBRARY}
|
|
)
|
|
|
|
add_executable(test_libhdfs_read
|
|
@@ -169,7 +168,6 @@ add_executable(test_libhdfs_read
|
|
)
|
|
target_link_libraries(test_libhdfs_read
|
|
hdfs_static
|
|
- ${JAVA_JVM_LIBRARY}
|
|
)
|
|
|
|
add_executable(test_libhdfs_write
|
|
@@ -177,7 +175,6 @@ add_executable(test_libhdfs_write
|
|
)
|
|
target_link_libraries(test_libhdfs_write
|
|
hdfs_static
|
|
- ${JAVA_JVM_LIBRARY}
|
|
)
|
|
|
|
add_library(native_mini_dfs
|
|
@@ -189,17 +186,9 @@ add_library(native_mini_dfs
|
|
${OS_DIR}/thread_local_storage.c
|
|
)
|
|
target_link_libraries(native_mini_dfs
|
|
- ${JAVA_JVM_LIBRARY}
|
|
${OS_LINK_LIBRARIES}
|
|
)
|
|
|
|
-add_executable(test_native_mini_dfs
|
|
- main/native/libhdfs/test_native_mini_dfs.c
|
|
-)
|
|
-target_link_libraries(test_native_mini_dfs
|
|
- native_mini_dfs
|
|
-)
|
|
-
|
|
add_executable(test_libhdfs_threaded
|
|
main/native/libhdfs/expect.c
|
|
main/native/libhdfs/test_libhdfs_threaded.c
|