Skip to content

Commit

Permalink
[FFI/Jtreg_JDK21] Fix the native segment access in test
Browse files Browse the repository at this point in the history
The change is to restore the previous fix in OpenJDK
to deal with the native memory access given 
SymbolLookup.loaderLookup().find() returns a zero-sized
segment for ADDRESS as explained in OpenJDK, in which
case it should be reinterpreted as an valid segment
with the specified size to ensure it works correctly.

Fixes: #eclipse-openj9/openj9/issues/17676

Signed-off-by: ChengJin01 <jincheng@ca.ibm.com>
  • Loading branch information
ChengJin01 committed Jun 26, 2023
1 parent 8fdc0f1 commit d54cac2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test/jdk/java/foreign/TestClassLoaderFindNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2022, 2022 All Rights Reserved
* (c) Copyright IBM Corp. 2022, 2023 All Rights Reserved
* ===========================================================================
*/

Expand All @@ -41,6 +41,7 @@
import org.testng.annotations.Test;

import static java.lang.foreign.ValueLayout.JAVA_BYTE;
import static java.lang.foreign.ValueLayout.JAVA_INT;
import static org.testng.Assert.*;

// FYI this test is run on 64-bit platforms only for now,
Expand All @@ -65,11 +66,11 @@ public void testInvalidSymbolLookup() {

@Test
public void testVariableSymbolLookup() {
MemorySegment segment = SymbolLookup.loaderLookup().find("c").get();
MemorySegment segment = SymbolLookup.loaderLookup().find("c").get().reinterpret(JAVA_INT.byteSize());
/* The variable is 'int c;', so JAVA_INT is a better choice than JAVA_BYTE.
* See libLookupTest.c.
*/
assertEquals(segment.get(ValueLayout.JAVA_INT, 0), 42);
assertEquals(segment.get(JAVA_INT, 0), 42);
}

@Test
Expand Down

0 comments on commit d54cac2

Please sign in to comment.