You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by nn...@apache.org on 2014/06/25 23:21:20 UTC

git commit: Cleaned up libjvm to use DynamicLibrary.

Repository: mesos
Updated Branches:
  refs/heads/master 9fd2da85d -> b2d13bc3b


Cleaned up libjvm to use DynamicLibrary.

Updated the code to leverage stout/dynamiclibrary.

Review: https://reviews.apache.org/r/21598


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b2d13bc3
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b2d13bc3
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b2d13bc3

Branch: refs/heads/master
Commit: b2d13bc3b4c9a154a3520fc3887717dcd04779e5
Parents: 9fd2da8
Author: Timothy St. Clair <ts...@redhat.com>
Authored: Tue Jun 24 14:31:46 2014 -0700
Committer: Niklas Q. Nielsen <ni...@mesosphere.io>
Committed: Wed Jun 25 13:03:17 2014 -0700

----------------------------------------------------------------------
 src/jvm/jvm.cpp | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b2d13bc3/src/jvm/jvm.cpp
----------------------------------------------------------------------
diff --git a/src/jvm/jvm.cpp b/src/jvm/jvm.cpp
index 745b48f..d33a655 100644
--- a/src/jvm/jvm.cpp
+++ b/src/jvm/jvm.cpp
@@ -1,5 +1,4 @@
 #include <stdarg.h>
-#include <dlfcn.h>
 
 #include <glog/logging.h>
 
@@ -9,6 +8,7 @@
 #include <sstream>
 #include <vector>
 
+#include <stout/dynamiclibrary.hpp>
 #include <stout/exit.hpp>
 #include <stout/foreach.hpp>
 #include <stout/os.hpp>
@@ -63,25 +63,30 @@ Try<Jvm*> Jvm::create(
     libJvmPath = mesos::internal::build::JAVA_JVM_LIBRARY;
   }
 
-  void* handle = dlopen(libJvmPath.c_str(), RTLD_NOW);
+  static DynamicLibrary* libJvm = new DynamicLibrary();
+  Try<Nothing> openResult = libJvm->open(libJvmPath);
 
-  if (handle == NULL) {
-    return Error(dlerror());
+  if (openResult.isError()) {
+    return Error(openResult.error());
+  }
+
+  Try<void*> symbol = libJvm->loadSymbol("JNI_CreateJavaVM");
+
+  if (symbol.isError()) {
+    libJvm->close();
+    return Error(symbol.error());
   }
 
   // typedef function pointer to JNI.
   typedef jint (*fnptr_JNI_CreateJavaVM)(JavaVM**, void**, void*);
 
   fnptr_JNI_CreateJavaVM fn_JNI_CreateJavaVM =
-    (fnptr_JNI_CreateJavaVM)dlsym(handle, "JNI_CreateJavaVM");
-
-  if (fn_JNI_CreateJavaVM == NULL) {
-    return Error(dlerror());
-  }
+    (fnptr_JNI_CreateJavaVM)symbol.get();
 
-  int result = fn_JNI_CreateJavaVM(&jvm, JNIENV_CAST(&env), &vmArgs);
+  int createResult = fn_JNI_CreateJavaVM(&jvm, JNIENV_CAST(&env), &vmArgs);
 
-  if (result == JNI_ERR) {
+  if (createResult == JNI_ERR) {
+    libJvm->close();
     return Error("Failed to create JVM!");
   }