Skip to content

Commit 9fd3b45

Browse files
authored
Merge pull request #215 from apache/prepare_release_3.0.2-RC2
Prepare Release 3.0.2-RC2
2 parents 15eb875 + f9e083f commit 9fd3b45

File tree

5 files changed

+73
-107
lines changed

5 files changed

+73
-107
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Note: *primitive* = *{byte, short, int, long, float, double}*
5858
* **Memory-Mapped Files**
5959
* *WritableMemory.writableMap(File)* method.
6060

61-
# Release [3.0.0, 4.0.0)
61+
# Releases 3.0.0 (inclusive) to 4.0.0 (exclusive)
6262
These are transitional releases that also supports Java 8 and 11.
6363
However, the goal of this set of releases is to migrate the API to what it will be in release 4.0.0.
6464
The 4.0.0 release will require Java 17 and will utilize the Project Panama (FFM) capabilites introduced in Java 17.
@@ -79,7 +79,7 @@ It is our expectation that this set of releases will be the last that support Ja
7979

8080
The comments in the following section for releases [2.0.0, 3.0.0) still apply.
8181

82-
# Releases [2.0.0, 3.0.0)
82+
# Releases 2.0.0 (inclusive) to 3.0.0 (exclusive)
8383
Starting with release *datasketches-memory-2.0.0*, this Memory component supports Java 8 and 11. Providing access to the off-heap resources in Java 8 only requires reflection. However, **Java 9 introduced the Java Platform Module System (JPMS) where access to these internal classes requires starting up the JVM with special JPMS arguments.** The actual JVM arguments required will depend on how the user intends to use the Memory API, the Java version used to run the user's application and whether the user's application is a JPMS application or not.
8484

8585
Also see the [usage examples](docs/usage-examples.md) for more information.

datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*/
3838
@SuppressWarnings("restriction")
3939
public abstract class ResourceImpl implements Resource {
40-
static final String JDK; //must be at least "1.8"
40+
static final String JDK;
4141
static final int JDK_MAJOR; //8, 11, 17, etc
4242

4343
//Used to convert "type" to bytes: bytes = longs << LONG_SHIFT
@@ -141,10 +141,19 @@ public static void checkBounds(final long reqOff, final long reqLen, final long
141141
}
142142
}
143143

144+
/**
145+
* Checks the runtime Java Version string. Note that Java 17 and 21 is allowed only because some clients do not use the
146+
* WritableMemory.allocateDirect(..) and related functions, which will not work with Java versions >= 14.
147+
* The on-heap functions may work with 17 and 21, nonetheless, versions > Java 11 are not officially supported.
148+
* Caveat emptor.
149+
* @param jdkVer the <i>System.getProperty("java.version")</i> string of the form "p0.p1.X"
150+
* @param p0 The first number group
151+
* @param p1 The second number group
152+
*/
144153
static void checkJavaVersion(final String jdkVer, final int p0, final int p1 ) {
145-
final boolean ok = ((p0 == 1) && (p1 == 8)) || (p0 == 8) || (p0 == 11) || (p0 == 17);
154+
final boolean ok = ((p0 == 1) && (p1 == 8)) || (p0 == 8) || (p0 == 11) || (p0 == 17 || (p0 == 21));
146155
if (!ok) { throw new IllegalArgumentException(
147-
"Unsupported JDK Major Version. It must be one of 1.8, 8, 11, 17: " + jdkVer);
156+
"Unsupported JDK Major Version. It must be one of 1.8, 8, 11, 17, 21: " + jdkVer);
148157
}
149158
}
150159

