8345119: Some java/foreign tests wrongly assume aligned memory
Reviewed-by: mcimadamore, jvernee
This commit is contained in:
parent
1a07d542ec
commit
ce9d543eb1
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -171,7 +171,7 @@ public class TestByteBuffer {
|
|||||||
@Test
|
@Test
|
||||||
public void testOffheap() {
|
public void testOffheap() {
|
||||||
try (Arena arena = Arena.ofConfined()) {
|
try (Arena arena = Arena.ofConfined()) {
|
||||||
MemorySegment segment = arena.allocate(tuples);;
|
MemorySegment segment = arena.allocate(tuples);
|
||||||
initTuples(segment, tuples.elementCount());
|
initTuples(segment, tuples.elementCount());
|
||||||
|
|
||||||
ByteBuffer bb = segment.asByteBuffer();
|
ByteBuffer bb = segment.asByteBuffer();
|
||||||
@ -385,7 +385,7 @@ public class TestByteBuffer {
|
|||||||
public void testScopedBuffer(Function<ByteBuffer, Buffer> bufferFactory, @NoInjection Method method, Object[] args) {
|
public void testScopedBuffer(Function<ByteBuffer, Buffer> bufferFactory, @NoInjection Method method, Object[] args) {
|
||||||
Buffer bb;
|
Buffer bb;
|
||||||
try (Arena arena = Arena.ofConfined()) {
|
try (Arena arena = Arena.ofConfined()) {
|
||||||
MemorySegment segment = arena.allocate(bytes);;
|
MemorySegment segment = arena.allocate(bytes);
|
||||||
bb = bufferFactory.apply(segment.asByteBuffer());
|
bb = bufferFactory.apply(segment.asByteBuffer());
|
||||||
}
|
}
|
||||||
//outside of session!!
|
//outside of session!!
|
||||||
@ -411,7 +411,7 @@ public class TestByteBuffer {
|
|||||||
public void testScopedBufferAndVarHandle(VarHandle bufferHandle) {
|
public void testScopedBufferAndVarHandle(VarHandle bufferHandle) {
|
||||||
ByteBuffer bb;
|
ByteBuffer bb;
|
||||||
try (Arena arena = Arena.ofConfined()) {
|
try (Arena arena = Arena.ofConfined()) {
|
||||||
MemorySegment segment = arena.allocate(bytes);;
|
MemorySegment segment = arena.allocate(bytes, Long.BYTES);
|
||||||
bb = segment.asByteBuffer();
|
bb = segment.asByteBuffer();
|
||||||
for (Map.Entry<MethodHandle, Object[]> e : varHandleMembers(bb, bufferHandle).entrySet()) {
|
for (Map.Entry<MethodHandle, Object[]> e : varHandleMembers(bb, bufferHandle).entrySet()) {
|
||||||
MethodHandle handle = e.getKey().bindTo(bufferHandle)
|
MethodHandle handle = e.getKey().bindTo(bufferHandle)
|
||||||
@ -445,7 +445,7 @@ public class TestByteBuffer {
|
|||||||
@Test(dataProvider = "bufferOps")
|
@Test(dataProvider = "bufferOps")
|
||||||
public void testDirectBuffer(Function<ByteBuffer, Buffer> bufferFactory, @NoInjection Method method, Object[] args) {
|
public void testDirectBuffer(Function<ByteBuffer, Buffer> bufferFactory, @NoInjection Method method, Object[] args) {
|
||||||
try (Arena arena = Arena.ofConfined()) {
|
try (Arena arena = Arena.ofConfined()) {
|
||||||
MemorySegment segment = arena.allocate(bytes);;
|
MemorySegment segment = arena.allocate(bytes);
|
||||||
Buffer bb = bufferFactory.apply(segment.asByteBuffer());
|
Buffer bb = bufferFactory.apply(segment.asByteBuffer());
|
||||||
assertTrue(bb.isDirect());
|
assertTrue(bb.isDirect());
|
||||||
DirectBuffer directBuffer = ((DirectBuffer)bb);
|
DirectBuffer directBuffer = ((DirectBuffer)bb);
|
||||||
@ -458,7 +458,7 @@ public class TestByteBuffer {
|
|||||||
@Test(dataProvider="resizeOps")
|
@Test(dataProvider="resizeOps")
|
||||||
public void testResizeOffheap(Consumer<MemorySegment> checker, Consumer<MemorySegment> initializer, SequenceLayout seq) {
|
public void testResizeOffheap(Consumer<MemorySegment> checker, Consumer<MemorySegment> initializer, SequenceLayout seq) {
|
||||||
try (Arena arena = Arena.ofConfined()) {
|
try (Arena arena = Arena.ofConfined()) {
|
||||||
MemorySegment segment = arena.allocate(seq);;
|
MemorySegment segment = arena.allocate(seq);
|
||||||
initializer.accept(segment);
|
initializer.accept(segment);
|
||||||
checker.accept(segment);
|
checker.accept(segment);
|
||||||
}
|
}
|
||||||
@ -496,7 +496,7 @@ public class TestByteBuffer {
|
|||||||
@Test(dataProvider="resizeOps")
|
@Test(dataProvider="resizeOps")
|
||||||
public void testResizeRoundtripNative(Consumer<MemorySegment> checker, Consumer<MemorySegment> initializer, SequenceLayout seq) {
|
public void testResizeRoundtripNative(Consumer<MemorySegment> checker, Consumer<MemorySegment> initializer, SequenceLayout seq) {
|
||||||
try (Arena arena = Arena.ofConfined()) {
|
try (Arena arena = Arena.ofConfined()) {
|
||||||
MemorySegment segment = arena.allocate(seq);;
|
MemorySegment segment = arena.allocate(seq);
|
||||||
initializer.accept(segment);
|
initializer.accept(segment);
|
||||||
MemorySegment second = MemorySegment.ofBuffer(segment.asByteBuffer());
|
MemorySegment second = MemorySegment.ofBuffer(segment.asByteBuffer());
|
||||||
checker.accept(second);
|
checker.accept(second);
|
||||||
@ -507,7 +507,7 @@ public class TestByteBuffer {
|
|||||||
public void testBufferOnClosedSession() {
|
public void testBufferOnClosedSession() {
|
||||||
MemorySegment leaked;
|
MemorySegment leaked;
|
||||||
try (Arena arena = Arena.ofConfined()) {
|
try (Arena arena = Arena.ofConfined()) {
|
||||||
leaked = arena.allocate(bytes);;
|
leaked = arena.allocate(bytes);
|
||||||
}
|
}
|
||||||
ByteBuffer byteBuffer = leaked.asByteBuffer(); // ok
|
ByteBuffer byteBuffer = leaked.asByteBuffer(); // ok
|
||||||
byteBuffer.get(); // should throw
|
byteBuffer.get(); // should throw
|
||||||
@ -615,7 +615,7 @@ public class TestByteBuffer {
|
|||||||
checkByteArrayAlignment(seq.elementLayout());
|
checkByteArrayAlignment(seq.elementLayout());
|
||||||
int bytes = (int)seq.byteSize();
|
int bytes = (int)seq.byteSize();
|
||||||
try (Arena arena = Arena.ofConfined()) {
|
try (Arena arena = Arena.ofConfined()) {
|
||||||
MemorySegment nativeArray = arena.allocate(bytes, 1);;
|
MemorySegment nativeArray = arena.allocate(bytes, 1);
|
||||||
MemorySegment heapArray = MemorySegment.ofArray(new byte[bytes]);
|
MemorySegment heapArray = MemorySegment.ofArray(new byte[bytes]);
|
||||||
initializer.accept(heapArray);
|
initializer.accept(heapArray);
|
||||||
nativeArray.copyFrom(heapArray);
|
nativeArray.copyFrom(heapArray);
|
||||||
@ -628,7 +628,7 @@ public class TestByteBuffer {
|
|||||||
checkByteArrayAlignment(seq.elementLayout());
|
checkByteArrayAlignment(seq.elementLayout());
|
||||||
int bytes = (int)seq.byteSize();
|
int bytes = (int)seq.byteSize();
|
||||||
try (Arena arena = Arena.ofConfined()) {
|
try (Arena arena = Arena.ofConfined()) {
|
||||||
MemorySegment nativeArray = arena.allocate(seq);;
|
MemorySegment nativeArray = arena.allocate(seq);
|
||||||
MemorySegment heapArray = MemorySegment.ofArray(new byte[bytes]);
|
MemorySegment heapArray = MemorySegment.ofArray(new byte[bytes]);
|
||||||
initializer.accept(nativeArray);
|
initializer.accept(nativeArray);
|
||||||
heapArray.copyFrom(nativeArray);
|
heapArray.copyFrom(nativeArray);
|
||||||
@ -700,7 +700,7 @@ public class TestByteBuffer {
|
|||||||
@Test
|
@Test
|
||||||
public void testRoundTripAccess() {
|
public void testRoundTripAccess() {
|
||||||
try (Arena arena = Arena.ofConfined()) {
|
try (Arena arena = Arena.ofConfined()) {
|
||||||
MemorySegment ms = arena.allocate(4, 1);;
|
MemorySegment ms = arena.allocate(4, 1);
|
||||||
MemorySegment msNoAccess = ms.asReadOnly();
|
MemorySegment msNoAccess = ms.asReadOnly();
|
||||||
MemorySegment msRoundTrip = MemorySegment.ofBuffer(msNoAccess.asByteBuffer());
|
MemorySegment msRoundTrip = MemorySegment.ofBuffer(msNoAccess.asByteBuffer());
|
||||||
assertEquals(msRoundTrip.scope(), ms.scope());
|
assertEquals(msRoundTrip.scope(), ms.scope());
|
||||||
@ -741,7 +741,7 @@ public class TestByteBuffer {
|
|||||||
tmp.deleteOnExit();
|
tmp.deleteOnExit();
|
||||||
try (FileChannel channel = FileChannel.open(tmp.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE) ;
|
try (FileChannel channel = FileChannel.open(tmp.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE) ;
|
||||||
Arena arena = arenaSupplier.get()) {
|
Arena arena = arenaSupplier.get()) {
|
||||||
MemorySegment segment = arena.allocate(10, 1);;
|
MemorySegment segment = arena.allocate(10, 1);
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
segment.set(JAVA_BYTE, i, (byte) i);
|
segment.set(JAVA_BYTE, i, (byte) i);
|
||||||
}
|
}
|
||||||
@ -780,7 +780,7 @@ public class TestByteBuffer {
|
|||||||
@Test
|
@Test
|
||||||
public void buffersAndArraysFromSlices() {
|
public void buffersAndArraysFromSlices() {
|
||||||
try (Arena arena = Arena.ofShared()) {
|
try (Arena arena = Arena.ofShared()) {
|
||||||
MemorySegment segment = arena.allocate(16, 1);;
|
MemorySegment segment = arena.allocate(16, 1);
|
||||||
int newSize = 8;
|
int newSize = 8;
|
||||||
var slice = segment.asSlice(4, newSize);
|
var slice = segment.asSlice(4, newSize);
|
||||||
|
|
||||||
@ -798,7 +798,7 @@ public class TestByteBuffer {
|
|||||||
@Test
|
@Test
|
||||||
public void viewsFromSharedSegment() {
|
public void viewsFromSharedSegment() {
|
||||||
try (Arena arena = Arena.ofShared()) {
|
try (Arena arena = Arena.ofShared()) {
|
||||||
MemorySegment segment = arena.allocate(16, 1);;
|
MemorySegment segment = arena.allocate(16, 1);
|
||||||
var byteBuffer = segment.asByteBuffer();
|
var byteBuffer = segment.asByteBuffer();
|
||||||
byteBuffer.asReadOnlyBuffer();
|
byteBuffer.asReadOnlyBuffer();
|
||||||
byteBuffer.slice(0, 8);
|
byteBuffer.slice(0, 8);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -173,7 +173,7 @@ public class TestDereferencePath {
|
|||||||
ValueLayout.ADDRESS.withTargetLayout(ValueLayout.JAVA_INT).withName("x"));
|
ValueLayout.ADDRESS.withTargetLayout(ValueLayout.JAVA_INT).withName("x"));
|
||||||
|
|
||||||
try (Arena arena = Arena.ofConfined()) {
|
try (Arena arena = Arena.ofConfined()) {
|
||||||
MemorySegment segment = arena.allocate(struct.byteSize() + 1).asSlice(1);
|
MemorySegment segment = arena.allocate(struct.byteSize() + 1, struct.byteAlignment()).asSlice(1);
|
||||||
VarHandle vhX = struct.varHandle(PathElement.groupElement("x"), PathElement.dereferenceElement());
|
VarHandle vhX = struct.varHandle(PathElement.groupElement("x"), PathElement.dereferenceElement());
|
||||||
vhX.set(segment, 0L, 42); // should throw
|
vhX.set(segment, 0L, 42); // should throw
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user