|
1 | | -use std::sync::atomic::Ordering; |
2 | | - |
| 1 | +use crate::scanning; |
3 | 2 | use crate::scanning::to_slots_closure; |
4 | 3 | use crate::OpenJDK; |
5 | 4 | use crate::OpenJDKSlot; |
6 | 5 | use crate::UPCALLS; |
7 | 6 | use mmtk::scheduler::*; |
| 7 | +use mmtk::util::Address; |
8 | 8 | use mmtk::vm::RootsWorkFactory; |
9 | 9 | use mmtk::vm::*; |
10 | 10 | use mmtk::MMTK; |
@@ -69,16 +69,51 @@ impl<const COMPRESSED: bool, F: RootsWorkFactory<OpenJDKSlot<COMPRESSED>>> |
69 | 69 | fn do_work( |
70 | 70 | &mut self, |
71 | 71 | _worker: &mut GCWorker<OpenJDK<COMPRESSED>>, |
72 | | - _mmtk: &'static MMTK<OpenJDK<COMPRESSED>>, |
| 72 | + mmtk: &'static MMTK<OpenJDK<COMPRESSED>>, |
73 | 73 | ) { |
74 | | - // Collect all the cached roots |
75 | | - let mut slots = Vec::with_capacity(crate::CODE_CACHE_ROOTS_SIZE.load(Ordering::Relaxed)); |
76 | | - for roots in (*crate::CODE_CACHE_ROOTS.lock().unwrap()).values() { |
77 | | - for r in roots { |
78 | | - slots.push((*r).into()) |
| 74 | + let is_current_gc_nursery = mmtk |
| 75 | + .get_plan() |
| 76 | + .generational() |
| 77 | + .is_some_and(|gen| gen.is_current_gc_nursery()); |
| 78 | + |
| 79 | + let mut slots = Vec::with_capacity(scanning::WORK_PACKET_CAPACITY); |
| 80 | + |
| 81 | + let mut nursery_slots = 0; |
| 82 | + let mut mature_slots = 0; |
| 83 | + |
| 84 | + let mut add_roots = |roots: &[Address]| { |
| 85 | + for root in roots { |
| 86 | + slots.push(OpenJDKSlot::<COMPRESSED>::from(*root)); |
| 87 | + if slots.len() >= scanning::WORK_PACKET_CAPACITY { |
| 88 | + self.factory |
| 89 | + .create_process_roots_work(std::mem::take(&mut slots)); |
| 90 | + } |
| 91 | + } |
| 92 | + }; |
| 93 | + |
| 94 | + { |
| 95 | + let mut mature = crate::MATURE_CODE_CACHE_ROOTS.lock().unwrap(); |
| 96 | + |
| 97 | + // Only scan mature roots in full-heap collections. |
| 98 | + if !is_current_gc_nursery { |
| 99 | + for roots in mature.values() { |
| 100 | + mature_slots += roots.len(); |
| 101 | + add_roots(roots); |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + { |
| 106 | + let mut nursery = crate::NURSERY_CODE_CACHE_ROOTS.lock().unwrap(); |
| 107 | + for (key, roots) in nursery.drain() { |
| 108 | + nursery_slots += roots.len(); |
| 109 | + add_roots(&roots); |
| 110 | + mature.insert(key, roots); |
| 111 | + } |
79 | 112 | } |
80 | 113 | } |
81 | | - // Create work packet |
| 114 | + |
| 115 | + probe!(mmtk_openjdk, code_cache_roots, nursery_slots, mature_slots); |
| 116 | + |
82 | 117 | if !slots.is_empty() { |
83 | 118 | self.factory.create_process_roots_work(slots); |
84 | 119 | } |
|
0 commit comments