@@ -441,7 +450,7 @@ static final String toHex(final ResourceImpl state, final String preamble, final
441450
sb.append("Read Only : ").append(state.isReadOnly()).append(LS);
442451
sb.append("Type Byte Order : ").append(state.getTypeByteOrder().toString()).append(LS);
443452
sb.append("Native Byte Order : ").append(ByteOrder.nativeOrder().toString()).append(LS);
444-
sb.append("JDK Runtime Version : ").append(UnsafeUtil.JDK).append(LS);
453+
sb.append("JDK Runtime Version : ").append(JDK).append(LS);
445454
//Data detail
446455
if (withData) {
447456
sb.append("Data, bytes : 0 1 2 3 4 5 6 7");

datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/UnsafeUtil.java

-43
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
@SuppressWarnings({"restriction","javadoc"})
3333
public final class UnsafeUtil {
3434
public static final Unsafe unsafe;
35-
public static final String JDK; //must be at least "1.8"
36-
public static final int JDK_MAJOR; //8, 9, 10, 11, 12, etc
3735

3836
//not an indicator of whether compressed references are used.
3937
public static final int ADDRESS_SIZE;
@@ -115,51 +113,10 @@ public final class UnsafeUtil {
115113

116114
ARRAY_OBJECT_INDEX_SCALE = unsafe.arrayIndexScale(Object[].class);
117115
OBJECT_SHIFT = ARRAY_OBJECT_INDEX_SCALE == 4 ? 2 : 3;
118-
119-
final String jdkVer = System.getProperty("java.version");
120-
final int[] p = parseJavaVersion(jdkVer);
121-
JDK = p[0] + "." + p[1];
122-
JDK_MAJOR = (p[0] == 1) ? p[1] : p[0];
123116
}
124117

125118
private UnsafeUtil() {}
126119

127-
/**
128-
* Returns first two number groups of the java version string.
129-
* @param jdkVer the java version string from System.getProperty("java.version").
130-
* @return first two number groups of the java version string.
131-
*/
132-
public static int[] parseJavaVersion(final String jdkVer) {
133-
final int p0, p1;
134-
try {
135-
String[] parts = jdkVer.trim().split("[^0-9\\.]");//grab only number groups and "."
136-
parts = parts[0].split("\\."); //split out the number groups
137-
p0 = Integer.parseInt(parts[0]); //the first number group
138-
p1 = (parts.length > 1) ? Integer.parseInt(parts[1]) : 0; //2nd number group, or 0
139-
} catch (final NumberFormatException | ArrayIndexOutOfBoundsException e) {
140-
throw new IllegalArgumentException("Improper Java -version string: " + jdkVer + LS + e);
141-
}
142-
checkJavaVersion(jdkVer, p0, p1);
143-
return new int[] {p0, p1};
144-
}
145-
146-
/**
147-
* Checks the runtime Java Version string. Note that Java 17 and 21 is allowed only because some clients do not use the
148-
* WritableMemory.allocateDirect(..) and related functions, which will not work with Java versions >= 14.
149-
* The on-heap functions may work with 17 and 21, nonetheless, versions > Java 11 are not officially supported.
150-
* Caveat emptor.
151-
* @param jdkVer the <i>System.getProperty("java.version")</i> string of the form "p0.p1.X"
152-
* @param p0 The first number group
153-
* @param p1 The second number group
154-
*/
155-
public static void checkJavaVersion(final String jdkVer, final int p0, final int p1) {
156-
final boolean ok = ( ((p0 == 1) && (p1 == 8)) || (p0 == 8) || (p0 == 11) || (p0 == 17) || (p0 == 21));
157-
if (!ok) {
158-
throw new IllegalArgumentException(
159-
"Unsupported Runtime JDK Major Version, must be one of 1.8, 8, 11, 17, 21: " + jdkVer);
160-
}
161-
}
162-
163120
/**
164121
* Gets the <i>unsafe.objectFieldOffset(..)</i> for declared fields of a class.
165122
* @param c the class

datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/ResourceTest.java

+58
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,64 @@ public void checkTypeDecode() {
121121
}
122122
}
123123

124+
@Test
125+
public void checkJdkString() {
126+
String jdkVer;
127+
int[] p = new int[2];
128+
String[] good1_Strings = {"1.8.0_121", "8", "11", "17", "21"};
129+
int len = good1_Strings.length;
130+
for (int i = 0; i < len; i++) {
131+
jdkVer = good1_Strings[i];
132+
p = ResourceImpl.parseJavaVersion(jdkVer);
133+
ResourceImpl.checkJavaVersion(jdkVer, p[0], p[1]);
134+
int jdkMajor = (p[0] == 1) ? p[1] : p[0]; //model the actual JDK_MAJOR
135+
if (p[0] == 1) { assertTrue(jdkMajor == p[1]); }
136+
if (p[0] > 1 ) { assertTrue(jdkMajor == p[0]); }
137+
}
138+
try {
139+
jdkVer = "14.0.4";
140+
p = ResourceImpl.parseJavaVersion(jdkVer);
141+
ResourceImpl.checkJavaVersion(jdkVer, p[0], p[1]);
142+
fail();
143+
} catch (IllegalArgumentException e) {
144+
println("" + e);
145+
}
146+
147+
try {
148+
jdkVer = "1.7.0_80";
149+
p = ResourceImpl.parseJavaVersion(jdkVer);
150+
ResourceImpl.checkJavaVersion(jdkVer, p[0], p[1]);
151+
fail();
152+
} catch (IllegalArgumentException e) {
153+
println("" + e);
154+
}
155+
try {
156+
jdkVer = "1.6.0_65";
157+
p = ResourceImpl.parseJavaVersion(jdkVer);
158+
ResourceImpl.checkJavaVersion(jdkVer, p[0], p[1]); //throws
159+
fail();
160+
} catch (IllegalArgumentException e) {
161+
println("" + e);
162+
}
163+
try {
164+
jdkVer = "b"; //invalid string
165+
p = ResourceImpl.parseJavaVersion(jdkVer);
166+
ResourceImpl.checkJavaVersion(jdkVer, p[0], p[1]); //throws
167+
fail();
168+
} catch (IllegalArgumentException e) {
169+
println("" + e);
170+
}
171+
try {
172+
jdkVer = ""; //invalid string
173+
p = ResourceImpl.parseJavaVersion(jdkVer);
174+
ResourceImpl.checkJavaVersion(jdkVer, p[0], p[1]); //throws
175+
fail();
176+
} catch (IllegalArgumentException e) {
177+
println("" + e);
178+
}
179+
}
180+
181+
124182
/********************/
125183
@Test
126184
public void printlnTest() {

datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/UnsafeUtilTest.java

-58
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.apache.datasketches.memory.internal;
2121

2222
import static org.testng.Assert.assertEquals;
23-
import static org.testng.Assert.assertTrue;
2423
import static org.testng.Assert.fail;
2524

2625
import java.util.ArrayList;
@@ -34,63 +33,6 @@
3433
public class UnsafeUtilTest {
3534
long testField = 1; //Do not remove & cannot be static. Used in reflection check.
3635

37-
@Test
38-
public void checkJdkString() {
39-
String jdkVer;
40-
int[] p = new int[2];
41-
String[] good1_Strings = {"1.8.0_121", "8", "11", "17"};
42-
int len = good1_Strings.length;
43-
for (int i = 0; i < len; i++) {
44-
jdkVer = good1_Strings[i];
45-
p = UnsafeUtil.parseJavaVersion(jdkVer);
46-
UnsafeUtil.checkJavaVersion(jdkVer, p[0], p[1]);
47-
int jdkMajor = (p[0] == 1) ? p[1] : p[0]; //model the actual JDK_MAJOR
48-
if (p[0] == 1) { assertTrue(jdkMajor == p[1]); }
49-
if (p[0] > 1 ) { assertTrue(jdkMajor == p[0]); }
50-
}
51-
try {
52-
jdkVer = "14.0.4"; //ver 14 string
53-
p = UnsafeUtil.parseJavaVersion(jdkVer);
54-
UnsafeUtil.checkJavaVersion(jdkVer, p[0], p[1]);
55-
fail();
56-
} catch (IllegalArgumentException e) {
57-
println("" + e);
58-
}
59-
60-
try {
61-
jdkVer = "1.7.0_80"; //1.7 string
62-
p = UnsafeUtil.parseJavaVersion(jdkVer);
63-
UnsafeUtil.checkJavaVersion(jdkVer, p[0], p[1]);
64-
fail();
65-
} catch (IllegalArgumentException e) {
66-
println("" + e);
67-
}
68-
try {
69-
jdkVer = "1.6.0_65"; //valid string but < 1.7
70-
p = UnsafeUtil.parseJavaVersion(jdkVer);
71-
UnsafeUtil.checkJavaVersion(jdkVer, p[0], p[1]); //throws
72-
fail();
73-
} catch (IllegalArgumentException e) {
74-
println("" + e);
75-
}
76-
try {
77-
jdkVer = "b"; //invalid string
78-
p = UnsafeUtil.parseJavaVersion(jdkVer);
79-
UnsafeUtil.checkJavaVersion(jdkVer, p[0], p[1]); //throws
80-
fail();
81-
} catch (IllegalArgumentException e) {
82-
println("" + e);
83-
}
84-
try {
85-
jdkVer = ""; //invalid string
86-
p = UnsafeUtil.parseJavaVersion(jdkVer);
87-
UnsafeUtil.checkJavaVersion(jdkVer, p[0], p[1]); //throws
88-
fail();
89-
} catch (IllegalArgumentException e) {
90-
println("" + e);
91-
}
92-
}
93-
9436
@Test
9537
public void checkFieldOffset() {
9638
assertEquals(testField, 1);

0 commit comments

Comments
 (0)