Skip to content
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

Fix Subclassed WeakReference to be GCed #3347

Merged
merged 4 commits into from Jun 29, 2023

Conversation

mox692
Copy link
Contributor

@mox692 mox692 commented Jun 24, 2023

Fix #3341

Instead of using WeakReferenceId directory to determine WeakReference, we use the ranges of WeakReference to make the determination, as Class.is does.

@mox692 mox692 marked this pull request as draft June 24, 2023 18:36
@armanbilge armanbilge added backport candidate PR which might be backported into previous major release of SN component:tools component:nativelib labels Jun 24, 2023
@mox692 mox692 marked this pull request as ready for review June 27, 2023 16:33
Copy link
Member

@tanishiking tanishiking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look at the changes (mostly for learning purposes), and it looks good to me. I can indeed confirm that this change address the specific examples mentioned in the original issue. 🎉
However, since I'm not very familiar with this particular area, I would appreciate it if someone else could review it as well 😃

@@ -86,7 +87,8 @@ static inline size_t Object_Size(Object *object) {
}

static inline bool Object_IsWeakReference(Object *object) {
return object->rtti->rt.id == __weak_ref_id;
int32_t id = object->rtti->rt.id;
return __weak_ref_ids_min <= id && id <= __weak_ref_ids_max;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note] range is closed set 👍

def loop(node: Class): Unit = {
out += node
val start = id
id += 1
val directSubclasses =
node.subclasses.filter(_.parent == Some(node)).toArray
directSubclasses.sortBy(_.name.show).foreach { subcls => loop(subcls) }
val end = id - 1
ids(node) = start
ranges(node) = start to end

@WojciechMazur WojciechMazur merged commit 8c87a9a into scala-native:main Jun 29, 2023
77 checks passed
@mox692 mox692 deleted the fix/subclassed_weakref branch June 30, 2023 12:35
WojciechMazur pushed a commit to WojciechMazur/scala-native that referenced this pull request Sep 1, 2023
Instead of using WeakReferenceId directly to determine WeakReference, we use the ranges of WeakReference to make the determination, as `Class.is` does.

(cherry picked from commit 8c87a9a)
WojciechMazur pushed a commit that referenced this pull request Sep 4, 2023
Instead of using WeakReferenceId directly to determine WeakReference, we use the ranges of WeakReference to make the determination, as `Class.is` does.

(cherry picked from commit 8c87a9a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport candidate PR which might be backported into previous major release of SN component:nativelib component:tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WeakReference does not work if subclassed
4 participants