4 ms·
This does not work when you can have threads executing arbitrary native code, that can do some non-GC related work for essentially unbounded time, which is cert
by dfox 16y ago
This does not work when you can have threads executing arbitrary native code, that can do some non-GC related work for essentially unbounded time, which is certainly case with .NET. In JVM any native code tends to be prepared to cope with this somehow, but .NET is explicitly designed to be able to seamlessly interoperate with random COM and legacy native libraries, so you cannot guarantee that such native code will get back to GC safe point in any bounded amount of time.
Edit: you can do stop-the-world GC at any point of program whan you scan stack conservatively, GC-safe points are only needed for precise scanning of stack and registers, so this is problem only when you want to be fully precise. Fully precise GC is certainly better when it is possible, but conservative scan works mostly well enough.
- barrkel 16y agoArbitrary native code is just fine - all you need to do is catch it when it returns back into the CLR. Native code can't (legally) have access to any managed memory that isn't already pinned. Since you (by you, I mean the CLR) control the call point to native code, you control the return point too - you can patch the instructions after the call if necessary.
- thedigitalengel 16y agoWhat happens if the native code enters, say, an infinite loop?
- ssp 16y agoYou can just consider native code a GC point. When executing native code, the registers don't need to be scanned, and you can keep track of what parts of the stack are native by noting the state of the stack before entering the native code.
- thedigitalengel 16y agoEven with the threads possibly stopping at unsafe points, a mostly precise scan (saving the last stack frame) can be done if the stack maps are maintained for all the call-sites.