-
Notifications
You must be signed in to change notification settings - Fork 89
jni: Unify common methods using generic implementations #582
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
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2bcdfef
Using generic implementation to get enum discriminator
sidepelican 1077843
Using generic implementation for toString methods
sidepelican a725538
Using generic implementation for destroy
sidepelican 044f7e4
Remove unused synthesizedFunction logic
sidepelican 3f3f91b
Fix test fixtures
sidepelican 8879b1f
Fix warning
sidepelican 4707500
Merge remote-tracking branch 'origin/main' into generic_runtime_func
sidepelican bd86420
swift format
sidepelican 584523f
Add comment explaining why traceDowncall is omitted
sidepelican 1c2d7c3
Use SwiftJavaMacros and rename file
sidepelican be833a4
Add generic benchmark
sidepelican c87e390
Revert "Use SwiftJavaMacros and rename file"
sidepelican 4a7e8dd
Reapply "Use SwiftJavaMacros and rename file"
sidepelican ff4e8e7
Fix usage of SwiftJavaMacros
sidepelican 4184025
apply formatting
sidepelican b412bed
Embed SwiftJavaRuntimeSupport into SwiftJava dynamic library
sidepelican File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
Samples/SwiftJavaExtractJNISampleApp/Sources/MySwiftLibrary/Benchmark.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift.org open source project | ||
| // | ||
| // Copyright (c) 2026 Apple Inc. and the Swift.org project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of Swift.org project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| public struct BasicStruct { | ||
| public var value: Int | ||
| public init(value: Int) { | ||
| self.value = value | ||
| } | ||
| } | ||
|
|
||
| public struct GenericStruct<T> { | ||
| public var value: Int | ||
| public init(value: Int) { | ||
| self.value = value | ||
| } | ||
| } | ||
|
|
||
| public func makeGenericStruct(value: Int) -> GenericStruct<Int> { | ||
| GenericStruct(value: value) | ||
| } |
71 changes: 71 additions & 0 deletions
71
Samples/SwiftJavaExtractJNISampleApp/src/jmh/java/com/example/swift/GenericBenchmark.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift.org open source project | ||
| // | ||
| // Copyright (c) 2026 Apple Inc. and the Swift.org project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of Swift.org project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| package com.example.swift; | ||
|
|
||
| import org.openjdk.jmh.annotations.*; | ||
| import org.openjdk.jmh.infra.Blackhole; | ||
| import org.swift.swiftkit.core.ClosableSwiftArena; | ||
| import org.swift.swiftkit.core.ConfinedSwiftMemorySession; | ||
| import org.swift.swiftkit.core.SwiftArena; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| @BenchmarkMode(Mode.AverageTime) | ||
| @Warmup(iterations = 5, time = 200, timeUnit = TimeUnit.MILLISECONDS) | ||
| @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS) | ||
| @OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
| @Fork(value = 3, jvmArgsAppend = { "--enable-native-access=ALL-UNNAMED" }) | ||
| public class GenericBenchmark { | ||
| @State(Scope.Benchmark) | ||
| public static class BenchmarkState { | ||
| ClosableSwiftArena arena; | ||
| BasicStruct basicStruct; | ||
| GenericStruct genericStruct; | ||
|
|
||
| @Setup(Level.Trial) | ||
| public void beforeAll() { | ||
| arena = SwiftArena.ofConfined(); | ||
| basicStruct = BasicStruct.init(42, arena); | ||
| genericStruct = MySwiftLibrary.makeGenericStruct(42, arena); | ||
| } | ||
|
|
||
| @TearDown(Level.Trial) | ||
| public void afterAll() { | ||
| arena.close(); | ||
| } | ||
| } | ||
|
|
||
| @Benchmark | ||
| public long basicStruct_basicGetter(BenchmarkState state, Blackhole bh) { | ||
| return state.basicStruct.getValue(); | ||
| } | ||
|
|
||
| @Benchmark | ||
| public long genericStruct_basicGetter(BenchmarkState state, Blackhole bh) { | ||
| return state.genericStruct.getValue(); | ||
| } | ||
|
|
||
| @Benchmark | ||
| public String basicStruct_toString(BenchmarkState state, Blackhole bh) { | ||
| // toString is internally implemented as a generic method in Swift | ||
| return state.basicStruct.toString(); | ||
| } | ||
|
|
||
| @Benchmark | ||
| public String genericStruct_toString(BenchmarkState state, Blackhole bh) { | ||
| // toString is internally implemented as a generic method in Swift | ||
| return state.genericStruct.toString(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