This is an automated email from the ASF dual-hosted git repository. leerho pushed a commit to branch Remove_JDK7 in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-memory.git
commit b806cda8cf9bdcc26ee09a868f3e61903baaa9a1 Author: Lee Rhodes <[email protected]> AuthorDate: Mon Jun 17 12:51:11 2019 -0700 Remove support for JDK 1.7. Also, no implied support for JDK 9 and above. --- .../memory/AllocateDirectWritableMap.java | 2 +- .../org/apache/datasketches/memory/NioBits.java | 4 +- .../memory/NonNativeWritableMemoryImpl.java | 7 +--- .../org/apache/datasketches/memory/UnsafeUtil.java | 49 ++++++++++------------ .../datasketches/memory/WritableMemoryImpl.java | 12 +----- .../apache/datasketches/memory/UnsafeUtilTest.java | 26 +++++++++--- 6 files changed, 47 insertions(+), 53 deletions(-) diff --git a/src/main/java/org/apache/datasketches/memory/AllocateDirectWritableMap.java b/src/main/java/org/apache/datasketches/memory/AllocateDirectWritableMap.java index a0d2646..d0b1046 100644 --- a/src/main/java/org/apache/datasketches/memory/AllocateDirectWritableMap.java +++ b/src/main/java/org/apache/datasketches/memory/AllocateDirectWritableMap.java @@ -51,7 +51,7 @@ final class AllocateDirectWritableMap extends AllocateDirectMap implements Writa capacityBytes); } catch (final Exception e) { throw new RuntimeException(String.format("Encountered %s exception in force. " - + UnsafeUtil.tryIllegalAccessPermit, e.getClass())); + + e.getClass())); } } } diff --git a/src/main/java/org/apache/datasketches/memory/NioBits.java b/src/main/java/org/apache/datasketches/memory/NioBits.java index e8377fd..ac853e1 100644 --- a/src/main/java/org/apache/datasketches/memory/NioBits.java +++ b/src/main/java/org/apache/datasketches/memory/NioBits.java @@ -49,7 +49,6 @@ final class NioBits { static { try { - //TODO-JDK9 VM_CLASS = Class.forName("jdk.internal.misc.VM"); VM_CLASS = Class.forName("sun.misc.VM"); VM_MAX_DIRECT_MEMORY_METHOD = VM_CLASS.getDeclaredMethod("maxDirectMemory"); @@ -86,8 +85,7 @@ final class NioBits { nioBitsTotalCapacity = (AtomicLong) (totalCapacityField.get(null)); } catch (final Exception e) { - throw new RuntimeException("Could not acquire java.nio.Bits class: " + e.getClass() - + UnsafeUtil.tryIllegalAccessPermit); + throw new RuntimeException("Could not acquire java.nio.Bits class: " + e.getClass()); } } diff --git a/src/main/java/org/apache/datasketches/memory/NonNativeWritableMemoryImpl.java b/src/main/java/org/apache/datasketches/memory/NonNativeWritableMemoryImpl.java index ad4430b..0de2304 100644 --- a/src/main/java/org/apache/datasketches/memory/NonNativeWritableMemoryImpl.java +++ b/src/main/java/org/apache/datasketches/memory/NonNativeWritableMemoryImpl.java @@ -255,12 +255,7 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl { assertValidAndBoundsForWrite(offsetBytes, ARRAY_LONG_INDEX_SCALE); final long addr = getCumulativeOffset(offsetBytes); final long newValueReverseBytes = Long.reverseBytes(newValue); - if (UnsafeUtil.JDK8_OR_ABOVE) { - return Long.reverseBytes(unsafe.getAndSetLong(getUnsafeObject(), addr, newValueReverseBytes)); - } else { - return Long.reverseBytes( - JDK7Compatible.getAndSetLong(getUnsafeObject(), addr, newValueReverseBytes)); - } + return Long.reverseBytes(unsafe.getAndSetLong(getUnsafeObject(), addr, newValueReverseBytes)); } @Override diff --git a/src/main/java/org/apache/datasketches/memory/UnsafeUtil.java b/src/main/java/org/apache/datasketches/memory/UnsafeUtil.java index 5fc1a31..04e521c 100644 --- a/src/main/java/org/apache/datasketches/memory/UnsafeUtil.java +++ b/src/main/java/org/apache/datasketches/memory/UnsafeUtil.java @@ -33,21 +33,17 @@ import sun.misc.Unsafe; * jdk8 and it must be done with both source and target versions of jdk7 specified in pom.xml. * The resultant jar will work on jdk7 and jdk8.</p> * - * <p>This may work with jdk9 but might require the JVM arg <i>-permit-illegal-access</i>, - * <i>–illegal-access=permit</i> or equivalent. Proper operation with jdk9 or above is not - * guaranteed and has not been tested. - * * @author Lee Rhodes */ public final class UnsafeUtil { public static final Unsafe unsafe; - public static final String JDK; - static final boolean JDK8_OR_ABOVE; + public static final String JDK; //must be at least "1.8" + public static final int JDK_MAJOR; //8, 9, 10, 11, 12, etc //not an indicator of whether compressed references are used. public static final int ADDRESS_SIZE; - //For 64-bit JVMs: varies depending on coop: 16 for JVM <= 32GB; 24 for JVM > 32GB + //For 64-bit JVMs: these offsets vary depending on coop: 16 for JVM <= 32GB; 24 for JVM > 32GB. // Making this constant long-typed, rather than int, to exclude possibility of accidental overflow // in expressions like arrayLength * ARRAY_BYTE_BASE_OFFSET, where arrayLength is int-typed. // The same consideration for constants below: ARRAY_*_INDEX_SCALE, ARRAY_*_INDEX_SHIFT. @@ -91,10 +87,6 @@ public final class UnsafeUtil { //@formatter:on - static String tryIllegalAccessPermit = - " If using JDK 9+ try setting JVM arg -permit-illegal-access, " - + "–illegal-access=permit or equivalent."; - static { try { final Constructor<Unsafe> unsafeConstructor = Unsafe.class.getDeclaredConstructor(); @@ -109,7 +101,7 @@ public final class UnsafeUtil { } catch (final InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException e) { e.printStackTrace(); - throw new RuntimeException("Unable to acquire Unsafe. " + tryIllegalAccessPermit, e); + throw new RuntimeException("Unable to acquire Unsafe. " + e); } //4 on 32-bit systems. 4 on 64-bit systems < 32GB, otherwise 8. @@ -132,32 +124,35 @@ public final class UnsafeUtil { final String jdkVer = System.getProperty("java.version"); final int[] p = parseJavaVersion(jdkVer); JDK = p[0] + "." + p[1]; - JDK8_OR_ABOVE = checkJavaVersion(JDK, p[0], p[1]); + JDK_MAJOR = (p[0] == 1) ? p[1] : p[0]; } private UnsafeUtil() {} + /** + * Returns first two number groups of the java version string. + * @param jdkVer the java version string from System.getProperty("java.version"). + * @return first two number groups of the java version string. + */ static int[] parseJavaVersion(final String jdkVer) { + final int p0, p1; try { - String[] parts = jdkVer.trim().split("[^0-9\\.]"); - if (parts.length == 0) { - throw new ExceptionInInitializerError("Improper Java -version string: " + jdkVer); - } - parts = parts[0].split("\\."); - final int p0 = Integer.parseInt(parts[0]); - final int p1 = (parts.length > 1) ? Integer.parseInt(parts[1]) : 0; - return new int[] {p0, p1}; + String[] parts = jdkVer.trim().split("[^0-9\\.]");//grab only number groups and "." + parts = parts[0].split("\\."); //split out the number groups + p0 = Integer.parseInt(parts[0]); //the first number group + p1 = (parts.length > 1) ? Integer.parseInt(parts[1]) : 0; //2nd number group, or 0 } catch (final Exception e) { - throw new ExceptionInInitializerError("Improper Java -version string: " - + jdkVer + "\n" + e); + throw new ExceptionInInitializerError("Improper Java -version string: " + jdkVer + "\n" + e); } + checkJavaVersion(jdkVer, p0, p1); + return new int[] {p0, p1}; } - static boolean checkJavaVersion(final String jdk, final int p0, final int p1) { - if ( (p0 < 1) || ((p0 == 1) && (p1 < 7)) ) { - throw new ExceptionInInitializerError("JDK Major Version must be >= 1.7: " + jdk); + static void checkJavaVersion(final String jdkVer, final int p0, final int p1) { + if ( (p0 < 1) || ((p0 == 1) && (p1 < 8)) || (p0 >= 9) ) { + throw new ExceptionInInitializerError( + "Unsupported JDK Major Version, must be 1.8: " + jdkVer); } - return !( (p0 == 1) && (p1 == 7) ); } static long getFieldOffset(final Class<?> c, final String fieldName) { diff --git a/src/main/java/org/apache/datasketches/memory/WritableMemoryImpl.java b/src/main/java/org/apache/datasketches/memory/WritableMemoryImpl.java index ec0442a..9a5f812 100644 --- a/src/main/java/org/apache/datasketches/memory/WritableMemoryImpl.java +++ b/src/main/java/org/apache/datasketches/memory/WritableMemoryImpl.java @@ -308,22 +308,14 @@ abstract class WritableMemoryImpl extends BaseWritableMemoryImpl { public long getAndAddLong(final long offsetBytes, final long delta) { //JDK 8+ assertValidAndBoundsForWrite(offsetBytes, ARRAY_LONG_INDEX_SCALE); final long addr = getCumulativeOffset(offsetBytes); - if (UnsafeUtil.JDK8_OR_ABOVE) { - return unsafe.getAndAddLong(getUnsafeObject(), addr, delta); - } else { - return JDK7Compatible.getAndAddLong(getUnsafeObject(), addr, delta); - } + return unsafe.getAndAddLong(getUnsafeObject(), addr, delta); } @Override public long getAndSetLong(final long offsetBytes, final long newValue) { //JDK 8+ assertValidAndBoundsForWrite(offsetBytes, ARRAY_LONG_INDEX_SCALE); final long addr = getCumulativeOffset(offsetBytes); - if (UnsafeUtil.JDK8_OR_ABOVE) { - return unsafe.getAndSetLong(getUnsafeObject(), addr, newValue); - } else { - return JDK7Compatible.getAndSetLong(getUnsafeObject(), addr, newValue); - } + return unsafe.getAndSetLong(getUnsafeObject(), addr, newValue); } @Override diff --git a/src/test/java/org/apache/datasketches/memory/UnsafeUtilTest.java b/src/test/java/org/apache/datasketches/memory/UnsafeUtilTest.java index b7c18c9..2afa8e3 100644 --- a/src/test/java/org/apache/datasketches/memory/UnsafeUtilTest.java +++ b/src/test/java/org/apache/datasketches/memory/UnsafeUtilTest.java @@ -20,7 +20,6 @@ package org.apache.datasketches.memory; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; @@ -54,16 +53,31 @@ public class UnsafeUtilTest { public void checkJdkString() { String jdkVer; int[] p = new int[2]; - String[] good1_8Strings = {"1.8.0_121", "1.8.0_162", "9.0.4", "10.0.1", "11", "12b", "12_.2"}; + String[] good1_8Strings = {"1.8.0_121", "1.8.0_162"}; int len = good1_8Strings.length; for (int i = 0; i < len; i++) { jdkVer = good1_8Strings[i]; p = UnsafeUtil.parseJavaVersion(jdkVer); - assertTrue(UnsafeUtil.checkJavaVersion(jdkVer, p[0], p[1])); + UnsafeUtil.checkJavaVersion(jdkVer, p[0], p[1]); + int jdkMajor = (p[0] == 1) ? p[1] : p[0]; //model the actual JDK_MAJOR + if (p[0] == 1) { assertTrue(jdkMajor == p[1]); } + if (p[0] > 1 ) { assertTrue(jdkMajor == p[0]); } + } + try { + jdkVer = "9.0.4"; //ver 9 string + p = UnsafeUtil.parseJavaVersion(jdkVer); + UnsafeUtil.checkJavaVersion(jdkVer, p[0], p[1]); + } catch (Error e) { + println("" + e); + } + + try { + jdkVer = "1.7.0_80"; //1.7 string + p = UnsafeUtil.parseJavaVersion(jdkVer); + UnsafeUtil.checkJavaVersion(jdkVer, p[0], p[1]); + } catch (Error e) { + println("" + e); } - jdkVer = "1.7.0_80"; //1.7 string - p = UnsafeUtil.parseJavaVersion(jdkVer); - assertFalse(UnsafeUtil.checkJavaVersion(jdkVer, p[0], p[1])); try { jdkVer = "1.6.0_65"; //valid string but < 1.7 p = UnsafeUtil.parseJavaVersion(jdkVer); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
