You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2018/01/22 13:04:27 UTC
ignite git commit: IGNITE-7477 .NET: Java 9 support
Repository: ignite
Updated Branches:
refs/heads/master 924b1faa6 -> e052f941c
IGNITE-7477 .NET: Java 9 support
This closes #3415
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e052f941
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e052f941
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e052f941
Branch: refs/heads/master
Commit: e052f941c96d8a397d2b419fe41edf585107302f
Parents: 924b1fa
Author: Pavel Tupitsyn <pt...@apache.org>
Authored: Mon Jan 22 16:04:18 2018 +0300
Committer: Pavel Tupitsyn <pt...@apache.org>
Committed: Mon Jan 22 16:04:18 2018 +0300
----------------------------------------------------------------------
.../Cache/DataStorageMetricsTest.cs | 2 +-
.../Apache.Ignite.Core.Tests/ExecutableTest.cs | 19 +++-
.../Impl/Unmanaged/Jni/Jvm.cs | 93 +++++++++++++++++---
.../Impl/Unmanaged/Jni/JvmDll.cs | 33 ++++++-
4 files changed, 128 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/e052f941/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/DataStorageMetricsTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/DataStorageMetricsTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/DataStorageMetricsTest.cs
index d98254d..caac58a 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/DataStorageMetricsTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/DataStorageMetricsTest.cs
@@ -79,7 +79,7 @@ namespace Apache.Ignite.Core.Tests.Cache
Assert.AreEqual(0, metrics.WalArchiveSegments);
Assert.AreEqual(0, metrics.WalFsyncTimeAverage);
- Assert.Greater(metrics.LastCheckpointTotalPagesNumber, 26);
+ Assert.GreaterOrEqual(metrics.LastCheckpointTotalPagesNumber, 26);
Assert.AreEqual(0, metrics.LastCheckpointDataPagesNumber);
Assert.AreEqual(0, metrics.LastCheckpointCopiedOnWritePagesNumber);
Assert.AreEqual(TimeSpan.Zero, metrics.LastCheckpointLockWaitDuration);
http://git-wip-us.apache.org/repos/asf/ignite/blob/e052f941/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs
index eb1e68e..faf2119 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs
@@ -321,6 +321,17 @@ namespace Apache.Ignite.Core.Tests
[Test]
public void TestInvalidCmdArgs()
{
+ var ignoredWarns = new[]
+ {
+ "WARNING: An illegal reflective access operation has occurred",
+ "WARNING: Illegal reflective access by org.apache.ignite.internal.util.GridUnsafe$2 " +
+ "(file:/C:/w/incubator-ignite/modules/core/target/classes/) to field java.nio.Buffer.address",
+ "WARNING: Please consider reporting this to the maintainers of org.apache.ignite.internal.util." +
+ "GridUnsafe$2",
+ "WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations",
+ "WARNING: All illegal access operations will be denied in a future release"
+ };
+
Action<string, string> checkError = (args, err) =>
{
var reader = new ListDataReader();
@@ -330,7 +341,9 @@ namespace Apache.Ignite.Core.Tests
Assert.IsTrue(proc.Join(30000, out exitCode));
Assert.AreEqual(-1, exitCode);
- Assert.AreEqual(err, reader.GetOutput().FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)));
+ Assert.AreEqual(err, reader.GetOutput()
+ .Except(ignoredWarns)
+ .FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)));
};
checkError("blabla", "ERROR: Apache.Ignite.Core.Common.IgniteException: Missing argument value: " +
@@ -396,8 +409,8 @@ namespace Apache.Ignite.Core.Tests
private static void AssertJvmMaxMemory(long expected, long actual)
{
// allow 20% tolerance because max memory in Java is not exactly equal to Xmx parameter value
- Assert.LessOrEqual(actual, expected);
- Assert.Greater(actual, expected/5*4);
+ Assert.LessOrEqual(actual, expected / 4 * 5);
+ Assert.Greater(actual, expected / 5 * 4);
}
/// <summary>
http://git-wip-us.apache.org/repos/asf/ignite/blob/e052f941/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/Jni/Jvm.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/Jni/Jvm.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/Jni/Jvm.cs
index 3d119cd..6d706e8 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/Jni/Jvm.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/Jni/Jvm.cs
@@ -21,6 +21,7 @@ namespace Apache.Ignite.Core.Impl.Unmanaged.Jni
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
+ using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
@@ -35,7 +36,21 @@ namespace Apache.Ignite.Core.Impl.Unmanaged.Jni
{
/** */
// ReSharper disable once InconsistentNaming
- private const int JNI_VERSION_1_6 = 0x00010006;
+ private const int JNI_VERSION_1_8 = 0x00010008;
+
+ /** */
+ // ReSharper disable once InconsistentNaming
+ private const int JNI_VERSION_9 = 0x00090000;
+
+ /** Options to enable startup on Java 9. */
+ private static readonly string[] Java9Options =
+ {
+ "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
+ "--add-exports=java.base/sun.nio.ch=ALL-UNNAMED",
+ "--add-exports=java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED",
+ "--add-exports=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED",
+ "--illegal-access=permit"
+ };
/** */
private readonly IntPtr _jvmPtr;
@@ -220,35 +235,85 @@ namespace Apache.Ignite.Core.Impl.Unmanaged.Jni
return jvm;
}
+ return CreateJvm(options);
+ }
+
+ /// <summary>
+ /// Determines whether we are on Java 9.
+ /// </summary>
+ private static bool IsJava9()
+ {
+ var args = new JvmInitArgs
+ {
+ version = JNI_VERSION_9
+ };
+
+ // Returns error on Java 8 and lower.
+ var res = JvmDll.Instance.GetDefaultJvmInitArgs(&args);
+ return res == JniResult.Success;
+ }
+
+ /// <summary>
+ /// Creates the JVM.
+ /// </summary>
+ private static IntPtr CreateJvm(IList<string> options)
+ {
+ if (IsJava9())
+ {
+ options = options == null
+ ? Java9Options.ToList()
+ : new List<string>(options.Concat(Java9Options));
+ }
+
var args = new JvmInitArgs
{
- version = JNI_VERSION_1_6
+ version = JNI_VERSION_1_8,
+ nOptions = options.Count
};
- if (options != null && options.Count > 0)
+ var opts = GetJvmOptions(options);
+
+ try
{
- args.nOptions = options.Count;
- var opt = new JvmOption[options.Count];
+ JniResult res;
+ IntPtr jvm;
- for (int i = 0; i < options.Count; i++)
+ fixed (JvmOption* optPtr = &opts[0])
+ {
+ args.options = optPtr;
+ IntPtr env;
+ res = JvmDll.Instance.CreateJvm(out jvm, out env, &args);
+ }
+
+ if (res != JniResult.Success)
{
- opt[i].optionString = Marshal.StringToHGlobalAnsi(options[i]);
+ throw new IgniteException("JNI_CreateJavaVM failed: " + res);
}
- fixed (JvmOption* a = &opt[0])
+ return jvm;
+ }
+ finally
+ {
+ foreach (var opt in opts)
{
- args.options = a;
+ Marshal.FreeHGlobal(opt.optionString);
}
}
+ }
- IntPtr env;
- res = JvmDll.Instance.CreateJvm(out jvm, out env, &args);
- if (res != JniResult.Success)
+ /// <summary>
+ /// Gets the JVM options.
+ /// </summary>
+ private static JvmOption[] GetJvmOptions(IList<string> options)
+ {
+ var opt = new JvmOption[options.Count];
+
+ for (var i = 0; i < options.Count; i++)
{
- throw new IgniteException("JNI_CreateJavaVM failed: " + res);
+ opt[i].optionString = Marshal.StringToHGlobalAnsi(options[i]);
}
- return jvm;
+ return opt;
}
/// <summary>
http://git-wip-us.apache.org/repos/asf/ignite/blob/e052f941/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/Jni/JvmDll.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/Jni/JvmDll.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/Jni/JvmDll.cs
index 3e1d3a9..ef161f4 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/Jni/JvmDll.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/Jni/JvmDll.cs
@@ -85,6 +85,9 @@ namespace Apache.Ignite.Core.Impl.Unmanaged.Jni
private unsafe delegate JniResult CreateJvmDel(out IntPtr pvm, out IntPtr penv, JvmInitArgs* args);
/** */
+ private unsafe delegate JniResult GetDefaultArgsDel(JvmInitArgs* args);
+
+ /** */
private delegate JniResult GetCreatedJvmsDel(out IntPtr pvm, int size, out int size2);
/** */
@@ -93,6 +96,9 @@ namespace Apache.Ignite.Core.Impl.Unmanaged.Jni
/** */
private readonly GetCreatedJvmsDel _getCreatedJvms;
+ /** */
+ private readonly GetDefaultArgsDel _getDefaultArgs;
+
/// <summary>
/// Initializes a new instance of the <see cref="JvmDll"/> class.
/// </summary>
@@ -121,16 +127,22 @@ namespace Apache.Ignite.Core.Impl.Unmanaged.Jni
var getJvmsPtr = DllLoader.NativeMethodsMacOs.dlsym(ptr, "JNI_GetCreatedJavaVMs");
_getCreatedJvms = (GetCreatedJvmsDel) Marshal.GetDelegateForFunctionPointer(getJvmsPtr,
typeof(GetCreatedJvmsDel));
+
+ var getArgsPtr = DllLoader.NativeMethodsMacOs.dlsym(ptr, "JNI_GetDefaultJavaVMInitArgs");
+ _getDefaultArgs = (GetDefaultArgsDel) Marshal.GetDelegateForFunctionPointer(getArgsPtr,
+ typeof(GetDefaultArgsDel));
}
else if (Os.IsWindows)
{
_createJvm = JniNativeMethodsWindows.JNI_CreateJavaVM;
_getCreatedJvms = JniNativeMethodsWindows.JNI_GetCreatedJavaVMs;
+ _getDefaultArgs = JniNativeMethodsWindows.JNI_GetDefaultJavaVMInitArgs;
}
else
{
_createJvm = JniNativeMethodsLinux.JNI_CreateJavaVM;
_getCreatedJvms = JniNativeMethodsLinux.JNI_GetCreatedJavaVMs;
+ _getDefaultArgs = JniNativeMethodsLinux.JNI_GetDefaultJavaVMInitArgs;
}
}
@@ -159,6 +171,17 @@ namespace Apache.Ignite.Core.Impl.Unmanaged.Jni
}
/// <summary>
+ /// Gets the default JVM init args.
+ /// Before calling this function, native code must set the vm_args->version field to the JNI version
+ /// it expects the VM to support. After this function returns, vm_args->version will be set
+ /// to the actual JNI version the VM supports.
+ /// </summary>
+ public unsafe JniResult GetDefaultJvmInitArgs(JvmInitArgs* args)
+ {
+ return _getDefaultArgs(args);
+ }
+
+ /// <summary>
/// Loads the JVM DLL into process memory.
/// </summary>
public static void Load(string configJvmDllPath, ILogger log)
@@ -398,6 +421,10 @@ namespace Apache.Ignite.Core.Impl.Unmanaged.Jni
[DllImport("jvm.dll", CallingConvention = CallingConvention.StdCall)]
internal static extern JniResult JNI_GetCreatedJavaVMs(out IntPtr pvm, int size,
[Out] out int size2);
+
+ [SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass")]
+ [DllImport("jvm.dll", CallingConvention = CallingConvention.StdCall)]
+ internal static extern JniResult JNI_GetDefaultJavaVMInitArgs(JvmInitArgs* args);
}
/// <summary>
@@ -413,6 +440,10 @@ namespace Apache.Ignite.Core.Impl.Unmanaged.Jni
[DllImport("libjvm.so", CallingConvention = CallingConvention.StdCall)]
internal static extern JniResult JNI_GetCreatedJavaVMs(out IntPtr pvm, int size,
[Out] out int size2);
+
+ [SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass")]
+ [DllImport("libjvm.so", CallingConvention = CallingConvention.StdCall)]
+ internal static extern JniResult JNI_GetDefaultJavaVMInitArgs(JvmInitArgs* args);
}
- }
+ }
}
\ No newline at end of file