-
Notifications
You must be signed in to change notification settings - Fork 46
SwiftArena and invoking destroy on objects as arena is destroyed #67
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
18 commits
Select commit
Hold shift + click to select a range
6b64073
SwiftKit: use inner-static class pattern for DESC/ADDR/HANDLE constants
ktoso c802914
progress towards SwiftArena which manages swift values and heap objects
ktoso ce04978
introduce tests for metadata size etc
ktoso f968343
avoid explicitly loading libs; they can be loaded by the generated mo…
ktoso 27895d3
add a default toString to imported heap objects
ktoso 18e7f94
work in progress on calling destroy of a class
ktoso 18ad313
pass the self pointer through another pointer indirectly to destroy
ktoso 97c2eac
fix passing wtable to destroy
ktoso 6ca633c
cleanup
ktoso 0d15c84
remove un-necessary loadLibrary with dylib
ktoso 079a6d2
Fix constructor test
ktoso 8fddb7f
remove not used LockedState
ktoso 92d11ee
debugging CI, unsure why crash happens, probably paths
ktoso 5669314
Discard changes to Sources/JavaKitVM/LockedState.swift
ktoso db8fc4f
debugging linux x86 issue
ktoso 0f60bff
Disable test on linux/amd64 until we figure it out, in meantime it wo…
ktoso 74076aa
license ignore generated java files
ktoso fa6a5b8
ignore generated jextract files, we dont commit them anymore
ktoso 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
78 changes: 78 additions & 0 deletions
78
Samples/SwiftKitSampleApp/src/test/java/org/swift/swiftkit/SwiftArenaTest.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,78 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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.generated.MySwiftClass; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.DisabledIf; | ||
import org.swift.swiftkit.util.PlatformUtils; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.swift.swiftkit.SwiftKit.*; | ||
import static org.swift.swiftkit.SwiftKit.retainCount; | ||
|
||
public class SwiftArenaTest { | ||
|
||
@BeforeAll | ||
static void beforeAll() { | ||
System.out.printf("java.library.path = %s\n", SwiftKit.getJavaLibraryPath()); | ||
System.out.printf("jextract.trace.downcalls = %s\n", SwiftKit.getJextractTraceDowncalls()); | ||
} | ||
|
||
static boolean isAmd64() { | ||
return PlatformUtils.isAmd64(); | ||
} | ||
|
||
// FIXME: The destroy witness table call hangs on x86_64 platforms during the destroy witness table call | ||
// See: https://github.com/swiftlang/swift-java/issues/97 | ||
@Test | ||
@DisabledIf("isAmd64") | ||
public void arena_releaseClassOnClose_class_ok() { | ||
try (var arena = SwiftArena.ofConfined()) { | ||
var obj = new MySwiftClass(arena,1, 2); | ||
|
||
retain(obj.$memorySegment()); | ||
assertEquals(2, retainCount(obj.$memorySegment())); | ||
|
||
release(obj.$memorySegment()); | ||
assertEquals(1, retainCount(obj.$memorySegment())); | ||
} | ||
|
||
// TODO: should we zero out the $memorySegment perhaps? | ||
} | ||
|
||
@Test | ||
public void arena_releaseClassOnClose_class_leaked() { | ||
String memorySegmentDescription = "<none>"; | ||
|
||
try { | ||
try (var arena = SwiftArena.ofConfined()) { | ||
var obj = new MySwiftClass(arena,1, 2); | ||
memorySegmentDescription = obj.$memorySegment().toString(); | ||
|
||
// Pretend that we "leaked" the class, something still holds a reference to it while we try to destroy it | ||
retain(obj.$memorySegment()); | ||
assertEquals(2, retainCount(obj.$memorySegment())); | ||
} | ||
|
||
fail("Expected exception to be thrown while the arena is closed!"); | ||
} catch (Exception ex) { | ||
// The message should point out which objects "leaked": | ||
assertTrue(ex.getMessage().contains(memorySegmentDescription)); | ||
} | ||
|
||
} | ||
} |
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.
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.
Moved some functionality out of SwiftKit, keeping it for things end users might wanna use.