-
Notifications
You must be signed in to change notification settings - Fork 70
make SwiftJava a dynamic lib and add class lookup fallbacks
#493
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,6 @@ | |
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import SwiftJava | ||
| import CSwiftJavaJNI | ||
|
|
||
| /// A type that represents the shared JNI environment | ||
|
|
@@ -21,36 +20,28 @@ import CSwiftJavaJNI | |
| /// This is initialized when the `JNI_OnLoad` is triggered, | ||
| /// which happens when you call `System.loadLibrary(...)` | ||
| /// from Java. | ||
| public final class JNI { | ||
| package final class JNI { | ||
| /// The shared JNI object, initialized by `JNI_OnLoad` | ||
| public fileprivate(set) static var shared: JNI! | ||
| /// | ||
| /// This may be `nil` in the case where `SwiftJava` is not loaded as a dynamic lib | ||
| /// by the Java sources. | ||
| package fileprivate(set) static var shared: JNI? | ||
|
|
||
| /// The default application class loader | ||
| public let applicationClassLoader: JavaClassLoader | ||
|
|
||
| /// The default auto arena of SwiftKitCore | ||
| public let defaultAutoArena: JavaSwiftArena | ||
| package let applicationClassLoader: JavaClassLoader | ||
|
|
||
| init(fromVM javaVM: JavaVirtualMachine) { | ||
| // Update the global JavaVM | ||
| JavaVirtualMachine.sharedJVM.withLock { | ||
| $0 = javaVM | ||
| } | ||
| let environment = try! javaVM.environment() | ||
|
|
||
| self.applicationClassLoader = try! JavaClass<JavaThread>(environment: environment).currentThread().getContextClassLoader() | ||
|
|
||
| // Find global arena | ||
| let swiftMemoryClass = environment.interface.FindClass(environment, "org/swift/swiftkit/core/SwiftMemoryManagement")! | ||
| let arenaFieldID = environment.interface.GetStaticFieldID( | ||
| environment, | ||
| swiftMemoryClass, | ||
| "DEFAULT_SWIFT_JAVA_AUTO_ARENA", | ||
| JavaSwiftArena.mangledName | ||
| ) | ||
| let localObject = environment.interface.GetStaticObjectField(environment, swiftMemoryClass, arenaFieldID)! | ||
| self.defaultAutoArena = JavaSwiftArena(javaThis: localObject, environment: environment) | ||
| environment.interface.DeleteLocalRef(environment, localObject) | ||
| } | ||
| } | ||
|
|
||
| // Called by generated code, and not automatically by Java. | ||
| public func _JNI_OnLoad(_ javaVM: JavaVMPointer, _ reserved: UnsafeMutableRawPointer) { | ||
| @_cdecl("JNI_OnLoad") | ||
| func SwiftJava_JNI_OnLoad(javaVM: JavaVMPointer, reserved: UnsafeMutableRawPointer) -> jint { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't we need this "lower", in a lib that does not have macros?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note, we'll do that later |
||
| JNI.shared = JNI(fromVM: JavaVirtualMachine(adoptingJVM: javaVM)) | ||
| return JNI_VERSION_1_6 | ||
| } | ||
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
23 changes: 23 additions & 0 deletions
23
Sources/SwiftJavaRuntimeSupport/generated/JavaSwiftMemoryManagement.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,23 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 SwiftJava | ||
|
|
||
| @JavaClass("org.swift.swiftkit.core.SwiftMemoryManagement") | ||
| public class JavaSwiftMemoryManagement: JavaObject {} | ||
|
|
||
| extension JavaClass<JavaSwiftMemoryManagement> { | ||
| @JavaStaticField("DEFAULT_SWIFT_JAVA_AUTO_ARENA", isFinal: true) | ||
| var defaultSwiftJavaAutoArena: JavaSwiftArena! | ||
| } |
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
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.
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.
Uh oh!
There was an error while loading. Please reload this page.