You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by is...@apache.org on 2019/04/15 15:43:07 UTC
[ignite] branch ignite-2.7.5 updated: IGNITE-11195: C++ fix for
Java 11 for Linux.
This is an automated email from the ASF dual-hosted git repository.
isapego pushed a commit to branch ignite-2.7.5
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/ignite-2.7.5 by this push:
new 5f2c52d IGNITE-11195: C++ fix for Java 11 for Linux.
5f2c52d is described below
commit 5f2c52d076b3fba498d7315e098561a173de6599
Author: Igor Sapego <is...@apache.org>
AuthorDate: Fri Mar 1 13:34:54 2019 +0300
IGNITE-11195: C++ fix for Java 11 for Linux.
(cherry picked from commit a5fe467bad1dc64f1cdd46ceacdffe246583e33f)
---
modules/platforms/cpp/core/src/ignition.cpp | 55 +++++++--------
modules/platforms/cpp/jni/Makefile.am | 1 +
.../platforms/cpp/jni/include/ignite/jni/java.h | 7 ++
modules/platforms/cpp/jni/os/linux/src/utils.cpp | 10 ++-
modules/platforms/cpp/jni/src/java.cpp | 79 +++++++++-------------
5 files changed, 74 insertions(+), 78 deletions(-)
diff --git a/modules/platforms/cpp/core/src/ignition.cpp b/modules/platforms/cpp/core/src/ignition.cpp
index 7d90a52..087d42d 100644
--- a/modules/platforms/cpp/core/src/ignition.cpp
+++ b/modules/platforms/cpp/core/src/ignition.cpp
@@ -75,8 +75,7 @@ namespace ignite
* Constructor.
*/
JvmOptions() :
- size(0),
- opts(0)
+ opts()
{
// No-op.
}
@@ -100,39 +99,43 @@ namespace ignite
{
Deinit();
- size = 3 + static_cast<int>(cfg.jvmOpts.size());
+ const size_t REQ_OPTS_CNT = 4;
+ const size_t JAVA9_OPTS_CNT = 6;
- if (!home.empty())
- ++size;
-
- // Brackets '()' here guarantee for the array to be zeroed.
- // Important to avoid crash in case of exception.
- opts = new char*[size]();
-
- int idx = 0;
+ opts.reserve(cfg.jvmOpts.size() + REQ_OPTS_CNT + JAVA9_OPTS_CNT);
// 1. Set classpath.
std::string cpFull = "-Djava.class.path=" + cp;
- opts[idx++] = CopyChars(cpFull.c_str());
+ opts.push_back(CopyChars(cpFull.c_str()));
// 2. Set home.
if (!home.empty()) {
std::string homeFull = "-DIGNITE_HOME=" + home;
- opts[idx++] = CopyChars(homeFull.c_str());
+ opts.push_back(CopyChars(homeFull.c_str()));
}
// 3. Set Xms, Xmx.
std::string xmsStr = JvmMemoryString("-Xms", cfg.jvmInitMem);
std::string xmxStr = JvmMemoryString("-Xmx", cfg.jvmMaxMem);
- opts[idx++] = CopyChars(xmsStr.c_str());
- opts[idx++] = CopyChars(xmxStr.c_str());
+ opts.push_back(CopyChars(xmsStr.c_str()));
+ opts.push_back(CopyChars(xmxStr.c_str()));
// 4. Set the rest options.
for (std::list<std::string>::const_iterator i = cfg.jvmOpts.begin(); i != cfg.jvmOpts.end(); ++i)
- opts[idx++] = CopyChars(i->c_str());
+ opts.push_back(CopyChars(i->c_str()));
+
+ // Adding options for Java 9 or later
+ if (IsJava9OrLater()) {
+ opts.push_back(CopyChars("--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED"));
+ opts.push_back(CopyChars("--add-exports=java.base/sun.nio.ch=ALL-UNNAMED"));
+ opts.push_back(CopyChars("--add-exports=java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED"));
+ opts.push_back(CopyChars("--add-exports=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED"));
+ opts.push_back(CopyChars("--add-exports=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED"));
+ opts.push_back(CopyChars("--illegal-access=permit"));
+ }
}
/**
@@ -140,13 +143,10 @@ namespace ignite
*/
void Deinit()
{
- if (opts)
- {
- for (int i = 0; i < size; ++i)
- ReleaseChars(opts[i]);
+ for (size_t i = 0; i < opts.size(); ++i)
+ ReleaseChars(opts[i]);
- delete[] opts;
- }
+ opts.clear();
}
/**
@@ -154,9 +154,9 @@ namespace ignite
*
* @return Built options
*/
- char** GetOpts() const
+ char** GetOpts()
{
- return opts;
+ return &opts[0];
}
/**
@@ -166,15 +166,12 @@ namespace ignite
*/
int GetSize() const
{
- return size;
+ return static_cast<int>(opts.size());
}
private:
- /** Size */
- int size;
-
/** Options array. */
- char** opts;
+ std::vector<char*> opts;
};
Ignite Ignition::Start(const IgniteConfiguration& cfg)
diff --git a/modules/platforms/cpp/jni/Makefile.am b/modules/platforms/cpp/jni/Makefile.am
index 56eaa6c..da107a2 100644
--- a/modules/platforms/cpp/jni/Makefile.am
+++ b/modules/platforms/cpp/jni/Makefile.am
@@ -39,6 +39,7 @@ AM_CXXFLAGS = \
libignite_jni_la_LIBADD = \
-L$(JAVA_HOME)/jre/lib/amd64/server \
+ -L$(JAVA_HOME)/lib/server \
@top_srcdir@/common/libignite-common.la
libignite_jni_la_LDFLAGS = \
diff --git a/modules/platforms/cpp/jni/include/ignite/jni/java.h b/modules/platforms/cpp/jni/include/ignite/jni/java.h
index c713e81..196d941 100644
--- a/modules/platforms/cpp/jni/include/ignite/jni/java.h
+++ b/modules/platforms/cpp/jni/include/ignite/jni/java.h
@@ -115,6 +115,13 @@ namespace ignite
typedef long long(JNICALL *InLongLongLongObjectOutLongHandler)(void* target, int type, long long val1, long long val2, long long val3, void* arg);
/**
+ * Is Java 9 or later is used.
+ *
+ * @return true if the Java 9 or later is in use.
+ */
+ bool IGNITE_IMPORT_EXPORT IsJava9OrLater();
+
+ /**
* JNI handlers holder.
*/
struct JniHandlers {
diff --git a/modules/platforms/cpp/jni/os/linux/src/utils.cpp b/modules/platforms/cpp/jni/os/linux/src/utils.cpp
index 52e4097..0fda52d 100644
--- a/modules/platforms/cpp/jni/os/linux/src/utils.cpp
+++ b/modules/platforms/cpp/jni/os/linux/src/utils.cpp
@@ -37,7 +37,8 @@ namespace ignite
namespace jni
{
const char* JAVA_HOME = "JAVA_HOME";
- const char* JAVA_DLL = "/jre/lib/amd64/server/libjvm.so";
+ const char* JAVA_DLL1 = "/jre/lib/amd64/server/libjvm.so";
+ const char* JAVA_DLL2 = "/lib/server/libjvm.so";
const char* IGNITE_HOME = "IGNITE_HOME";
@@ -311,7 +312,12 @@ namespace ignite
if (!javaEnv.empty())
{
- std::string javaDll = javaEnv + JAVA_DLL;
+ std::string javaDll = javaEnv + JAVA_DLL1;
+
+ if (FileExists(javaDll))
+ return javaDll;
+
+ javaDll = javaEnv + JAVA_DLL2;
if (FileExists(javaDll))
return javaDll;
diff --git a/modules/platforms/cpp/jni/src/java.cpp b/modules/platforms/cpp/jni/src/java.cpp
index ac4ba63..9a07a5f 100644
--- a/modules/platforms/cpp/jni/src/java.cpp
+++ b/modules/platforms/cpp/jni/src/java.cpp
@@ -23,10 +23,15 @@
#include <algorithm>
#include <stdexcept>
-#include "ignite/jni/utils.h"
-#include "ignite/common/concurrent.h"
-#include "ignite/jni/java.h"
+#include <ignite/jni/utils.h>
+#include <ignite/common/concurrent.h>
+#include <ignite/jni/java.h>
#include <ignite/ignite_error.h>
+#include <ignite/common/utils.h>
+
+#ifndef JNI_VERSION_9
+#define JNI_VERSION_9 0x00090000
+#endif // JNI_VERSION_9
#define IGNITE_SAFE_PROC_NO_ARG(jniEnv, envPtr, type, field) { \
JniHandlers* hnds = reinterpret_cast<JniHandlers*>(envPtr); \
@@ -94,7 +99,18 @@ namespace ignite
{
namespace java
{
- namespace gcc = ignite::common::concurrent;
+ namespace icc = ignite::common::concurrent;
+
+ bool IGNITE_IMPORT_EXPORT IsJava9OrLater()
+ {
+ JavaVMInitArgs args;
+
+ memset(&args, 0, sizeof(args));
+
+ args.version = JNI_VERSION_9;
+
+ return JNI_GetDefaultJavaVMInitArgs(&args) == JNI_OK;
+ }
/* --- Startup exception. --- */
class JvmException : public std::exception {
@@ -114,26 +130,6 @@ namespace ignite
}
};
- /**
- * Heloper function to copy characters.
- *
- * @param src Source.
- * @return Result.
- */
- char* CopyChars(const char* src)
- {
- if (src)
- {
- size_t len = strlen(src);
- char* dest = new char[len + 1];
- strcpy(dest, src);
- *(dest + len) = 0;
- return dest;
- }
- else
- return NULL;
- }
-
JniErrorInfo::JniErrorInfo() : code(IGNITE_JNI_ERR_SUCCESS), errCls(NULL), errMsg(NULL)
{
// No-op.
@@ -141,14 +137,14 @@ namespace ignite
JniErrorInfo::JniErrorInfo(int code, const char* errCls, const char* errMsg) : code(code)
{
- this->errCls = CopyChars(errCls);
- this->errMsg = CopyChars(errMsg);
+ this->errCls = common::CopyChars(errCls);
+ this->errMsg = common::CopyChars(errMsg);
}
JniErrorInfo::JniErrorInfo(const JniErrorInfo& other) : code(other.code)
{
- this->errCls = CopyChars(other.errCls);
- this->errMsg = CopyChars(other.errMsg);
+ this->errCls = common::CopyChars(other.errCls);
+ this->errMsg = common::CopyChars(other.errMsg);
}
JniErrorInfo& JniErrorInfo::operator=(const JniErrorInfo& other)
@@ -159,17 +155,9 @@ namespace ignite
JniErrorInfo tmp(other);
// 2. Swap with temp.
- int code0 = code;
- char* errCls0 = errCls;
- char* errMsg0 = errMsg;
-
- code = tmp.code;
- errCls = tmp.errCls;
- errMsg = tmp.errMsg;
-
- tmp.code = code0;
- tmp.errCls = errCls0;
- tmp.errMsg = errMsg0;
+ std::swap(code, tmp.code);
+ std::swap(errCls, tmp.errCls);
+ std::swap(errMsg, tmp.errMsg);
}
return *this;
@@ -177,11 +165,8 @@ namespace ignite
JniErrorInfo::~JniErrorInfo()
{
- if (errCls)
- delete[] errCls;
-
- if (errMsg)
- delete[] errMsg;
+ delete[] errCls;
+ delete[] errMsg;
}
/**
@@ -255,8 +240,8 @@ namespace ignite
JniMethod M_PLATFORM_IGNITION_STOP_ALL = JniMethod("stopAll", "(Z)V", true);
/* STATIC STATE. */
- gcc::CriticalSection JVM_LOCK;
- gcc::CriticalSection CONSOLE_LOCK;
+ icc::CriticalSection JVM_LOCK;
+ icc::CriticalSection CONSOLE_LOCK;
JniJvm JVM;
bool PRINT_EXCEPTION = false;
std::vector<ConsoleWriteHandler> consoleWriteHandlers;
@@ -725,7 +710,7 @@ namespace ignite
}
void JniContext::Detach() {
- gcc::Memory::Fence();
+ icc::Memory::Fence();
if (JVM.GetJvm()) {
JNIEnv* env;