-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into wip-witness-funcs
- Loading branch information
Showing
19 changed files
with
421 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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 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
46 changes: 46 additions & 0 deletions
46
Samples/SwiftKitSampleApp/Sources/MySwiftLibrary/jni/JNIImplementations.swift
This file contains 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,46 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2024 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import JavaKit | ||
import JavaRuntime | ||
|
||
@JavaClass("com.example.swift.HelloJava2Swift") | ||
open class HelloJava2Swift: JavaObject { | ||
} | ||
|
||
extension JavaClass<HelloJava2Swift> { | ||
} | ||
|
||
/// Describes the Java `native` methods for ``HelloJava2Swift``. | ||
/// | ||
/// To implement all of the `native` methods for HelloSwift in Swift, | ||
/// extend HelloSwift to conform to this protocol and mark each | ||
/// implementation of the protocol requirement with `@JavaMethod`. | ||
protocol HelloJava2SwiftNativeMethods { | ||
func jniWriteString(_ message: String) -> Int32 | ||
func jniGetInt() -> Int32 | ||
} | ||
|
||
@JavaImplementation("com.example.swift.HelloJava2Swift") | ||
extension HelloJava2Swift: HelloJava2SwiftNativeMethods { | ||
@JavaMethod | ||
func jniWriteString(_ message: String) -> Int32 { | ||
return Int32(message.count) | ||
} | ||
|
||
@JavaMethod | ||
func jniGetInt() -> Int32 { | ||
return 12 | ||
} | ||
} |
This file contains 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 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
86 changes: 86 additions & 0 deletions
86
Samples/SwiftKitSampleApp/src/jmh/java/org/swift/swiftkit/StringPassingBenchmark.java
This file contains 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,86 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2024 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 org.swift.swiftkit; | ||
|
||
import com.example.swift.HelloJava2Swift; | ||
import com.example.swift.MySwiftClass; | ||
import com.example.swift.MySwiftLibrary; | ||
import org.openjdk.jmh.annotations.*; | ||
|
||
import java.lang.foreign.Arena; | ||
import java.nio.charset.StandardCharsets; | ||
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) | ||
@State(Scope.Thread) | ||
@Fork(value = 2, jvmArgsAppend = {"--enable-native-access=ALL-UNNAMED"}) | ||
public class StringPassingBenchmark { | ||
|
||
@Param({ | ||
"5", | ||
"10", | ||
"100", | ||
"200" | ||
}) | ||
public int stringLen; | ||
public String string; | ||
|
||
ClosableSwiftArena arena; | ||
MySwiftClass obj; | ||
|
||
@Setup(Level.Trial) | ||
public void beforeAll() { | ||
arena = SwiftArena.ofConfined(); | ||
obj = new MySwiftClass(arena, 1, 2); | ||
string = makeString(stringLen); | ||
} | ||
|
||
@TearDown(Level.Trial) | ||
public void afterAll() { | ||
arena.close(); | ||
} | ||
|
||
@Benchmark | ||
public long writeString_global_fmm() { | ||
return MySwiftLibrary.globalWriteString(string); | ||
} | ||
|
||
@Benchmark | ||
public long writeString_global_jni() { | ||
return HelloJava2Swift.jniWriteString(string); | ||
} | ||
|
||
@Benchmark | ||
public long writeString_baseline() { | ||
return string.length(); | ||
} | ||
|
||
static String makeString(int size) { | ||
var text = | ||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut in augue ullamcorper, mattis lacus tincidunt, " + | ||
"accumsan massa. Morbi gravida purus ut porttitor iaculis. Vestibulum lacinia, mi in tincidunt hendrerit," + | ||
"lectus est placerat magna, vitae vestibulum nulla ligula at massa. Pellentesque nibh quam, pulvinar eu " + | ||
"nunc congue, molestie molestie augue. Nam convallis consectetur velit, at dictum risus ullamcorper iaculis. " + | ||
"Vestibulum lacinia nisi in elit consectetur vulputate. Praesent id odio tristique, tincidunt arcu et, convallis velit. " + | ||
"Sed vitae pulvinar arcu. Curabitur euismod mattis dui in suscipit. Morbi aliquet facilisis vulputate. Phasellus " + | ||
"non lectus dapibus, semper magna eu, aliquet magna. Suspendisse vel enim at augue luctus gravida. Suspendisse " + | ||
"venenatis justo non accumsan sollicitudin. Suspendisse vitae ornare odio, id blandit nibh. Nulla facilisi. " + | ||
"Nulla nulla orci, finibus nec luctus et, faucibus et ligula."; | ||
return text.substring(0, size); | ||
} | ||
} |
This file contains 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 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 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 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.