Summary
Clarify specification of Unsafe.allocateMemory
as to when the return value may be zero.
Problem
The specification of Unsafe.allocateMemory
states
"The resulting native pointer will never be zero"
which is not true.
Solution
Revise specification of Unsafe.allocateMemory
to state that zero is returned if and only if the requested size is zero.
Specification
--- a/src/java.base/share/classes/jdk/internal/misc/Unsafe.java
+++ b/src/java.base/share/classes/jdk/internal/misc/Unsafe.java
@@ -597,9 +597,10 @@ private long alignToHeapWordSize(long bytes) {
/**
* Allocates a new block of native memory, of the given size in bytes. The
* contents of the memory are uninitialized; they will generally be
- * garbage. The resulting native pointer will never be zero, and will be
- * aligned for all value types. Dispose of this memory by calling {@link
- * #freeMemory}, or resize it with {@link #reallocateMemory}.
+ * garbage. The resulting native pointer will be zero if and only if the
+ * requested size is zero. The resulting native pointer will be aligned for
+ * all value types. Dispose of this memory by calling {@link #freeMemory}
+ * or resize it with {@link #reallocateMemory}.
*
* <em>Note:</em> It is the responsibility of the caller to make
* sure arguments are checked before the methods are called. While
--- a/src/jdk.unsupported/share/classes/sun/misc/Unsafe.java
+++ b/src/jdk.unsupported/share/classes/sun/misc/Unsafe.java
@@ -436,9 +436,10 @@ public void putAddress(long address, long x) {
/**
* Allocates a new block of native memory, of the given size in bytes. The
* contents of the memory are uninitialized; they will generally be
- * garbage. The resulting native pointer will never be zero, and will be
- * aligned for all value types. Dispose of this memory by calling {@link
- * #freeMemory}, or resize it with {@link #reallocateMemory}.
+ * garbage. The resulting native pointer will be zero if and only if the
+ * requested size is zero. The resulting native pointer will be aligned for
+ * all value types. Dispose of this memory by calling {@link #freeMemory}
+ * or resize it with {@link #reallocateMemory}.
*
* <em>Note:</em> It is the responsibility of the caller to make
* sure arguments are checked before the methods are called. While
- csr of
-
JDK-8324960 Unsafe.allocateMemory documentation incorrect regarding zero return value
- Resolved