diff --git a/ci.jsonnet b/ci.jsonnet
index 4aaa6a5b75f..dc61a36cb42 100644
--- a/ci.jsonnet
+++ b/ci.jsonnet
@@ -246,13 +246,13 @@ local contains(str, needle) = std.findSubstr(needle, str) != [];
# Downstream Graal branch to test against. If you change this value to anything but
# "master", you must create an ol-jira issue to change it back to master once the
# next JVMCI release has been made. Add the issue id as a comment here.
- local downstream_branch = "master",
+ local downstream_branch = "release/graal-vm/24.0",
local clone_graal(defs) = {
# Checkout the graal-enterprise repo to the "_gate" version of the
# named downstream branch. This ensures the graal-enterprise and
# graal repos will be in sync.
- local branch = if downstream_branch == "master" then "master" else downstream_branch + "_gate",
+ local branch = if downstream_branch == "release/graal-vm/24.0" then "release/graal-vm/24.0" else downstream_branch + "_gate",
run+: [
["git", "clone", defs.graal_enterprise_url],
diff --git a/src/hotspot/cpu/x86/assembler_x86.cpp b/src/hotspot/cpu/x86/assembler_x86.cpp
index cedddaed975..8a2b3aa0436 100644
--- a/src/hotspot/cpu/x86/assembler_x86.cpp
+++ b/src/hotspot/cpu/x86/assembler_x86.cpp
@@ -920,6 +920,7 @@ address Assembler::locate_operand(address inst, WhichOperand which) {
case 0x11: // movups
case 0x12: // movlps
case 0x28: // movaps
+ case 0x29: // movaps
case 0x2E: // ucomiss
case 0x2F: // comiss
case 0x54: // andps
@@ -969,7 +970,7 @@ address Assembler::locate_operand(address inst, WhichOperand which) {
assert(which == call32_operand, "jcc has no disp32 or imm");
return ip;
default:
- ShouldNotReachHere();
+ fatal("not handled: 0x0F%2X", 0xFF & *(ip-1));
}
break;
diff --git a/src/hotspot/share/cds/cdsConfig.hpp b/src/hotspot/share/cds/cdsConfig.hpp
index d7de147d20c..ec5352b3703 100644
--- a/src/hotspot/share/cds/cdsConfig.hpp
+++ b/src/hotspot/share/cds/cdsConfig.hpp
@@ -52,7 +52,7 @@ class CDSConfig : public AllStatic {
static void initialize() NOT_CDS_RETURN;
static void check_system_property(const char* key, const char* value) NOT_CDS_RETURN;
static void check_unsupported_dumping_properties() NOT_CDS_RETURN;
- static bool check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line) NOT_CDS_RETURN_(false);
+ static bool check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line) NOT_CDS_RETURN_(true);
// Basic CDS features
static bool is_dumping_archive() { return is_dumping_static_archive() || is_dumping_dynamic_archive(); }
diff --git a/src/hotspot/share/prims/unsafe.cpp b/src/hotspot/share/prims/unsafe.cpp
index ece60d32f9a..1a05c0fa13e 100644
--- a/src/hotspot/share/prims/unsafe.cpp
+++ b/src/hotspot/share/prims/unsafe.cpp
@@ -390,7 +390,10 @@ UNSAFE_ENTRY_SCOPED(void, Unsafe_SetMemory0(JNIEnv *env, jobject unsafe, jobject
oop base = JNIHandles::resolve(obj);
void* p = index_oop_from_field_offset_long(base, offset);
- Copy::fill_to_memory_atomic(p, sz, value);
+ {
+ GuardUnsafeAccess guard(thread);
+ Copy::fill_to_memory_atomic(p, sz, value);
+ }
} UNSAFE_END
UNSAFE_ENTRY_SCOPED(void, Unsafe_CopyMemory0(JNIEnv *env, jobject unsafe, jobject srcObj, jlong srcOffset, jobject dstObj, jlong dstOffset, jlong size)) {
diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleAttribute.java
index 05c1e792d9e..721719d2851 100644
--- a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleAttribute.java
+++ b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleAttribute.java
@@ -202,7 +202,7 @@ default ModuleAttributeBuilder moduleFlags(AccessFlag... moduleFlags) {
}
/**
- * Sets the module flags
+ * Sets the module version
* @param version the module version
* @return this builder
*/
diff --git a/src/java.base/share/classes/java/lang/foreign/MemoryLayout.java b/src/java.base/share/classes/java/lang/foreign/MemoryLayout.java
index 0933c637acb..321d9b09bad 100644
--- a/src/java.base/share/classes/java/lang/foreign/MemoryLayout.java
+++ b/src/java.base/share/classes/java/lang/foreign/MemoryLayout.java
@@ -631,6 +631,9 @@ public sealed interface MemoryLayout
*
The accessed memory segment must be
* {@link MemorySegment#isAccessibleBy(Thread) accessible} from the thread
* performing the access operation, or a {@link WrongThreadException} is thrown.
+ *
For write operations, the accessed memory segment must not be
+ * {@link MemorySegment#isReadOnly() read only}, or an
+ * {@link IllegalArgumentException} is thrown.
*
The {@linkplain MemorySegment#scope() scope} associated with the accessed
* segment must be {@linkplain MemorySegment.Scope#isAlive() alive}, or an
* {@link IllegalStateException} is thrown.
diff --git a/src/java.base/share/classes/java/lang/foreign/MemorySegment.java b/src/java.base/share/classes/java/lang/foreign/MemorySegment.java
index 0b0a2e136cb..da255b9912b 100644
--- a/src/java.base/share/classes/java/lang/foreign/MemorySegment.java
+++ b/src/java.base/share/classes/java/lang/foreign/MemorySegment.java
@@ -869,7 +869,7 @@ MemorySegment reinterpret(long newSize,
* this segment is not {@linkplain Scope#isAlive() alive}
* @throws WrongThreadException if this method is called from a thread {@code T},
* such that {@code isAccessibleBy(T) == false}
- * @throws UnsupportedOperationException if this segment is
+ * @throws IllegalArgumentException if this segment is
* {@linkplain #isReadOnly() read-only}
*/
MemorySegment fill(byte value);
@@ -894,7 +894,7 @@ MemorySegment reinterpret(long newSize,
* {@code src} is not {@linkplain Scope#isAlive() alive}
* @throws WrongThreadException if this method is called from a thread {@code T},
* such that {@code src.isAccessibleBy(T) == false}
- * @throws UnsupportedOperationException if this segment is
+ * @throws IllegalArgumentException if this segment is
* {@linkplain #isReadOnly() read-only}
* @return this segment
*/
@@ -1269,6 +1269,8 @@ MemorySegment reinterpret(long newSize,
* this segment is not {@linkplain Scope#isAlive() alive}
* @throws WrongThreadException if this method is called from a thread {@code T},
* such that {@code isAccessibleBy(T) == false}
+ * @throws IllegalArgumentException if this segment is
+ * {@linkplain #isReadOnly() read-only}
*/
void setString(long offset, String str);
@@ -1306,6 +1308,8 @@ MemorySegment reinterpret(long newSize,
* such that {@code isAccessibleBy(T) == false}
* @throws IllegalArgumentException if {@code charset} is not a
* {@linkplain StandardCharsets standard charset}
+ * @throws IllegalArgumentException if this segment is
+ * {@linkplain #isReadOnly() read-only}
*/
void setString(long offset, String str, Charset charset);
@@ -1493,7 +1497,7 @@ static MemorySegment ofAddress(long address) {
* @throws IndexOutOfBoundsException if {@code dstOffset > dstSegment.byteSize() - bytes}
* @throws IndexOutOfBoundsException if either {@code srcOffset},
* {@code dstOffset} or {@code bytes} are {@code < 0}
- * @throws UnsupportedOperationException if {@code dstSegment} is
+ * @throws IllegalArgumentException if {@code dstSegment} is
* {@linkplain #isReadOnly() read-only}
*/
@ForceInline
@@ -1552,7 +1556,7 @@ static void copy(MemorySegment srcSegment, long srcOffset,
* {@code dstSegment} is not {@linkplain Scope#isAlive() alive}
* @throws WrongThreadException if this method is called from a thread {@code T},
* such that {@code dstSegment.isAccessibleBy(T) == false}
- * @throws UnsupportedOperationException if {@code dstSegment} is {@linkplain #isReadOnly() read-only}
+ * @throws IllegalArgumentException if {@code dstSegment} is {@linkplain #isReadOnly() read-only}
* @throws IndexOutOfBoundsException if {@code elementCount * srcLayout.byteSize()} overflows
* @throws IndexOutOfBoundsException if {@code elementCount * dtsLayout.byteSize()} overflows
* @throws IndexOutOfBoundsException if {@code srcOffset > srcSegment.byteSize() - (elementCount * srcLayout.byteSize())}
@@ -1605,7 +1609,7 @@ static void copy(MemorySegment srcSegment, ValueLayout srcElementLayout, long sr
* incompatible with the alignment constraint
* in the provided layout
* @throws IndexOutOfBoundsException if {@code offset > byteSize() - layout.byteSize()}
- * @throws UnsupportedOperationException if this segment is
+ * @throws IllegalArgumentException if this segment is
* {@linkplain #isReadOnly() read-only}
*/
void set(ValueLayout.OfByte layout, long offset, byte value);
@@ -1643,7 +1647,7 @@ static void copy(MemorySegment srcSegment, ValueLayout srcElementLayout, long sr
* incompatible with the alignment constraint
* in the provided layout
* @throws IndexOutOfBoundsException if {@code offset > byteSize() - layout.byteSize()}
- * @throws UnsupportedOperationException if this segment is
+ * @throws IllegalArgumentException if this segment is
* {@linkplain #isReadOnly() read-only}
*/
void set(ValueLayout.OfBoolean layout, long offset, boolean value);
@@ -1681,7 +1685,7 @@ static void copy(MemorySegment srcSegment, ValueLayout srcElementLayout, long sr
* incompatible with the alignment constraint
* in the provided layout
* @throws IndexOutOfBoundsException if {@code offset > byteSize() - layout.byteSize()}
- * @throws UnsupportedOperationException if this segment is
+ * @throws IllegalArgumentException if this segment is
* {@linkplain #isReadOnly() read-only}
*/
void set(ValueLayout.OfChar layout, long offset, char value);
@@ -1719,7 +1723,7 @@ static void copy(MemorySegment srcSegment, ValueLayout srcElementLayout, long sr
* incompatible with the alignment constraint
* in the provided layout
* @throws IndexOutOfBoundsException if {@code offset > byteSize() - layout.byteSize()}
- * @throws UnsupportedOperationException if this segment is
+ * @throws IllegalArgumentException if this segment is
* {@linkplain #isReadOnly() read-only}
*/
void set(ValueLayout.OfShort layout, long offset, short value);
@@ -1757,7 +1761,7 @@ static void copy(MemorySegment srcSegment, ValueLayout srcElementLayout, long sr
* incompatible with the alignment constraint
* in the provided layout
* @throws IndexOutOfBoundsException if {@code offset > byteSize() - layout.byteSize()}
- * @throws UnsupportedOperationException if this segment is
+ * @throws IllegalArgumentException if this segment is
* {@linkplain #isReadOnly() read-only}
*/
void set(ValueLayout.OfInt layout, long offset, int value);
@@ -1795,7 +1799,7 @@ static void copy(MemorySegment srcSegment, ValueLayout srcElementLayout, long sr
* incompatible with the alignment constraint
* in the provided layout
* @throws IndexOutOfBoundsException if {@code offset > byteSize() - layout.byteSize()}
- * @throws UnsupportedOperationException if this segment is
+ * @throws IllegalArgumentException if this segment is
* {@linkplain #isReadOnly() read-only}
*/
void set(ValueLayout.OfFloat layout, long offset, float value);
@@ -1833,7 +1837,7 @@ static void copy(MemorySegment srcSegment, ValueLayout srcElementLayout, long sr
* incompatible with the alignment constraint
* in the provided layout
* @throws IndexOutOfBoundsException if {@code offset > byteSize() - layout.byteSize()}
- * @throws UnsupportedOperationException if this segment is
+ * @throws IllegalArgumentException if this segment is
* {@linkplain #isReadOnly() read-only}
*/
void set(ValueLayout.OfLong layout, long offset, long value);
@@ -1871,7 +1875,7 @@ static void copy(MemorySegment srcSegment, ValueLayout srcElementLayout, long sr
* incompatible with the alignment constraint
* in the provided layout
* @throws IndexOutOfBoundsException if {@code offset > byteSize() - layout.byteSize()}
- * @throws UnsupportedOperationException if this segment is
+ * @throws IllegalArgumentException if this segment is
* {@linkplain #isReadOnly() read-only}
*/
void set(ValueLayout.OfDouble layout, long offset, double value);
@@ -1921,8 +1925,10 @@ static void copy(MemorySegment srcSegment, ValueLayout srcElementLayout, long sr
* @throws IndexOutOfBoundsException if {@code offset > byteSize() - layout.byteSize()}
* @throws UnsupportedOperationException if this segment is
* {@linkplain #isReadOnly() read-only}
- * @throws UnsupportedOperationException if {@code value} is not a
+ * @throws IllegalArgumentException if {@code value} is not a
* {@linkplain #isNative() native} segment
+ * @throws IllegalArgumentException if this segment is
+ * {@linkplain #isReadOnly() read-only}
*/
void set(AddressLayout layout, long offset, MemorySegment value);
@@ -2055,7 +2061,7 @@ static void copy(MemorySegment srcSegment, ValueLayout srcElementLayout, long sr
* @throws IllegalArgumentException if {@code layout.byteAlignment() > layout.byteSize()}
* @throws IndexOutOfBoundsException if {@code index * layout.byteSize()} overflows
* @throws IndexOutOfBoundsException if {@code index * layout.byteSize() > byteSize() - layout.byteSize()}
- * @throws UnsupportedOperationException if this segment is {@linkplain #isReadOnly() read-only}
+ * @throws IllegalArgumentException if this segment is {@linkplain #isReadOnly() read-only}
*/
void setAtIndex(ValueLayout.OfByte layout, long index, byte value);
@@ -2078,7 +2084,7 @@ static void copy(MemorySegment srcSegment, ValueLayout srcElementLayout, long sr
* @throws IllegalArgumentException if {@code layout.byteAlignment() > layout.byteSize()}
* @throws IndexOutOfBoundsException if {@code index * layout.byteSize()} overflows
* @throws IndexOutOfBoundsException if {@code index * layout.byteSize() > byteSize() - layout.byteSize()}
- * @throws UnsupportedOperationException if this segment is {@linkplain #isReadOnly() read-only}
+ * @throws IllegalArgumentException if this segment is {@linkplain #isReadOnly() read-only}
*/
void setAtIndex(ValueLayout.OfBoolean layout, long index, boolean value);
@@ -2101,7 +2107,7 @@ static void copy(MemorySegment srcSegment, ValueLayout srcElementLayout, long sr
* @throws IllegalArgumentException if {@code layout.byteAlignment() > layout.byteSize()}
* @throws IndexOutOfBoundsException if {@code index * layout.byteSize()} overflows
* @throws IndexOutOfBoundsException if {@code index * layout.byteSize() > byteSize() - layout.byteSize()}
- * @throws UnsupportedOperationException if this segment is {@linkplain #isReadOnly() read-only}
+ * @throws IllegalArgumentException if this segment is {@linkplain #isReadOnly() read-only}
*/
void setAtIndex(ValueLayout.OfShort layout, long index, short value);
@@ -2146,7 +2152,7 @@ static void copy(MemorySegment srcSegment, ValueLayout srcElementLayout, long sr
* @throws IllegalArgumentException if {@code layout.byteAlignment() > layout.byteSize()}
* @throws IndexOutOfBoundsException if {@code index * layout.byteSize()} overflows
* @throws IndexOutOfBoundsException if {@code index * layout.byteSize() > byteSize() - layout.byteSize()}
- * @throws UnsupportedOperationException if this segment is {@linkplain #isReadOnly() read-only}
+ * @throws IllegalArgumentException if this segment is {@linkplain #isReadOnly() read-only}
*/
void setAtIndex(ValueLayout.OfInt layout, long index, int value);
@@ -2191,7 +2197,7 @@ static void copy(MemorySegment srcSegment, ValueLayout srcElementLayout, long sr
* @throws IllegalArgumentException if {@code layout.byteAlignment() > layout.byteSize()}
* @throws IndexOutOfBoundsException if {@code index * layout.byteSize()} overflows
* @throws IndexOutOfBoundsException if {@code index * layout.byteSize() > byteSize() - layout.byteSize()}
- * @throws UnsupportedOperationException if this segment is {@linkplain #isReadOnly() read-only}
+ * @throws IllegalArgumentException if this segment is {@linkplain #isReadOnly() read-only}
*/
void setAtIndex(ValueLayout.OfFloat layout, long index, float value);
@@ -2236,7 +2242,7 @@ static void copy(MemorySegment srcSegment, ValueLayout srcElementLayout, long sr
* @throws IllegalArgumentException if {@code layout.byteAlignment() > layout.byteSize()}
* @throws IndexOutOfBoundsException if {@code index * layout.byteSize()} overflows
* @throws IndexOutOfBoundsException if {@code index * layout.byteSize() > byteSize() - layout.byteSize()}
- * @throws UnsupportedOperationException if this segment is {@linkplain #isReadOnly() read-only}
+ * @throws IllegalArgumentException if this segment is {@linkplain #isReadOnly() read-only}
*/
void setAtIndex(ValueLayout.OfLong layout, long index, long value);
@@ -2281,7 +2287,7 @@ static void copy(MemorySegment srcSegment, ValueLayout srcElementLayout, long sr
* @throws IllegalArgumentException if {@code layout.byteAlignment() > layout.byteSize()}
* @throws IndexOutOfBoundsException if {@code index * layout.byteSize()} overflows
* @throws IndexOutOfBoundsException if {@code index * layout.byteSize() > byteSize() - layout.byteSize()}
- * @throws UnsupportedOperationException if this segment is {@linkplain #isReadOnly() read-only}
+ * @throws IllegalArgumentException if this segment is {@linkplain #isReadOnly() read-only}
*/
void setAtIndex(ValueLayout.OfDouble layout, long index, double value);
@@ -2336,7 +2342,9 @@ static void copy(MemorySegment srcSegment, ValueLayout srcElementLayout, long sr
* @throws IndexOutOfBoundsException if {@code index * layout.byteSize()} overflows
* @throws IndexOutOfBoundsException if {@code index * layout.byteSize() > byteSize() - layout.byteSize()}
* @throws UnsupportedOperationException if this segment is {@linkplain #isReadOnly() read-only}
- * @throws UnsupportedOperationException if {@code value} is not a {@linkplain #isNative() native} segment
+ * @throws IllegalArgumentException if {@code value} is not a {@linkplain #isNative() native} segment
+ * @throws IllegalArgumentException if this segment is
+ * {@linkplain #isReadOnly() read-only}
*/
void setAtIndex(AddressLayout layout, long index, MemorySegment value);
@@ -2460,7 +2468,7 @@ static void copy(MemorySegment srcSegment, ValueLayout srcLayout, long srcOffset
* incompatible with the alignment constraint
* in the source element layout
* @throws IllegalArgumentException if {@code dstLayout.byteAlignment() > dstLayout.byteSize()}
- * @throws UnsupportedOperationException if {@code dstSegment} is {@linkplain #isReadOnly() read-only}
+ * @throws IllegalArgumentException if {@code dstSegment} is {@linkplain #isReadOnly() read-only}
* @throws IndexOutOfBoundsException if {@code elementCount * dstLayout.byteSize()} overflows
* @throws IndexOutOfBoundsException if {@code dstOffset > dstSegment.byteSize() - (elementCount * dstLayout.byteSize())}
* @throws IndexOutOfBoundsException if {@code srcIndex > srcArray.length - elementCount}
diff --git a/src/java.base/share/classes/java/lang/foreign/SegmentAllocator.java b/src/java.base/share/classes/java/lang/foreign/SegmentAllocator.java
index a4977d62d00..6be9d949ea6 100644
--- a/src/java.base/share/classes/java/lang/foreign/SegmentAllocator.java
+++ b/src/java.base/share/classes/java/lang/foreign/SegmentAllocator.java
@@ -350,7 +350,7 @@ default MemorySegment allocateFrom(ValueLayout.OfDouble layout, double value) {
*
* @param layout the layout of the block of memory to be allocated
* @param value the value to be set in the newly allocated memory segment
- * @throws UnsupportedOperationException if {@code value} is not
+ * @throws IllegalArgumentException if {@code value} is not
* a {@linkplain MemorySegment#isNative() native} segment
*/
default MemorySegment allocateFrom(AddressLayout layout, MemorySegment value) {
@@ -670,9 +670,11 @@ default MemorySegment allocate(long byteSize) {
*
* @param segment the segment from which the returned allocator should slice from
* @return a new slicing allocator
+ * @throws IllegalArgumentException if the {@code segment} is
+ * {@linkplain MemorySegment#isReadOnly() read-only}
*/
static SegmentAllocator slicingAllocator(MemorySegment segment) {
- Objects.requireNonNull(segment);
+ assertWritable(segment);
return new SlicingAllocator(segment);
}
@@ -700,9 +702,19 @@ static SegmentAllocator slicingAllocator(MemorySegment segment) {
* @param segment the memory segment to be recycled by the returned allocator
* @return an allocator that recycles an existing segment upon each new
* allocation request
+ * @throws IllegalArgumentException if the {@code segment} is
+ * {@linkplain MemorySegment#isReadOnly() read-only}
*/
static SegmentAllocator prefixAllocator(MemorySegment segment) {
- return (AbstractMemorySegmentImpl)Objects.requireNonNull(segment);
+ assertWritable(segment);
+ return (AbstractMemorySegmentImpl)segment;
+ }
+
+ private static void assertWritable(MemorySegment segment) {
+ // Implicit null check
+ if (segment.isReadOnly()) {
+ throw new IllegalArgumentException("read-only segment");
+ }
}
@ForceInline
diff --git a/src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java b/src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java
index 2f902e57ee5..305594952d4 100644
--- a/src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java
+++ b/src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java
@@ -361,7 +361,7 @@ private Z toArray(Class arrayClass, ValueLayout elemLayout, IntFunction keyMap, String operation, String prevBinding
}
}
+ // JDK specific modification
+ @Override
+ public void zeroOut() {
+ buf.zeroOut();
+ parsedLine = null;
+ }
}
diff --git a/test/hotspot/jtreg/gc/g1/pinnedobjs/TestPinnedObjectTypes.java b/test/hotspot/jtreg/gc/g1/pinnedobjs/TestPinnedObjectTypes.java
index ff730a30106..1223bfdd027 100644
--- a/test/hotspot/jtreg/gc/g1/pinnedobjs/TestPinnedObjectTypes.java
+++ b/test/hotspot/jtreg/gc/g1/pinnedobjs/TestPinnedObjectTypes.java
@@ -52,6 +52,7 @@ private static void testPinning(String type, boolean shouldSucceed) throws Excep
"-XX:+UnlockDiagnosticVMOptions",
"-XX:+WhiteBoxAPI",
"-Xbootclasspath/a:.",
+ "-XX:-CreateCoredumpOnCrash",
"-Xmx32M",
"-Xmn16M",
"-Xlog:gc",
diff --git a/test/hotspot/jtreg/runtime/Unsafe/InternalErrorTest.java b/test/hotspot/jtreg/runtime/Unsafe/InternalErrorTest.java
index 57599cffd62..fcf48a7a2d7 100644
--- a/test/hotspot/jtreg/runtime/Unsafe/InternalErrorTest.java
+++ b/test/hotspot/jtreg/runtime/Unsafe/InternalErrorTest.java
@@ -41,6 +41,7 @@
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
+import java.lang.foreign.MemorySegment;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.MappedByteBuffer;
@@ -60,6 +61,8 @@ public class InternalErrorTest {
private static final String failureMsg1 = "InternalError not thrown";
private static final String failureMsg2 = "Wrong InternalError: ";
+ private static final int NUM_TESTS = 4;
+
public static void main(String[] args) throws Throwable {
Unsafe unsafe = Unsafe.getUnsafe();
@@ -71,9 +74,9 @@ public static void main(String[] args) throws Throwable {
s.append("1");
}
Files.write(file.toPath(), s.toString().getBytes());
- FileChannel fileChannel = new RandomAccessFile(file, "r").getChannel();
+ FileChannel fileChannel = new RandomAccessFile(file, "rw").getChannel();
MappedByteBuffer buffer =
- fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
+ fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, fileChannel.size());
// Get address of mapped memory.
long mapAddr = 0;
@@ -86,13 +89,13 @@ public static void main(String[] args) throws Throwable {
}
long allocMem = unsafe.allocateMemory(4000);
- for (int i = 0; i < 3; i++) {
+ for (int i = 0; i < NUM_TESTS; i++) {
test(buffer, unsafe, mapAddr, allocMem, i);
}
Files.write(file.toPath(), "2".getBytes());
buffer.position(buffer.position() + pageSize);
- for (int i = 0; i < 3; i++) {
+ for (int i = 0; i < NUM_TESTS; i++) {
try {
test(buffer, unsafe, mapAddr, allocMem, i);
WhiteBox.getWhiteBox().forceSafepoint();
@@ -107,7 +110,7 @@ public static void main(String[] args) throws Throwable {
Method m = InternalErrorTest.class.getMethod("test", MappedByteBuffer.class, Unsafe.class, long.class, long.class, int.class);
WhiteBox.getWhiteBox().enqueueMethodForCompilation(m, 3);
- for (int i = 0; i < 3; i++) {
+ for (int i = 0; i < NUM_TESTS; i++) {
try {
test(buffer, unsafe, mapAddr, allocMem, i);
WhiteBox.getWhiteBox().forceSafepoint();
@@ -121,7 +124,7 @@ public static void main(String[] args) throws Throwable {
WhiteBox.getWhiteBox().enqueueMethodForCompilation(m, 4);
- for (int i = 0; i < 3; i++) {
+ for (int i = 0; i < NUM_TESTS; i++) {
try {
test(buffer, unsafe, mapAddr, allocMem, i);
WhiteBox.getWhiteBox().forceSafepoint();
@@ -143,13 +146,18 @@ public static void test(MappedByteBuffer buffer, Unsafe unsafe, long mapAddr, lo
buffer.get(new byte[8]);
break;
case 1:
- // testing Unsafe.copySwapMemory, trying to access next page after truncation.
+ // testing Unsafe.copySwapMemory, trying to access next page after truncation.
unsafe.copySwapMemory(null, mapAddr + pageSize, new byte[4000], 16, 2000, 2);
break;
case 2:
- // testing Unsafe.copySwapMemory, trying to access next page after truncation.
+ // testing Unsafe.copySwapMemory, trying to access next page after truncation.
unsafe.copySwapMemory(null, mapAddr + pageSize, null, allocMem, 2000, 2);
break;
+ case 3:
+ MemorySegment segment = MemorySegment.ofBuffer(buffer);
+ // testing Unsafe.setMemory, trying to access next page after truncation.
+ segment.fill((byte) 0xF0);
+ break;
}
}
diff --git a/test/jdk/java/foreign/TestArrayCopy.java b/test/jdk/java/foreign/TestArrayCopy.java
index 0a04f00e4f5..9a1c48a394e 100644
--- a/test/jdk/java/foreign/TestArrayCopy.java
+++ b/test/jdk/java/foreign/TestArrayCopy.java
@@ -26,12 +26,9 @@
* @run testng TestArrayCopy
*/
-import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
-import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
import java.lang.invoke.VarHandle;
import java.nio.ByteOrder;
import java.util.ArrayList;
@@ -240,7 +237,7 @@ public void testCopyReadOnlyDest(CopyMode mode, CopyHelper