Skip to content

[JExtract] Generate JNI code for classes (static methods and initializers) #298

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

Merged
merged 9 commits into from
Jul 3, 2025

Conversation

madsodgaard
Copy link
Contributor

This PR adds support for generating Java wrappers for Swift classes. It generates static methods and initializers.

Currently, this PR is only focused on actual allocation and initialization. Memory management is not yet addressed. We first need to provide a non-FFM version of SwiftKit and its tools for memory management, @ktoso said he would look into this.

This PR differs from the way FFM does it by delegating memory allocations to Swift instead of Java. This means we do not have to rely on any "unsafe" Java APIs for allocating memory without FFM. It also simplifies the code needed to allocate for structs, for example. We can easily change this approach later, if we decide to.

The code generates a java method init, which calls down into a native allocatingInit which does the actual allocation and returns the pointer to Java, for it to store. The plan is later to migrate over to something similiar to SwiftInstance to be used for memory cleanup.

@ktoso ktoso requested review from rintaro and ktoso July 3, 2025 03:24
@ktoso
Copy link
Collaborator

ktoso commented Jul 3, 2025

Nice, and here's the issue to track the swiftkit split-up #299

@ktoso
Copy link
Collaborator

ktoso commented Jul 3, 2025

Very nice so far! :-)

@madsodgaard madsodgaard marked this pull request as ready for review July 3, 2025 10:53
@madsodgaard madsodgaard changed the title [WIP]: [JExtract] Generate JNI code for classes (static methods and initializers) [JExtract] Generate JNI code for classes (static methods and initializers) Jul 3, 2025
@ktoso ktoso merged commit e887a9f into swiftlang:main Jul 3, 2025
28 checks passed
@madsodgaard madsodgaard deleted the jni-classes branch July 3, 2025 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants