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

* fixed: libgdx/7212 -- crash when getting value by pointer, affected by GC #743

Merged

Conversation

dkimitsa
Copy link
Contributor

@dkimitsa dkimitsa commented Sep 2, 2023

Source

libgdx/libgdx#7212

root case

GC code was setting up mark handler only for direct subclass of Struct class to mark its native structure content during GC mark phase. As result memory behind native struct area was release and available for allocations. As result this area was taken by next requested object/data. That caused crashed related to ObjC marshalling, like objc[503]: Attempt to use unknown class 0x104094d80. But all pointer extended intermediate classes after Struct: in this case NSErrorPtr->Ptr->Struct

Fix

Code changed to check for subclass instead direct subclass.

Minimal sample to reproduce.

void test2() {
   	NSObjectPtr ptr = new NSObjectPtr();
   	NSObject o = new NSObject();
   	ptr.set(o);
   	for (int i = 0; i < 100_000_000;i++) {
   		new NSObject();
   		if (VM.getLong(ptr.getHandle()) != o.getHandle()) {
   			throw new RuntimeException(ptr.getClass() + " " + Long.toHexString(ptr.getHandle()) + "-" + Long.toHexString(VM.getLong(ptr.getHandle())));
   		}
   	}
}

… by GC

original: libgdx/libgdx#7212
root case: GC code was setting up mark handler only for direct subclass of Struct class to mark its native structure content during GC mark phase. As result memory behind native struct area was release and available for allocations. As result this area was taken by next requested object/data. That caused crashed related to ObjC marshalling, like `objc[503]: Attempt to use unknown class 0x104094d80.`
But all pointer extended intermediate classes after Struct: in this case NSErrorPtr->Ptr->Struct
Code changed to check for subclass instead direct subclass.
Minimal sample to reproduce.
```
void test2() {
   	NSObjectPtr ptr = new NSObjectPtr();
   	NSObject o = new NSObject();
   	ptr.set(o);
   	for (int i = 0; i < 100_000_000;i++) {
   		new NSObject();
   		if (VM.getLong(ptr.getHandle()) != o.getHandle()) {
   			throw new RuntimeException(ptr.getClass() + " " + Long.toHexString(ptr.getHandle()) + "-" + Long.toHexString(VM.getLong(ptr.getHandle())));
   		}
   	}
}
```
@Tom-Ski Tom-Ski merged commit a94a6b2 into MobiVM:master Sep 2, 2023
1 check passed
dkimitsa added a commit to dkimitsa/robovm that referenced this pull request Apr 15, 2024
… by GC (MobiVM#743)

original: libgdx/libgdx#7212
root case: GC code was setting up mark handler only for direct subclass of Struct class to mark its native structure content during GC mark phase. As result memory behind native struct area was release and available for allocations. As result this area was taken by next requested object/data. That caused crashed related to ObjC marshalling, like `objc[503]: Attempt to use unknown class 0x104094d80.`
But all pointer extended intermediate classes after Struct: in this case NSErrorPtr->Ptr->Struct
Code changed to check for subclass instead direct subclass.
Minimal sample to reproduce.
```
void test2() {
   	NSObjectPtr ptr = new NSObjectPtr();
   	NSObject o = new NSObject();
   	ptr.set(o);
   	for (int i = 0; i < 100_000_000;i++) {
   		new NSObject();
   		if (VM.getLong(ptr.getHandle()) != o.getHandle()) {
   			throw new RuntimeException(ptr.getClass() + " " + Long.toHexString(ptr.getHandle()) + "-" + Long.toHexString(VM.getLong(ptr.getHandle())));
   		}
   	}
}
```

(cherry picked from commit a94a6b2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants