Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FFI/Jtreg_JDK21] IndexOutOfBoundsException detected in TestClassLoaderFindNative.java #17676

Closed
ChengJin01 opened this issue Jun 26, 2023 · 2 comments
Labels
jdk21 project:panama Used to track Project Panama related work test failure

Comments

@ChengJin01
Copy link

ChengJin01 commented Jun 26, 2023

The test suite ended up with the following error:

test TestClassLoaderFindNative.testVariableSymbolLookup(): failure
java.lang.IndexOutOfBoundsException: Out of bound access on segment MemorySegment{ heapBase: Optional.empty address:139995130122248 limit: 0 }; new offset = 0; new length = 4
        at java.base/jdk.internal.foreign.AbstractMemorySegmentImpl.outOfBoundException(AbstractMemorySegmentImpl.java:426)
        at java.base/jdk.internal.foreign.AbstractMemorySegmentImpl.apply(AbstractMemorySegmentImpl.java:407)
        at java.base/jdk.internal.foreign.AbstractMemorySegmentImpl.apply(AbstractMemorySegmentImpl.java:69)
        at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:98)
        at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:124)
        at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:448)
        at java.base/jdk.internal.foreign.AbstractMemorySegmentImpl.checkBounds(AbstractMemorySegmentImpl.java:396)
        at java.base/jdk.internal.foreign.AbstractMemorySegmentImpl.checkAccess(AbstractMemorySegmentImpl.java:356)
        at java.base/java.lang.invoke.VarHandleSegmentAsInts.checkAddress(VarHandleSegmentAsInts.java:81)
        at java.base/java.lang.invoke.VarHandleSegmentAsInts.get(VarHandleSegmentAsInts.java:108)
        at java.base/java.lang.foreign.MemorySegment.get(MemorySegment.java:1517)
        at TestClassLoaderFindNative.testVariableSymbolLookup(TestClassLoaderFindNative.java:75)

FYI: @tajila, @pshipton

@ChengJin01 ChengJin01 added project:panama Used to track Project Panama related work test failure jdk21 labels Jun 26, 2023
@ChengJin01
Copy link
Author

ChengJin01 commented Jun 26, 2023

Looking at the test code at https://github.com/ibmruntimes/openj9-openjdk-jdk21/blob/0bf8e32b3c5e101ce38ef51a5fa795ea1d28f5f6/test/jdk/java/foreign/TestClassLoaderFindNative.java#L62

    public void testVariableSymbolLookup() {
        MemorySegment segment = SymbolLookup.loaderLookup().find("c").get(); <--------
        /* 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);
    }

It turns out SymbolLookup.loaderLookup().find("c").get() returns a zero-sized segment for ADDRESS as specified in OpenJDK at https://github.com/ibmruntimes/openj9-openjdk-jdk21/blob/8fdc0f13b1557ace8be6a63c1f1c429e3b5bac54/src/java.base/share/classes/java/lang/foreign/SymbolLookup.java#L129:

    /**
     * Returns the address of the symbol with the given name.
     * @param name the symbol name.
     * @return a zero-length memory segment whose address indicates the address of the symbol, if found. <-----------
     */
    Optional<MemorySegment> find(String name); 

in which case we have to restore the previous fix for reinterpret() the size as mentioned at ibmruntimes/openj9-openjdk-jdk21#3 (comment) to ensure the value can be accessed correctly.

ChengJin01 pushed a commit to ChengJin01/openj9-openjdk-jdk21 that referenced this issue Jun 26, 2023
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>
@tajila tajila added this to the Java 21 milestone Jun 27, 2023
ChengJin01 pushed a commit to ChengJin01/openj9-openjdk-jdk21 that referenced this issue Jun 27, 2023
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>
ChengJin01 pushed a commit to ChengJin01/openj9-openjdk-jdk21 that referenced this issue Jun 27, 2023
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>
@ChengJin01
Copy link
Author

Close the issue as resolved at ibmruntimes/openj9-openjdk-jdk21#11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jdk21 project:panama Used to track Project Panama related work test failure
Projects
None yet
Development

No branches or pull requests

2 participants