|
1 | 1 | pub(crate) use _testinternalcapi::module_def; |
2 | 2 |
|
| 3 | +use core::sync::atomic::{AtomicUsize, Ordering}; |
| 4 | + |
| 5 | +static RARE_SET_CLASS: AtomicUsize = AtomicUsize::new(0); |
| 6 | +static RARE_SET_BASES: AtomicUsize = AtomicUsize::new(0); |
| 7 | +static RARE_SET_EVAL_FRAME_FUNC: AtomicUsize = AtomicUsize::new(0); |
| 8 | +static RARE_BUILTIN_DICT: AtomicUsize = AtomicUsize::new(0); |
| 9 | +static RARE_FUNC_MODIFICATION: AtomicUsize = AtomicUsize::new(0); |
| 10 | + |
| 11 | +pub(crate) fn note_set_class() { |
| 12 | + RARE_SET_CLASS.fetch_add(1, Ordering::Relaxed); |
| 13 | +} |
| 14 | + |
| 15 | +pub(crate) fn note_set_bases() { |
| 16 | + RARE_SET_BASES.fetch_add(1, Ordering::Relaxed); |
| 17 | +} |
| 18 | + |
| 19 | +pub(crate) fn note_builtin_dict() { |
| 20 | + RARE_BUILTIN_DICT.fetch_add(1, Ordering::Relaxed); |
| 21 | +} |
| 22 | + |
| 23 | +pub(crate) fn note_func_modification() { |
| 24 | + RARE_FUNC_MODIFICATION.fetch_add(1, Ordering::Relaxed); |
| 25 | +} |
| 26 | + |
3 | 27 | #[pymodule] |
4 | 28 | mod _testinternalcapi { |
5 | | - use crate::{PyObjectRef, VirtualMachine}; |
| 29 | + use super::*; |
| 30 | + use crate::{PyObjectRef, PyResult, VirtualMachine, builtins::PyDictRef}; |
| 31 | + |
| 32 | + // ADAPTIVE_WARMUP_VALUE + 1 |
| 33 | + #[pyattr] |
| 34 | + const SPECIALIZATION_THRESHOLD: usize = 2; |
| 35 | + |
| 36 | + // ADAPTIVE_COOLDOWN_VALUE + 1 |
| 37 | + #[pyattr] |
| 38 | + const SPECIALIZATION_COOLDOWN: usize = 53; |
| 39 | + |
| 40 | + #[pyattr] |
| 41 | + const SHARED_KEYS_MAX_SIZE: usize = crate::object::SHARED_KEYS_MAX_SIZE; |
6 | 42 |
|
7 | 43 | #[pyfunction] |
8 | 44 | fn has_inline_values(obj: PyObjectRef, _vm: &VirtualMachine) -> bool { |
9 | 45 | obj.has_inline_values() |
10 | 46 | } |
| 47 | + |
| 48 | + #[pyfunction] |
| 49 | + fn get_recursion_depth(vm: &VirtualMachine) -> usize { |
| 50 | + vm.current_recursion_depth() |
| 51 | + } |
| 52 | + |
| 53 | + #[pyfunction] |
| 54 | + fn reset_rare_event_counters() { |
| 55 | + RARE_SET_CLASS.store(0, Ordering::Relaxed); |
| 56 | + RARE_SET_BASES.store(0, Ordering::Relaxed); |
| 57 | + RARE_SET_EVAL_FRAME_FUNC.store(0, Ordering::Relaxed); |
| 58 | + RARE_BUILTIN_DICT.store(0, Ordering::Relaxed); |
| 59 | + RARE_FUNC_MODIFICATION.store(0, Ordering::Relaxed); |
| 60 | + } |
| 61 | + |
| 62 | + #[pyfunction] |
| 63 | + fn get_rare_event_counters(vm: &VirtualMachine) -> PyResult<PyDictRef> { |
| 64 | + let dict = vm.ctx.new_dict(); |
| 65 | + dict.set_item( |
| 66 | + "set_class", |
| 67 | + vm.ctx |
| 68 | + .new_int(RARE_SET_CLASS.load(Ordering::Relaxed)) |
| 69 | + .into(), |
| 70 | + vm, |
| 71 | + )?; |
| 72 | + dict.set_item( |
| 73 | + "set_bases", |
| 74 | + vm.ctx |
| 75 | + .new_int(RARE_SET_BASES.load(Ordering::Relaxed)) |
| 76 | + .into(), |
| 77 | + vm, |
| 78 | + )?; |
| 79 | + dict.set_item( |
| 80 | + "set_eval_frame_func", |
| 81 | + vm.ctx |
| 82 | + .new_int(RARE_SET_EVAL_FRAME_FUNC.load(Ordering::Relaxed)) |
| 83 | + .into(), |
| 84 | + vm, |
| 85 | + )?; |
| 86 | + dict.set_item( |
| 87 | + "builtin_dict", |
| 88 | + vm.ctx |
| 89 | + .new_int(RARE_BUILTIN_DICT.load(Ordering::Relaxed)) |
| 90 | + .into(), |
| 91 | + vm, |
| 92 | + )?; |
| 93 | + dict.set_item( |
| 94 | + "func_modification", |
| 95 | + vm.ctx |
| 96 | + .new_int(RARE_FUNC_MODIFICATION.load(Ordering::Relaxed)) |
| 97 | + .into(), |
| 98 | + vm, |
| 99 | + )?; |
| 100 | + Ok(dict) |
| 101 | + } |
| 102 | + |
| 103 | + #[pyfunction] |
| 104 | + fn set_eval_frame_record(_recorder: PyObjectRef) { |
| 105 | + RARE_SET_EVAL_FRAME_FUNC.fetch_add(1, Ordering::Relaxed); |
| 106 | + } |
| 107 | + |
| 108 | + #[pyfunction] |
| 109 | + fn set_eval_frame_default() {} |
11 | 110 | } |
0 commit comments