Skip to content

Commit be789b2

Browse files
committed
State machine and deprecated things
1 parent 94f192b commit be789b2

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

docs/userguide/src/portingguide/topics/weakref.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,58 @@ only need to run `process_weak_refs` twice:
273273
objects.
274274
2. Handle `PhandomReference`.
275275

276+
To implement this, the VM binding may need to implement some kind of *state machine* so that the
277+
`Scanning::process_weak_refs` function behaves differently each time it is called. For example,
278+
279+
```rust
280+
fn process_weak_ref(...) -> bool {
281+
let mut state = /* Get VM-specific states here. */;
282+
283+
match *state {
284+
State::ProcessSoftReference => {
285+
process_soft_references(...);
286+
*state = State::ProcessWeakReference;
287+
return true; // Run this function again.
288+
}
289+
State::ProcessWeakReference => {
290+
process_weak_references(...);
291+
*state = State::ProcessFinalizableObjects;
292+
return true; // Run this function again.
293+
}
294+
State::ProcessFinalizableObjects => {
295+
process_finalizable_objects(...);
296+
*state = State::ProcessPhantomReferences;
297+
return true; // Run this function again.
298+
}
299+
State::ProcessPhantomReferences => {
300+
process_phantom_references(...);
301+
*state = State::ProcessSoftReference
302+
return false; // Proceed to the Release stage.
303+
}
304+
}
305+
306+
}
307+
```
308+
276309
### Ephemerons
277310

278311
TODO
279312

280313

314+
## Deprecated reference and finalizable processors
315+
316+
When porting MMTk from JikesRVM to a dedicated Rust library, we also ported the `ReferenceProcessor`
317+
and the `FinalizableProcessor` from JikesRVM. They are implemented in mmtk-core, and provide the
318+
mechanisms for handling Java-style soft/weak/phantom references and finalizable objects. The VM
319+
binding can use those utilities by implementing the `mmtk::vm::ReferenceGlue` and the
320+
`mmtk::vm::Finalizable` traits, and calling the
321+
`mmtk::memory_manager::add_{soft,weak,phantom}_candidate` and the
322+
`mmtk::memory_manager::add_finalizer` functions.
323+
324+
However, those mechanisms are too specific to Java, and are not applicable to most other VMs. **New
325+
VM bindings should use the `Scanning::process_weak_refs` API**, and we are porting existing VM
326+
bindings away from the built-in reference/finalizable processors.
327+
281328
<!--
282329
vim: tw=100 ts=4 sw=4 sts=4 et
283330
-->

0 commit comments

Comments
 (0)