4 ms·
This gives me flashbacks to the Objective-C / Java bridge [1] from over a decade ago. It makes me wonder how they are dealing with memory management when Java o
by koito17 2y ago
This gives me flashbacks to the Objective-C / Java bridge [1] from over a decade ago. It makes me wonder how they are dealing with memory management when Java objects are being used from Swift (or Swift objects from Java). This was one (of various) issues that made using the Cocoa Java bridge a bit unpleasant.
I guess Swift has a lot less run-time dynamism going on, so it may not be too hard to translate Swift semantics to Java. Definitely interested to see how this unfolds over the next year.
[1] https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Legacy/JavaBridge/JavaBridge.pdf https://developer.apple.com/library/archive/documentation/Co...
- lukeh 2y agoIIRC, the ObjC/Java bridge was first done at NeXT for WebObjects around 1996... almost thirty years ago!
- favorited 2y ago> It makes me wonder how they are dealing with memory management when Java objects are being used from Swift It uses Swift macros to add a `JavaObjectHolder` property to Swift types annotated with `@JavaClass`[0]. `JavaObjectHolder` is a Swift class that takes a global JNI reference to the Java object, and releases it when the holder is destroyed[1]. The result is that a codegen utility emits Swift structs[2] that wrap the JNI values, and the JNI glue code for method invocation is applied at compile-time when the macros are expanded. [0] https://github.com/swiftlang/swift-java/blob/e7d7a217e37d49b326b3367e8299fedcd54cabe2/Sources/JavaKitMacros/JavaClassMacro.swift#L67 https://github.com/swiftlang/swift-java/blob/e7d7a217e37d49b... [1] https://github.com/swiftlang/swift-java/blob/main/Sources/JavaKit/JavaObjectHolder.swift https://github.com/swiftlang/swift-java/blob/main/Sources/Ja... [2] https://github.com/swiftlang/swift-java/blob/main/Sources/JavaKitNetwork/generated/URI.swift https://github.com/swiftlang/swift-java/blob/main/Sources/Ja...