scoop:scoop.core:0.1.0
src/gc.scoop
Selected production source · src/gc.scoop
1
// GC facilities (spec 14.1, M12 DESIGN section 4.2). Public operations are2
// ordinary unsafe core functions; pressure uses a direct C leaf binding.4
/**5
* An outstanding explicit pin that keeps a managed object at a stable address until unpinned.6
* Copying the token does not acquire another pin.7
*/8
public struct PinnedPtr<T : ref>(val raw: ULong)10
/**11
* An outstanding native handle keeping a managed reference alive without promising a stable object12
* address. Copying the token does not retain it.13
*/14
public struct GcHandle<T : ref>(val raw: ULong)16
@Unsafe17
@Intrinsic("gc_pin_raw")18
internal fun <T : ref> _pin(v: T): ULong20
@Unsafe21
@Intrinsic("gc_unpin_raw")22
internal fun <T : ref> _unpin(raw: ULong): T24
@Unsafe25
@Intrinsic("gc_get_handle_raw")26
internal fun <T : ref> _getGcHandle(v: T): ULong28
@Unsafe29
@Intrinsic("gc_release_handle_raw")30
internal fun <T : ref> _releaseGcHandle(raw: ULong): T32
/**33
* Acquires an explicit pin on a managed object. Balance each acquired pin with exactly one unpin.34
*/35
@Unsafe36
public fun <T : ref> pin(v: T): PinnedPtr<T> = PinnedPtr<T>(_pin(v))38
/**39
* Releases this acquired pin and returns the managed reference; do not reuse the released token.40
*/41
@Unsafe42
public fun <T : ref> unpin(p: PinnedPtr<T>): T = _unpin<T>(p.raw)44
/**45
* Acquires a stable native handle that roots the managed reference until released.46
*/47
@Unsafe48
public fun <T : ref> getGcHandle(v: T): GcHandle<T> = GcHandle<T>(_getGcHandle(v))50
/**51
* Releases this acquired handle and returns the managed reference; do not reuse the released52
* token.53
*/54
@Unsafe55
public fun <T : ref> releaseGcHandle(h: GcHandle<T>): T = _releaseGcHandle<T>(h.raw)57
// Test-only hooks (not part of the spec): force a collection and58
// read the live object count.59
/**60
* Forces a collection for diagnostics and runtime tests.61
*/62
@Intrinsic("rt_gc_collect")63
public fun gcCollect()65
/**66
* Returns the runtime's live managed-object count for diagnostics and tests.67
*/68
@Intrinsic("rt_gc_stats")69
public fun gcStats(): ULong71
// A leaf hint only: it never collects, allocates, or accesses thread state.72
/**73
* Adds a signed native-memory pressure hint. This leaf operation does not itself allocate or74
* collect; release external memory with a matching negative adjustment.75
*/76
@GCLeaf77
@Extern(name = "scoop_rt_gc_adjust_pressure")78
public fun gcAdjustPressure(delta: Long)