Skip to content

Conversation

graalvmbot
Copy link
Collaborator

We identified direct upcalls by the cracked direct method handle (i.e. using DirectMethodHandleDesc). However, it is possible that the same target method may be called with different C signatures. For example:
If we have static method

static MemorySegment upcallTarget(MemorySegment a, MemorySegment b) {
    // ...
}

and if there are two different C structs:

struct S_FF {
    float p0;
    float p1;
}
struct S_FFFFFFF {
    float p0;
    float p1;
    float p2;
    float p3;
    float p4;
    float p5;
    float p6;
}

Then it is possible to create two (different) upcall stubs:

MemorySegment stub0 = Linker.nativeLinker().upcallStub(MethodHandles.lookup().findStatic(MyClass.class, "upcallTarget", mt), FunctionDescriptor.of(S_FF, S_FF, S_FF), arena);

MemorySegment stub1 = Linker.nativeLinker().upcallStub(MethodHandles.lookup().findStatic(MyClass.class, "upcallTarget", mt), FunctionDescriptor.of(S_FFFFFFF, S_FFFFFFF, S_FFFFFFF), arena);

In case of stub0, the return value fits into registers but in case of stub1, the return value must be passed in a buffer. Therefore, the method handle invoked by the call stub is different.

In order to fix that, we need to identify a direct upcall by its method handle descriptor AND the JavaEntryPointInfo.

Furthermore, when re-creating the method handle for the direct upcall stub, we also need to adapt the direct method handle for in-memory return.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label May 14, 2025
@graalvmbot graalvmbot closed this May 16, 2025
@graalvmbot graalvmbot deleted the fa/GR-60350/use_direct_upcalls_in_tests branch May 16, 2025 11:02
@graalvmbot graalvmbot merged commit 753b81f into master May 16, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants