/* automatically generated by rust-bindgen 0.69.5 */
#[repr(C)]
#[derive(Default)]
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
impl<T> __IncompleteArrayField<T> {
#[inline]
pub const fn new() -> Self {
__IncompleteArrayField(::std::marker::PhantomData, [])
}
#[inline]
pub fn as_ptr(&self) -> *const T {
self as *const _ as *const T
}
#[inline]
pub fn as_mut_ptr(&mut self) -> *mut T {
self as *mut _ as *mut T
}
#[inline]
pub unsafe fn as_slice(&self, len: usize) -> &[T] {
::std::slice::from_raw_parts(self.as_ptr(), len)
}
#[inline]
pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] {
::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
}
}
impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
fmt.write_str("__IncompleteArrayField")
}
}
pub const VORTEX_CACHE_MAX_SIZE: u32 = 268435456;
pub const VORTEX_T1_THRESHOLD: u32 = 1000;
pub const VORTEX_T2_THRESHOLD: u32 = 10000;
pub const VORTEX_COMPILE_THREADS: u32 = 0;
pub const VORTEX_T3_THRESHOLD: u32 = 100000;
pub const VTX_TAG_BITS: u32 = 3;
pub const VTX_TAG_MASK: u32 = 7;
pub const VTX_SMI_MAX: u64 = 70368744177663;
pub const VTX_SMI_MIN: i64 = -70368744177664;
pub const VTX_POLY_LIMIT: u32 = 4;
pub const VTX_MAX_TRACE_LENGTH: u32 = 1048576;
pub const VTX_MAX_TREE_DEPTH: u32 = 64;
pub const VTX_MAX_HYPERBLOCK_NODES: u32 = 4194304;
pub const VTX_MAX_NATIVE_SIZE: u32 = 268435456;
pub const VTX_CACHE_SEGMENT_SIZE: u32 = 1048576;
pub const VTX_ARENA_PAGE_SIZE: u32 = 65536;
pub const VTX_FRAME_ALIGNMENT: u32 = 16;
pub const VTX_INLINE_THRESHOLD: f64 = 0.6;
pub const VTX_INLINE_SIZE_LIMIT: u32 = 4096;
pub const VTX_INLINE_DEPTH_CHAIN: u32 = 16;
pub const VTX_INLINE_BUDGET_CHAIN: u32 = 16384;
pub const VTX_GUARD_ALPHA: f64 = 0.1;
pub const VTX_GUARD_WEAKEN_THRESHOLD: f64 = 0.01;
pub const VTX_GUARD_ABANDON_THRESHOLD: f64 = 0.25;
pub const VTX_VALUE_STABILITY_THRESHOLD: f64 = 0.95;
pub const VTX_VALUE_MIN_OBSERVATIONS: u32 = 100;
pub const VTX_VALUE_SAMPLE_INTERVAL_DEFAULT: u32 = 64;
pub const VTX_VALUE_SAMPLE_INTERVAL_STABLE: u32 = 256;
pub const VTX_VALUE_SAMPLE_INTERVAL_UNSTABLE: u32 = 16;
pub const VTX_NULL_PAGE_LIMIT: u32 = 65536;
pub const VTX_PROFILE_DIVERGENCE_THRESHOLD: f64 = 0.5;
pub const VTX_SIDE_EXIT_THRESHOLD: u32 = 5;
pub const VTX_STITCH_THRESHOLD: u32 = 10;
pub const VTX_LOOP_CV_THRESHOLD: f64 = 0.8;
pub const VTX_SPILL_THRESHOLD: f64 = 0.1;
pub const VTX_INLINE_DEOPT_THRESHOLD: f64 = 0.05;
pub const VTX_PHASE_MIN_METHODS: u32 = 3;
pub const VTX_PHASE_MIN_FREQUENCY: u32 = 1000;
pub const VTX_CONFIDENCE_THRESHOLD_BRANCH: u32 = 100;
pub const VTX_CONFIDENCE_THRESHOLD_CALL_TARGET: u32 = 50;
pub const VTX_CONFIDENCE_THRESHOLD_TYPE_DIST: u32 = 200;
pub const VTX_CONFIDENCE_THRESHOLD_LOOP_TRIP: u32 = 50;
pub const VTX_CONFIDENCE_THRESHOLD_FIELD_SHAPE: u32 = 100;
pub const VTX_PROMOTION_CONFIDENCE_T2: f64 = 0.5;
pub const VTX_PROMOTION_CONFIDENCE_T3: f64 = 0.75;
pub const VTX_PROMOTION_CONFIDENCE_T4: f64 = 0.9;
pub const VTX_RECOMP_HYSTERESIS_CONSECUTIVE: u32 = 3;
pub const VTX_RECOMP_QUEUE_SOFT_CAP: u32 = 64;
pub const VTX_RECOMP_QUEUE_HARD_CAP: u32 = 256;
pub const VTX_RECOMP_COALESCE_WINDOW_SEC: u32 = 1;
pub const VTX_RECOMP_COALESCE_MAX_DUPLICATES: u32 = 5;
pub const VTX_LRU_UPDATE_INTERVAL: u32 = 100;
pub const VTX_BENCH_WARMUP: u32 = 100;
pub const VTX_BENCH_ITERATIONS: u32 = 1000000;
pub const VTX_FEEDBACK_WINDOW: u32 = 10000;
pub const VTX_PROFILE_TYPE_BUFFER_SIZE: u32 = 32;
pub const VTX_GVN_MAX_ITERATIONS: u32 = 100;
pub const VTX_PIPELINE_MAX_ITERATIONS: u32 = 20;
pub const VTX_MAX_FIELDS_PER_OBJ: u32 = 256;
pub const VTX_TAG_SMI: u32 = 0;
pub const VTX_TAG_HEAP_PTR: u32 = 1;
pub const VTX_TAG_DOUBLE: u32 = 2;
pub const VTX_TAG_BOOL: u32 = 3;
pub const VTX_TAG_NULL: u32 = 4;
pub const VTX_TAG_UNDEFINED: u32 = 5;
pub const VTX_NAN_BOX_HEADER: u64 = 9221120237041090560;
pub const VTX_NAN_DATA_SHIFT: u32 = 3;
pub const VTX_NAN_DATA_MASK: u64 = 281474976710655;
pub const VTX_TYPE_INVALID: u32 = 0;
pub const VTX_TYPE_OBJECT: u32 = 1;
pub const VTX_TYPE_SMI: u32 = 2;
pub const VTX_SHAPE_INVALID: u32 = 0;
pub const VTX_SHAPE_OBJECT: u32 = 1;
pub const VTX_SYMBOL_TABLE_INITIAL_CAPACITY: u32 = 256;
pub const VTX_SYMBOL_INVALID: u32 = 4294967295;
pub const VTX_TYPE_SYSTEM_INITIAL_CAPACITY: u32 = 64;
pub const VTX_GC_YOUNG_SIZE: u32 = 4194304;
pub const VTX_GC_OLD_SIZE: u32 = 67108864;
pub const VTX_GC_PROMOTION_AGE: u32 = 3;
pub const VTX_GC_ROOT_STACK_SIZE: u32 = 4096;
pub const VTX_GC_REMEMBERED_SET_INIT: u32 = 256;
pub const VTX_CARD_SIZE: u32 = 512;
pub const VTX_CARD_SHIFT: u32 = 9;
pub const VTX_CARD_CLEAN: u32 = 0;
pub const VTX_CARD_DIRTY: u32 = 1;
pub const VTX_CALL_ARG_REGS: u32 = 6;
pub const VTX_SAFEOINT_MAX_THREADS: u32 = 256;
pub const VTX_FRAME_STACK_BLOCK_SIZE: u32 = 262144;
pub const VTX_FRAME_MAX_STACK_DEPTH: u32 = 1024;
pub const VTX_FRAME_MAX_LOCALS: u32 = 1024;
pub const VTX_CATCH_NONE: u32 = 4294967295;
pub const VTX_TIER_UP_INITIAL_COUNT: u32 = 10000;
pub const VTX_PROFILER_LRU_SIZE: u32 = 8;
pub const VTX_TYPE_FEEDBACK_BUFFER_SIZE: u32 = 32;
pub const VTX_TYPE_FREQ_MAX_SLOTS: u32 = 8;
pub const VTX_TYPE_SIGNATURE_MAX_SLOTS: u32 = 8;
pub const VTX_TYPE_STABILITY_WINDOW: u32 = 1000;
pub const VTX_SHAPE_STABILITY_WINDOW: u32 = 500;
pub const VTX_PQ_INITIAL_CAPACITY: u32 = 64;
pub const VTX_COMPILE_PRIORITY_LOW: u32 = 100;
pub const VTX_COMPILE_PRIORITY_NORMAL: u32 = 1000;
pub const VTX_COMPILE_PRIORITY_HIGH: u32 = 5000;
pub const VTX_MARKOV_MAX_PHASES: u32 = 16;
pub const VTX_MARKOV_MAX_METHODS: u32 = 256;
pub const VTX_FRAME_CALLER_RBP_OFFSET: u32 = 0;
pub const VTX_FRAME_PROFILE_DATA_OFFSET: u32 = 8;
pub const VTX_FRAME_DEOPT_INFO_OFFSET: u32 = 16;
pub const VTX_FRAME_METHOD_PTR_OFFSET: u32 = 24;
pub const VTX_FRAME_RETURN_ADDR_OFFSET: u32 = 32;
pub const VTX_FRAME_SAVED_RBX_OFFSET: i32 = -8;
pub const VTX_FRAME_SAVED_R12_OFFSET: i32 = -16;
pub const VTX_FRAME_SAVED_REGS_COUNT: u32 = 2;
pub const VTX_FRAME_SAVED_REGS_SIZE: u32 = 16;
pub const VTX_FRAME_HEADER_SLOTS_ABOVE: u32 = 4;
pub const VTX_EXPR_REG_COUNT: u32 = 4;
pub const VTX_GUARDS_INITIAL_CAPACITY: u32 = 32;
pub const VTX_NODE_INITIAL_INPUT_CAPACITY: u32 = 4;
pub const VTX_NODE_INITIAL_USE_CAPACITY: u32 = 4;
pub const VTX_NODE_TABLE_INITIAL_CAPACITY: u32 = 256;
pub const VTX_DEOPT_NO_HANDLER: u32 = 4294967295;
pub const VTX_STF_CALL_SITE: u32 = 1;
pub const VTX_STF_GUARD: u32 = 2;
pub const VTX_STF_SAFEPPOINT: u32 = 4;
pub const VTX_STF_ALLOCATION: u32 = 8;
pub const VTX_STF_OSR_ENTRY: u32 = 16;
pub const VTX_SIDE_TABLE_INITIAL_CAPACITY: u32 = 64;
pub const VTX_DEOPT_STUBS_INITIAL_CAPACITY: u32 = 32;
pub const VTX_RELOC_INITIAL_CAPACITY: u32 = 64;
pub const VTX_METHOD_REGISTRY_INITIAL_CAPACITY: u32 = 256;
pub const VTX_TYPEID_MEGAMORPHIC: u32 = 4294967294;
pub const VTX_PROFILE_INITIAL_METHOD_CAPACITY: u32 = 256;
pub const VTX_PROFILE_INITIAL_EDGE_CAPACITY: u32 = 512;
pub const VTX_TRIP_STABILITY_WINDOW: u32 = 500;
pub const VTX_PHASE_NONE: u32 = 4294967295;
pub const VTX_PHASE_PARTITION_INITIAL_CAPACITY: u32 = 16;
pub const VTX_INLINE_FEATURE_COUNT: u32 = 15;
pub const VTX_FEEDBACK_INITIAL_CAPACITY: u32 = 256;
pub const VTX_DEOPTLESS_MAX_VERSIONS: u32 = 8;
pub const VTX_PHASE_MATCH_THRESHOLD: f64 = 0.5;
pub const VTX_PHASE_SIGNATURE_SIZE: u32 = 10;
pub const VTX_VERSION_INITIAL_CAPACITY: u32 = 256;
pub const VTX_FDI_INITIAL_CAPACITY: u32 = 64;
pub const VTX_PHASE_REACT_MAX_PARKED: u32 = 16;
pub const VTX_PHASE_HASH_NONE: u32 = 0;
pub const VTX_PHASE_REACT_INITIAL_CAPACITY: u32 = 256;
pub const VTX_PHASE_REACT_DEFAULT_CODE_BUDGET: u32 = 8388608;
pub const VTX_ORCHESTRATOR_CHECK_INTERVAL_MS: u32 = 100;
pub const VTX_ORCHESTRATOR_MIN_PROFILE_OBS: u32 = 100;
pub const VTX_ORCHESTRATOR_PROACTIVE_COMPILE_LIMIT: u32 = 8;
pub const VTX_SPEC_VERSION_MAX: u32 = 64;
pub const VTX_SPEC_VERSION_MAX_ARGS: u32 = 4;
pub const VTX_SPEC_VERSION_FREQUENCY_THRESHOLD: f64 = 0.1;
pub const VTX_SPEC_VERSION_MIN_OBSERVATIONS: u32 = 500;
pub const VTX_SPEC_VERSION_STABILITY_THRESHOLD: f64 = 0.9;
pub const VTX_LOOP_VERSION_MAX: u32 = 8;
pub const VTX_LOOP_VERSION_MIN_TRIP_COUNT: u32 = 100;
pub const VTX_LOOP_VERSION_FREQUENCY_THRESHOLD: f64 = 0.7;
pub const VTX_LOOP_VERSION_MIN_OBSERVATIONS: u32 = 200;
pub const VTX_SPEC_VERSION_INITIAL_CAPACITY: u32 = 256;
pub const VTX_LOOP_VERSION_INITIAL_CAPACITY: u32 = 4;
pub const VTX_DEOPT_SITE_WINDOW_NS: u32 = 1000000000;
pub const VTX_DEOPT_SITE_FAIL_THRESHOLD: u32 = 100;
pub const VTX_DEOPT_BATCH_WINDOW_NS: u32 = 1000000;
pub const VTX_DEOPT_BATCH_MAX_PENDING: u32 = 64;
pub const VTX_DEOPT_GLOBAL_WINDOW_NS: u32 = 1000000000;
pub const VTX_DEOPT_GLOBAL_FAIL_THRESHOLD: u32 = 10000;
pub const VTX_DEOPT_COORD_MAX_SITES: u32 = 4096;
pub const VTX_VERSIONED_CACHE_MAX_METHODS: u32 = 4096;
pub const VTX_VERSIONED_CACHE_MAX_RETIRED: u32 = 8;
pub const VTX_CODE_BUFFER_INITIAL_CAPACITY: u32 = 4096;
pub const VTX_POLY_IC_SIZE: u32 = 4;
pub const VTX_POLY_IC_TYPE_IDS_OFFSET: u32 = 0;
pub const VTX_POLY_IC_TARGETS_OFFSET: u32 = 16;
pub const VTX_POLY_IC_COUNT_OFFSET: u32 = 48;
pub const VTX_POLY_IC_ENTRY_SIZE_TYPE: u32 = 4;
pub const VTX_POLY_IC_ENTRY_SIZE_TARGET: u32 = 8;
pub const VTX_DEP_SET_INITIAL_CAPACITY: u32 = 8;
pub const VTX_INVERTED_INDEX_CAPACITY: u32 = 256;
pub const VTX_GUARD_DEP_INITIAL_CAPACITY: u32 = 16;
pub const VTX_PROFILE_MAGIC: u32 = 1448038996;
pub const VTX_PROFILE_VERSION: u32 = 2;
pub const VTX_PROFILE_HASH_SIZE: u32 = 32;
pub const VTX_T1_CACHE_MAGIC: u32 = 1448039473;
pub const VTX_T1_CACHE_VERSION: u32 = 1;
pub const VTX_T1_CACHE_MAX_METHODS: u32 = 4096;
pub const VTX_T1_CACHE_MAX_CODE_SIZE: u32 = 16777216;
pub const VTX_GBDT_MAX_TREES: u32 = 100;
pub const VTX_GBDT_MAX_DEPTH: u32 = 5;
pub const VTX_GBDT_DEFAULT_TREE_COUNT: u32 = 30;
pub const VTX_GBDT_DEFAULT_DEPTH: u32 = 3;
pub const VTX_GBDT_LEAF_MARKER: u32 = 65535;
pub const VTX_GBDT_MAX_NODES_PER_TREE: u32 = 64;
pub const VTX_GBDT_MAX_TOTAL_NODES: u32 = 6400;
pub const VTX_MAX_CHAIN_DEPTH: u32 = 4;
pub const VTX_CHAIN_INLINE_BUDGET: u32 = 1024;
pub const VTX_CPU_SSE2: u32 = 1;
pub const VTX_CPU_AVX2: u32 = 2;
pub const VTX_CPU_AVX512: u32 = 4;
pub const VTX_VREG_COUNT_INITIAL: u32 = 256;
pub const VTX_VREG_FLAG_NONE: u32 = 0;
pub const VTX_VREG_FLAG_FIXED: u32 = 1;
pub const VTX_VREG_FLAG_XMM: u32 = 2;
pub const VTX_INST_MAX_OPERANDS: u32 = 3;
pub const VTX_INST_FLAG_NONE: u32 = 0;
pub const VTX_INST_FLAG_HAS_IMM: u32 = 1;
pub const VTX_INST_FLAG_HAS_MEM: u32 = 2;
pub const VTX_INST_FLAG_HAS_COND: u32 = 4;
pub const VTX_INST_FLAG_CLOBBER_RAX: u32 = 8;
pub const VTX_INST_FLAG_CLOBBER_RDX: u32 = 16;
pub const VTX_INST_FLAG_CLOBBER_RCX: u32 = 32;
pub const VTX_INST_FLAG_IS_CALL: u32 = 64;
pub const VTX_INST_FLAG_IS_GUARD: u32 = 128;
pub const VTX_INST_FLAG_IS_DEOPT: u32 = 256;
pub const VTX_INST_FLAG_IS_BRANCH: u32 = 512;
pub const VTX_INST_FLAG_CLOBBER_RSI: u32 = 1024;
pub const VTX_INST_FLAG_CLOBBER_RDI: u32 = 2048;
pub const VTX_INST_FLAG_CLOBBER_R8: u32 = 4096;
pub const VTX_INST_FLAG_CLOBBER_R9: u32 = 8192;
pub const VTX_INST_FLAG_CLOBBER_R10: u32 = 16384;
pub const VTX_INST_FLAG_CLOBBER_R11: u32 = 32768;
pub const VTX_INST_FLAG_PHI_COPY: u32 = 65536;
pub const VTX_INST_FLAG_SPILL_LOAD: u32 = 131072;
pub const VTX_INST_FLAG_SPILL_STORE: u32 = 262144;
pub const VTX_INST_FLAG_FUSED: u32 = 524288;
pub const VTX_INST_FLAG_IS_SSE: u32 = 1048576;
pub const VTX_INST_FLAG_IS_SAFEPOINT: u32 = 2097152;
pub const VTX_INST_FLAG_IMPLICIT_NULL: u32 = 4194304;
pub const VTX_INST_FLAG_VALUE_GUARD: u32 = 8388608;
pub const VTX_INST_FLAG_NO_TEST: u32 = 16777216;
pub const VTX_INST_FLAG_NO_COALESCE: u32 = 33554432;
pub const VTX_INST_FLAG_TARGET_SET: u32 = 67108864;
pub const VTX_INST_BLOCK_INITIAL_CAPACITY: u32 = 64;
pub const VTX_PHYS_REG_COUNT: u32 = 14;
pub const VTX_CALLER_SAVED_COUNT: u32 = 9;
pub const VTX_CALLEE_SAVED_COUNT: u32 = 5;
pub const VTX_REG_RESERVED_MASK: u32 = 15408;
pub const VTX_CALLER_SAVED_MASK: u32 = 4039;
pub const VTX_CALLEE_SAVED_MASK: u32 = 61448;
pub const VTX_XMM_COUNT: u32 = 16;
pub const VTX_XMM0: u32 = 0;
pub const VTX_XMM1: u32 = 1;
pub const VTX_XMM2: u32 = 2;
pub const VTX_XMM3: u32 = 3;
pub const VTX_XMM4: u32 = 4;
pub const VTX_XMM5: u32 = 5;
pub const VTX_XMM6: u32 = 6;
pub const VTX_XMM7: u32 = 7;
pub const VTX_XMM8: u32 = 8;
pub const VTX_XMM9: u32 = 9;
pub const VTX_XMM10: u32 = 10;
pub const VTX_XMM11: u32 = 11;
pub const VTX_XMM12: u32 = 12;
pub const VTX_XMM13: u32 = 13;
pub const VTX_XMM14: u32 = 14;
pub const VTX_XMM15: u32 = 15;
pub const VTX_XMM_RESERVED_MASK: u32 = 49152;
pub const VTX_XMM_ALL_MASK: u32 = 65535;
pub const VTX_XMM_ALLOCATABLE_MASK: u32 = 16383;
pub const VTX_EMIT_INITIAL_CAPACITY: u32 = 4096;
pub const VTX_GUARD_DESC_INITIAL_CAPACITY: u32 = 32;
pub const VTX_ENSEMBLE_MAX_RUNS: u32 = 5;
pub const VTX_ENSEMBLE_MIN_RUNS: u32 = 2;
pub const VTX_ENSEMBLE_MIN_SAMPLES: u32 = 1000;
pub const VTX_ENSEMBLE_MIN_DURATION_S: f64 = 1.0;
pub const VTX_ENSEMBLE_QUALITY_THRESHOLD: f64 = 0.3;
pub const VTX_ENSEMBLE_VALIDATION_WINDOW_S: u32 = 30;
pub const VTX_ENSEMBLE_ROLLBACK_DEOPT_RATE: f64 = 0.1;
pub const VTX_INPUT_SHAPE_DEFAULT: u32 = 0;
pub const VTX_INPUT_SHAPE_VERSION: u32 = 1;
pub const VTX_INPUT_SHAPE_MAX_PER_METHOD: u32 = 8;
pub const VTX_INPUT_SHAPE_MIN_SAMPLES_FOR_MULTI_VERSION: u32 = 100;
pub const VTX_SHAPE_DISPATCH_MAX_VERSIONS: u32 = 8;
pub const VTX_PATCH_LOG_MAGIC: u32 = 1448103756;
pub const VTX_PATCH_LOG_VERSION: u32 = 1;
pub const VTX_PATCH_LOG_MAX_PAYLOAD: u32 = 65536;
pub const VTX_PATCH_LOG_COMPACTION_THRESHOLD: u32 = 1000;
#[repr(C)]
#[derive(Copy, Clone)]
pub union __atomic_wide_counter {
pub __value64: ::std::os::raw::c_ulonglong,
pub __value32: __atomic_wide_counter__bindgen_ty_1,
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct __atomic_wide_counter__bindgen_ty_1 {
pub __low: ::std::os::raw::c_uint,
pub __high: ::std::os::raw::c_uint,
}
impl Default for __atomic_wide_counter {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __pthread_internal_list {
pub __prev: *mut __pthread_internal_list,
pub __next: *mut __pthread_internal_list,
}
impl Default for __pthread_internal_list {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
pub type __pthread_list_t = __pthread_internal_list;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __pthread_mutex_s {
pub __lock: ::std::os::raw::c_int,
pub __count: ::std::os::raw::c_uint,
pub __owner: ::std::os::raw::c_int,
pub __nusers: ::std::os::raw::c_uint,
pub __kind: ::std::os::raw::c_int,
pub __spins: ::std::os::raw::c_short,
pub __elision: ::std::os::raw::c_short,
pub __list: __pthread_list_t,
}
impl Default for __pthread_mutex_s {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct __pthread_cond_s {
pub __wseq: __atomic_wide_counter,
pub __g1_start: __atomic_wide_counter,
pub __g_size: [::std::os::raw::c_uint; 2usize],
pub __g1_orig_size: ::std::os::raw::c_uint,
pub __wrefs: ::std::os::raw::c_uint,
pub __g_signals: [::std::os::raw::c_uint; 2usize],
pub __unused_initialized_1: ::std::os::raw::c_uint,
pub __unused_initialized_2: ::std::os::raw::c_uint,
}
impl Default for __pthread_cond_s {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
pub type pthread_t = ::std::os::raw::c_ulong;
#[repr(C)]
#[derive(Copy, Clone)]
pub union pthread_mutex_t {
pub __data: __pthread_mutex_s,
pub __size: [::std::os::raw::c_char; 40usize],
pub __align: ::std::os::raw::c_long,
}
impl Default for pthread_mutex_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union pthread_cond_t {
pub __data: __pthread_cond_s,
pub __size: [::std::os::raw::c_char; 48usize],
pub __align: ::std::os::raw::c_longlong,
}
impl Default for pthread_cond_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " VORTEX Arena Allocator\n\n Region-based allocator used throughout the compiler pipeline.\n Each compilation gets its own arena; when compilation finishes,\n the entire arena is freed. No individual free — only wholesale reset.\n\n Pages are allocated via mmap and tracked in a singly-linked list.\n Allocations are 16-byte aligned within each page."]
pub type vtx_arena_page_t = vtx_arena_page;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_arena_page {
pub next: *mut vtx_arena_page_t,
pub size: usize,
pub used: usize,
}
impl Default for vtx_arena_page {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_arena_t {
pub first_page: *mut vtx_arena_page_t,
pub current_page: *mut vtx_arena_page_t,
pub total_allocated: usize,
}
impl Default for vtx_arena_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize an arena with its initial 64KB page.\n Returns 0 on success, -1 on failure (mmap error)."]
pub fn vtx_arena_init(arena: *mut vtx_arena_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Allocate `size` bytes from the arena with 16-byte alignment.\n If the current page doesn't have enough space, a new 64KB page\n (or larger if size requires it) is allocated via mmap.\n Returns a valid pointer on success, NULL on failure."]
pub fn vtx_arena_alloc(arena: *mut vtx_arena_t, size: usize) -> *mut ::std::os::raw::c_void;
}
extern "C" {
#[doc = " Reset the arena: free all pages except the first, and reset\n the allocation position within the first page to the beginning."]
pub fn vtx_arena_reset(arena: *mut vtx_arena_t);
}
extern "C" {
#[doc = " Destroy the arena: munmap all pages and zero out the struct."]
pub fn vtx_arena_destroy(arena: *mut vtx_arena_t);
}
extern "C" {
#[doc = " Return total number of bytes currently allocated from this arena."]
pub fn vtx_arena_total_allocated(arena: *const vtx_arena_t) -> usize;
}
pub type vtx_value_t = u64;
#[doc = " Heap object layout:\n\n +-------------------+\n | type_id (4) | Type descriptor index\n | gc_mark (1) | GC mark bit\n | gc_age (1) | Number of young-gen collections survived\n | gc_pinned (1) | 1 if pinned (cannot be moved by GC)\n | gc_remembered (1) | 1 if in old gen remembered set\n | size (4) | Total size in bytes including this header\n | shape_id (4) | Shape/layout fingerprint\n | field_count (4) | Number of fields following this header\n +-------------------+\n | fields[0] (8) | Field 0 (tagged value)\n | fields[1] (8) | Field 1\n | ... |\n +-------------------+\n\n The header is padded to 8-byte alignment. Fields are vtx_value_t (8 bytes each)."]
#[repr(C)]
#[derive(Debug, Default)]
pub struct vtx_heap_object_t {
pub type_id: u32,
pub gc_mark: u8,
pub gc_age: u8,
pub gc_pinned: u8,
pub gc_remembered: u8,
pub size: u32,
pub shape_id: u32,
pub field_count: u32,
pub fields: __IncompleteArrayField<vtx_value_t>,
}
extern "C" {
#[doc = " Initialize a heap object header. Does NOT initialize fields."]
pub fn vtx_heap_object_init(
obj: *mut vtx_heap_object_t,
type_id: u32,
shape_id: u32,
field_count: u32,
total_size: u32,
);
}
extern "C" {
#[doc = " Get the type_id from a tagged value that is a heap pointer."]
pub fn vtx_value_typeid(v: vtx_value_t) -> u32;
}
pub const vtx_opcode_t_VT_OP_HALT: vtx_opcode_t = 0;
pub const vtx_opcode_t_VT_OP_NOP: vtx_opcode_t = 1;
pub const vtx_opcode_t_VT_OP_LOAD_LOCAL: vtx_opcode_t = 2;
pub const vtx_opcode_t_VT_OP_STORE_LOCAL: vtx_opcode_t = 3;
pub const vtx_opcode_t_VT_OP_LOAD_FIELD: vtx_opcode_t = 4;
pub const vtx_opcode_t_VT_OP_STORE_FIELD: vtx_opcode_t = 5;
pub const vtx_opcode_t_VT_OP_LOAD_CONST_INT: vtx_opcode_t = 6;
pub const vtx_opcode_t_VT_OP_LOAD_CONST_FLOAT: vtx_opcode_t = 7;
pub const vtx_opcode_t_VT_OP_LOAD_CONST_STR: vtx_opcode_t = 8;
pub const vtx_opcode_t_VT_OP_LOAD_NULL: vtx_opcode_t = 9;
pub const vtx_opcode_t_VT_OP_LOAD_TRUE: vtx_opcode_t = 10;
pub const vtx_opcode_t_VT_OP_LOAD_FALSE: vtx_opcode_t = 11;
pub const vtx_opcode_t_VT_OP_LOAD_UNDEFINED: vtx_opcode_t = 12;
pub const vtx_opcode_t_VT_OP_IADD: vtx_opcode_t = 13;
pub const vtx_opcode_t_VT_OP_ISUB: vtx_opcode_t = 14;
pub const vtx_opcode_t_VT_OP_IMUL: vtx_opcode_t = 15;
pub const vtx_opcode_t_VT_OP_IDIV: vtx_opcode_t = 16;
pub const vtx_opcode_t_VT_OP_IMOD: vtx_opcode_t = 17;
pub const vtx_opcode_t_VT_OP_FADD: vtx_opcode_t = 18;
pub const vtx_opcode_t_VT_OP_FSUB: vtx_opcode_t = 19;
pub const vtx_opcode_t_VT_OP_FMUL: vtx_opcode_t = 20;
pub const vtx_opcode_t_VT_OP_FDIV: vtx_opcode_t = 21;
pub const vtx_opcode_t_VT_OP_ISHL: vtx_opcode_t = 22;
pub const vtx_opcode_t_VT_OP_ISHR: vtx_opcode_t = 23;
pub const vtx_opcode_t_VT_OP_IAND: vtx_opcode_t = 24;
pub const vtx_opcode_t_VT_OP_IOR: vtx_opcode_t = 25;
pub const vtx_opcode_t_VT_OP_IXOR: vtx_opcode_t = 26;
pub const vtx_opcode_t_VT_OP_INEG: vtx_opcode_t = 27;
pub const vtx_opcode_t_VT_OP_INOT: vtx_opcode_t = 28;
pub const vtx_opcode_t_VT_OP_ICMP_EQ: vtx_opcode_t = 29;
pub const vtx_opcode_t_VT_OP_ICMP_NE: vtx_opcode_t = 30;
pub const vtx_opcode_t_VT_OP_ICMP_LT: vtx_opcode_t = 31;
pub const vtx_opcode_t_VT_OP_ICMP_LE: vtx_opcode_t = 32;
pub const vtx_opcode_t_VT_OP_ICMP_GT: vtx_opcode_t = 33;
pub const vtx_opcode_t_VT_OP_ICMP_GE: vtx_opcode_t = 34;
pub const vtx_opcode_t_VT_OP_FCMP_EQ: vtx_opcode_t = 35;
pub const vtx_opcode_t_VT_OP_FCMP_NE: vtx_opcode_t = 36;
pub const vtx_opcode_t_VT_OP_FCMP_LT: vtx_opcode_t = 37;
pub const vtx_opcode_t_VT_OP_FCMP_LE: vtx_opcode_t = 38;
pub const vtx_opcode_t_VT_OP_FCMP_GT: vtx_opcode_t = 39;
pub const vtx_opcode_t_VT_OP_FCMP_GE: vtx_opcode_t = 40;
pub const vtx_opcode_t_VT_OP_GOTO: vtx_opcode_t = 41;
pub const vtx_opcode_t_VT_OP_IF_TRUE: vtx_opcode_t = 42;
pub const vtx_opcode_t_VT_OP_IF_FALSE: vtx_opcode_t = 43;
pub const vtx_opcode_t_VT_OP_CALL_STATIC: vtx_opcode_t = 44;
pub const vtx_opcode_t_VT_OP_CALL_VIRTUAL: vtx_opcode_t = 45;
pub const vtx_opcode_t_VT_OP_CALL_INTERFACE: vtx_opcode_t = 46;
pub const vtx_opcode_t_VT_OP_RETURN: vtx_opcode_t = 47;
pub const vtx_opcode_t_VT_OP_RETURN_VALUE: vtx_opcode_t = 48;
pub const vtx_opcode_t_VT_OP_NEW: vtx_opcode_t = 49;
pub const vtx_opcode_t_VT_OP_NEWARRAY: vtx_opcode_t = 50;
pub const vtx_opcode_t_VT_OP_CHECKCAST: vtx_opcode_t = 51;
pub const vtx_opcode_t_VT_OP_INSTANCEOF: vtx_opcode_t = 52;
pub const vtx_opcode_t_VT_OP_ARRAY_LOAD: vtx_opcode_t = 53;
pub const vtx_opcode_t_VT_OP_ARRAY_STORE: vtx_opcode_t = 54;
pub const vtx_opcode_t_VT_OP_ARRAY_LENGTH: vtx_opcode_t = 55;
pub const vtx_opcode_t_VT_OP_THROW: vtx_opcode_t = 56;
pub const vtx_opcode_t_VT_OP_CATCH: vtx_opcode_t = 57;
pub const vtx_opcode_t_VT_OP_CATCH_TYPED: vtx_opcode_t = 58;
pub const vtx_opcode_t_VT_OP_MONITOR_ENTER: vtx_opcode_t = 59;
pub const vtx_opcode_t_VT_OP_MONITOR_EXIT: vtx_opcode_t = 60;
pub const vtx_opcode_t_VT_OP_DUP: vtx_opcode_t = 61;
pub const vtx_opcode_t_VT_OP_POP: vtx_opcode_t = 62;
pub const vtx_opcode_t_VT_OP_SWAP: vtx_opcode_t = 63;
pub const vtx_opcode_t_VT_OP_ISNULL: vtx_opcode_t = 64;
pub const vtx_opcode_t_VT_OP_TYPEOF: vtx_opcode_t = 65;
pub const vtx_opcode_t_VT_OP_CALL_RUNTIME: vtx_opcode_t = 66;
pub const vtx_opcode_t_VT_OP_COUNT: vtx_opcode_t = 67;
#[doc = " VORTEX Bytecode Format\n\n Variable-length instruction stream. Each instruction consists of:\n - 1 byte: opcode\n - 0, 1, or 2 bytes: operand (depending on opcode)\n\n Operands are stored in big-endian format (2-byte operands).\n The constant pool contains tagged values indexed by LOAD_CONST_* operands."]
pub type vtx_opcode_t = ::std::os::raw::c_uint;
#[doc = " Per-opcode metadata: name, stack input/output counts, operand info."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_opcode_info_t {
pub name: *const ::std::os::raw::c_char,
pub stack_input_count: u8,
pub stack_output_count: u8,
pub has_operand: bool,
pub operand_size: u8,
}
impl Default for vtx_opcode_info_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " A bytecode module: code + constant pool."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_bytecode_t {
pub code: *const u8,
pub length: usize,
pub constant_pool: *mut vtx_value_t,
pub constant_count: u32,
pub max_locals: u16,
pub max_stack: u16,
}
impl Default for vtx_bytecode_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Read the opcode at the given PC."]
pub fn vtx_bytecode_opcode_at(bc: *const vtx_bytecode_t, pc: usize) -> vtx_opcode_t;
}
extern "C" {
#[doc = " Read a 2-byte big-endian operand at pc+1.\n Returns the 16-bit unsigned operand value."]
pub fn vtx_bytecode_read_operand(bc: *const vtx_bytecode_t, pc: usize) -> u16;
}
extern "C" {
#[doc = " Compute the net stack effect of an opcode (output_count - input_count).\n Returns a negative number if the opcode pops more than it pushes."]
pub fn vtx_bytecode_stack_effect(opcode: vtx_opcode_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Compute the actual maximum operand stack depth by abstract interpretation.\n\n Walks the bytecode tracking stack depth at each PC, handling branches\n via a worklist algorithm. This produces an accurate max_stack that\n accounts for all control-flow paths, even when the bytecode's declared\n max_stack is too low (a common cause of spill-index-out-of-bounds bugs).\n\n @param bc The bytecode module\n @param max_locals Number of local variable slots (for context)\n @return The computed maximum stack depth (at least 0)"]
pub fn vtx_bytecode_compute_max_stack(bc: *const vtx_bytecode_t, max_locals: u32) -> u32;
}
extern "C" {
#[doc = " Disassemble one instruction at `pc` into the provided buffer.\n Returns the PC of the next instruction (pc + instruction length).\n Writes at most bufsize-1 characters plus a null terminator."]
pub fn vtx_bytecode_disassemble_op(
bc: *const vtx_bytecode_t,
pc: usize,
buf: *mut ::std::os::raw::c_char,
bufsize: usize,
) -> usize;
}
extern "C" {
#[doc = " Compute the length (in bytes) of the instruction at `pc`."]
pub fn vtx_bytecode_insn_length(bc: *const vtx_bytecode_t, pc: usize) -> usize;
}
extern "C" {
#[doc = " Scan the bytecode stream for the highest local index referenced by\n any LOAD_LOCAL or STORE_LOCAL instruction. Used as a fallback when\n the bytecode file format does not include an explicit max_locals\n field (VOBC v1 files, or files loaded by main_new.c's own loader).\n\n Without this scan, max_locals stays as uninitialized arena memory,\n causing the locals array to be undersized — STORE_LOCAL N then\n aliases with the operand stack, producing silent data corruption.\n\n @param bc The bytecode module (must have code + length populated)\n @return The highest local index used (0 if no locals are referenced)"]
pub fn vtx_bytecode_scan_max_locals(bc: *const vtx_bytecode_t) -> u16;
}
#[doc = " VORTEX Type System\n\n Types are represented as TypeIDs that index into a type descriptor table.\n Type descriptors contain: name, field layout, method table, parent type,\n implemented interfaces, and shape ID.\n\n Type identity is structural for interfaces, nominal for classes.\n Inline caches support monomorphic, polymorphic (up to VTX_POLY_LIMIT\n types per site), and megamorphic transitions."]
pub type vtx_typeid_t = u32;
pub type vtx_shapeid_t = u32;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_field_desc_t {
pub name: *const ::std::os::raw::c_char,
pub type_: vtx_typeid_t,
pub offset: u32,
}
impl Default for vtx_field_desc_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_method_desc_t {
pub name: *const ::std::os::raw::c_char,
pub signature: *const ::std::os::raw::c_char,
pub bytecode: *mut vtx_bytecode_t,
pub compiled_code: *mut ::std::os::raw::c_void,
pub vtable_index: u32,
pub arg_count: u32,
pub method_symbol_id: u32,
pub is_virtual: bool,
}
impl Default for vtx_method_desc_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
pub type vtx_type_desc_t = vtx_type_desc;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_type_desc {
pub name: *const ::std::os::raw::c_char,
pub type_id: vtx_typeid_t,
pub parent_type: vtx_typeid_t,
pub field_count: u32,
pub fields: *mut vtx_field_desc_t,
pub method_count: u32,
pub methods: *mut vtx_method_desc_t,
pub shape_id: vtx_shapeid_t,
pub instance_size: u32,
pub vtable: *mut *mut ::std::os::raw::c_void,
pub vtable_size: u32,
pub interface_count: u32,
pub interfaces: *mut vtx_typeid_t,
}
impl Default for vtx_type_desc {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_symbol_t {
pub name: *const ::std::os::raw::c_char,
pub hash: u32,
pub length: u32,
}
impl Default for vtx_symbol_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_symbol_table_t {
pub symbols: *mut vtx_symbol_t,
pub symbol_count: u32,
pub symbol_capacity: u32,
pub hash_buckets: *mut u32,
pub hash_bucket_count: u32,
}
impl Default for vtx_symbol_table_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_type_system_t {
pub types: *mut vtx_type_desc_t,
pub type_count: u32,
pub capacity: u32,
pub shape_counter: vtx_shapeid_t,
pub symbol_table: vtx_symbol_table_t,
}
impl Default for vtx_type_system_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the type system with the root Object type pre-registered.\n Returns 0 on success, -1 on failure."]
pub fn vtx_type_system_init(ts: *mut vtx_type_system_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the type system and free all allocated memory."]
pub fn vtx_type_system_destroy(ts: *mut vtx_type_system_t);
}
extern "C" {
#[doc = " Intern a string: returns the symbol ID, creating a new entry if needed.\n The name pointer must remain valid for the lifetime of the type system."]
pub fn vtx_symbol_intern(
ts: *mut vtx_type_system_t,
name: *const ::std::os::raw::c_char,
) -> u32;
}
extern "C" {
#[doc = " Look up a symbol by name: returns VTX_SYMBOL_INVALID if not found."]
pub fn vtx_symbol_lookup(
ts: *const vtx_type_system_t,
name: *const ::std::os::raw::c_char,
) -> u32;
}
extern "C" {
#[doc = " Get a symbol's name by ID. Returns NULL if the symbol ID is invalid."]
pub fn vtx_symbol_name(
ts: *const vtx_type_system_t,
symbol_id: u32,
) -> *const ::std::os::raw::c_char;
}
extern "C" {
#[doc = " Get/set the global type system instance.\n Used by the interpreter and runtime stubs for type queries."]
pub fn vtx_get_current_type_system() -> *mut vtx_type_system_t;
}
extern "C" {
pub fn vtx_set_current_type_system(ts: *mut vtx_type_system_t);
}
extern "C" {
#[doc = " Register a new type. Returns the new TypeID on success,\n VTX_TYPE_INVALID on failure.\n\n The type system takes ownership of the fields and methods arrays\n (but NOT the strings they point to — those must outlive the type system)."]
pub fn vtx_type_register(
ts: *mut vtx_type_system_t,
name: *const ::std::os::raw::c_char,
parent_id: vtx_typeid_t,
field_count: u32,
fields: *mut vtx_field_desc_t,
method_count: u32,
methods: *mut vtx_method_desc_t,
) -> vtx_typeid_t;
}
extern "C" {
#[doc = " Get a type descriptor by ID. Returns NULL if the ID is invalid."]
pub fn vtx_type_get(ts: *const vtx_type_system_t, id: vtx_typeid_t) -> *const vtx_type_desc_t;
}
extern "C" {
#[doc = " Check if child_id is a subtype of parent_id by walking the parent chain.\n A type is considered a subtype of itself."]
pub fn vtx_type_is_subtype(
ts: *const vtx_type_system_t,
child_id: vtx_typeid_t,
parent_id: vtx_typeid_t,
) -> bool;
}
extern "C" {
#[doc = " Check if obj_typeid is an instance of target_typeid.\n This includes subtype checking AND interface implementation checking."]
pub fn vtx_type_is_instance(
ts: *const vtx_type_system_t,
obj_typeid: vtx_typeid_t,
target_typeid: vtx_typeid_t,
) -> bool;
}
extern "C" {
#[doc = " Resolve a method by name for a given type.\n For virtual methods, walks the vtable. For non-virtual, looks up directly.\n Returns NULL if not found."]
pub fn vtx_type_resolve_method(
ts: *const vtx_type_system_t,
typeid: vtx_typeid_t,
method_name: *const ::std::os::raw::c_char,
) -> *const vtx_method_desc_t;
}
extern "C" {
#[doc = " Compute the instance size for a type based on its field layout\n with alignment rules. The instance size includes the heap object header."]
pub fn vtx_type_instance_size(ts: *mut vtx_type_system_t, typeid: vtx_typeid_t) -> u32;
}
extern "C" {
#[doc = " Compute a shape ID for the type. The shape is a layout fingerprint based\n on field offsets and types. Two types with the same shape have compatible\n field layouts and can share inline cache entries."]
pub fn vtx_type_compute_shape(
ts: *mut vtx_type_system_t,
typeid: vtx_typeid_t,
) -> vtx_shapeid_t;
}
extern "C" {
#[doc = " Add an interface to a type's implemented interfaces list.\n Returns 0 on success, -1 on failure."]
pub fn vtx_type_add_interface(
ts: *mut vtx_type_system_t,
impl_type: vtx_typeid_t,
interface_type: vtx_typeid_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " RT-13 fix: Update the vtable entry for a method after it has been compiled.\n Must be called when a method's compiled_code pointer changes (e.g., after JIT\n compilation) so that virtual dispatch through the vtable uses the new code.\n\n @param ts Type system\n @param typeid Type that owns the method\n @param method Pointer to the method descriptor (must be in the type's methods array)\n @return 0 on success, -1 on failure"]
pub fn vtx_type_update_vtable(
ts: *mut vtx_type_system_t,
typeid: vtx_typeid_t,
method: *const vtx_method_desc_t,
) -> ::std::os::raw::c_int;
}
pub const vtx_ic_state_t_VT_IC_MONOMORPHIC: vtx_ic_state_t = 0;
pub const vtx_ic_state_t_VT_IC_POLYMORPHIC: vtx_ic_state_t = 1;
pub const vtx_ic_state_t_VT_IC_MEGAMORPHIC: vtx_ic_state_t = 2;
pub type vtx_ic_state_t = ::std::os::raw::c_uint;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_ic_entry_t {
pub typeid_: vtx_typeid_t,
pub method: *const vtx_method_desc_t,
}
impl Default for vtx_ic_entry_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_inline_cache_t {
pub state: vtx_ic_state_t,
pub entries: [vtx_ic_entry_t; 5usize],
pub count: u32,
pub lock: ::std::os::raw::c_int,
}
impl Default for vtx_inline_cache_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize an inline cache to empty monomorphic state."]
pub fn vtx_ic_init(ic: *mut vtx_inline_cache_t);
}
extern "C" {
#[doc = " Look up a method in the inline cache for the given typeid.\n Returns the method pointer if found, NULL otherwise."]
pub fn vtx_ic_lookup(
ic: *const vtx_inline_cache_t,
typeid_: vtx_typeid_t,
) -> *const vtx_method_desc_t;
}
extern "C" {
#[doc = " Update the inline cache with a new typeid → method mapping.\n Transitions the state: monomorphic → polymorphic → megamorphic."]
pub fn vtx_ic_update(
ic: *mut vtx_inline_cache_t,
typeid_: vtx_typeid_t,
method: *const vtx_method_desc_t,
);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_safepoint_manager {
_unused: [u8; 0],
}
pub const vtx_gc_mode_t_VTX_GC_GENERATIONAL: vtx_gc_mode_t = 0;
pub const vtx_gc_mode_t_VTX_GC_NONE: vtx_gc_mode_t = 1;
pub const vtx_gc_mode_t_VTX_GC_MANUAL: vtx_gc_mode_t = 2;
pub const vtx_gc_mode_t_VTX_GC_ARENA: vtx_gc_mode_t = 3;
pub type vtx_gc_mode_t = ::std::os::raw::c_uint;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_semi_space_t {
pub start: *mut u8,
pub current: *mut u8,
pub size: usize,
}
impl Default for vtx_semi_space_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
pub type vtx_free_node_t = vtx_free_node;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_free_node {
pub pad_type_id: u32,
pub gc_mark: u8,
pub pad_age: u8,
pub pad_pinned: u8,
pub pad_remembered: u8,
pub size_low: u32,
pub size_high: u32,
pub next: *mut vtx_free_node_t,
}
impl Default for vtx_free_node {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_old_gen_t {
pub start: *mut u8,
pub size: usize,
pub used: usize,
pub free_list: *mut vtx_free_node_t,
}
impl Default for vtx_old_gen_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_remembered_entry_t {
pub obj: *mut vtx_heap_object_t,
}
impl Default for vtx_remembered_entry_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_root_entry_t {
pub value: vtx_value_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_gc_t {
pub young_from: vtx_semi_space_t,
pub young_to: vtx_semi_space_t,
pub old_gen: vtx_old_gen_t,
pub root_stack: *mut vtx_root_entry_t,
pub root_count: u32,
pub root_capacity: u32,
pub remembered_set: *mut vtx_remembered_entry_t,
pub remembered_count: u32,
pub remembered_capacity: u32,
pub type_system: *mut vtx_type_system_t,
pub collection_requested: bool,
pub collections_done: u32,
pub pinned_objects: *mut *mut vtx_heap_object_t,
pub pinned_count: u32,
pub pinned_capacity: u32,
pub mode: vtx_gc_mode_t,
pub fn_write_barrier: ::std::option::Option<
unsafe extern "C" fn(
gc: *mut vtx_gc_t,
obj: *mut vtx_heap_object_t,
field_offset: u32,
value: vtx_value_t,
),
>,
pub fn_safepoint: ::std::option::Option<unsafe extern "C" fn(gc: *mut vtx_gc_t)>,
pub fn_root_push:
::std::option::Option<unsafe extern "C" fn(gc: *mut vtx_gc_t, value: vtx_value_t)>,
pub fn_root_pop: ::std::option::Option<unsafe extern "C" fn(gc: *mut vtx_gc_t) -> vtx_value_t>,
pub manual_free_list: *mut vtx_free_node_t,
pub arena_save_point: *mut u8,
pub card_table: *mut u8,
pub card_table_size: usize,
pub heap_base: *mut u8,
pub heap_size: usize,
pub safepoint_mgr: *mut ::std::os::raw::c_void,
pub jit_root_scan_fn: ::std::option::Option<unsafe extern "C" fn(gc: *mut vtx_gc_t)>,
}
impl Default for vtx_gc_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the garbage collector. Requires a type_system for\n object size/field layout information.\n The mode parameter selects the GC strategy.\n Returns 0 on success, -1 on failure."]
pub fn vtx_gc_init(
gc: *mut vtx_gc_t,
ts: *mut vtx_type_system_t,
mode: vtx_gc_mode_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the garbage collector and release all memory."]
pub fn vtx_gc_destroy(gc: *mut vtx_gc_t);
}
extern "C" {
#[doc = " Allocate a heap object of the given size with the given type_id.\n Allocates in the young generation using bump-pointer allocation.\n Returns a pointer to the initialized heap object, or NULL on failure.\n The object header is initialized; fields are set to VTX_VALUE_UNDEFINED."]
pub fn vtx_gc_alloc(
gc: *mut vtx_gc_t,
size: usize,
type_id: vtx_typeid_t,
) -> *mut vtx_heap_object_t;
}
extern "C" {
#[doc = " Check if collection has been requested and if so, perform a young-gen\n collection. This should be called at safe points (backward branches,\n method calls)."]
pub fn vtx_gc_safepoint(gc: *mut vtx_gc_t);
}
extern "C" {
#[doc = " Push a value onto the GC root stack. The value (if it contains a\n heap pointer) will be traced during collection."]
pub fn vtx_gc_root_push(gc: *mut vtx_gc_t, value: vtx_value_t);
}
extern "C" {
#[doc = " Pop a value from the GC root stack."]
pub fn vtx_gc_root_pop(gc: *mut vtx_gc_t) -> vtx_value_t;
}
extern "C" {
#[doc = " Generational write barrier. Call this when storing a value into a\n field of an object. If the object is in old gen and the value is\n a young-gen pointer, the object is added to the remembered set."]
pub fn vtx_gc_write_barrier(
gc: *mut vtx_gc_t,
obj: *mut vtx_heap_object_t,
field_offset: u32,
value: vtx_value_t,
);
}
extern "C" {
#[doc = " Card marking write barrier. Replaces the old 10-branch barrier with\n ~3 instructions on the fast path: check if value is young-gen, compute\n card index, mark card dirty. Used in generational mode."]
pub fn vtx_gc_write_barrier_card(
gc: *mut vtx_gc_t,
obj: *mut vtx_heap_object_t,
field_offset: u32,
value: vtx_value_t,
);
}
extern "C" {
#[doc = " Card-table dirty-marking helper. Marks the card containing the\n given field address as dirty (0xFF). Called by the JIT write\n barrier runtime helper (vtx_helpers_write_barrier) and by the\n GC internals during card-table scanning.\n\n @param gc GC instance (must not be NULL)\n @param field_addr Address of the field that was written"]
pub fn vtx_gc_card_mark_dirty(gc: *mut vtx_gc_t, field_addr: *const ::std::os::raw::c_void);
}
extern "C" {
#[doc = " Perform a young-generation collection (copying collector).\n Copies live objects from young_from to young_to, then swaps.\n Promotes survivors that have survived >= VTX_GC_PROMOTION_AGE collections."]
pub fn vtx_gc_collect_young(gc: *mut vtx_gc_t);
}
extern "C" {
#[doc = " Perform an old-generation collection (mark-sweep).\n Marks all reachable objects from roots, then sweeps unreachable ones."]
pub fn vtx_gc_collect_old(gc: *mut vtx_gc_t);
}
extern "C" {
#[doc = " Pin an object so it won't be moved during young-gen collection.\n Used when JIT code holds raw pointers to the object."]
pub fn vtx_gc_pin(gc: *mut vtx_gc_t, obj: *mut vtx_heap_object_t);
}
extern "C" {
#[doc = " Unpin an object."]
pub fn vtx_gc_unpin(gc: *mut vtx_gc_t, obj: *mut vtx_heap_object_t);
}
extern "C" {
#[doc = " Check if an object is pinned."]
pub fn vtx_gc_is_pinned(gc: *mut vtx_gc_t, obj: *mut vtx_heap_object_t) -> bool;
}
extern "C" {
#[doc = " Set the GC mode at runtime. This reconfigures the function pointers\n and may adjust internal state for the new mode."]
pub fn vtx_gc_set_mode(gc: *mut vtx_gc_t, mode: vtx_gc_mode_t);
}
extern "C" {
#[doc = " Get the current GC mode."]
pub fn vtx_gc_get_mode(gc: *const vtx_gc_t) -> vtx_gc_mode_t;
}
extern "C" {
#[doc = " Manual mode: free a previously allocated object.\n Adds the block to a free list for O(1) free.\n Only valid when mode is VTX_GC_MANUAL."]
pub fn vtx_gc_manual_free(gc: *mut vtx_gc_t, ptr: *mut ::std::os::raw::c_void, size: usize);
}
extern "C" {
#[doc = " Arena mode: save current allocation point.\n Only valid when mode is VTX_GC_ARENA."]
pub fn vtx_gc_arena_enter(gc: *mut vtx_gc_t);
}
extern "C" {
#[doc = " Arena mode: restore to saved allocation point (free everything since enter).\n Only valid when mode is VTX_GC_ARENA."]
pub fn vtx_gc_arena_leave(gc: *mut vtx_gc_t);
}
extern "C" {
#[doc = " Get the current GC instance (thread-local in a full VM; global for now).\n This is used by runtime helpers (e.g., write barrier) that need GC access\n but are called from JIT-compiled code which doesn't pass a GC pointer."]
pub fn vtx_get_current_gc() -> *mut vtx_gc_t;
}
extern "C" {
#[doc = " Set the current GC instance. Called during VM initialization."]
pub fn vtx_set_current_gc(gc: *mut vtx_gc_t);
}
extern "C" {
#[doc = " Check if a pointer falls within the young generation from-space."]
pub fn vtx_gc_in_young(gc: *const vtx_gc_t, ptr: *const ::std::os::raw::c_void) -> bool;
}
extern "C" {
#[doc = " Check if a pointer falls within the old generation."]
pub fn vtx_gc_in_old(gc: *const vtx_gc_t, ptr: *const ::std::os::raw::c_void) -> bool;
}
extern "C" {
#[doc = " Get the total number of bytes allocated in young gen."]
pub fn vtx_gc_young_used(gc: *const vtx_gc_t) -> usize;
}
extern "C" {
#[doc = " Get the total number of bytes used in old gen."]
pub fn vtx_gc_old_used(gc: *const vtx_gc_t) -> usize;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_method_desc {
_unused: [u8; 0],
}
extern "C" {
#[doc = " Type check: verify that a value's heap object is an instance of\n the expected type. Returns true if the check passes.\n If the value is not a heap pointer, returns false."]
pub fn vtx_helpers_type_check(
ts: *const vtx_type_system_t,
obj_value: vtx_value_t,
expected_typeid: vtx_typeid_t,
) -> bool;
}
extern "C" {
#[doc = " Null check: returns true if the value is NOT null.\n Calls abort() (trap) if the value IS null. This is a runtime trap\n used by the interpreter and JIT code."]
pub fn vtx_helpers_null_check(value: vtx_value_t) -> bool;
}
extern "C" {
#[doc = " Bounds check: returns true if 0 <= index < length.\n Calls abort() (trap) if the index is out of bounds."]
pub fn vtx_helpers_bounds_check(index: i64, length: i64) -> bool;
}
extern "C" {
#[doc = " Check if integer addition would overflow.\n Returns true if a + b does NOT overflow int64_t."]
pub fn vtx_helpers_overflow_check_iadd(a: i64, b: i64) -> bool;
}
extern "C" {
#[doc = " Check if integer multiplication would overflow.\n Returns true if a * b does NOT overflow int64_t."]
pub fn vtx_helpers_overflow_check_imul(a: i64, b: i64) -> bool;
}
extern "C" {
#[doc = " Resolve a virtual method call using inline caching.\n First attempts IC lookup; on miss, does a full vtable walk and\n updates the IC.\n\n Returns the resolved method descriptor, or NULL if not found."]
pub fn vtx_helpers_resolve_virtual(
ts: *mut vtx_type_system_t,
ic: *mut vtx_inline_cache_t,
obj_value: vtx_value_t,
method_name: *const ::std::os::raw::c_char,
) -> *const vtx_method_desc_t;
}
extern "C" {
#[doc = " Resolve an interface method call using inline caching.\n Similar to virtual resolution but also checks interface implementations.\n\n Returns the resolved method descriptor, or NULL if not found."]
pub fn vtx_helpers_resolve_interface(
ts: *mut vtx_type_system_t,
ic: *mut vtx_inline_cache_t,
obj_value: vtx_value_t,
interface_typeid: vtx_typeid_t,
method_name: *const ::std::os::raw::c_char,
) -> *const vtx_method_desc_t;
}
extern "C" {
#[doc = " Compare two string objects stored as heap objects.\n Both values must be heap pointers to string objects.\n Returns <0, 0, >0 like strcmp.\n\n String objects have their character data stored starting at field index 0\n as a sequence of bytes. The first field (fields[0]) stores the length\n as an SMI, and subsequent fields store the character data packed into\n vtx_value_t words.\n\n Actually, for simplicity, we store strings with:\n field[0] = length (SMI)\n field[1] through field[N] = packed char data in vtx_value_t slots\n\n For a simpler approach, we store the string data as a C string\n in the fields array starting at offset 1."]
pub fn vtx_helpers_string_compare(a: vtx_value_t, b: vtx_value_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Get the C-string data from a string heap object.\n Returns a pointer to a null-terminated string, or \"\" if not a string."]
pub fn vtx_helpers_string_data(str_value: vtx_value_t) -> *const ::std::os::raw::c_char;
}
extern "C" {
#[doc = " Get the length of a string heap object."]
pub fn vtx_helpers_string_length(str_value: vtx_value_t) -> u32;
}
extern "C" {
#[doc = " GC write barrier: must be called after storing a reference to an object.\n Implements a card-table based write barrier for generational GC.\n Marks the card containing [obj + offset] as dirty so the GC can\n find cross-generational references during young-gen collection.\n\n @param obj Pointer to the heap object containing the field\n @param field_offset Byte offset of the field within the object"]
pub fn vtx_helpers_write_barrier(obj: *mut ::std::os::raw::c_void, field_offset: u32);
}
extern "C" {
#[doc = " Call a method with arguments passed in registers.\n\n B7/B8 fix: The JIT entry calling convention (T2) is:\n RDI = method_ptr, RSI = deopt_info, RDX = profile_data,\n RCX = args array pointer, R8 = arg_count\n\n The baseline codegen sets up exactly these registers and calls this\n helper. The helper ignores deopt_info/profile_data (they are\n per-callsite values that the callee resolves from its own\n compiled_code metadata), looks up the interpreter via\n vtx_get_current_interp(), and dispatches to vtx_interp_run().\n\n @param method Method descriptor for the target method\n @param deopt_info Deopt info pointer (NULL for fresh calls — ignored)\n @param profile_data Profile data pointer (NULL or sentinel 1 — ignored)\n @param args Array of argument values (already in the right order)\n @param arg_count Number of arguments in the args array\n @return The method's return value"]
pub fn vtx_runtime_call_reg(
method: *const vtx_method_desc_t,
deopt_info: *mut ::std::os::raw::c_void,
profile_data: *mut ::std::os::raw::c_void,
args: *mut vtx_value_t,
arg_count: u32,
) -> vtx_value_t;
}
extern "C" {
#[doc = " Call a virtual method with register-based dispatch.\n\n B7/B8 fix: Uses the same JIT entry calling convention as\n vtx_runtime_call_reg. The receiver is args[0]; the method name is\n derived from `method->name`. The receiver's type is used to resolve\n the actual target method.\n\n @param method Method descriptor (provides method name) — this is\n the statically-known method at the call site\n @param deopt_info Deopt info pointer (NULL — ignored)\n @param profile_data Profile data pointer (NULL or sentinel 1 — ignored)\n @param args Array of argument values; args[0] is the receiver\n @param arg_count Number of arguments in the args array (incl. receiver)\n @return The method's return value"]
pub fn vtx_runtime_call_virtual_reg(
method: *const vtx_method_desc_t,
deopt_info: *mut ::std::os::raw::c_void,
profile_data: *mut ::std::os::raw::c_void,
args: *mut vtx_value_t,
arg_count: u32,
) -> vtx_value_t;
}
extern "C" {
#[doc = " Call an interface method with register-based dispatch.\n\n B7/B8 fix: Uses the JIT entry calling convention. The interface\n typeid is derived from the receiver's type via the type system.\n\n @param method Method descriptor (provides method name)\n @param deopt_info Deopt info pointer (NULL — ignored)\n @param profile_data Profile data pointer (NULL or sentinel 1 — ignored)\n @param args Array of argument values; args[0] is the receiver\n @param arg_count Number of arguments (incl. receiver)\n @return The method's return value"]
pub fn vtx_runtime_call_interface_reg(
method: *const vtx_method_desc_t,
deopt_info: *mut ::std::os::raw::c_void,
profile_data: *mut ::std::os::raw::c_void,
args: *mut vtx_value_t,
arg_count: u32,
) -> vtx_value_t;
}
extern "C" {
#[doc = " Dispatch a runtime builtin call from JIT-compiled code.\n\n The JIT emits CALL_RUNTIME with a runtime function ID (0-6).\n This function dispatches to the correct implementation:\n 0 = typeof, 1 = monitor_enter, 2 = monitor_exit, 3 = throw,\n 4 = print_ln, 5 = print, 6 = exit\n\n @param func_id Runtime function ID (from the bytecode operand)\n @param arg The argument value (popped from the stack)\n @return Result value (undefined for void calls, SMI for typeof/exit)"]
pub fn vtx_runtime_builtin_call(func_id: u32, arg: vtx_value_t) -> vtx_value_t;
}
pub const vtx_thread_state_t_VTX_THREAD_STATE_RUNNING: vtx_thread_state_t = 0;
pub const vtx_thread_state_t_VTX_THREAD_STATE_SAFEPOINT: vtx_thread_state_t = 1;
pub const vtx_thread_state_t_VTX_THREAD_STATE_GC: vtx_thread_state_t = 2;
pub const vtx_thread_state_t_VTX_THREAD_STATE_EXITED: vtx_thread_state_t = 3;
pub type vtx_thread_state_t = ::std::os::raw::c_uint;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_safepoint_thread_t {
pub tid: pthread_t,
pub state: vtx_thread_state_t,
pub safepoint_count: u32,
pub total_wait_ns: u64,
}
impl Default for vtx_safepoint_thread_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct vtx_safepoint_manager_t {
pub gc: *mut vtx_gc_t,
pub mutex: pthread_mutex_t,
pub all_safepointed: pthread_cond_t,
pub released: pthread_cond_t,
pub threads: [vtx_safepoint_thread_t; 256usize],
pub thread_count: u32,
pub active_count: u32,
pub safepoint_requested: bool,
pub safepoint_id: u32,
pub safepointed_count: u32,
pub total_safepoints: u64,
pub total_wait_ns: u64,
}
impl Default for vtx_safepoint_manager_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
pub fn vtx_safepoint_manager_init(
mgr: *mut vtx_safepoint_manager_t,
gc: *mut vtx_gc_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn vtx_safepoint_manager_destroy(mgr: *mut vtx_safepoint_manager_t);
}
extern "C" {
pub fn vtx_safepoint_thread_register(
mgr: *mut vtx_safepoint_manager_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn vtx_safepoint_thread_unregister(mgr: *mut vtx_safepoint_manager_t);
}
extern "C" {
pub fn vtx_safepoint_mgr_check(mgr: *mut vtx_safepoint_manager_t);
}
extern "C" {
pub fn vtx_safepoint_request_all(mgr: *mut vtx_safepoint_manager_t) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn vtx_safepoint_release_all(mgr: *mut vtx_safepoint_manager_t) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn vtx_safepoint_stats_str(
mgr: *const vtx_safepoint_manager_t,
buf: *mut ::std::os::raw::c_char,
bufsize: usize,
);
}
extern "C" {
pub fn vtx_safepoint_thread_count(mgr: *const vtx_safepoint_manager_t) -> u32;
}
pub type vtx_frame_t = vtx_frame;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_frame {
pub locals: *mut vtx_value_t,
pub operand_stack: *mut vtx_value_t,
pub stack_top: ::std::os::raw::c_int,
pub stack_capacity: ::std::os::raw::c_int,
pub return_pc: u32,
pub caller: *mut vtx_frame_t,
pub method: *const vtx_method_desc_t,
pub bytecode: *mut vtx_bytecode_t,
pub monitored_types: *mut u32,
pub locals_count: u32,
pub catch_handler_pc: u32,
pub catch_type: vtx_typeid_t,
pub exception: vtx_value_t,
}
impl Default for vtx_frame {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " A single 256KB block in the frame stack. Blocks are chained together\n to allow the frame stack to grow beyond a single block."]
pub type vtx_frame_block_t = vtx_frame_block;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_frame_block {
pub memory: *mut u8,
pub size: usize,
pub used: usize,
pub prev: *mut vtx_frame_block_t,
}
impl Default for vtx_frame_block {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " The frame stack is a chain of pre-allocated memory blocks from which\n frames are carved out sequentially. This avoids malloc in the dispatch loop.\n When a block is full, a new block is allocated and becomes the current block.\n When the top frame is destroyed, if the current block is empty, it is\n freed and the previous block becomes current."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_frame_stack_t {
pub current: *mut vtx_frame_block_t,
pub block_size: usize,
pub block_count: u32,
}
impl Default for vtx_frame_stack_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the frame stack allocator.\n Allocates the first 256KB block.\n Returns 0 on success, -1 on failure."]
pub fn vtx_frame_stack_init(fs: *mut vtx_frame_stack_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the frame stack allocator and release all blocks."]
pub fn vtx_frame_stack_destroy(fs: *mut vtx_frame_stack_t);
}
extern "C" {
#[doc = " Get the total bytes currently in use across all blocks."]
pub fn vtx_frame_stack_used(fs: *const vtx_frame_stack_t) -> usize;
}
extern "C" {
#[doc = " Create a new frame for executing the given method.\n Allocates locals and operand stack from the frame stack.\n If the current block doesn't have enough space, a new block is allocated.\n Returns the new frame, or NULL if out of memory."]
pub fn vtx_frame_create(
method: *const vtx_method_desc_t,
caller_frame: *mut vtx_frame_t,
return_pc: u32,
fs: *mut vtx_frame_stack_t,
) -> *mut vtx_frame_t;
}
extern "C" {
#[doc = " Destroy a frame, returning its memory to the frame stack.\n Since frames are LIFO, this moves the used pointer back.\n If the current block becomes empty and has a previous block,\n the empty block is freed."]
pub fn vtx_frame_destroy(frame: *mut vtx_frame_t, fs: *mut vtx_frame_stack_t);
}
pub const vtx_compile_tier_t_VT_TIER_T0: vtx_compile_tier_t = 0;
pub const vtx_compile_tier_t_VT_TIER_T1: vtx_compile_tier_t = 1;
pub const vtx_compile_tier_t_VT_TIER_T2: vtx_compile_tier_t = 2;
pub const vtx_compile_tier_t_VT_TIER_T3: vtx_compile_tier_t = 3;
#[doc = " VORTEX Profiling Counters\n\n Per-method profile data collected by the interpreter (T0).\n Used to make compilation tier decisions and feed the optimizer.\n\n All counters are saturating — they never overflow."]
pub type vtx_compile_tier_t = ::std::os::raw::c_uint;
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_tier_up_state_t {
pub tier_up_counter: i32,
pub compilation_requested: bool,
}
#[doc = " Per-call-site IC data: up to VTX_POLY_LIMIT type observations.\n This is separate from the runtime inline cache (vtx_inline_cache_t)\n in that it stores the raw observations for profiling purposes,\n while the IC is used for dispatch optimization."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_call_site_profile_t {
pub entries: [vtx_ic_entry_t; 4usize],
pub count: u32,
}
impl Default for vtx_call_site_profile_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Per-method profiling data."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_profile_data_t {
pub method: *const vtx_method_desc_t,
pub invocation_count: u64,
pub backward_branch_count: u64,
pub call_site_types: *mut vtx_call_site_profile_t,
pub call_site_count: u32,
pub branch_taken_counts: *mut u32,
pub branch_total_counts: *mut u32,
pub branch_array_size: u32,
pub field_shape_ids: *mut u32,
pub field_array_size: u32,
pub compiled_tier: vtx_compile_tier_t,
pub deopt_count: u32,
pub tier_up: vtx_tier_up_state_t,
}
impl Default for vtx_profile_data_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_profiler_t {
pub data: *mut vtx_profile_data_t,
pub count: u32,
pub capacity: u32,
pub lru: [vtx_profiler_t__bindgen_ty_1; 8usize],
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_profiler_t__bindgen_ty_1 {
pub method: *const vtx_method_desc_t,
pub pd: *mut vtx_profile_data_t,
}
impl Default for vtx_profiler_t__bindgen_ty_1 {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
impl Default for vtx_profiler_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the profiler.\n Returns 0 on success, -1 on failure."]
pub fn vtx_profiler_init(profiler: *mut vtx_profiler_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the profiler and release all memory."]
pub fn vtx_profiler_destroy(profiler: *mut vtx_profiler_t);
}
extern "C" {
#[doc = " Get or create profile data for the given method.\n If the method is not yet being profiled, a new entry is created.\n Returns a pointer to the profile data, or NULL on failure."]
pub fn vtx_profiler_get_method_data(
profiler: *mut vtx_profiler_t,
method: *const vtx_method_desc_t,
) -> *mut vtx_profile_data_t;
}
extern "C" {
#[doc = " Record a method invocation. Increments the invocation counter\n (saturating at UINT64_MAX)."]
pub fn vtx_profiler_record_invocation(
profiler: *mut vtx_profiler_t,
method: *const vtx_method_desc_t,
);
}
extern "C" {
#[doc = " Record a backward branch execution. Increments the backward_branch_count\n (saturating at UINT64_MAX)."]
pub fn vtx_profiler_record_backward_branch(
profiler: *mut vtx_profiler_t,
method: *const vtx_method_desc_t,
);
}
extern "C" {
#[doc = " Record a branch outcome at the given PC.\n Increments the taken and total counters (saturating at UINT32_MAX)."]
pub fn vtx_profiler_record_branch(
profiler: *mut vtx_profiler_t,
method: *const vtx_method_desc_t,
pc: u32,
taken: bool,
);
}
extern "C" {
#[doc = " Record the receiver type at a call site.\n The call site is identified by its bytecode PC (call_pc)."]
pub fn vtx_profiler_record_call_type(
profiler: *mut vtx_profiler_t,
method: *const vtx_method_desc_t,
call_pc: u32,
typeid_: vtx_typeid_t,
);
}
extern "C" {
#[doc = " Record the shape ID at a field access site.\n The field access is identified by its bytecode PC (field_pc)."]
pub fn vtx_profiler_record_field_shape(
profiler: *mut vtx_profiler_t,
method: *const vtx_method_desc_t,
field_pc: u32,
shapeid: vtx_shapeid_t,
);
}
extern "C" {
#[doc = " Compute the \"heat\" of a method: a weighted score combining\n invocation count and backward branch density.\n\n heat = invocation_count + backward_branch_count * 2\n\n This means a method with many loop iterations is hotter than one\n that's called often but does little work per call."]
pub fn vtx_profiler_method_heat(
profiler: *mut vtx_profiler_t,
method: *const vtx_method_desc_t,
) -> u64;
}
extern "C" {
#[doc = " Check if a method should be compiled at T1 (baseline JIT).\n Returns true if heat > VORTEX_T1_THRESHOLD."]
pub fn vtx_profiler_should_compile_t1(
profiler: *mut vtx_profiler_t,
method: *const vtx_method_desc_t,
) -> bool;
}
extern "C" {
#[doc = " Check if a method should be compiled at T2 (optimizing JIT).\n Returns true if heat > VORTEX_T2_THRESHOLD."]
pub fn vtx_profiler_should_compile_t2(
profiler: *mut vtx_profiler_t,
method: *const vtx_method_desc_t,
) -> bool;
}
extern "C" {
#[doc = " Get the call site profile data for a given method and PC.\n Returns the call site profile, or NULL if not found."]
pub fn vtx_profiler_get_call_site_profile(
profiler: *const vtx_profiler_t,
method: *const vtx_method_desc_t,
call_pc: u32,
) -> *const vtx_call_site_profile_t;
}
extern "C" {
#[doc = " Get the branch probability (taken / total) at a given PC.\n Returns 0.5 if no data is available."]
pub fn vtx_profiler_get_branch_probability(
profiler: *const vtx_profiler_t,
method: *const vtx_method_desc_t,
pc: u32,
) -> f64;
}
extern "C" {
#[doc = " Get the field shape ID observed at a given PC.\n Returns VTX_SHAPE_INVALID if no data is available."]
pub fn vtx_profiler_get_field_shape(
profiler: *const vtx_profiler_t,
method: *const vtx_method_desc_t,
field_pc: u32,
) -> vtx_shapeid_t;
}
extern "C" {
#[doc = " Record a deoptimization from the given method.\n Increments deopt_count (saturating at UINT32_MAX)."]
pub fn vtx_profiler_record_deopt(
profiler: *mut vtx_profiler_t,
method: *const vtx_method_desc_t,
);
}
extern "C" {
#[doc = " Set the compilation tier for a method."]
pub fn vtx_profiler_set_compiled_tier(
profiler: *mut vtx_profiler_t,
method: *const vtx_method_desc_t,
tier: vtx_compile_tier_t,
);
}
extern "C" {
#[doc = " D7: Check and decrement the tier-up counter for a method.\n\n This is designed to be called from the interpreter dispatch loop at\n backward branches. It decrements the counter and returns true when\n the counter reaches zero (indicating the method should be compiled).\n\n After returning true, the compilation_requested flag is set so that\n subsequent calls are no-ops (the method has already been queued).\n\n The caller is responsible for triggering the actual compilation\n (e.g., via vtx_request_compilation or the compilation thread pool).\n\n @param profiler The profiler\n @param method The method being executed\n @return true if the method should be compiled, false otherwise"]
pub fn vtx_profiler_tier_up_check(
profiler: *mut vtx_profiler_t,
method: *const vtx_method_desc_t,
) -> bool;
}
extern "C" {
#[doc = " D7: Reset the tier-up counter for a method (e.g., after recompilation\n for a higher tier). This allows the method to be detected as hot\n again for the next tier transition.\n\n @param profiler The profiler\n @param method The method to reset\n @param new_initial_count The new initial counter value (0 for default)"]
pub fn vtx_profiler_tier_up_reset(
profiler: *mut vtx_profiler_t,
method: *const vtx_method_desc_t,
new_initial_count: i32,
);
}
extern "C" {
#[doc = " Look up a virtual method using an inline cache.\n\n Algorithm:\n 1. If receiver is a heap pointer, extract its typeid\n 2. Check the IC for a cached mapping (monomorphic fast path)\n 3. On miss, do a full vtable walk via vtx_type_resolve_method\n 4. Update the IC with the new mapping\n\n The IC transitions through states:\n - Monomorphic (1 entry): direct match on typeid\n - Polymorphic (2..VTX_POLY_LIMIT entries): linear scan\n - Megamorphic (>VTX_POLY_LIMIT types): vtable fallback, no IC update\n\n Returns the resolved method descriptor, or NULL if not found."]
pub fn vtx_lookup_method(
ts: *mut vtx_type_system_t,
ic: *mut vtx_inline_cache_t,
receiver: vtx_value_t,
method_name: *const ::std::os::raw::c_char,
) -> *const vtx_method_desc_t;
}
extern "C" {
#[doc = " Look up an interface method using an inline cache.\n\n Algorithm:\n 1. If receiver is a heap pointer, extract its typeid\n 2. Check the IC for a cached mapping\n 3. On miss, verify that the receiver's type implements the interface\n 4. Walk the type hierarchy to find the method\n 5. Update the IC\n\n Returns the resolved method descriptor, or NULL if not found."]
pub fn vtx_lookup_interface_method(
ts: *mut vtx_type_system_t,
ic: *mut vtx_inline_cache_t,
receiver: vtx_value_t,
interface_typeid: vtx_typeid_t,
method_name: *const ::std::os::raw::c_char,
) -> *const vtx_method_desc_t;
}
extern "C" {
#[doc = " Look up a static method by name from a given type.\n No IC is used for static calls (the target is always the same).\n\n Returns the resolved method descriptor, or NULL if not found."]
pub fn vtx_lookup_static_method(
ts: *mut vtx_type_system_t,
typeid_: vtx_typeid_t,
method_name: *const ::std::os::raw::c_char,
) -> *const vtx_method_desc_t;
}
#[doc = " A call site observation: receiver type and result type."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_tf_call_observation_t {
pub receiver_typeid: vtx_typeid_t,
pub result_typeid: vtx_typeid_t,
}
#[doc = " A field access observation: holder shape and value type."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_tf_field_observation_t {
pub holder_shapeid: vtx_shapeid_t,
pub value_typeid: vtx_typeid_t,
}
#[doc = " A branch observation: taken or not taken."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_tf_branch_observation_t {
pub taken: bool,
}
#[doc = " A single (type_id, count) entry in the per-type frequency table.\n Tracks how many times a specific receiver type was observed at a call site."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_type_freq_entry_t {
pub type_id: vtx_typeid_t,
pub count: u32,
}
#[doc = " Per-type frequency distribution for a single call site.\n Enables accurate KL divergence computation for recompilation decisions.\n Without this, the KL divergence is meaningless because uniform weights\n are used (each observed type gets equal weight regardless of actual\n frequency)."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_type_freq_t {
pub entries: [vtx_type_freq_entry_t; 8usize],
pub entry_count: u32,
pub total_count: u32,
}
#[doc = " A stable-type signature: the tuple (receiver_type, arg1_type, ..., result_type)\n observed at a call site. When all types in the signature have been stable\n for VTX_TYPE_STABILITY_WINDOW consecutive observations, the site is marked\n as hyper-stable and receives a single composite guard."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_type_signature_t {
pub types: [vtx_typeid_t; 8usize],
pub slot_count: u32,
pub stability_count: u32,
pub is_hyper_stable: bool,
}
#[doc = " Call site feedback: circular buffer of call observations."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_tf_call_site_t {
pub observations: [vtx_tf_call_observation_t; 32usize],
pub write_index: u8,
pub count: u8,
pub type_freq: vtx_type_freq_t,
pub stable_signature: vtx_type_signature_t,
}
#[doc = " Field access feedback: circular buffer of field observations."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_tf_field_site_t {
pub observations: [vtx_tf_field_observation_t; 32usize],
pub write_index: u8,
pub count: u8,
pub last_shapeid: vtx_shapeid_t,
pub shape_stability_count: u32,
pub is_shape_stable: bool,
}
#[doc = " Branch feedback: circular buffer of branch observations."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_tf_branch_site_t {
pub observations: [vtx_tf_branch_observation_t; 32usize],
pub write_index: u8,
pub count: u8,
}
#[doc = " The type feedback collector manages arrays of per-site feedback.\n Sites are indexed by an integer (typically derived from bytecode PC)."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_type_feedback_t {
pub call_sites: *mut vtx_tf_call_site_t,
pub call_site_count: u32,
pub field_sites: *mut vtx_tf_field_site_t,
pub field_site_count: u32,
pub branch_sites: *mut vtx_tf_branch_site_t,
pub branch_site_count: u32,
}
impl Default for vtx_type_feedback_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the type feedback collector with the given maximum\n number of sites for each category.\n Returns 0 on success, -1 on failure."]
pub fn vtx_type_feedback_init(
feedback: *mut vtx_type_feedback_t,
max_sites: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the type feedback collector and release all memory."]
pub fn vtx_type_feedback_destroy(feedback: *mut vtx_type_feedback_t);
}
extern "C" {
#[doc = " Ensure the feedback arrays can accommodate the given site index.\n Grows the arrays if necessary.\n Returns 0 on success, -1 on failure."]
pub fn vtx_type_feedback_ensure_site(
feedback: *mut vtx_type_feedback_t,
site_index: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Record a call site observation: receiver type and result type.\n site_index identifies which call site this observation belongs to."]
pub fn vtx_type_feedback_record_call(
feedback: *mut vtx_type_feedback_t,
site_index: u32,
receiver_typeid: vtx_typeid_t,
result_typeid: vtx_typeid_t,
);
}
extern "C" {
#[doc = " Record a field access observation: holder shape and value type.\n site_index identifies which field site this observation belongs to."]
pub fn vtx_type_feedback_record_field(
feedback: *mut vtx_type_feedback_t,
site_index: u32,
holder_shapeid: vtx_shapeid_t,
value_typeid: vtx_typeid_t,
);
}
extern "C" {
#[doc = " Record a branch observation.\n site_index identifies which branch site this observation belongs to."]
pub fn vtx_type_feedback_record_branch(
feedback: *mut vtx_type_feedback_t,
site_index: u32,
taken: bool,
);
}
extern "C" {
#[doc = " Get the dominant receiver type at a call site, weighted by recency.\n Uses exponential decay weighting:\n weight[i] = 0.9^distance, where distance is how many positions\n ago the observation was written (most recent = distance 1).\n\n Returns VTX_TYPE_INVALID if no observations."]
pub fn vtx_type_feedback_get_dominant_call_type(
feedback: *const vtx_type_feedback_t,
site_index: u32,
) -> vtx_typeid_t;
}
extern "C" {
#[doc = " Get the dominant field shape at a field access site, weighted by recency.\n Uses exponential decay weighting like call site queries.\n\n Returns VTX_SHAPE_INVALID if no observations."]
pub fn vtx_type_feedback_get_dominant_field_shape(
feedback: *const vtx_type_feedback_t,
site_index: u32,
) -> vtx_shapeid_t;
}
extern "C" {
#[doc = " Get the dominant value type at a field access site, weighted by recency.\n Uses exponential decay weighting.\n\n Returns VTX_TYPE_INVALID if no observations."]
pub fn vtx_type_feedback_get_dominant_field_value_type(
feedback: *const vtx_type_feedback_t,
site_index: u32,
) -> vtx_typeid_t;
}
extern "C" {
#[doc = " Get the branch probability (taken / total) at a branch site.\n Uses exponential decay weighting for recency.\n Returns 0.5 (unknown) if no observations."]
pub fn vtx_type_feedback_get_branch_probability(
feedback: *const vtx_type_feedback_t,
site_index: u32,
) -> f64;
}
extern "C" {
#[doc = " Get the number of unique receiver types observed at a call site."]
pub fn vtx_type_feedback_get_call_site_type_count(
feedback: *const vtx_type_feedback_t,
site_index: u32,
) -> u32;
}
extern "C" {
#[doc = " Get the per-type frequency distribution for a call site.\n Returns a pointer to the type_freq structure embedded in the call site.\n Returns NULL if the site does not exist.\n\n The returned pointer is valid as long as the feedback structure is valid\n and the site is not re-allocated (i.e., until vtx_type_feedback_destroy)."]
pub fn vtx_type_feedback_get_type_freq(
feedback: *const vtx_type_feedback_t,
site_index: u32,
) -> *const vtx_type_freq_t;
}
extern "C" {
#[doc = " Compute KL divergence between two per-type frequency distributions.\n KL(P || Q) = sum_i P(i) * log(P(i) / Q(i))\n where P = current distribution, Q = compiled-time distribution.\n\n New types not seen at compilation time receive a large penalty (10.0)\n to ensure they trigger recompilation.\n\n Returns 0.0 if either distribution has zero total observations."]
pub fn vtx_type_freq_kl_divergence(
current: *const vtx_type_freq_t,
compiled: *const vtx_type_freq_t,
) -> f64;
}
extern "C" {
#[doc = " Update the stable-type signature for a call site with a new observation.\n If the new observation matches the existing signature, increment stability.\n If it differs, reset the signature and stability counter.\n\n @param site The call site to update\n @param receiver Receiver type ID\n @param result Result type ID"]
pub fn vtx_tf_call_site_update_signature(
site: *mut vtx_tf_call_site_t,
receiver: vtx_typeid_t,
result: vtx_typeid_t,
);
}
extern "C" {
#[doc = " Check if a call site is hyper-stable (signature stable for\n VTX_TYPE_STABILITY_WINDOW observations).\n\n @param site The call site\n @return true if hyper-stable"]
pub fn vtx_tf_call_site_is_hyper_stable(site: *const vtx_tf_call_site_t) -> bool;
}
extern "C" {
#[doc = " Get the stable-type signature for a call site.\n Returns NULL if the site has no observations yet.\n\n @param site The call site\n @return Pointer to the signature, or NULL"]
pub fn vtx_tf_call_site_get_signature(
site: *const vtx_tf_call_site_t,
) -> *const vtx_type_signature_t;
}
extern "C" {
#[doc = " Compute a 64-bit hash of a type signature for fast comparison.\n Used by composite guards to check the entire signature in one CMP.\n\n @param sig The type signature\n @return 64-bit hash value"]
pub fn vtx_type_signature_hash(sig: *const vtx_type_signature_t) -> u64;
}
extern "C" {
#[doc = " Check if a field site's shape has been stable for long enough\n to warrant shape-specialized code generation."]
pub fn vtx_tf_field_site_is_shape_stable(site: *const vtx_tf_field_site_t) -> bool;
}
extern "C" {
#[doc = " Get the stable shape ID for a field site.\n Returns VTX_SHAPE_INVALID if the site is not shape-stable."]
pub fn vtx_tf_field_site_get_stable_shape(site: *const vtx_tf_field_site_t) -> vtx_shapeid_t;
}
#[doc = " A single compilation task in the priority queue."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_compile_task_t {
pub method_id: u32,
pub tier: vtx_compile_tier_t,
pub heat: u32,
pub priority: i64,
pub submit_time: u64,
pub task_fn: ::std::option::Option<unsafe extern "C" fn(arg: *mut ::std::os::raw::c_void)>,
pub arg: *mut ::std::os::raw::c_void,
pub arena: *mut vtx_arena_t,
}
impl Default for vtx_compile_task_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct vtx_priority_queue_t {
pub tasks: *mut vtx_compile_task_t,
pub count: u32,
pub capacity: u32,
pub mutex: pthread_mutex_t,
pub lock_free: bool,
pub starvation_threshold_ns: u64,
pub total_pushed: u64,
pub total_popped: u64,
pub max_queue_depth: u64,
}
impl Default for vtx_priority_queue_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the priority queue.\n Returns 0 on success, -1 on failure."]
pub fn vtx_pq_init(pq: *mut vtx_priority_queue_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the priority queue and free memory."]
pub fn vtx_pq_destroy(pq: *mut vtx_priority_queue_t);
}
extern "C" {
#[doc = " Push a task onto the priority queue.\n The task is copied into the queue (the caller can free their copy).\n Returns 0 on success, -1 on failure."]
pub fn vtx_pq_push(
pq: *mut vtx_priority_queue_t,
task: *const vtx_compile_task_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Pop the highest-priority task from the queue.\n Returns true if a task was popped, false if the queue is empty."]
pub fn vtx_pq_pop(pq: *mut vtx_priority_queue_t, out_task: *mut vtx_compile_task_t) -> bool;
}
extern "C" {
#[doc = " Peek at the highest-priority task without removing it.\n Returns true if a task was found, false if the queue is empty."]
pub fn vtx_pq_peek(pq: *const vtx_priority_queue_t, out_task: *mut vtx_compile_task_t) -> bool;
}
extern "C" {
#[doc = " Get the number of tasks in the queue."]
pub fn vtx_pq_count(pq: *const vtx_priority_queue_t) -> u32;
}
extern "C" {
#[doc = " Check if the queue is empty."]
pub fn vtx_pq_is_empty(pq: *const vtx_priority_queue_t) -> bool;
}
extern "C" {
#[doc = " Compute the effective priority of a task.\n Higher value = higher priority.\n\n Priority formula:\n effective_priority = (tier * TIER_WEIGHT) + (heat * HEAT_WEIGHT) + starvation_boost\n\n starvation_boost = max(0, (wait_time - threshold) / DIVISOR)\n\n This ensures:\n - Tier dominates (T3 is always prioritized over T2)\n - Within same tier, hotter methods are compiled first\n - Tasks waiting too long get a boost to prevent starvation"]
pub fn vtx_pq_task_priority(
task: *const vtx_compile_task_t,
starvation_threshold_ns: u64,
) -> i64;
}
pub const vtx_worker_state_t_VTX_WORKER_IDLE: vtx_worker_state_t = 0;
pub const vtx_worker_state_t_VTX_WORKER_COMPILING: vtx_worker_state_t = 1;
pub const vtx_worker_state_t_VTX_WORKER_SHUTDOWN: vtx_worker_state_t = 2;
#[doc = " VORTEX Compilation Thread Pool\n\n Fixed-size thread pool for concurrent method compilation. Worker threads\n pull compilation tasks from a shared priority queue.\n\n Design:\n - VTX_COMPILE_THREADS workers (default = CPU cores - 1, minimum 1)\n - Each worker thread has its own arena allocator for compilation\n - Workers block on a condition variable when the queue is empty\n - Tasks are prioritized by tier, heat, and wait time\n - Graceful shutdown: set a shutdown flag, signal all workers,\n wait for them to finish their current task\n\n Thread safety:\n - The priority queue is protected by its own mutex\n - The thread pool has a separate mutex for the condition variable\n - No locks are held during compilation (each worker has its own arena)"]
pub type vtx_worker_state_t = ::std::os::raw::c_uint;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_worker_t {
pub thread: pthread_t,
pub worker_id: u32,
pub state: vtx_worker_state_t,
pub arena: vtx_arena_t,
pub tasks_completed: u64,
pub current_method: u32,
pub current_tier: vtx_compile_tier_t,
}
impl Default for vtx_worker_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Compilation callback: invoked by worker threads when a task has\n method_id set but task_fn is NULL. The callback looks up the method,\n runs the pipeline, and installs the compiled code.\n\n @param method_id Method to compile\n @param tier Compilation tier\n @param context User-provided context (e.g. compile context)\n @return 0 on success, -1 on failure"]
pub type vtx_compile_callback_t = ::std::option::Option<
unsafe extern "C" fn(
method_id: u32,
tier: vtx_compile_tier_t,
context: *mut ::std::os::raw::c_void,
) -> ::std::os::raw::c_int,
>;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct vtx_threadpool_t {
pub workers: *mut vtx_worker_t,
pub num_workers: u32,
pub shutdown: bool,
pub task_queue: vtx_priority_queue_t,
pub pool_mutex: pthread_mutex_t,
pub work_available: pthread_cond_t,
pub compile_callback: vtx_compile_callback_t,
pub compile_callback_context: *mut ::std::os::raw::c_void,
pub total_tasks_completed: u64,
pub total_tasks_submitted: u64,
pub total_compile_time_ns: u64,
}
impl Default for vtx_threadpool_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the thread pool with the given number of worker threads.\n Creates worker threads and starts them waiting for tasks.\n\n @param pool Thread pool to initialize\n @param num_threads Number of worker threads (0 = use VORTEX_COMPILE_THREADS)\n @return 0 on success, -1 on failure"]
pub fn vtx_threadpool_init(
pool: *mut vtx_threadpool_t,
num_threads: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Set the compilation callback for the thread pool.\n\n When a worker receives a task with method_id set but task_fn == NULL,\n it calls this callback to perform the compilation. This is the fix\n for the critical bug where orchestrator-submitted tasks (which have\n method_id but no task_fn) were silently discarded.\n\n Must be called BEFORE starting any compilation tasks.\n\n @param pool Thread pool\n @param callback Compilation callback function\n @param context Context pointer passed to the callback"]
pub fn vtx_threadpool_set_compile_callback(
pool: *mut vtx_threadpool_t,
callback: vtx_compile_callback_t,
context: *mut ::std::os::raw::c_void,
);
}
extern "C" {
#[doc = " Shutdown the thread pool. Signals all workers to stop, waits for\n them to finish their current task, then destroys resources.\n\n @param pool Thread pool to shut down"]
pub fn vtx_threadpool_shutdown(pool: *mut vtx_threadpool_t);
}
extern "C" {
#[doc = " Submit a compilation task to the thread pool.\n\n @param pool Thread pool\n @param task_fn Function to execute for compilation\n @param arg Argument to pass to task_fn\n @param priority Task priority (higher = compiled sooner)\n @return 0 on success, -1 on failure"]
pub fn vtx_threadpool_submit(
pool: *mut vtx_threadpool_t,
task_fn: ::std::option::Option<unsafe extern "C" fn(arg: *mut ::std::os::raw::c_void)>,
arg: *mut ::std::os::raw::c_void,
priority: i64,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Submit a full compilation task (with all metadata) to the thread pool.\n\n @param pool Thread pool\n @param task Task to submit\n @return 0 on success, -1 on failure"]
pub fn vtx_threadpool_submit_task(
pool: *mut vtx_threadpool_t,
task: *const vtx_compile_task_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Get the number of idle workers."]
pub fn vtx_threadpool_idle_workers(pool: *const vtx_threadpool_t) -> u32;
}
extern "C" {
#[doc = " Get the number of tasks in the queue."]
pub fn vtx_threadpool_queue_depth(pool: *const vtx_threadpool_t) -> u32;
}
extern "C" {
#[doc = " Check if the thread pool is shutting down."]
pub fn vtx_threadpool_is_shutdown(pool: *const vtx_threadpool_t) -> bool;
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_phase_desc_t {
pub phase_id: u32,
pub dominant_method_ids: [u32; 8usize],
pub dominant_method_counts: [u32; 8usize],
pub dominant_method_count: u32,
pub total_calls: u64,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_markov_t {
pub transition_matrix: [[u32; 16usize]; 16usize],
pub current_phase: u32,
pub phases: [vtx_phase_desc_t; 16usize],
pub phase_count: u32,
pub method_phase_map: [u32; 256usize],
pub total_transitions: u64,
pub is_trained: bool,
pub current_phase_method_calls: [u32; 256usize],
pub current_phase_total_calls: u64,
pub min_observations: u32,
}
impl Default for vtx_markov_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
pub fn vtx_markov_init(mk: *mut vtx_markov_t) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn vtx_markov_record_transition(mk: *mut vtx_markov_t, from_phase: u32, to_phase: u32);
}
extern "C" {
pub fn vtx_markov_record_method_call(mk: *mut vtx_markov_t, method_id: u32);
}
extern "C" {
pub fn vtx_markov_predict_next(mk: *mut vtx_markov_t, current_phase: u32) -> u32;
}
extern "C" {
pub fn vtx_markov_transition_prob(mk: *mut vtx_markov_t, from: u32, to: u32) -> f64;
}
extern "C" {
pub fn vtx_markov_predict_hot_methods(
mk: *mut vtx_markov_t,
next_phase: u32,
method_ids: *mut u32,
max_methods: u32,
) -> u32;
}
extern "C" {
pub fn vtx_markov_detect_transition(mk: *mut vtx_markov_t, new_phase: *mut u32) -> bool;
}
#[doc = " VORTEX Segmented Code Cache\n\n The code cache is divided into segments of VTX_CACHE_SEGMENT_SIZE (1MB).\n Each segment is an mmap'd region of executable memory. Segments are\n allocated on demand and freed when empty.\n\n Allocation flow:\n 1. Request N bytes from vtx_code_cache_alloc()\n 2. If current segment has space, allocate from it\n 3. If not, allocate a new segment\n 4. After filling, mprotect to PROT_EXEC|PROT_READ\n\n Thread safety: The code cache is NOT thread-safe. The caller must\n synchronize access (e.g., via the compilation thread pool's lock)."]
pub type vtx_code_segment_t = vtx_code_segment;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_code_segment {
pub memory: *mut u8,
pub size: u32,
pub used: u32,
pub method_count: u32,
pub writable: bool,
pub next: *mut vtx_code_segment_t,
pub free_list: *mut vtx_code_segment__bindgen_ty_1,
pub free_count: u32,
pub free_capacity: u32,
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_code_segment__bindgen_ty_1 {
pub offset: u32,
pub size: u32,
}
impl Default for vtx_code_segment {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_code_cache {
pub segments: *mut vtx_code_segment_t,
pub current_segment: *mut vtx_code_segment_t,
pub segment_count: u32,
pub total_size: u64,
pub max_size: u64,
}
impl Default for vtx_code_cache {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
pub type vtx_code_cache_t = vtx_code_cache;
extern "C" {
#[doc = " Initialize the code cache.\n The max_size defaults to VORTEX_CACHE_MAX_SIZE.\n Returns 0 on success, -1 on failure."]
pub fn vtx_code_cache_init(
cache: *mut vtx_code_cache_t,
max_size: u64,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the code cache and unmap all segments."]
pub fn vtx_code_cache_destroy(cache: *mut vtx_code_cache_t);
}
extern "C" {
#[doc = " Allocate `size` bytes of executable memory from the code cache.\n The returned pointer is aligned to 16 bytes.\n\n After writing code to the allocated memory, call\n vtx_code_cache_finalize() to make the memory executable.\n\n Returns a pointer to the allocated memory, or NULL on failure."]
pub fn vtx_code_cache_alloc(
cache: *mut vtx_code_cache_t,
size: u32,
) -> *mut ::std::os::raw::c_void;
}
extern "C" {
#[doc = " Finalize the current segment: make it executable (PROT_EXEC|PROT_READ).\n Must be called after writing code to the allocated memory.\n\n Returns 0 on success, -1 on failure."]
pub fn vtx_code_cache_finalize(cache: *mut vtx_code_cache_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Make a specific range executable.\n @param cache Code cache\n @param ptr Pointer within the cache memory\n @param size Size of the range\n @return 0 on success, -1 on failure"]
pub fn vtx_code_cache_make_exec(
cache: *mut vtx_code_cache_t,
ptr: *mut ::std::os::raw::c_void,
size: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Make a specific range writable (for patching).\n @param cache Code cache\n @param ptr Pointer within the cache memory\n @param size Size of the range\n @return 0 on success, -1 on failure"]
pub fn vtx_code_cache_make_writable(
cache: *mut vtx_code_cache_t,
ptr: *mut ::std::os::raw::c_void,
size: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Get the total number of bytes used in the cache."]
pub fn vtx_code_cache_total_used(cache: *const vtx_code_cache_t) -> u64;
}
extern "C" {
#[doc = " Get the total number of segments."]
pub fn vtx_code_cache_segment_count(cache: *const vtx_code_cache_t) -> u32;
}
extern "C" {
#[doc = " Check if the cache has exceeded its maximum size."]
pub fn vtx_code_cache_is_full(cache: *const vtx_code_cache_t) -> bool;
}
extern "C" {
#[doc = " Free a method's code from its segment.\n If the segment becomes empty, it is freed (unmapped).\n\n @param cache Code cache\n @param code_ptr Pointer to the method's code in the cache\n @param code_size Size of the method's code\n @return 0 on success, -1 on failure"]
pub fn vtx_code_cache_free(
cache: *mut vtx_code_cache_t,
code_ptr: *mut ::std::os::raw::c_void,
code_size: u32,
) -> ::std::os::raw::c_int;
}
#[doc = " The side table: a sorted array of entries mapping native PC offsets\n to FrameState indices and register maps."]
pub type vtx_side_table_t = vtx_side_table_struct;
#[doc = " Per-method deoptimization information stored in the JIT frame.\n Maps native PC offsets to bytecode PCs and stack states for deopt."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_deopt_info_t {
pub method: *const vtx_method_desc_t,
pub native_offsets: *mut u32,
pub pc_map: *mut u32,
pub pc_map_count: u32,
pub stack_depth_map: *mut u32,
pub side_table: *mut vtx_side_table_t,
}
impl Default for vtx_deopt_info_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Describes the layout of a compiled method's stack frame.\n All offsets are relative to RBP. Negative offsets point below RBP\n (locals and spills), positive offsets point above RBP (header).\n\n The total_frame_size is the number of bytes to subtract from RSP\n during prologue (locals + spills, not including the 4 pushed header values\n and the saved RBP which are handled by push instructions)."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_jit_frame_layout_t {
pub max_locals: u32,
pub max_stack: u32,
pub max_spills: u32,
pub locals_base: i32,
pub spill_base: i32,
pub total_frame_size: u32,
pub frame_bottom: i32,
}
extern "C" {
#[doc = " Compute the JIT frame layout for a method.\n\n Layout:\n 1. Frame header above RBP (pushed by prologue + CALL).\n 2. Locals below RBP, starting at RBP-8, growing downward.\n 3. Expression stack spills below locals, growing downward.\n Spill slots = max(0, max_stack - VTX_EXPR_REG_COUNT).\n 4. Total frame size = locals_bytes + spill_bytes, rounded to 16.\n\n @param method The method descriptor (provides max_locals, max_stack)\n @return The computed frame layout"]
pub fn vtx_frame_layout_compute(method: *const vtx_method_desc_t) -> vtx_jit_frame_layout_t;
}
extern "C" {
#[doc = " Determine which physical register or spill slot holds the Nth element\n of the expression stack.\n\n The topmost VTX_EXPR_REG_COUNT (4) values are in registers:\n TOS → RAX (reg 0), TOS-1 → RCX (reg 1),\n TOS-2 → RDX (reg 2), TOS-3 → RBX (reg 3).\n Values deeper than that are spilled to the frame.\n\n @param stack_index 0-based index from the bottom of the expression stack\n @param stack_depth current depth of the expression stack\n @param layout frame layout (for spill offset computation)\n @param[out] reg set to the register number (0=RAX,1=RCX,2=RDX,3=RBX)\n if the value is in a register, or -1 if spilled\n @param[out] spill_offset set to the RBP-relative offset if spilled,\n or 0 if in a register"]
pub fn vtx_frame_layout_expr_location(
stack_index: u32,
stack_depth: u32,
layout: *const vtx_jit_frame_layout_t,
reg: *mut ::std::os::raw::c_int,
spill_offset: *mut i32,
);
}
pub const vtx_guard_kind_t_VTX_GUARD_TYPE_CHECK: vtx_guard_kind_t = 0;
pub const vtx_guard_kind_t_VTX_GUARD_NULL_CHECK: vtx_guard_kind_t = 1;
pub const vtx_guard_kind_t_VTX_GUARD_BOUNDS_CHECK: vtx_guard_kind_t = 2;
pub const vtx_guard_kind_t_VTX_GUARD_OVERFLOW: vtx_guard_kind_t = 3;
pub const vtx_guard_kind_t_VTX_GUARD_DIV_ZERO: vtx_guard_kind_t = 4;
#[doc = " VORTEX Baseline JIT Guard Emission\n\n Guards are speculative checks inserted by the baseline compiler.\n If a guard fails, execution transfers to a deopt stub that\n reconstructs the interpreter frame state and resumes in the\n interpreter at the correct bytecode PC.\n\n Each guard records metadata needed for deoptimization:\n - Bytecode PC where the guard was inserted\n - Guard kind (type check, null check, bounds check, overflow)\n - Expected value (e.g., expected TypeID)\n - Deopt continuation (bytecode PC to resume in interpreter)\n - Stack depth at the guard point\n\n Guard emission writes x86-64 machine code into a code buffer.\n The emitted code performs the check and conditionally jumps to\n a deopt stub on failure."]
pub type vtx_guard_kind_t = ::std::os::raw::c_uint;
#[doc = " Metadata for a single guard. Recorded during compilation so that\n deopt stubs can be generated after the main code is emitted."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_guard_info_t {
pub kind: vtx_guard_kind_t,
pub bytecode_pc: u32,
pub native_pc_offset: u32,
pub deopt_continuation: u32,
pub stack_depth: u32,
pub expected_value: u64,
pub branch_offset: i32,
}
impl Default for vtx_guard_info_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_guard_array_t {
pub guards: *mut vtx_guard_info_t,
pub count: u32,
pub capacity: u32,
}
impl Default for vtx_guard_array_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize a guard array.\n Returns 0 on success, -1 on failure."]
pub fn vtx_guard_array_init(arr: *mut vtx_guard_array_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy a guard array and free memory."]
pub fn vtx_guard_array_destroy(arr: *mut vtx_guard_array_t);
}
extern "C" {
#[doc = " Add a guard info record to the array.\n Returns the index of the new guard, or UINT32_MAX on failure."]
pub fn vtx_guard_array_add(arr: *mut vtx_guard_array_t, guard: vtx_guard_info_t) -> u32;
}
pub const vtx_reg_t_VTX_REG_RAX: vtx_reg_t = 0;
pub const vtx_reg_t_VTX_REG_RCX: vtx_reg_t = 1;
pub const vtx_reg_t_VTX_REG_RDX: vtx_reg_t = 2;
pub const vtx_reg_t_VTX_REG_RBX: vtx_reg_t = 3;
pub const vtx_reg_t_VTX_REG_RSP: vtx_reg_t = 4;
pub const vtx_reg_t_VTX_REG_RBP: vtx_reg_t = 5;
pub const vtx_reg_t_VTX_REG_RSI: vtx_reg_t = 6;
pub const vtx_reg_t_VTX_REG_RDI: vtx_reg_t = 7;
pub const vtx_reg_t_VTX_REG_R8: vtx_reg_t = 8;
pub const vtx_reg_t_VTX_REG_R9: vtx_reg_t = 9;
pub const vtx_reg_t_VTX_REG_R10: vtx_reg_t = 10;
pub const vtx_reg_t_VTX_REG_R11: vtx_reg_t = 11;
pub const vtx_reg_t_VTX_REG_R12: vtx_reg_t = 12;
pub const vtx_reg_t_VTX_REG_R13: vtx_reg_t = 13;
pub const vtx_reg_t_VTX_REG_R14: vtx_reg_t = 14;
pub const vtx_reg_t_VTX_REG_R15: vtx_reg_t = 15;
pub const vtx_reg_t_VTX_REG_NONE: vtx_reg_t = 255;
#[doc = " Register numbering used by the baseline compiler.\n These correspond to x86-64 physical registers."]
pub type vtx_reg_t = ::std::os::raw::c_uint;
pub type vtx_code_buffer_t = vtx_code_buffer;
extern "C" {
#[doc = " Emit a type check guard: verify that the object in `obj_reg` has the\n expected TypeID. If the type doesn't match, jump to a deopt stub.\n\n Generated code sequence:\n 1. Extract the heap object pointer from the tagged value in obj_reg\n 2. Load the type_id from the object header at offset 0\n 3. Compare against expected_typeid\n 4. If not equal, jump to deopt stub\n\n @param buf Code buffer to emit into\n @param obj_reg Register holding the tagged value (heap pointer)\n @param expected_typeid Expected TypeID to check against\n @param guard_info Guard metadata (bytecode_pc, stack_depth, etc.)\n native_pc_offset is set by this function\n @param guard_arr Guard array to record the guard (for deopt stub gen)"]
pub fn vtx_guard_emit_type_check(
buf: *mut vtx_code_buffer_t,
obj_reg: vtx_reg_t,
expected_typeid: vtx_typeid_t,
guard_info: vtx_guard_info_t,
guard_arr: *mut vtx_guard_array_t,
);
}
extern "C" {
#[doc = " Emit a null check guard: verify that the value in `obj_reg` is not null.\n If the value is null, jump to a deopt stub.\n\n Generated code sequence:\n 1. Test the tagged value against VTX_VALUE_NULL\n 2. If equal, jump to deopt stub\n\n Alternatively (for heap pointers):\n 1. Test the raw pointer value\n 2. If zero, jump to deopt stub\n\n @param buf Code buffer to emit into\n @param obj_reg Register holding the value to check\n @param guard_info Guard metadata\n @param guard_arr Guard array to record the guard"]
pub fn vtx_guard_emit_null_check(
buf: *mut vtx_code_buffer_t,
obj_reg: vtx_reg_t,
guard_info: vtx_guard_info_t,
guard_arr: *mut vtx_guard_array_t,
);
}
extern "C" {
#[doc = " Emit a bounds check guard: verify that 0 <= index < length.\n If the index is out of bounds, jump to a deopt stub.\n\n Generated code sequence:\n 1. Compare index_reg (sign-extended) against 0 (unsigned comparison)\n 2. If below (index < 0 unsigned), jump to deopt\n 3. Compare index_reg against length_reg\n 4. If above-or-equal, jump to deopt\n\n @param buf Code buffer to emit into\n @param index_reg Register holding the index value\n @param length_reg Register holding the length value\n @param guard_info Guard metadata\n @param guard_arr Guard array to record the guard"]
pub fn vtx_guard_emit_bounds_check(
buf: *mut vtx_code_buffer_t,
index_reg: vtx_reg_t,
length_reg: vtx_reg_t,
guard_info: vtx_guard_info_t,
guard_arr: *mut vtx_guard_array_t,
);
}
extern "C" {
#[doc = " Emit an overflow check guard for integer addition.\n Uses the CPU's overflow flag after an add instruction.\n\n Generated code sequence:\n 1. After the add instruction, check the overflow flag (JO)\n 2. If overflow, jump to deopt stub\n\n @param buf Code buffer to emit into\n @param guard_info Guard metadata\n @param guard_arr Guard array to record the guard"]
pub fn vtx_guard_emit_overflow_check(
buf: *mut vtx_code_buffer_t,
guard_info: vtx_guard_info_t,
guard_arr: *mut vtx_guard_array_t,
);
}
extern "C" {
#[doc = " Emit a division-by-zero guard.\n\n Generated code sequence:\n 1. Test the divisor register\n 2. If zero, jump to deopt stub\n\n @param buf Code buffer to emit into\n @param divisor_reg Register holding the divisor value\n @param guard_info Guard metadata\n @param guard_arr Guard array to record the guard"]
pub fn vtx_guard_emit_div_zero_check(
buf: *mut vtx_code_buffer_t,
divisor_reg: vtx_reg_t,
guard_info: vtx_guard_info_t,
guard_arr: *mut vtx_guard_array_t,
);
}
#[doc = " VORTEX Sea-of-Nodes IR — Node Taxonomy\n\n Every value, control point, memory operation, allocation, and deoptimization\n marker in the IR is represented as a Node. Nodes reference each other by\n NodeID (uint32_t). The graph is stored in a flat node table with growing\n capacity. NodeIDs are never reused within a compilation.\n\n Node inputs form a directed graph. Control, memory, and data edges are\n distinguished by per-node flags, not by input position — the consumer\n inspects the producer's flags to determine edge kind."]
pub type vtx_nodeid_t = u32;
pub const vtx_node_opcode_t_VTX_OP_Start: vtx_node_opcode_t = 0;
pub const vtx_node_opcode_t_VTX_OP_End: vtx_node_opcode_t = 1;
pub const vtx_node_opcode_t_VTX_OP_If: vtx_node_opcode_t = 2;
pub const vtx_node_opcode_t_VTX_OP_Goto: vtx_node_opcode_t = 3;
pub const vtx_node_opcode_t_VTX_OP_Switch: vtx_node_opcode_t = 4;
pub const vtx_node_opcode_t_VTX_OP_LoopBegin: vtx_node_opcode_t = 5;
pub const vtx_node_opcode_t_VTX_OP_LoopEnd: vtx_node_opcode_t = 6;
pub const vtx_node_opcode_t_VTX_OP_Return: vtx_node_opcode_t = 7;
pub const vtx_node_opcode_t_VTX_OP_Unwind: vtx_node_opcode_t = 8;
pub const vtx_node_opcode_t_VTX_OP_Catch: vtx_node_opcode_t = 9;
pub const vtx_node_opcode_t_VTX_OP_Province: vtx_node_opcode_t = 10;
pub const vtx_node_opcode_t_VTX_OP_Constant: vtx_node_opcode_t = 11;
pub const vtx_node_opcode_t_VTX_OP_Parameter: vtx_node_opcode_t = 12;
pub const vtx_node_opcode_t_VTX_OP_Add: vtx_node_opcode_t = 13;
pub const vtx_node_opcode_t_VTX_OP_Sub: vtx_node_opcode_t = 14;
pub const vtx_node_opcode_t_VTX_OP_Mul: vtx_node_opcode_t = 15;
pub const vtx_node_opcode_t_VTX_OP_Div: vtx_node_opcode_t = 16;
pub const vtx_node_opcode_t_VTX_OP_Mod: vtx_node_opcode_t = 17;
pub const vtx_node_opcode_t_VTX_OP_Shl: vtx_node_opcode_t = 18;
pub const vtx_node_opcode_t_VTX_OP_Shr: vtx_node_opcode_t = 19;
pub const vtx_node_opcode_t_VTX_OP_Sar: vtx_node_opcode_t = 20;
pub const vtx_node_opcode_t_VTX_OP_And: vtx_node_opcode_t = 21;
pub const vtx_node_opcode_t_VTX_OP_Or: vtx_node_opcode_t = 22;
pub const vtx_node_opcode_t_VTX_OP_Xor: vtx_node_opcode_t = 23;
pub const vtx_node_opcode_t_VTX_OP_Neg: vtx_node_opcode_t = 24;
pub const vtx_node_opcode_t_VTX_OP_Not: vtx_node_opcode_t = 25;
pub const vtx_node_opcode_t_VTX_OP_Cmp: vtx_node_opcode_t = 26;
pub const vtx_node_opcode_t_VTX_OP_CmpP: vtx_node_opcode_t = 27;
pub const vtx_node_opcode_t_VTX_OP_CmpF: vtx_node_opcode_t = 28;
pub const vtx_node_opcode_t_VTX_OP_CmpD: vtx_node_opcode_t = 29;
pub const vtx_node_opcode_t_VTX_OP_AddF: vtx_node_opcode_t = 30;
pub const vtx_node_opcode_t_VTX_OP_SubF: vtx_node_opcode_t = 31;
pub const vtx_node_opcode_t_VTX_OP_MulF: vtx_node_opcode_t = 32;
pub const vtx_node_opcode_t_VTX_OP_DivF: vtx_node_opcode_t = 33;
pub const vtx_node_opcode_t_VTX_OP_NegF: vtx_node_opcode_t = 34;
pub const vtx_node_opcode_t_VTX_OP_Min: vtx_node_opcode_t = 35;
pub const vtx_node_opcode_t_VTX_OP_Max: vtx_node_opcode_t = 36;
pub const vtx_node_opcode_t_VTX_OP_Load: vtx_node_opcode_t = 37;
pub const vtx_node_opcode_t_VTX_OP_Store: vtx_node_opcode_t = 38;
pub const vtx_node_opcode_t_VTX_OP_LoadField: vtx_node_opcode_t = 39;
pub const vtx_node_opcode_t_VTX_OP_StoreField: vtx_node_opcode_t = 40;
pub const vtx_node_opcode_t_VTX_OP_LoadIndexed: vtx_node_opcode_t = 41;
pub const vtx_node_opcode_t_VTX_OP_StoreIndexed: vtx_node_opcode_t = 42;
pub const vtx_node_opcode_t_VTX_OP_MemBar: vtx_node_opcode_t = 43;
pub const vtx_node_opcode_t_VTX_OP_Initialize: vtx_node_opcode_t = 44;
pub const vtx_node_opcode_t_VTX_OP_CallStatic: vtx_node_opcode_t = 45;
pub const vtx_node_opcode_t_VTX_OP_CallVirtual: vtx_node_opcode_t = 46;
pub const vtx_node_opcode_t_VTX_OP_CallInterface: vtx_node_opcode_t = 47;
pub const vtx_node_opcode_t_VTX_OP_CallRuntime: vtx_node_opcode_t = 48;
pub const vtx_node_opcode_t_VTX_OP_CheckCast: vtx_node_opcode_t = 49;
pub const vtx_node_opcode_t_VTX_OP_InstanceOf: vtx_node_opcode_t = 50;
pub const vtx_node_opcode_t_VTX_OP_Guard: vtx_node_opcode_t = 51;
pub const vtx_node_opcode_t_VTX_OP_Phi: vtx_node_opcode_t = 52;
pub const vtx_node_opcode_t_VTX_OP_Region: vtx_node_opcode_t = 53;
pub const vtx_node_opcode_t_VTX_OP_Proj: vtx_node_opcode_t = 54;
pub const vtx_node_opcode_t_VTX_OP_ExceptProj: vtx_node_opcode_t = 55;
pub const vtx_node_opcode_t_VTX_OP_NewObject: vtx_node_opcode_t = 56;
pub const vtx_node_opcode_t_VTX_OP_NewArray: vtx_node_opcode_t = 57;
pub const vtx_node_opcode_t_VTX_OP_Allocate: vtx_node_opcode_t = 58;
pub const vtx_node_opcode_t_VTX_OP_InitializeKlass: vtx_node_opcode_t = 59;
pub const vtx_node_opcode_t_VTX_OP_Deopt: vtx_node_opcode_t = 60;
pub const vtx_node_opcode_t_VTX_OP_DeoptGuard: vtx_node_opcode_t = 61;
pub const vtx_node_opcode_t_VTX_OP_FrameState: vtx_node_opcode_t = 62;
pub const vtx_node_opcode_t_VTX_OP_VectorLoad: vtx_node_opcode_t = 63;
pub const vtx_node_opcode_t_VTX_OP_VectorStore: vtx_node_opcode_t = 64;
pub const vtx_node_opcode_t_VTX_OP_VectorAdd: vtx_node_opcode_t = 65;
pub const vtx_node_opcode_t_VTX_OP_VectorMul: vtx_node_opcode_t = 66;
pub const vtx_node_opcode_t_VTX_OP_UnboxInt: vtx_node_opcode_t = 67;
pub const vtx_node_opcode_t_VTX_OP_BoxInt: vtx_node_opcode_t = 68;
pub const vtx_node_opcode_t_VTX_NODE_OP_COUNT: vtx_node_opcode_t = 69;
pub type vtx_node_opcode_t = ::std::os::raw::c_uint;
pub const vtx_nodetype_t_VTX_TYPE_Bottom: vtx_nodetype_t = 0;
pub const vtx_nodetype_t_VTX_TYPE_Int: vtx_nodetype_t = 1;
pub const vtx_nodetype_t_VTX_TYPE_Float: vtx_nodetype_t = 2;
pub const vtx_nodetype_t_VTX_TYPE_Ptr: vtx_nodetype_t = 3;
pub const vtx_nodetype_t_VTX_TYPE_Void: vtx_nodetype_t = 4;
pub const vtx_nodetype_t_VTX_TYPE_Top: vtx_nodetype_t = 5;
#[doc = " Each node carries a type from a simple lattice:\n\n Top (unreachable / not yet computed)\n |\n Int / Float / Ptr / Void (concrete types)\n |\n Bottom (overdefined / multiple types meet)"]
pub type vtx_nodetype_t = ::std::os::raw::c_uint;
pub const vtx_node_flags_t_VTX_NF_NONE: vtx_node_flags_t = 0;
pub const vtx_node_flags_t_VTX_NF_CONTROL: vtx_node_flags_t = 1;
pub const vtx_node_flags_t_VTX_NF_MEMORY: vtx_node_flags_t = 2;
pub const vtx_node_flags_t_VTX_NF_DATA: vtx_node_flags_t = 4;
pub const vtx_node_flags_t_VTX_NF_SIDE_EFFECT: vtx_node_flags_t = 8;
pub const vtx_node_flags_t_VTX_NF_PINNED: vtx_node_flags_t = 16;
pub const vtx_node_flags_t_VTX_NF_WRITE_BARRIER: vtx_node_flags_t = 32;
pub const vtx_node_flags_t_VTX_NF_RAW_INT: vtx_node_flags_t = 64;
pub type vtx_node_flags_t = ::std::os::raw::c_uint;
#[doc = " For VTX_OP_Constant nodes, the value field holds the actual constant.\n We use a tagged union discriminated by the node's vtx_nodetype_t."]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct vtx_constval_t {
pub kind: vtx_nodetype_t,
pub as_: vtx_constval_t__bindgen_ty_1,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union vtx_constval_t__bindgen_ty_1 {
pub int_val: i64,
pub float_val: f64,
pub ptr_val: *mut ::std::os::raw::c_void,
}
impl Default for vtx_constval_t__bindgen_ty_1 {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
impl Default for vtx_constval_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
pub const vtx_cond_t_VTX_COND_EQ: vtx_cond_t = 0;
pub const vtx_cond_t_VTX_COND_NE: vtx_cond_t = 1;
pub const vtx_cond_t_VTX_COND_LT: vtx_cond_t = 2;
pub const vtx_cond_t_VTX_COND_LE: vtx_cond_t = 3;
pub const vtx_cond_t_VTX_COND_GT: vtx_cond_t = 4;
pub const vtx_cond_t_VTX_COND_GE: vtx_cond_t = 5;
pub const vtx_cond_t_VTX_COND_ULT: vtx_cond_t = 6;
pub const vtx_cond_t_VTX_COND_ULE: vtx_cond_t = 7;
pub const vtx_cond_t_VTX_COND_UGT: vtx_cond_t = 8;
pub const vtx_cond_t_VTX_COND_UGE: vtx_cond_t = 9;
pub const vtx_cond_t_VTX_COND_ALWAYS: vtx_cond_t = 10;
pub const vtx_cond_t_VTX_COND_NEVER: vtx_cond_t = 11;
pub type vtx_cond_t = ::std::os::raw::c_uint;
#[doc = " Use-def list: nodes that reference this node as an input.\n This is the inverse of the inputs array. For each node N that\n has N->inputs[i] == this->id, there is a use entry (N, i).\n\n This enables O(K) traversal of a node's users (where K is the\n number of users) instead of O(N²) scanning of all nodes."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_use_entry {
pub user_id: vtx_nodeid_t,
pub input_index: u32,
}
#[doc = " Use-def list: nodes that reference this node as an input.\n This is the inverse of the inputs array. For each node N that\n has N->inputs[i] == this->id, there is a use entry (N, i).\n\n This enables O(K) traversal of a node's users (where K is the\n number of users) instead of O(N²) scanning of all nodes."]
pub type vtx_use_entry_t = vtx_use_entry;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct vtx_node_t {
pub id: vtx_nodeid_t,
pub opcode: vtx_node_opcode_t,
pub type_: vtx_nodetype_t,
pub flags: vtx_node_flags_t,
pub inputs: *mut vtx_nodeid_t,
pub input_count: u32,
pub input_capacity: u32,
pub constval: vtx_constval_t,
pub cond: vtx_cond_t,
pub local_index: u32,
pub field_offset: u32,
pub method_index: u32,
pub type_id: u32,
pub bytecode_pc: u32,
pub frame_state: vtx_nodeid_t,
pub output_count: u32,
pub uses: *mut vtx_use_entry_t,
pub use_count: u32,
pub use_capacity: u32,
pub value_number: u32,
pub dead: bool,
pub mark: bool,
}
impl Default for vtx_node_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_node_opcode_info_t {
pub name: *const ::std::os::raw::c_char,
pub default_flags: vtx_node_flags_t,
pub fixed_inputs: u32,
}
impl Default for vtx_node_opcode_info_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_node_table_t {
pub nodes: *mut vtx_node_t,
pub count: u32,
pub capacity: u32,
pub next_id: vtx_nodeid_t,
}
impl Default for vtx_node_table_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize a node table with initial capacity.\n Returns 0 on success, -1 on failure (allocation error)."]
pub fn vtx_node_table_init(
table: *mut vtx_node_table_t,
initial_capacity: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy a node table and free all memory (inputs arrays + nodes array)."]
pub fn vtx_node_table_destroy(table: *mut vtx_node_table_t);
}
extern "C" {
#[doc = " Create a new node in the table with the given opcode.\n Sets id, opcode, type (Top), flags (from opcode metadata), empty inputs.\n Returns the new node's ID, or VTX_NODEID_INVALID on failure."]
pub fn vtx_node_create(table: *mut vtx_node_table_t, opcode: vtx_node_opcode_t)
-> vtx_nodeid_t;
}
extern "C" {
#[doc = " Look up a node by ID. Returns NULL if the ID is invalid or out of range."]
pub fn vtx_node_get(table: *mut vtx_node_table_t, id: vtx_nodeid_t) -> *mut vtx_node_t;
}
extern "C" {
#[doc = " Look up a const node by ID. Returns NULL if the ID is invalid."]
pub fn vtx_node_get_const(
table: *const vtx_node_table_t,
id: vtx_nodeid_t,
) -> *const vtx_node_t;
}
extern "C" {
#[doc = " Add an input edge from this node to the producer with the given ID.\n Increments the producer's output_count.\n Returns 0 on success, -1 on failure."]
pub fn vtx_node_add_input(
table: *mut vtx_node_table_t,
consumer: vtx_nodeid_t,
producer: vtx_nodeid_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Remove the input at the given index from the consumer node.\n Decrements the producer's output_count.\n Shifts subsequent inputs down by one.\n Returns 0 on success, -1 on failure (index out of bounds)."]
pub fn vtx_node_remove_input(
table: *mut vtx_node_table_t,
consumer: vtx_nodeid_t,
index: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Replace the input at the given index with a new producer.\n Decrements old producer's output_count and increments new producer's output_count.\n Returns 0 on success, -1 on failure."]
pub fn vtx_node_replace_input(
table: *mut vtx_node_table_t,
consumer: vtx_nodeid_t,
index: u32,
new_producer: vtx_nodeid_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Find the first input index that matches the given producer ID.\n Returns the index, or -1 if not found."]
pub fn vtx_node_find_input(
node: *const vtx_node_t,
producer: vtx_nodeid_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Compute the default type for a given opcode (before any propagation)."]
pub fn vtx_node_default_type(opcode: vtx_node_opcode_t) -> vtx_nodetype_t;
}
extern "C" {
#[doc = " Get the human-readable name for an opcode."]
pub fn vtx_node_opcode_name(opcode: vtx_node_opcode_t) -> *const ::std::os::raw::c_char;
}
extern "C" {
#[doc = " Get the human-readable name for a node type."]
pub fn vtx_nodetype_name(t: vtx_nodetype_t) -> *const ::std::os::raw::c_char;
}
extern "C" {
#[doc = " Check whether a node has side effects and must be kept by DCE."]
pub fn vtx_node_is_side_effecting(opcode: vtx_node_opcode_t) -> bool;
}
extern "C" {
#[doc = " Check whether a node is a control node."]
pub fn vtx_node_is_control(opcode: vtx_node_opcode_t) -> bool;
}
extern "C" {
#[doc = " Check whether a node is a memory node."]
pub fn vtx_node_is_memory(opcode: vtx_node_opcode_t) -> bool;
}
extern "C" {
#[doc = " Check whether a node is a pure data node."]
pub fn vtx_node_is_data(opcode: vtx_node_opcode_t) -> bool;
}
extern "C" {
#[doc = " Check whether two constant values are equal."]
pub fn vtx_constval_equal(a: vtx_constval_t, b: vtx_constval_t) -> bool;
}
extern "C" {
#[doc = " Hash a constant value."]
pub fn vtx_constval_hash(v: vtx_constval_t) -> u32;
}
extern "C" {
#[doc = " Clear all mark bits in the node table."]
pub fn vtx_node_table_clear_marks(table: *mut vtx_node_table_t);
}
extern "C" {
#[doc = " Clear all dead flags in the node table."]
pub fn vtx_node_table_clear_dead(table: *mut vtx_node_table_t);
}
extern "C" {
#[doc = " Get a pointer to the first use entry of a node.\n Returns NULL if the node has no uses."]
pub fn vtx_node_uses_begin(node: *mut vtx_node_t) -> *mut vtx_use_entry_t;
}
extern "C" {
#[doc = " Get a pointer one past the last use entry of a node."]
pub fn vtx_node_uses_end(node: *mut vtx_node_t) -> *mut vtx_use_entry_t;
}
extern "C" {
#[doc = " Get a const pointer to the first use entry of a node."]
pub fn vtx_node_uses_begin_const(node: *const vtx_node_t) -> *const vtx_use_entry_t;
}
extern "C" {
#[doc = " Get a const pointer one past the last use entry of a node."]
pub fn vtx_node_uses_end_const(node: *const vtx_node_t) -> *const vtx_use_entry_t;
}
extern "C" {
#[doc = " Replace ALL uses of old_id with new_id throughout the graph.\n This is the O(K) version of what was previously O(N²) —\n it walks old_id's use list and updates each user's input.\n\n Returns 0 on success, -1 on failure."]
pub fn vtx_node_replace_all_uses(
table: *mut vtx_node_table_t,
old_id: vtx_nodeid_t,
new_id: vtx_nodeid_t,
) -> ::std::os::raw::c_int;
}
#[doc = " Callback type for vtx_node_for_each_user.\n Called with (table, user_id, input_index, context).\n Return 0 to continue iteration, non-zero to stop."]
pub type vtx_user_callback_t = ::std::option::Option<
unsafe extern "C" fn(
table: *mut vtx_node_table_t,
user_id: vtx_nodeid_t,
input_index: u32,
context: *mut ::std::os::raw::c_void,
) -> ::std::os::raw::c_int,
>;
extern "C" {
#[doc = " Iterate over all users of a node, calling fn for each use entry.\n Stops early if fn returns non-zero.\n Returns the last return value from fn (0 if all calls returned 0)."]
pub fn vtx_node_for_each_user(
table: *mut vtx_node_table_t,
node_id: vtx_nodeid_t,
fn_: vtx_user_callback_t,
context: *mut ::std::os::raw::c_void,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Remove a use entry (user_id, input_index) from the producer's use-def list.\n This is the public wrapper around the internal node_remove_use helper.\n Used by passes like DCE that need to maintain use-def list consistency\n when disconnecting edges without going through the full add/remove input API."]
pub fn vtx_node_remove_use_entry(
producer: *mut vtx_node_t,
user_id: vtx_nodeid_t,
input_index: u32,
);
}
extern "C" {
#[doc = " Add a use entry (user_id, input_index) to the producer's use-def list.\n This is the public wrapper around the internal node_add_use helper.\n Used by passes that need to maintain use-def list consistency when\n adding edges without going through the full add input API."]
pub fn vtx_node_add_use_entry(
producer: *mut vtx_node_t,
user_id: vtx_nodeid_t,
input_index: u32,
);
}
#[doc = " Represents the state of a single monitor (lock) held at a deopt point.\n The monitor_object is a NodeID that evaluates to the locked object."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_monitor_state_t {
pub monitor_object: vtx_nodeid_t,
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_exception_state_t {
pub handler_pc: u32,
pub catch_type: vtx_typeid_t,
}
#[doc = " Complete execution state at a single deopt point.\n\n locals and stack are arrays of NodeIDs. Each NodeID represents the\n SoN node that produces the value in that slot at the deopt point.\n VTX_NODEID_INVALID means the slot is undefined/unused.\n\n The structure is allocated from an arena (no individual free)."]
pub type vtx_frame_state_t = vtx_frame_state;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_frame_state {
pub bytecode_pc: u32,
pub method_id: u32,
pub locals: *mut vtx_nodeid_t,
pub local_count: u32,
pub stack: *mut vtx_nodeid_t,
pub stack_count: u32,
pub monitors: *mut vtx_monitor_state_t,
pub monitor_count: u32,
pub exception: vtx_exception_state_t,
pub caller: *mut vtx_frame_state_t,
pub relock_needed: bool,
}
impl Default for vtx_frame_state {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Create a FrameState allocated from the given arena.\n Allocates locals and stack arrays from the arena.\n Returns NULL on allocation failure.\n\n @param arena Arena to allocate from\n @param pc Bytecode PC at the deopt point\n @param method_id Method identifier\n @param local_count Number of local variable slots\n @param stack_count Number of operand stack slots"]
pub fn vtx_frame_state_create(
arena: *mut vtx_arena_t,
pc: u32,
method_id: u32,
local_count: u32,
stack_count: u32,
) -> *mut vtx_frame_state_t;
}
extern "C" {
#[doc = " Create a chain of FrameStates representing a full call stack.\n The frames array is ordered from innermost (callee) to outermost (caller).\n Each frame's `caller` pointer is set to the next frame in the array.\n\n @param arena Arena to allocate from\n @param frame_pcs Array of bytecode PCs (innermost first)\n @param method_ids Array of method IDs (innermost first)\n @param local_counts Array of local counts (innermost first)\n @param stack_counts Array of stack counts (innermost first)\n @param depth Number of frames in the chain\n @return The innermost FrameState (head of the chain), or NULL on failure"]
pub fn vtx_frame_state_chain_create(
arena: *mut vtx_arena_t,
frame_pcs: *const u32,
method_ids: *const u32,
local_counts: *const u32,
stack_counts: *const u32,
depth: u32,
) -> *mut vtx_frame_state_t;
}
extern "C" {
#[doc = " Walk the caller chain and return the depth (number of frames)."]
pub fn vtx_frame_state_chain_depth(fs: *const vtx_frame_state_t) -> u32;
}
extern "C" {
#[doc = " Find the FrameState for the nth caller (0 = self, 1 = caller, etc.).\n Returns NULL if n exceeds the chain depth."]
pub fn vtx_frame_state_nth_caller(
fs: *const vtx_frame_state_t,
n: u32,
) -> *const vtx_frame_state_t;
}
#[doc = " A single entry in the register map: which register holds which NodeID.\n The register number is architecture-specific (e.g., RAX=0, RCX=1, etc.\n on x86-64)."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_reg_map_entry_t {
pub register_number: u32,
pub node_id: vtx_nodeid_t,
}
#[doc = " A single entry in the side table: maps a native PC offset to a FrameState\n and provides the register map for reconstructing values."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_side_table_entry_t {
pub native_pc_offset: u32,
pub frame_state_index: u32,
pub register_map: *mut vtx_reg_map_entry_t,
pub register_map_count: u32,
pub flags: u32,
}
impl Default for vtx_side_table_entry_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " The side table: a sorted array of entries mapping native PC offsets\n to FrameState indices and register maps."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_side_table_struct {
pub entries: *mut vtx_side_table_entry_t,
pub entry_count: u32,
pub entry_capacity: u32,
pub frame_states: *mut *mut vtx_frame_state_t,
pub frame_state_count: u32,
pub frame_state_capacity: u32,
}
impl Default for vtx_side_table_struct {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Build a new side table. If arena is non-NULL, entries are allocated from it.\n If arena is NULL, entries are allocated with malloc.\n Returns a new side table, or NULL on failure."]
pub fn vtx_side_table_build(arena: *mut vtx_arena_t) -> *mut vtx_side_table_t;
}
extern "C" {
#[doc = " Destroy a side table and free all memory.\n Only frees malloc'd tables (not arena-allocated ones)."]
pub fn vtx_side_table_destroy(table: *mut vtx_side_table_t);
}
extern "C" {
#[doc = " Add an entry to the side table. Entries must be added in increasing\n native_pc_offset order (this is natural since code is emitted sequentially).\n Returns the index of the new entry, or UINT32_MAX on failure.\n\n @param table The side table\n @param native_pc_offset Native PC offset of the deopt point\n @param frame_state_index Index into the FrameState array\n @param flags Bit flags for this entry\n @return Entry index, or UINT32_MAX on failure"]
pub fn vtx_side_table_add_entry(
table: *mut vtx_side_table_t,
native_pc_offset: u32,
frame_state_index: u32,
flags: u32,
) -> u32;
}
extern "C" {
#[doc = " Add a register map entry to the most recently added side table entry.\n Returns 0 on success, -1 on failure."]
pub fn vtx_side_table_add_register(
table: *mut vtx_side_table_t,
register_number: u32,
node_id: vtx_nodeid_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Register a FrameState with the side table. Returns the index.\n The FrameState pointer is stored; it must remain valid for the\n lifetime of the side table."]
pub fn vtx_side_table_add_frame_state(
table: *mut vtx_side_table_t,
fs: *mut vtx_frame_state_t,
) -> u32;
}
extern "C" {
#[doc = " Get a FrameState by index."]
pub fn vtx_side_table_get_frame_state(
table: *const vtx_side_table_t,
index: u32,
) -> *mut vtx_frame_state_t;
}
extern "C" {
#[doc = " Look up the side table entry for a given native PC offset.\n Uses binary search on the sorted entries array.\n\n If an exact match is not found, returns the entry with the largest\n native_pc_offset that is <= the given pc. This is correct because\n the side table entry at or before the PC describes the state at that point.\n\n Returns the frame_state_index, or UINT32_MAX if no entry exists\n at or before the given PC."]
pub fn vtx_side_table_lookup(table: *const vtx_side_table_t, native_pc_offset: u32) -> u32;
}
extern "C" {
#[doc = " Look up the full side table entry for a given native PC offset.\n Same semantics as vtx_side_table_lookup, but returns the full entry.\n Returns NULL if no entry is found."]
pub fn vtx_side_table_lookup_entry(
table: *const vtx_side_table_t,
native_pc_offset: u32,
) -> *const vtx_side_table_entry_t;
}
extern "C" {
#[doc = " Get a side table entry by its index."]
pub fn vtx_side_table_get_entry(
table: *const vtx_side_table_t,
index: u32,
) -> *const vtx_side_table_entry_t;
}
extern "C" {
#[doc = " Get the number of entries in the side table."]
pub fn vtx_side_table_entry_count(table: *const vtx_side_table_t) -> u32;
}
extern "C" {
#[doc = " Look up the NodeID held in a specific register at a given native PC.\n Returns VTX_NODEID_INVALID if the register is not mapped at that PC."]
pub fn vtx_side_table_find_register(
table: *const vtx_side_table_t,
native_pc_offset: u32,
register_number: u32,
) -> vtx_nodeid_t;
}
extern "C" {
#[doc = " Get the full register map for a given native PC offset.\n Sets *out_count to the number of register map entries.\n Returns a pointer to the first entry, or NULL if no entry found."]
pub fn vtx_side_table_get_register_map(
table: *const vtx_side_table_t,
native_pc_offset: u32,
out_count: *mut u32,
) -> *const vtx_reg_map_entry_t;
}
extern "C" {
#[doc = " Record a safepoint with GC root map at the given native PC offset.\n\n Creates a side table entry at the given native PC offset, flagged with\n VTX_STF_SAFEPPOINT, and records the GC root map (which NodeIDs hold\n object references at this point). The root_node_ids array must remain\n valid for the lifetime of the side table (typically arena-allocated).\n\n @param table The side table\n @param native_pc_offset Native PC offset of the safepoint\n @param root_node_ids Array of NodeIDs that are GC roots at this point\n @param root_count Number of entries in root_node_ids\n @return 0 on success, -1 on failure"]
pub fn vtx_side_table_record_safepoint(
table: *mut vtx_side_table_t,
native_pc_offset: u32,
root_node_ids: *const u32,
root_count: u32,
) -> ::std::os::raw::c_int;
}
#[doc = " VORTEX Baseline JIT Deoptimization Stub Generation\n\n For each guard that can fail, a deopt stub is generated. When a guard\n fails, execution jumps to the deopt stub which:\n\n 1. Saves all live register values into the JIT frame (locals and\n spill slots) so the interpreter can find them.\n 2. Reconstructs the interpreter operand stack from the JIT frame\n state: register-resident values are stored into the interpreter\n stack frame, spill slot values are copied.\n 3. Restores the interpreter frame pointer from the JIT frame header.\n 4. Sets the interpreter's bytecode PC to the deopt continuation point.\n 5. Jumps to the interpreter dispatch loop.\n\n The deopt stubs are appended after the main method code in the same\n code buffer. Each stub is a self-contained sequence that does not\n fall through to the next stub."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_deopt_stub_t {
pub native_code: *mut u8,
pub native_code_size: u32,
pub native_code_offset: u32,
pub guard_index: u32,
pub bytecode_pc: u32,
pub stack_depth: u32,
pub frame_state_index: u32,
}
impl Default for vtx_deopt_stub_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_deopt_stub_array_t {
pub stubs: *mut vtx_deopt_stub_t,
pub count: u32,
pub capacity: u32,
}
impl Default for vtx_deopt_stub_array_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize a deopt stub array.\n Returns 0 on success, -1 on failure."]
pub fn vtx_deopt_stub_array_init(arr: *mut vtx_deopt_stub_array_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy a deopt stub array."]
pub fn vtx_deopt_stub_array_destroy(arr: *mut vtx_deopt_stub_array_t);
}
extern "C" {
#[doc = " Add a deopt stub to the array.\n Returns the index, or UINT32_MAX on failure."]
pub fn vtx_deopt_stub_array_add(
arr: *mut vtx_deopt_stub_array_t,
stub: vtx_deopt_stub_t,
) -> u32;
}
#[doc = " Context for deopt stub generation. Passed between the stub emitter\n and the code generator to resolve addresses and offsets."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_deopt_context_t {
pub code_buf: *mut vtx_code_buffer_t,
pub guards: *mut vtx_guard_array_t,
pub frame_layout: vtx_jit_frame_layout_t,
pub side_table: *mut vtx_side_table_t,
pub arena: *mut vtx_arena_t,
pub code_start: *mut u8,
pub method_id: u32,
pub stub_array: *mut vtx_deopt_stub_array_t,
}
impl Default for vtx_deopt_context_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Generate deopt stubs for all guards in the guard array.\n\n For each guard, emits a deopt stub after the main method code.\n Patches the guard's conditional jump to point to the stub.\n\n Each stub performs:\n 1. Save all expression stack registers (RAX, RCX, RDX, RBX) to\n their spill slots in the JIT frame.\n 2. Set up the interpreter frame pointer from the JIT frame's\n caller RBP slot.\n 3. Store the bytecode PC (deopt continuation) into a well-known\n location that the interpreter reads on entry.\n 4. Copy locals from the JIT frame to the interpreter frame.\n 5. Reconstruct the interpreter operand stack from the saved\n register values and spill slots.\n 6. Jump to the interpreter dispatch loop entry point.\n\n @param ctx Deopt context with all necessary references\n @return Number of stubs generated, or -1 on failure"]
pub fn vtx_deopt_stubs_emit_all(ctx: *mut vtx_deopt_context_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Generate a single deopt stub for a specific guard.\n\n @param ctx Deopt context\n @param guard_index Index of the guard in the guard array\n @return The deopt stub descriptor, or NULL on failure"]
pub fn vtx_deopt_stub_emit(
ctx: *mut vtx_deopt_context_t,
guard_index: u32,
) -> *const vtx_deopt_stub_t;
}
extern "C" {
#[doc = " Patch all guard conditional jumps to point to their deopt stubs.\n Must be called after all stubs have been emitted.\n\n @param ctx Deopt context\n @return 0 on success, -1 on failure"]
pub fn vtx_deopt_stubs_patch_guards(ctx: *mut vtx_deopt_context_t) -> ::std::os::raw::c_int;
}
#[doc = " Get the address of the interpreter re-entry point.\n This is where deopt stubs jump to resume interpretation.\n The re-entry point expects:\n - RBP = interpreter frame pointer\n - RIP-relative stored bytecode PC\n - Operand stack reconstructed in the interpreter frame\n\n This function returns a function pointer that the runtime must\n provide (the interpreter dispatch loop entry)."]
pub type vtx_interp_entry_t = ::std::option::Option<unsafe extern "C" fn()>;
extern "C" {
#[doc = " Set the interpreter entry point for deopt stubs to jump to.\n Must be called before any deopt stubs are generated."]
pub fn vtx_deopt_set_interp_entry(entry: vtx_interp_entry_t);
}
extern "C" {
#[doc = " Get the current interpreter entry point."]
pub fn vtx_deopt_get_interp_entry() -> vtx_interp_entry_t;
}
extern "C" {
pub fn vtx_deopt_interp_entry_wrapper();
}
extern "C" {
#[doc = " Deoptimization runtime function. Called by deopt stubs to transition\n from JIT code back to the interpreter.\n\n This function:\n 1. Reads the deopt info from the current frame\n 2. Reconstructs the interpreter frame\n 3. Returns the interpreter frame pointer and bytecode PC\n\n @param jit_rbp The JIT frame's RBP value\n @param native_pc The native PC where deopt occurred\n @return The interpreter frame pointer (or NULL on error)"]
pub fn vtx_deopt_runtime_transition(
jit_rbp: *mut ::std::os::raw::c_void,
native_pc: u32,
) -> *mut ::std::os::raw::c_void;
}
#[doc = " Configuration for tier-aware deoptimization (Proposal #5).\n When a deopt stub is entered, it checks whether a lower-tier compiled\n version exists before falling back to the interpreter."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_deopt_tier_config_t {
pub prefer_lower_tier: bool,
pub require_same_frame_layout: bool,
}
#[doc = " Polymorphic inline cache for virtual/interface dispatch.\n\n Each CALL_VIRTUAL / CALL_INTERFACE site gets its own IC.\n The emitted machine code probes the type_ids array; on a hit,\n it calls the corresponding target directly. On a miss, it\n falls through to the runtime helper which updates the IC.\n\n Layout (designed for cache-friendly access from emitted code):\n offset 0: type_ids[0..3] — 4 × uint32_t = 16 bytes, contiguous\n offset 16: targets[0..3] — 4 × void* = 32 bytes, contiguous\n offset 48: count — uint32_t\n offset 52: misses — uint32_t"]
pub type vtx_poly_ic_t = vtx_poly_ic;
#[doc = " VORTEX Code Cache — Shared Compiled Code Type Definitions\n\n This header contains the canonical definition of vtx_compiled_code_t,\n which is used by both the baseline JIT code generator and the deopt/OSR\n subsystems."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_bc_pc_map_entry_t {
pub bytecode_pc: u32,
pub native_offset: u32,
pub stack_depth: u32,
}
#[doc = " The result of compilation: contains the generated native code\n and all associated metadata.\n\n Fields from baseline/codegen.h:\n code, code_size, frame_layout, guards, deopt_stubs, side_table,\n deopt_info, bc_pc_map, bc_pc_map_count, native_to_bc_pc,\n native_to_bc_pc_count, method\n\n Fields from deopt/osr.h:\n entry_point, method_id, stack_slots, local_slots"]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_compiled_code_t {
pub code: *mut u8,
pub code_size: u32,
pub frame_layout: vtx_jit_frame_layout_t,
pub guards: vtx_guard_array_t,
pub deopt_stubs: vtx_deopt_stub_array_t,
pub side_table: *mut vtx_side_table_t,
pub deopt_info: *mut vtx_deopt_info_t,
pub bc_pc_map: *mut vtx_bc_pc_map_entry_t,
pub bc_pc_map_count: u32,
pub native_to_bc_pc: *mut u32,
pub native_to_bc_pc_count: u32,
pub method: *const vtx_method_desc_t,
pub poly_ics: *mut *mut vtx_poly_ic_t,
pub poly_ic_count: u32,
pub entry_point: *mut ::std::os::raw::c_void,
pub method_id: u32,
pub stack_slots: u32,
pub local_slots: u32,
}
impl Default for vtx_compiled_code_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
pub const vtx_reloc_kind_t_VTX_RELOC_REL32: vtx_reloc_kind_t = 0;
pub const vtx_reloc_kind_t_VTX_RELOC_ABS64: vtx_reloc_kind_t = 1;
pub const vtx_reloc_kind_t_VTX_RELOC_RIP_REL32: vtx_reloc_kind_t = 2;
#[doc = " VORTEX Relocations and Fixups\n\n Handles fixups for:\n - Forward branches (patched after target is emitted)\n - Call targets (patched after callee is compiled)\n - Constant pool references (RIP-relative)\n - Deopt handler addresses (absolute)\n\n Relocations are recorded during code emission and applied in a final\n pass once all code positions are known."]
pub type vtx_reloc_kind_t = ::std::os::raw::c_uint;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_reloc_t {
pub kind: vtx_reloc_kind_t,
pub offset: u32,
pub target_offset: u32,
pub target_address: u64,
pub symbol: u32,
pub addend: i32,
pub is_external: bool,
}
impl Default for vtx_reloc_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_reloc_table_t {
pub entries: *mut vtx_reloc_t,
pub count: u32,
pub capacity: u32,
}
impl Default for vtx_reloc_table_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize a relocation table.\n Returns 0 on success, -1 on failure."]
pub fn vtx_reloc_table_init(
table: *mut vtx_reloc_table_t,
arena: *mut vtx_arena_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy a relocation table."]
pub fn vtx_reloc_table_destroy(table: *mut vtx_reloc_table_t);
}
extern "C" {
#[doc = " Add a relocation entry to the table.\n Returns the index of the new entry, or UINT32_MAX on failure.\n\n @param table Relocation table\n @param kind Relocation type\n @param offset Offset in code buffer where fixup goes\n @param target_offset Target offset (for REL32)\n @param target_address Absolute target address (for ABS64)\n @param symbol Symbol index (0 = none)\n @param addend Additional offset\n @param arena Arena for allocation"]
pub fn vtx_reloc_add(
table: *mut vtx_reloc_table_t,
kind: vtx_reloc_kind_t,
offset: u32,
target_offset: u32,
target_address: u64,
symbol: u32,
addend: i32,
arena: *mut vtx_arena_t,
) -> u32;
}
extern "C" {
#[doc = " Apply all relocations to the code buffer.\n\n For REL32: patch the 32-bit value at `offset` with\n (target_offset - offset - 4 + addend)\n\n For ABS64: patch the 64-bit value at `offset` with\n (target_address + addend)\n\n For RIP_REL32: patch the 32-bit value at `offset` with\n (target_offset - (offset + 4) + addend)\n\n @param table Relocation table\n @param code_buffer Code buffer to patch\n @param code_size Size of the code buffer\n @return 0 on success, -1 on failure"]
pub fn vtx_reloc_apply_all(
table: *mut vtx_reloc_table_t,
code_buffer: *mut u8,
code_size: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Add a forward branch relocation.\n Convenience function for the common case of a JCC/JMP that targets\n a not-yet-emitted location.\n\n @param table Relocation table\n @param patch_offset Offset of the 32-bit displacement to patch\n @param source_offset Offset of the branch instruction start\n @param target_offset Offset of the branch target (0 = unknown, will be set later)\n @param arena Arena"]
pub fn vtx_reloc_add_branch(
table: *mut vtx_reloc_table_t,
patch_offset: u32,
source_offset: u32,
target_offset: u32,
arena: *mut vtx_arena_t,
) -> u32;
}
extern "C" {
#[doc = " Add a call target relocation.\n\n @param table Relocation table\n @param patch_offset Offset of the 32-bit displacement\n @param target_address Absolute address of the callee\n @param arena Arena"]
pub fn vtx_reloc_add_call(
table: *mut vtx_reloc_table_t,
patch_offset: u32,
target_address: u64,
arena: *mut vtx_arena_t,
) -> u32;
}
extern "C" {
#[doc = " Add a deopt handler address relocation (absolute 64-bit).\n\n @param table Relocation table\n @param patch_offset Offset of the 64-bit address to patch\n @param handler_addr Address of the deopt handler\n @param arena Arena"]
pub fn vtx_reloc_add_deopt_handler(
table: *mut vtx_reloc_table_t,
patch_offset: u32,
handler_addr: u64,
arena: *mut vtx_arena_t,
) -> u32;
}
extern "C" {
#[doc = " Apply deferred external call relocations at install time.\n\n When code is installed in the code cache, the base address changes\n from the temporary emission buffer to the final code cache address.\n External call relocations (calls to runtime helpers) use REL32 relative\n addressing, so the displacement depends on the code's final address.\n\n This function must be called AFTER the code has been copied to its\n final location in the code cache, and BEFORE the code is made executable.\n\n Only relocations marked is_external=true are processed. Intra-code\n relocations were already resolved by vtx_reloc_apply_all() and are\n not affected.\n\n @param table Relocation table\n @param code_base Final base address of the installed code\n @param code_buffer Writable pointer to the installed code\n @param code_size Size of the code\n @return 0 on success, -1 on failure"]
pub fn vtx_reloc_apply_external(
table: *mut vtx_reloc_table_t,
code_base: *const ::std::os::raw::c_void,
code_buffer: *mut u8,
code_size: u32,
) -> ::std::os::raw::c_int;
}
#[doc = " Per-method state for the clock (Second Chance) eviction algorithm.\n The use_bit is set when the method is called (touch) and cleared\n by the clock hand during eviction scanning. Methods with a cleared\n use_bit are eviction candidates."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_clock_state_t {
pub clock_hand: u32,
pub use_bit: bool,
}
#[doc = " Metadata for a compiled method, stored separately from the code.\n This includes everything needed for deoptimization and invalidation."]
pub type vtx_compiled_method_t = vtx_compiled_method;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_compiled_method {
pub method_id: u32,
pub method_desc: *const vtx_method_desc_t,
pub code_start: *mut u8,
pub code_size: u32,
pub side_table: *mut vtx_side_table_t,
pub deopt_info: *mut vtx_deopt_info_t,
pub reloc_table: *mut vtx_reloc_table_t,
pub dep_type_ids: *mut u32,
pub dep_type_count: u32,
pub dep_shape_ids: *mut u32,
pub dep_shape_count: u32,
pub last_used_timestamp: u64,
pub call_count: u32,
pub clock_state: vtx_clock_state_t,
pub poly_ics: *mut *mut vtx_poly_ic_t,
pub poly_ic_count: u32,
pub is_installed: bool,
pub is_valid: bool,
pub frame_layout: vtx_jit_frame_layout_t,
pub bc_pc_map: *mut vtx_bc_pc_map_entry_t,
pub bc_pc_map_count: u32,
pub next: *mut vtx_compiled_method_t,
}
impl Default for vtx_compiled_method {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_method_registry {
pub methods: *mut *mut vtx_compiled_method_t,
pub method_count: u32,
pub capacity: u32,
pub capacity_mask: u32,
pub clock_hand: u32,
pub malloc_allocated: bool,
}
impl Default for vtx_method_registry {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
pub type vtx_method_registry_t = vtx_method_registry;
extern "C" {
#[doc = " Initialize the method registry."]
pub fn vtx_method_registry_init(
registry: *mut vtx_method_registry_t,
arena: *mut vtx_arena_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the method registry."]
pub fn vtx_method_registry_destroy(registry: *mut vtx_method_registry_t);
}
extern "C" {
#[doc = " Register a compiled method in the registry."]
pub fn vtx_method_registry_add(
registry: *mut vtx_method_registry_t,
method: *mut vtx_compiled_method_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Look up a compiled method by its method_id."]
pub fn vtx_method_registry_get(
registry: *mut vtx_method_registry_t,
method_id: u32,
) -> *mut vtx_compiled_method_t;
}
extern "C" {
#[doc = " Remove a compiled method from the registry."]
pub fn vtx_method_registry_remove(
registry: *mut vtx_method_registry_t,
method_id: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Install a compiled method into the code cache.\n\n Steps:\n 1. Allocate space in the cache for the compiled code\n 2. Copy the code into the cache\n 3. Make the code executable\n 4. Register the method in the registry\n 5. Update the method's code pointer atomically\n\n @param cache Code cache\n @param registry Method registry\n @param method Method descriptor\n @param code Compiled code bytes\n @param code_size Size of compiled code\n @param side_table Deoptimization side table (ownership transferred)\n @param reloc_table Relocation table (for external call fixups at install time)\n @param dep_types Array of TypeIDs this method depends on\n @param dep_type_count Number of TypeIDs\n @param dep_shapes Array of ShapeIDs this method depends on\n @param dep_shape_count Number of ShapeIDs\n @param arena Arena for allocations\n @param poly_ics Array of polymorphic inline cache pointers (ownership transferred)\n @param poly_ic_count Number of ICs in the array\n @return true on success, false on failure"]
pub fn vtx_install_method(
cache: *mut vtx_code_cache_t,
registry: *mut vtx_method_registry_t,
method: *const vtx_method_desc_t,
method_id: u32,
code: *const u8,
code_size: u32,
side_table: *mut vtx_side_table_t,
reloc_table: *mut vtx_reloc_table_t,
dep_types: *const u32,
dep_type_count: u32,
dep_shapes: *const u32,
dep_shape_count: u32,
arena: *mut vtx_arena_t,
poly_ics: *mut *mut vtx_poly_ic_t,
poly_ic_count: u32,
frame_layout: *const vtx_jit_frame_layout_t,
bc_pc_map: *const vtx_bc_pc_map_entry_t,
bc_pc_map_count: u32,
) -> bool;
}
extern "C" {
#[doc = " Uninstall a method: mark it as not compiled and free its metadata.\n The code in the cache is freed separately (when the segment is empty).\n\n @param cache Code cache\n @param registry Method registry\n @param method_id Method ID to uninstall\n @return 0 on success, -1 on failure"]
pub fn vtx_uninstall_method(
cache: *mut vtx_code_cache_t,
registry: *mut vtx_method_registry_t,
method_id: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Get the entry point for a compiled method.\n Returns NULL if the method is not compiled or not installed."]
pub fn vtx_method_entry_point(
method: *const vtx_compiled_method_t,
) -> *mut ::std::os::raw::c_void;
}
#[doc = " Records the receiver types observed at a single call site.\n Up to VTX_POLY_LIMIT types are stored; once exceeded the site is megamorphic."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_callsite_profile_t {
pub types: [vtx_typeid_t; 4usize],
pub count: u32,
pub megamorphic: bool,
}
#[doc = " Records taken / not-taken counts for a single branch bytecode PC.\n Both counters use saturating increment."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_branch_profile_t {
pub bytecode_pc: u32,
pub taken: u64,
pub not_taken: u64,
}
#[doc = " Records the shape IDs observed at a single field access site.\n Up to VTX_POLY_LIMIT shapes are stored; once exceeded the site is megamorphic."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_field_profile_t {
pub field_offset: u32,
pub shapes: [vtx_shapeid_t; 4usize],
pub count: u32,
pub megamorphic: bool,
}
#[doc = " Records the back-edge count for a single loop (identified by its header PC)."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_loop_profile_t {
pub loop_header_pc: u32,
pub backedge_count: u64,
pub last_trip_count: u64,
pub trip_stability_count: u32,
pub is_trip_stable: bool,
}
#[doc = " Complete profile data for a single method.\n\n Call sites, branches, field accesses, and loops are stored in dynamically\n grown arrays keyed by bytecode PC or field offset. Lookup is linear scan\n (the arrays are small: typical methods have < 100 sites of each kind)."]
pub type vtx_profile_method_t = vtx_profile_method;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_profile_method {
pub method_id: u32,
pub invocation_count: u64,
pub call_sites: *mut vtx_callsite_profile_t,
pub call_site_count: u32,
pub call_site_capacity: u32,
pub branches: *mut vtx_branch_profile_t,
pub branch_count: u32,
pub branch_capacity: u32,
pub field_accesses: *mut vtx_field_profile_t,
pub field_access_count: u32,
pub field_access_capacity: u32,
pub loops: *mut vtx_loop_profile_t,
pub loop_count: u32,
pub loop_capacity: u32,
}
impl Default for vtx_profile_method {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " A directed edge in the method call graph: caller → callee with frequency."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_call_edge_t {
pub caller_method_id: u32,
pub callee_method_id: u32,
pub frequency: u64,
}
#[doc = " A directed edge in the phase transition graph.\n Represents a transition from one phase (SCC) to another."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_phase_transition_t {
pub from_phase_id: u32,
pub to_phase_id: u32,
pub frequency: u64,
}
#[doc = " Global profile data spanning all methods.\n\n Owns the method profile array, the call graph edges, and the phase\n transition graph. The phase transition graph is populated by\n vtx_phase_detect() in phase.h."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_profile_global_t {
pub methods: *mut vtx_profile_method_t,
pub method_count: u32,
pub method_capacity: u32,
pub call_edges: *mut vtx_call_edge_t,
pub call_edge_count: u32,
pub call_edge_capacity: u32,
pub phase_transitions: *mut vtx_phase_transition_t,
pub phase_transition_count: u32,
pub phase_transition_capacity: u32,
pub phase_graph: *mut vtx_phase_graph,
}
impl Default for vtx_profile_global_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize a global profile structure. Allocates initial arrays.\n Returns 0 on success, -1 on failure."]
pub fn vtx_profile_global_init(global: *mut vtx_profile_global_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy a global profile structure and free all memory."]
pub fn vtx_profile_global_destroy(global: *mut vtx_profile_global_t);
}
extern "C" {
#[doc = " Add a new method profile for the given method_id.\n Returns a pointer to the new method profile, or NULL on failure.\n If a profile for method_id already exists, returns the existing one."]
pub fn vtx_profile_add_method(
global: *mut vtx_profile_global_t,
method_id: u32,
) -> *mut vtx_profile_method_t;
}
extern "C" {
#[doc = " Look up a method profile by method_id.\n Returns the profile, or NULL if not found."]
pub fn vtx_profile_get_method(
global: *const vtx_profile_global_t,
method_id: u32,
) -> *mut vtx_profile_method_t;
}
extern "C" {
#[doc = " Record a method invocation. Increments the invocation counter (saturating).\n Creates the method profile if it does not exist."]
pub fn vtx_profile_record_invocation(global: *mut vtx_profile_global_t, method_id: u32);
}
extern "C" {
#[doc = " Record a receiver type observation at a call site.\n Creates the method profile and call site entry if they do not exist.\n If the call site is already megamorphic, this is a no-op.\n If the type is already recorded, this is a no-op.\n If VTX_POLY_LIMIT distinct types have been seen and this is a new type,\n the site transitions to megamorphic."]
pub fn vtx_profile_record_callsite_type(
global: *mut vtx_profile_global_t,
method_id: u32,
callsite_index: u32,
receiver_type: vtx_typeid_t,
);
}
extern "C" {
#[doc = " Record a branch outcome at the given bytecode PC.\n Creates the method profile and branch entry if they do not exist.\n taken=true increments the taken counter; taken=false increments not_taken.\n Both use saturating arithmetic."]
pub fn vtx_profile_record_branch(
global: *mut vtx_profile_global_t,
method_id: u32,
bytecode_pc: u32,
taken: bool,
);
}
extern "C" {
#[doc = " Record a field access shape observation.\n Creates the method profile and field access entry if they do not exist.\n If the site is already megamorphic, this is a no-op.\n If the shape is already recorded, this is a no-op.\n If VTX_POLY_LIMIT distinct shapes have been seen and this is a new shape,\n the site transitions to megamorphic."]
pub fn vtx_profile_record_field_shape(
global: *mut vtx_profile_global_t,
method_id: u32,
field_offset: u32,
shape_id: vtx_shapeid_t,
);
}
extern "C" {
#[doc = " Record a loop back-edge at the given loop header PC.\n Creates the method profile and loop entry if they do not exist.\n Increments the back-edge counter (saturating)."]
pub fn vtx_profile_record_loop_backedge(
global: *mut vtx_profile_global_t,
method_id: u32,
loop_header_pc: u32,
);
}
extern "C" {
#[doc = " Record a call graph edge (caller → callee).\n If an edge with the same (caller, callee) pair already exists,\n increments its frequency (saturating). Otherwise creates a new edge."]
pub fn vtx_profile_record_call_edge(
global: *mut vtx_profile_global_t,
caller_method_id: u32,
callee_method_id: u32,
);
}
extern "C" {
#[doc = " Get the callsite profile for a method at the given callsite index.\n Returns NULL if the method or callsite does not exist."]
pub fn vtx_profile_get_callsite(
global: *const vtx_profile_global_t,
method_id: u32,
callsite_index: u32,
) -> *const vtx_callsite_profile_t;
}
extern "C" {
#[doc = " Get the branch profile for a method at the given bytecode PC.\n Returns NULL if the method or branch does not exist."]
pub fn vtx_profile_get_branch(
global: *const vtx_profile_global_t,
method_id: u32,
bytecode_pc: u32,
) -> *const vtx_branch_profile_t;
}
extern "C" {
#[doc = " Compute the branch taken probability for a branch profile.\n Returns 0.0 if no observations, otherwise taken / (taken + not_taken)."]
pub fn vtx_profile_branch_probability(branch: *const vtx_branch_profile_t) -> f64;
}
extern "C" {
#[doc = " Check if a method is \"hot\" (invocation count >= threshold)."]
pub fn vtx_profile_method_is_hot(method: *const vtx_profile_method_t, threshold: u64) -> bool;
}
extern "C" {
#[doc = " Record a loop trip count observation and update stability tracking.\n If the new trip count matches the previous observation, increment\n the stability counter. If it differs, reset the counter.\n\n @param global Global profile\n @param method_id Method ID\n @param loop_header_pc Bytecode PC of the loop header\n @param trip_count Trip count observed for this entry"]
pub fn vtx_profile_record_trip_count(
global: *mut vtx_profile_global_t,
method_id: u32,
loop_header_pc: u32,
trip_count: u64,
);
}
extern "C" {
#[doc = " Check if a loop is trip-stable (trip count constant for\n VTX_TRIP_STABILITY_WINDOW observations).\n\n @param global Global profile\n @param method_id Method ID\n @param loop_header_pc Loop header PC\n @return true if trip-stable"]
pub fn vtx_profile_is_trip_stable(
global: *const vtx_profile_global_t,
method_id: u32,
loop_header_pc: u32,
) -> bool;
}
extern "C" {
#[doc = " Get the stable trip count for a trip-stable loop.\n Returns 0 if the loop is not trip-stable.\n\n @param global Global profile\n @param method_id Method ID\n @param loop_header_pc Loop header PC\n @return Stable trip count, or 0"]
pub fn vtx_profile_get_stable_trip_count(
global: *const vtx_profile_global_t,
method_id: u32,
loop_header_pc: u32,
) -> u64;
}
#[doc = " A single phase: an SCC in the call graph that meets the size and\n frequency thresholds."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_phase_t {
pub phase_id: u32,
pub method_ids: *mut u32,
pub method_count: u32,
pub method_capacity: u32,
pub total_frequency: u64,
pub is_significant: bool,
}
impl Default for vtx_phase_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " The phase graph: the result of phase detection.\n Contains the list of phases and the transitions between them."]
pub type vtx_phase_graph_t = vtx_phase_graph;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_phase_graph {
pub phases: *mut vtx_phase_t,
pub phase_count: u32,
pub phase_capacity: u32,
pub transitions: *mut vtx_phase_transition_t,
pub transition_count: u32,
pub transition_capacity: u32,
pub method_to_phase: *mut u32,
pub method_to_phase_capacity: u32,
}
impl Default for vtx_phase_graph {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Detect phases from the call graph in the global profile.\n Returns a newly allocated phase graph (caller must free with\n vtx_phase_graph_destroy), or NULL on failure.\n\n Algorithm:\n 1. Build adjacency lists from the call edges in the profile.\n 2. Run Tarjan's SCC algorithm.\n 3. For each SCC, compute total invocation frequency.\n 4. Mark SCCs as significant if they meet the thresholds.\n 5. Phase transitions = inter-SCC edges between significant SCCs."]
pub fn vtx_phase_detect(global: *const vtx_profile_global_t) -> *mut vtx_phase_graph_t;
}
extern "C" {
#[doc = " Destroy a phase graph and free all memory."]
pub fn vtx_phase_graph_destroy(graph: *mut vtx_phase_graph_t);
}
extern "C" {
#[doc = " Check if the program is transitioning from one phase to another.\n A transition occurs when the current top-of-stack method changes\n from one phase to a different phase.\n\n prev_top_method: the method_id of the previous top-of-stack method.\n curr_top_method: the method_id of the current top-of-stack method.\n\n Returns true if there is a phase transition (different phases).\n Returns false if both methods are in the same phase, or if either\n method is not in any phase, or if either is VTX_PHASE_NONE."]
pub fn vtx_phase_is_entering(
graph: *const vtx_phase_graph_t,
prev_top_method: u32,
curr_top_method: u32,
) -> bool;
}
extern "C" {
#[doc = " Look up the phase ID for a method. Returns VTX_PHASE_NONE if not in any phase."]
pub fn vtx_phase_for_method(graph: *const vtx_phase_graph_t, method_id: u32) -> u32;
}
extern "C" {
#[doc = " Get a phase by its ID. Returns NULL if not found."]
pub fn vtx_phase_get_by_id(
graph: *const vtx_phase_graph_t,
phase_id: u32,
) -> *const vtx_phase_t;
}
#[doc = " A single phase's profile storage.\n\n The `profile` is a fully-owned vtx_profile_global_t — the partition\n manager initializes and destroys it."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_phase_profile_entry_t {
pub phase_id: u32,
pub profile: vtx_profile_global_t,
pub transition_count: u64,
pub last_transition_ns: u64,
pub valid: bool,
}
impl Default for vtx_phase_profile_entry_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Phase-aware profile partition manager.\n\n Owns N per-phase profile globals and tracks which one is currently\n \"active\" (i.e., the one the interpreter is recording to and the\n orchestrator is reading from for recomp decisions).\n\n Lifecycle:\n 1. init() — creates the default phase (VTX_PHASE_NONE) and makes\n it active.\n 2. transition(new_phase) — saves the current active phase's stats,\n creates the new phase if needed, makes it\n active.\n 3. get_active() — returns the currently-active profile (used by\n the recording path and the orchestrator).\n 4. destroy() — destroys all per-phase profiles."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_phase_partition_t {
pub entries: *mut vtx_phase_profile_entry_t,
pub entry_count: u32,
pub entry_capacity: u32,
pub active_index: u32,
pub total_transitions: u64,
pub total_phase_creations: u64,
}
impl Default for vtx_phase_partition_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the partition manager.\n\n Creates the default phase (phase_id == VTX_PHASE_NONE) and makes it\n active. The default phase is where all recording goes until the first\n explicit transition.\n\n Returns 0 on success, -1 on failure."]
pub fn vtx_phase_partition_init(part: *mut vtx_phase_partition_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the partition manager and all per-phase profiles."]
pub fn vtx_phase_partition_destroy(part: *mut vtx_phase_partition_t);
}
extern "C" {
#[doc = " Get the currently-active phase's profile.\n\n This is the profile that:\n - The interpreter records to (via the orchestrator's wiring)\n - The orchestrator reads from for recomp decisions\n - The compiler uses for speculative optimization\n\n Returns NULL only if init() failed."]
pub fn vtx_phase_partition_get_active(
part: *mut vtx_phase_partition_t,
) -> *mut vtx_profile_global_t;
}
extern "C" {
#[doc = " Get the phase_id of the currently-active phase.\n Returns VTX_PHASE_NONE for the default phase."]
pub fn vtx_phase_partition_active_phase(part: *const vtx_phase_partition_t) -> u32;
}
extern "C" {
#[doc = " Transition to a new phase.\n\n 1. Records transition stats for the outgoing phase.\n 2. Looks up (or creates) the entry for `new_phase_id`.\n 3. Makes that entry the active phase.\n\n If `new_phase_id` is the same as the currently-active phase, this is\n a no-op (returns the active profile without modifying state).\n\n After this call, vtx_phase_partition_get_active() returns the new\n phase's profile. The interpreter's recording pointer must be updated\n by the caller.\n\n @param part Partition manager\n @param new_phase_id Phase to transition to (VTX_PHASE_NONE for default)\n @param now_ns Monotonic timestamp (pass 0 to use internal clock)\n @return The new active profile, or NULL on failure"]
pub fn vtx_phase_partition_transition(
part: *mut vtx_phase_partition_t,
new_phase_id: u32,
now_ns: u64,
) -> *mut vtx_profile_global_t;
}
extern "C" {
#[doc = " Get the profile for a specific phase, or NULL if it doesn't exist.\n\n Does NOT change the active phase. Use this to inspect or save a\n phase's profile (e.g., for persistence or preemptive recompilation\n of the predicted-next phase)."]
pub fn vtx_phase_partition_get_phase(
part: *mut vtx_phase_partition_t,
phase_id: u32,
) -> *mut vtx_profile_global_t;
}
extern "C" {
#[doc = " Get or create the profile for a specific phase.\n\n If the phase doesn't exist, it's created (but NOT made active —\n call transition() for that). Returns the phase's profile."]
pub fn vtx_phase_partition_get_or_create(
part: *mut vtx_phase_partition_t,
phase_id: u32,
) -> *mut vtx_profile_global_t;
}
extern "C" {
#[doc = " Number of distinct phases tracked (including the default phase)."]
pub fn vtx_phase_partition_phase_count(part: *const vtx_phase_partition_t) -> u32;
}
extern "C" {
#[doc = " Given a phase graph and a target phase, populate `out_methods` with\n the method IDs that are hot in that phase and should be preemptively\n recompiled when entering the phase.\n\n The methods are sorted by descending invocation_count in the phase's\n profile (so the hottest come first). At most `out_capacity` methods\n are written.\n\n @param part Partition manager\n @param graph Phase graph (from vtx_phase_detect)\n @param phase_id Target phase\n @param out_methods Output array\n @param out_capacity Max methods to write\n @return Number of methods written (may be 0)"]
pub fn vtx_phase_partition_hot_methods_for_phase(
part: *mut vtx_phase_partition_t,
graph: *const vtx_phase_graph_t,
phase_id: u32,
out_methods: *mut u32,
out_capacity: u32,
) -> u32;
}
extern "C" {
#[doc = " Get aggregate partition statistics.\n\n @param part Partition manager\n @param total_transitions Out: total phase transitions\n @param total_creations Out: total phases created\n @param active_phase_id Out: currently-active phase ID"]
pub fn vtx_phase_partition_stats(
part: *const vtx_phase_partition_t,
total_transitions: *mut u64,
total_creations: *mut u64,
active_phase_id: *mut u32,
);
}
#[doc = " VORTEX SoN Graph — Construction from Bytecode\n\n The graph is the central data structure for the Sea-of-Nodes IR.\n It owns the node table and provides the entry point for building\n the graph from a bytecode method.\n\n Construction algorithm:\n 1. Create Start node + Parameter projections (one per method parameter).\n 2. Walk bytecode in linear order, identifying basic block boundaries.\n 3. Each basic block entry becomes a Region node (or LoopBegin for loop headers).\n 4. Within each block, emit data nodes for arithmetic, memory nodes for\n loads/stores (threaded as a chain), and control nodes for branches.\n 5. At Region merge points, insert Phi nodes for variables that differ\n across predecessors.\n 6. Loop back-edges connect to LoopBegin nodes; LoopEnd marks the latch.\n 7. Memory state is threaded: each memory-consuming node takes the previous\n memory node as input and produces a new memory state."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_block_info_t {
pub start_pc: usize,
pub end_pc: usize,
pub is_loop_header: bool,
pub is_loop_end: bool,
pub is_catch_handler: bool,
pub is_unreachable: bool,
pub region_node: vtx_nodeid_t,
pub control_node: vtx_nodeid_t,
pub memory_node: vtx_nodeid_t,
pub exception_target: vtx_nodeid_t,
pub locals: *mut vtx_nodeid_t,
pub pred_indices: *mut u32,
pub pred_count: u32,
pub pred_capacity: u32,
pub succ_indices: *mut u32,
pub succ_count: u32,
pub succ_capacity: u32,
pub exit_stack: *mut vtx_nodeid_t,
pub exit_sp: i32,
}
impl Default for vtx_block_info_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_graph_t {
pub node_table: vtx_node_table_t,
pub start_node: vtx_nodeid_t,
pub entry_control: vtx_nodeid_t,
pub entry_memory: vtx_nodeid_t,
pub parameter_count: u32,
pub parameters: *mut vtx_nodeid_t,
pub blocks: *mut vtx_block_info_t,
pub block_count: u32,
pub block_capacity: u32,
}
impl Default for vtx_graph_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize an empty graph. Creates the node table and Start node.\n Returns 0 on success, -1 on failure."]
pub fn vtx_graph_init(graph: *mut vtx_graph_t, max_params: u32) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the graph and free all memory."]
pub fn vtx_graph_destroy(graph: *mut vtx_graph_t);
}
extern "C" {
#[doc = " Build the SoN graph from bytecode.\n\n This is the main entry point: walks the bytecode, identifies basic blocks,\n constructs the Sea-of-Nodes IR with proper control flow, memory chains,\n and Phi nodes at merge points.\n\n The graph must be initialized before calling this function.\n The arena is used for temporary construction data (block info, locals).\n\n Returns 0 on success, -1 on failure."]
pub fn vtx_graph_build(
graph: *mut vtx_graph_t,
bytecode: *const vtx_bytecode_t,
method: *const vtx_method_desc_t,
arena: *mut vtx_arena_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Look up a node in the graph by ID. Convenience wrapper."]
pub fn vtx_graph_node(graph: *mut vtx_graph_t, id: vtx_nodeid_t) -> *mut vtx_node_t;
}
extern "C" {
#[doc = " Get the total number of nodes in the graph."]
pub fn vtx_graph_node_count(graph: *const vtx_graph_t) -> u32;
}
extern "C" {
#[doc = " Print the graph to stderr for debugging."]
pub fn vtx_graph_print(graph: *const vtx_graph_t);
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_inline_features_t {
pub features: [f64; 15usize],
}
#[doc = " Context needed for feature extraction beyond the graph and profile.\n The caller provides this to avoid the feature extractor needing\n knowledge of the entire compilation infrastructure."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_inline_context_t {
pub caller_bytecode_size: u32,
pub call_depth: u32,
pub inline_history: u32,
pub callee_bytecode_size: u32,
pub callee_method_id: u32,
pub callee_deopt_count: u64,
pub callee_invocation_count: u64,
pub caller_node_count: u32,
pub callee_graph: *const vtx_graph_t,
}
impl Default for vtx_inline_context_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Extract features for a call site.\n\n @param graph The caller's SoN graph\n @param call_node The call node (CallStatic/CallVirtual/CallInterface) NodeID\n @param profile Global profile data (may be NULL if no profiling available)\n @param context Additional context for extraction\n @return Populated feature vector"]
pub fn vtx_features_extract(
graph: *const vtx_graph_t,
call_node: vtx_nodeid_t,
profile: *const vtx_profile_global_t,
context: *const vtx_inline_context_t,
) -> vtx_inline_features_t;
}
extern "C" {
#[doc = " Get the human-readable name of a feature by index.\n Returns \"unknown\" if the index is out of range."]
pub fn vtx_feature_name(index: u32) -> *const ::std::os::raw::c_char;
}
extern "C" {
#[doc = " Normalize a feature vector to [0, 1] range using known bounds.\n Each feature has a principled maximum derived from system limits:\n - sizes capped at VTX_INLINE_SIZE_LIMIT\n - frequencies capped at UINT64_MAX (saturating)\n - ratios already in [0, 1]\n - depths capped at VTX_MAX_TREE_DEPTH"]
pub fn vtx_features_normalize(features: *mut vtx_inline_features_t);
}
extern "C" {
#[doc = " Write a feature vector as a CSV line (without trailing newline).\n Format: f0,f1,...,f14\n Writes at most buf_size bytes including null terminator.\n Returns the number of characters written (excluding null), or -1 on error."]
pub fn vtx_features_to_csv(
features: *const vtx_inline_features_t,
buf: *mut ::std::os::raw::c_char,
buf_size: usize,
) -> ::std::os::raw::c_int;
}
pub const vtx_inline_outcome_t_VTX_OUTCOME_UNKNOWN: vtx_inline_outcome_t = 0;
pub const vtx_inline_outcome_t_VTX_OUTCOME_PROFITABLE: vtx_inline_outcome_t = 1;
pub const vtx_inline_outcome_t_VTX_OUTCOME_UNPROFITABLE: vtx_inline_outcome_t = 2;
#[doc = " VORTEX ML Inliner — Online Feedback\n\n Tracks inlining decision outcomes to enable:\n 1. Runtime detection of unprofitable inlines (deopt at inlined guard)\n 2. Confirmation of profitable inlines (stable execution for window)\n 3. CSV export of feature→label data for offline model retraining\n 4. Recompilation triggers when inlining decisions prove suboptimal\n\n Each inlining decision is recorded with:\n - call_site_id: unique identifier for the call site\n - features: the feature vector that was used for the decision\n - inlined: whether the decision was to inline\n - outcome: not yet determined at decision time\n\n Outcomes are recorded later:\n - If a deoptimization occurs at an inlined call site's guard,\n the inlining is marked as potentially unprofitable.\n - If the compiled code runs stably for VTX_FEEDBACK_WINDOW executions\n without deopt at that site, the inlining is marked as profitable.\n\n Thread safety: this module is NOT thread-safe. The caller must\n synchronize access if used from multiple threads."]
pub type vtx_inline_outcome_t = ::std::os::raw::c_uint;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_inline_decision_t {
pub call_site_id: u64,
pub method_id: u32,
pub features: vtx_inline_features_t,
pub inlined: bool,
pub outcome: vtx_inline_outcome_t,
pub execution_count: u64,
pub deopt_count: u64,
pub decision_timestamp: u64,
}
impl Default for vtx_inline_decision_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_inline_feedback_t {
pub decisions: *mut vtx_inline_decision_t,
pub decision_count: u32,
pub decision_capacity: u32,
pub profitable_count: u32,
pub unprofitable_count: u32,
pub unknown_count: u32,
}
impl Default for vtx_inline_feedback_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize a feedback tracker.\n Returns 0 on success, -1 on failure."]
pub fn vtx_feedback_init(feedback: *mut vtx_inline_feedback_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy a feedback tracker and free all memory."]
pub fn vtx_feedback_destroy(feedback: *mut vtx_inline_feedback_t);
}
extern "C" {
#[doc = " Record an inlining decision.\n\n @param feedback Feedback tracker\n @param call_site_id Unique identifier for the call site\n @param features Feature vector used for the decision\n @param inlined Whether the decision was to inline\n @return 0 on success, -1 on failure"]
pub fn vtx_feedback_record_decision(
feedback: *mut vtx_inline_feedback_t,
call_site_id: u64,
method_id: u32,
features: *const vtx_inline_features_t,
inlined: bool,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Record an outcome for a previously recorded decision.\n\n If the decision has already been marked with an outcome, this\n updates the outcome only if the new outcome is worse\n (PROFITABLE → UNPROFITABLE is allowed; UNPROFITABLE → PROFITABLE is not).\n\n @param feedback Feedback tracker\n @param call_site_id Call site identifier\n @param profitable true if the inlining was profitable, false if not\n @return 0 on success, -1 if call_site_id not found"]
pub fn vtx_feedback_record_outcome(
feedback: *mut vtx_inline_feedback_t,
call_site_id: u64,
profitable: bool,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Increment the execution count for a call site.\n Called each time the compiled code containing this inlined call site executes.\n\n If the execution count reaches VTX_FEEDBACK_WINDOW and the outcome\n is still UNKNOWN, automatically mark it as PROFITABLE.\n\n @param feedback Feedback tracker\n @param call_site_id Call site identifier"]
pub fn vtx_feedback_increment_executions(
feedback: *mut vtx_inline_feedback_t,
call_site_id: u64,
);
}
extern "C" {
#[doc = " Increment the deopt count for a call site.\n Called when a deoptimization occurs at an inlined call site's guard.\n\n If the deopt rate exceeds VTX_INLINE_DEOPT_THRESHOLD, automatically\n mark the outcome as UNPROFITABLE.\n\n @param feedback Feedback tracker\n @param call_site_id Call site identifier"]
pub fn vtx_feedback_increment_deopts(feedback: *mut vtx_inline_feedback_t, call_site_id: u64);
}
extern "C" {
#[doc = " Check whether a call site should be recompiled with a different\n inlining strategy.\n\n A site should be recompiled if:\n - It was inlined and the outcome is UNPROFITABLE\n - It was NOT inlined but the call site is now hot and the\n features suggest inlining would be profitable (heuristic check)\n\n @param feedback Feedback tracker\n @param call_site_id Call site identifier\n @return true if recompilation is recommended"]
pub fn vtx_feedback_should_recompile(
feedback: *mut vtx_inline_feedback_t,
call_site_id: u64,
) -> bool;
}
extern "C" {
#[doc = " Look up the decision for a call site.\n Returns NULL if no decision has been recorded for this call site."]
pub fn vtx_feedback_lookup(
feedback: *const vtx_inline_feedback_t,
call_site_id: u64,
) -> *const vtx_inline_decision_t;
}
extern "C" {
#[doc = " Write all recorded decisions with known outcomes to a CSV file.\n\n Format: one line per decision\n f0,f1,...,f14,label\n where label is 1 for PROFITABLE, 0 for UNPROFITABLE.\n Decisions with UNKNOWN outcome are excluded.\n\n @param feedback Feedback tracker\n @param filename Path to the output CSV file\n @return Number of records written, or -1 on error"]
pub fn vtx_feedback_write_csv(
feedback: *const vtx_inline_feedback_t,
filename: *const ::std::os::raw::c_char,
) -> ::std::os::raw::c_int;
}
#[doc = " A guard identifier: the NodeID of the DeoptGuard node in the SoN graph."]
pub type vtx_guard_id_t = vtx_nodeid_t;
#[doc = " A deoptless continuation version: compiled code with a specific guard removed."]
pub type vtx_deoptless_version_t = vtx_deoptless_version;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_deoptless_version {
pub method_id: u32,
pub failed_guard_id: vtx_guard_id_t,
pub continuation_code: *mut ::std::os::raw::c_void,
pub continuation_size: u32,
pub next_version: *mut vtx_deoptless_version_t,
pub version_number: u32,
pub guard_branch_offset: u32,
pub code_start: *mut u8,
pub graph: *mut vtx_graph_t,
pub parent_version: *mut vtx_deoptless_version_t,
pub original_jcc_disp: i32,
pub is_patched: bool,
}
impl Default for vtx_deoptless_version {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Per-method version table: tracks all continuation versions for a method."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_deoptless_table_struct {
pub method_id: u32,
pub versions: *mut vtx_deoptless_version_t,
pub version_count: u32,
pub original_code: *mut ::std::os::raw::c_void,
pub original_graph: *mut vtx_graph_t,
pub failed_guards: *mut vtx_guard_id_t,
pub failed_guard_count: u32,
pub failed_guard_capacity: u32,
pub decision_vector_hash: u64,
pub compiled_profile_hash: u64,
}
impl Default for vtx_deoptless_table_struct {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Per-method version table: tracks all continuation versions for a method."]
pub type vtx_deoptless_table_t = vtx_deoptless_table_struct;
extern "C" {
#[doc = " Create a continuation version of the graph with the specified guard removed.\n\n Steps:\n 1. Clone the original graph (or start from the last version's graph).\n 2. Find the DeoptGuard node identified by failed_guard_id.\n 3. Replace the guard with an unconditional branch (removing the speculation).\n 4. Invalidate all optimizations that depended on this guard:\n - CheckCast nodes that were guarded by this guard become unconditional\n - Inlined methods that were guarded by this guard are un-inlined\n - Constant-folded values that depended on this guard are un-folded\n 5. Re-run GVN and DCE on the modified graph.\n 6. Return the new graph.\n\n @param graph The original SoN graph (NOT modified)\n @param failed_guard_id The NodeID of the DeoptGuard that failed\n @param arena Arena for allocations during graph manipulation\n @return A new graph with the guard removed, or NULL on failure"]
pub fn vtx_deoptless_create_continuation(
graph: *mut vtx_graph_t,
failed_guard_id: vtx_guard_id_t,
arena: *mut vtx_arena_t,
) -> *mut vtx_graph_t;
}
extern "C" {
#[doc = " Install a deoptless continuation version. This compiles the continuation\n graph into native code and patches the guard's failure path to jump\n directly to the continuation code instead of the deopt stub.\n\n @param version The continuation version to install (must have continuation_code set)\n @return true on success, false on failure"]
pub fn vtx_deoptless_install(version: *mut vtx_deoptless_version_t) -> bool;
}
extern "C" {
#[doc = " Initialize a deoptless version table for a method."]
pub fn vtx_deoptless_table_init(
table: *mut vtx_deoptless_table_t,
method_id: u32,
original_code: *mut ::std::os::raw::c_void,
original_graph: *mut vtx_graph_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy a deoptless version table and free all versions."]
pub fn vtx_deoptless_table_destroy(table: *mut vtx_deoptless_table_t);
}
extern "C" {
#[doc = " Look up a continuation version by the failed guard ID.\n Returns the version, or NULL if not found."]
pub fn vtx_deoptless_find_version(
table: *const vtx_deoptless_table_t,
failed_guard_id: vtx_guard_id_t,
) -> *mut vtx_deoptless_version_t;
}
extern "C" {
#[doc = " Add a continuation version to the table.\n If the table is at capacity (VTX_DEOPTLESS_MAX_VERSIONS),\n the oldest version is evicted.\n Returns the added version, or NULL on failure."]
pub fn vtx_deoptless_add_version(
table: *mut vtx_deoptless_table_t,
failed_guard_id: vtx_guard_id_t,
continuation_code: *mut ::std::os::raw::c_void,
continuation_size: u32,
) -> *mut vtx_deoptless_version_t;
}
extern "C" {
#[doc = " Check if deoptless deoptimization is possible for a guard.\n Returns false if the version table is full and the guard has no version yet."]
pub fn vtx_deoptless_can_deoptless(
table: *const vtx_deoptless_table_t,
failed_guard_id: vtx_guard_id_t,
) -> bool;
}
extern "C" {
#[doc = " Evict the oldest continuation version from the table.\n Called when the table is full and a new version is needed."]
pub fn vtx_deoptless_evict_oldest(table: *mut vtx_deoptless_table_t);
}
extern "C" {
#[doc = " Create an incremental continuation: remove a single guard from the\n latest version's graph (or the original graph if no versions exist).\n\n This is the key improvement: instead of generating each continuation\n from the original graph (which creates combinatorial explosion), we\n chain them: V2 is generated from V1's graph with one more guard removed.\n\n @param table The deoptless version table\n @param failed_guard_id The guard that just failed\n @param arena Arena for graph allocations\n @return New graph with the guard removed, or NULL on failure"]
pub fn vtx_deoptless_create_incremental_continuation(
table: *mut vtx_deoptless_table_t,
failed_guard_id: vtx_guard_id_t,
arena: *mut vtx_arena_t,
) -> *mut vtx_graph_t;
}
extern "C" {
#[doc = " Find the latest version in the chain that can be used as a base\n for the next incremental continuation.\n\n @param table The deoptless version table\n @return The latest version with a graph, or NULL"]
pub fn vtx_deoptless_find_latest_version(
table: *const vtx_deoptless_table_t,
) -> *mut vtx_deoptless_version_t;
}
extern "C" {
#[doc = " Check if a guard has already been removed in any active continuation.\n\n @param table The deoptless version table\n @param guard_id The guard to check\n @return true if this guard has already been removed"]
pub fn vtx_deoptless_is_guard_removed(
table: *const vtx_deoptless_table_t,
guard_id: vtx_guard_id_t,
) -> bool;
}
extern "C" {
#[doc = " Record a failed guard ID in the table's tracking array.\n\n @param table The deoptless version table\n @param guard_id The guard that failed\n @return 0 on success, -1 on failure"]
pub fn vtx_deoptless_record_failed_guard(
table: *mut vtx_deoptless_table_t,
guard_id: vtx_guard_id_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Compute a decision vector hash from the current graph's guard assumptions.\n The hash encodes all speculation decisions as a compact fingerprint.\n Two graphs with the same decision vector hash make the same speculative\n assumptions, so recompilation would produce identical code.\n\n @param graph The SoN graph\n @return 64-bit hash of the speculation decisions"]
pub fn vtx_deoptless_compute_decision_hash(graph: *const vtx_graph_t) -> u64;
}
extern "C" {
#[doc = " Check if recompilation is needed by comparing the current profile\n hash against the compiled profile hash.\n\n @param table Deoptless version table\n @param current_hash Hash of the current profile state\n @return true if recompilation is needed (hashes differ)"]
pub fn vtx_deoptless_needs_recompilation(
table: *const vtx_deoptless_table_t,
current_hash: u64,
) -> bool;
}
extern "C" {
#[doc = " Compute a 64-bit hash of the current profile state for a method.\n Used to detect profile changes that might affect speculation decisions.\n\n @param type_feedback Type feedback data\n @param method_id Method ID\n @return 64-bit hash"]
pub fn vtx_profile_compute_hash(
type_feedback: *const vtx_type_feedback_t,
method_id: u32,
) -> u64;
}
#[doc = " A snapshot of the currently executing methods, used to match\n against known phases."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_phase_signature_t {
pub method_ids: [u32; 10usize],
pub count: u32,
pub insert_pos: u32,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_sota_phase_t {
pub phase_graph: *mut vtx_phase_graph_t,
pub current_sig: vtx_phase_signature_t,
pub predicted_phase: u32,
pub precompiled_methods: *mut u32,
pub precompiled_count: u32,
pub precompiled_capacity: u32,
pub predictions_made: u32,
pub predictions_correct: u32,
pub predictions_wrong: u32,
pub hits_in_current_prediction: u32,
}
impl Default for vtx_sota_phase_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the phase prediction system.\n If phase_graph is non-NULL, it is used for predictions (takes ownership).\n If NULL, predictions are disabled until a graph is loaded.\n\n @param phase Phase prediction state to initialize\n @param phase_graph Phase graph from previous run (may be NULL)\n @param arena Arena for allocations\n @return 0 on success, -1 on failure"]
pub fn vtx_sota_phase_init(
phase: *mut vtx_sota_phase_t,
phase_graph: *mut vtx_phase_graph_t,
arena: *mut vtx_arena_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the phase prediction system.\n Does NOT destroy the phase_graph (caller owns it)."]
pub fn vtx_sota_phase_destroy(phase: *mut vtx_sota_phase_t);
}
extern "C" {
#[doc = " Record a method entry for phase monitoring.\n Updates the current signature with the new method ID.\n\n @param phase Phase prediction state\n @param method_id Method that was just entered"]
pub fn vtx_sota_phase_record_method(phase: *mut vtx_sota_phase_t, method_id: u32);
}
extern "C" {
#[doc = " Update the phase graph with a newly entered method.\n\n When a method is entered at the top level, this function:\n 1. Adds the method to the sliding window signature\n 2. Checks if the current method's phase matches the predicted phase\n 3. If a phase transition is detected, triggers prediction evaluation\n 4. If the method was pre-compiled by a phase prediction, records a hit\n\n This is the primary entry point called from the interpreter/JIT at each\n method entry to keep the phase monitor up-to-date.\n\n @param phase Phase prediction state\n @param entered_method Method that was just entered"]
pub fn vtx_sota_phase_update(phase: *mut vtx_sota_phase_t, entered_method: u32);
}
extern "C" {
#[doc = " Predict which methods should be pre-compiled based on the\n current method call pattern.\n\n Compares the current signature against all known phases\n using Jaccard similarity. Returns the method IDs that\n should be queued for compilation.\n\n @param phase Phase prediction state\n @param[out] methods Array of method IDs to pre-compile (arena-allocated)\n @param[out] count Number of methods in the array\n @return 0 on success, -1 on failure"]
pub fn vtx_sota_phase_predict(
phase: *mut vtx_sota_phase_t,
arena: *mut vtx_arena_t,
methods: *mut *mut u32,
count: *mut u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Predict which methods should be pre-compiled based on an explicit\n set of current top-level method call patterns.\n\n This variant accepts an explicit array of current method IDs\n rather than using the internal sliding window. Useful when\n the caller has already computed the hot method set.\n\n Computes Jaccard similarity between the provided method set\n and each known phase's method set. Returns the method IDs\n from the best-matching phase that should be queued for\n T2/T3 compilation.\n\n @param phase Phase prediction state\n @param current_methods Array of current top-level method IDs\n @param method_count Number of methods in the array\n @param arena Arena for output allocation\n @param[out] out_methods Array of method IDs to pre-compile (arena-allocated)\n @param[out] out_count Number of methods in the output array\n @return 0 on success, -1 on failure"]
pub fn vtx_sota_phase_predict_with_methods(
phase: *mut vtx_sota_phase_t,
current_methods: *const u32,
method_count: u32,
arena: *mut vtx_arena_t,
out_methods: *mut *mut u32,
out_count: *mut u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Compute Jaccard similarity between two sets of method IDs.\n\n Jaccard(A, B) = |A ∩ B| / |A ∪ B|\n\n Returns a value in [0, 1]. 1.0 means identical sets."]
pub fn vtx_sota_phase_jaccard(
set_a: *const u32,
count_a: u32,
set_b: *const u32,
count_b: u32,
) -> f64;
}
extern "C" {
#[doc = " Compute Jaccard similarity between the current signature\n and a phase's method set."]
pub fn vtx_sota_phase_match_score(
phase: *const vtx_sota_phase_t,
phase_def: *const vtx_phase_t,
) -> f64;
}
extern "C" {
#[doc = " Record that a pre-compiled method was actually called (prediction correct).\n\n @param phase Phase prediction state\n @param method_id Method that was called"]
pub fn vtx_sota_phase_record_hit(phase: *mut vtx_sota_phase_t, method_id: u32);
}
extern "C" {
#[doc = " Record that the current phase prediction has ended\n (e.g., the program has moved to a different phase).\n Updates prediction accuracy statistics.\n\n @param phase Phase prediction state"]
pub fn vtx_sota_phase_end_prediction(phase: *mut vtx_sota_phase_t);
}
pub const vtx_version_state_t_VTX_VERSION_COMPILING: vtx_version_state_t = 0;
pub const vtx_version_state_t_VTX_VERSION_ACTIVE: vtx_version_state_t = 1;
pub const vtx_version_state_t_VTX_VERSION_DEPRECATED: vtx_version_state_t = 2;
pub const vtx_version_state_t_VTX_VERSION_INVALIDATED: vtx_version_state_t = 3;
pub const vtx_version_state_t_VTX_VERSION_FREED: vtx_version_state_t = 4;
pub const vtx_version_state_t_VTX_VERSION_PARKED: vtx_version_state_t = 5;
#[doc = " VORTEX Code Version Management\n\n Manages multiple compiled versions of a single method. This is essential\n for concurrent compilation and tiered optimization:\n\n - While T2 compiles in the background, T1 code continues to run\n - When T2 finishes, T1 is deprecated (not removed — running threads\n may still be executing it)\n - T1 is freed only after all threads have exited the old version\n - Deoptless continuations create alternative versions with failed\n speculations removed\n - Class loads may invalidate specific versions\n\n Version lifecycle:\n\n Compiling → Active → Deprecated → Freed\n ↓\n Invalidated\n\n Transitions:\n Compiling → Active: compilation finished, code installed\n Active → Deprecated: a newer version is installed\n Deprecated → Freed: no threads are executing this version\n Active → Invalidated: a dependency was broken (class load, etc.)\n Compiling → Invalidated: compilation was cancelled\n\n Thread safety:\n - Version state transitions are protected by a per-method mutex\n - Reference counting tracks how many threads are executing each version\n - A version is freed only when refcount drops to zero after deprecation"]
pub type vtx_version_state_t = ::std::os::raw::c_uint;
extern "C" {
pub fn vtx_version_state_name(s: vtx_version_state_t) -> *const ::std::os::raw::c_char;
}
#[doc = " A single compiled version of a method. Multiple versions can exist\n simultaneously (e.g., T1 active while T2 compiles, or deoptless\n continuation alongside the main version)."]
pub type vtx_code_version_t = vtx_code_version;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_code_version {
pub method_id: u32,
pub version_id: u32,
pub tier: vtx_compile_tier_t,
pub state: vtx_version_state_t,
pub compiled: *mut vtx_compiled_method_t,
pub refcount: i32,
pub compile_start_ns: u64,
pub compile_end_ns: u64,
pub activate_ns: u64,
pub deprecate_ns: u64,
pub next_version: *mut vtx_code_version_t,
pub prev_version: *mut vtx_code_version_t,
pub is_deoptless: bool,
pub deoptless_guard_id: u32,
}
impl Default for vtx_code_version {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Per-method version chain: linked list of versions from oldest to newest."]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct vtx_method_versions_t {
pub method_id: u32,
pub newest: *mut vtx_code_version_t,
pub oldest: *mut vtx_code_version_t,
pub version_count: u32,
pub method_mutex: pthread_mutex_t,
}
impl Default for vtx_method_versions_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct vtx_version_manager_t {
pub methods: *mut *mut vtx_method_versions_t,
pub method_count: u32,
pub capacity: u32,
pub global_mutex: pthread_mutex_t,
pub total_versions_created: u32,
pub total_versions_deprecated: u32,
pub total_versions_invalidated: u32,
pub total_versions_freed: u32,
pub arena: *mut vtx_arena_t,
}
impl Default for vtx_version_manager_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the version manager.\n\n @param manager Version manager to initialize\n @param arena Arena for allocating version structures\n @return 0 on success, -1 on failure"]
pub fn vtx_version_manager_init(
manager: *mut vtx_version_manager_t,
arena: *mut vtx_arena_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the version manager and free all resources."]
pub fn vtx_version_manager_destroy(manager: *mut vtx_version_manager_t);
}
extern "C" {
#[doc = " Create a new code version for a method (in Compiling state).\n\n @param manager Version manager\n @param method_id Method ID\n @param tier Compilation tier\n @return New code version, or NULL on failure"]
pub fn vtx_version_create_compiling(
manager: *mut vtx_version_manager_t,
method_id: u32,
tier: vtx_compile_tier_t,
) -> *mut vtx_code_version_t;
}
extern "C" {
#[doc = " Install a compiled version: transition from Compiling → Active.\n\n @param manager Version manager\n @param method_id Method ID\n @param version The version to install\n @param compiled The compiled method metadata\n @return 0 on success, -1 on failure"]
pub fn vtx_version_install(
manager: *mut vtx_version_manager_t,
method_id: u32,
version: *mut vtx_code_version_t,
compiled: *mut vtx_compiled_method_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Deprecate a version: transition from Active → Deprecated.\n This happens when a newer version is installed.\n\n The deprecated version is not freed immediately — it remains in\n memory until all threads have exited it (refcount drops to zero).\n\n @param manager Version manager\n @param version The version to deprecate\n @return 0 on success, -1 on failure"]
pub fn vtx_version_deprecate(
manager: *mut vtx_version_manager_t,
version: *mut vtx_code_version_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Invalidate all versions of a method.\n This happens when a class load breaks a dependency.\n\n All active and compiling versions are transitioned to Invalidated.\n Deprecated versions are also invalidated if they haven't been freed yet.\n\n @param manager Version manager\n @param method_id Method ID to invalidate\n @return Number of versions invalidated"]
pub fn vtx_version_invalidate(manager: *mut vtx_version_manager_t, method_id: u32) -> u32;
}
extern "C" {
#[doc = " Free a deprecated version whose refcount has dropped to zero.\n Transition: Deprecated → Freed.\n\n @param manager Version manager\n @param version The version to free\n @return 0 on success, -1 on failure"]
pub fn vtx_version_free(
manager: *mut vtx_version_manager_t,
version: *mut vtx_code_version_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Increment the reference count of a version (a thread is entering it)."]
pub fn vtx_version_enter(version: *mut vtx_code_version_t);
}
extern "C" {
#[doc = " Decrement the reference count of a version (a thread is leaving it).\n If the count drops to zero and the version is deprecated, it is freed.\n\n @param manager Version manager\n @param version The version being exited\n @return true if the version was freed, false otherwise"]
pub fn vtx_version_exit(
manager: *mut vtx_version_manager_t,
version: *mut vtx_code_version_t,
) -> bool;
}
extern "C" {
#[doc = " Get the active version for a method.\n Returns NULL if no active version exists."]
pub fn vtx_version_get_active(
manager: *mut vtx_version_manager_t,
method_id: u32,
) -> *mut vtx_code_version_t;
}
extern "C" {
#[doc = " Get the newest version for a method (regardless of state).\n Returns NULL if no versions exist."]
pub fn vtx_version_get_newest(
manager: *mut vtx_version_manager_t,
method_id: u32,
) -> *mut vtx_code_version_t;
}
extern "C" {
#[doc = " Get the number of versions for a method."]
pub fn vtx_version_count(manager: *mut vtx_version_manager_t, method_id: u32) -> u32;
}
extern "C" {
#[doc = " Check if a specific version is still valid for execution."]
pub fn vtx_version_is_executable(version: *const vtx_code_version_t) -> bool;
}
extern "C" {
#[doc = " Find the highest active version for a method at or below the given tier.\n Used for direct T3→T2 deoptimization: when a T3 guard fails and deoptless\n is unavailable, find a T2 version to jump to instead of the interpreter.\n\n @param manager Version manager\n @param method_id Method ID\n @param max_tier Maximum tier to consider (e.g., VTX_TIER_OPTIMIZING for T2)\n @return Active version at or below max_tier, or NULL if none found"]
pub fn vtx_version_find_tier(
manager: *mut vtx_version_manager_t,
method_id: u32,
max_tier: vtx_compile_tier_t,
) -> *mut vtx_code_version_t;
}
#[doc = " VORTEX SOTA — Continuous Background Recompilation\n\n Monitors profile data in real-time and triggers recompilation when\n type profiles diverge from the assumptions used during the previous\n compilation.\n\n The key metric is KL divergence (Kullback-Leibler) between the\n type profile at compilation time and the current type profile.\n When KL divergence exceeds VTX_PROFILE_DIVERGENCE_THRESHOLD (0.5),\n the method is queued for recompilation with updated profile data.\n\n The new version is compiled in the background and installed at the\n next safe point, with zero pause to the executing application.\n\n KL divergence measures how much information is lost when using the\n old profile to approximate the current profile. A value of 0 means\n identical distributions; values > 0.5 indicate significant divergence.\n\n Formula:\n KL(P || Q) = Σ P(i) * ln(P(i) / Q(i))\n where P = current profile, Q = compilation-time profile\n\n Smoothing: to avoid ln(0), we add a small epsilon (1e-6) to both\n P(i) and Q(i) before computing the ratio."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_recomp_check_t {
pub should_recompile: bool,
pub kl_divergence: f64,
pub divergent_call_sites: u32,
pub method_id: u32,
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_recomp_queue_entry_t {
pub method_id: u32,
pub kl_divergence: f64,
pub enqueue_time_ns: u64,
pub processed: bool,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_recomp_snapshot {
_unused: [u8; 0],
}
pub type vtx_recomp_snapshot_t = vtx_recomp_snapshot;
#[doc = " Per-method hysteresis state for KL-divergence recompilation.\n\n Without hysteresis, the orchestrator fires recomp on every divergent\n sample. A workload that oscillates between two phases causes the same\n method to be recompiled repeatedly — thrashing.\n\n Hysteresis requires VTX_RECOMP_HYSTERESIS_CONSECUTIVE consecutive\n divergent samples before triggering recompilation. A non-divergent\n sample resets the counter to zero.\n\n The state is keyed by method_id and stored in a small hash table\n inside vtx_sota_recomp_t. Lookups are O(1) amortized."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_recomp_hysteresis_t {
pub method_id: u32,
pub consecutive_divergent: u32,
pub last_recomp_time_ns: u64,
pub recomp_count_in_window: u64,
pub window_start_ns: u64,
pub valid: bool,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_sota_recomp_t {
pub snapshots: *mut vtx_recomp_snapshot_t,
pub snapshot_count: u32,
pub snapshot_capacity: u32,
pub recomp_queue: *mut vtx_recomp_queue_entry_t,
pub recomp_queue_count: u32,
pub recomp_queue_capacity: u32,
pub hysteresis: *mut vtx_recomp_hysteresis_t,
pub hysteresis_count: u32,
pub hysteresis_capacity: u32,
pub total_dropped_soft_cap: u64,
pub total_dropped_hard_cap: u64,
pub total_coalesced: u64,
pub total_checks: u64,
pub total_recompilations_triggered: u64,
pub total_false_positives: u64,
pub total_hysteresis_blocks: u64,
}
impl Default for vtx_sota_recomp_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the recompilation monitor.\n Returns 0 on success, -1 on failure."]
pub fn vtx_sota_recomp_init(recomp: *mut vtx_sota_recomp_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the recompilation monitor and free memory."]
pub fn vtx_sota_recomp_destroy(recomp: *mut vtx_sota_recomp_t);
}
extern "C" {
#[doc = " Save a profile snapshot for a method at compilation time.\n This snapshot is used later for KL divergence comparison.\n\n @param recomp Recompilation monitor\n @param method_id Method that was compiled\n @param profile Global profile data at compilation time\n @return 0 on success, -1 on failure"]
pub fn vtx_sota_recomp_save_snapshot(
recomp: *mut vtx_sota_recomp_t,
method_id: u32,
profile: *const vtx_profile_global_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Remove the snapshot for a method (e.g., when the method is invalidated)."]
pub fn vtx_sota_recomp_remove_snapshot(recomp: *mut vtx_sota_recomp_t, method_id: u32);
}
extern "C" {
#[doc = " Check if a compiled method should be recompiled based on\n profile divergence.\n\n Compares the current type profile at each call site with the\n snapshot taken at compilation time. If the KL divergence at\n any call site exceeds VTX_PROFILE_DIVERGENCE_THRESHOLD,\n recommends recompilation.\n\n @param recomp Recompilation monitor\n @param profile Current global profile data\n @param method_id Method to check\n @return Check result with should_recompile flag and details"]
pub fn vtx_sota_recomp_check(
recomp: *const vtx_sota_recomp_t,
profile: *const vtx_profile_global_t,
method_id: u32,
) -> vtx_recomp_check_t;
}
extern "C" {
#[doc = " Compute KL divergence between two type distributions.\n\n Each distribution is represented as an array of (type_id, frequency) pairs.\n The frequencies are normalized to probabilities internally.\n\n @param types_a Type IDs in distribution A (current)\n @param freqs_a Frequencies for distribution A\n @param count_a Number of entries in distribution A\n @param types_b Type IDs in distribution B (compilation-time)\n @param freqs_b Frequencies for distribution B\n @param count_b Number of entries in distribution B\n @return KL divergence value (>= 0)"]
pub fn vtx_kl_divergence(
types_a: *const vtx_typeid_t,
freqs_a: *const u64,
count_a: u32,
types_b: *const vtx_typeid_t,
freqs_b: *const u64,
count_b: u32,
) -> f64;
}
extern "C" {
#[doc = " Compute KL divergence between two call site profiles.\n Convenience wrapper that extracts type distributions."]
pub fn vtx_kl_divergence_callsite(
current: *const vtx_callsite_profile_t,
compiled: *const vtx_callsite_profile_t,
) -> f64;
}
extern "C" {
#[doc = " Compute KL divergence between two per-type frequency distributions.\n Uses the D5 per-type frequency data for accurate divergence measurement.\n New types not seen at compilation time receive a large penalty (10.0).\n\n @param current Current per-type frequency distribution\n @param compiled Per-type frequency distribution at compilation time\n @return KL divergence value (>= 0)"]
pub fn vtx_recomp_kl_divergence_freq(
current: *const vtx_type_freq_t,
compiled: *const vtx_type_freq_t,
) -> f64;
}
extern "C" {
#[doc = " Compute KL divergence between two method profiles.\n\n This compares the type distributions at each call site between\n the old (compilation-time) profile and the new (current) profile.\n Returns the maximum KL divergence across all call sites.\n\n A high divergence means the current execution pattern has shifted\n significantly from what was assumed at compilation time, and\n recompilation would likely produce better code.\n\n @param old_profile Method profile at compilation time\n @param new_profile Current method profile\n @return Maximum KL divergence across call sites (>= 0)"]
pub fn vtx_sota_recomp_compute_divergence(
old_profile: *const vtx_profile_method_t,
new_profile: *const vtx_profile_method_t,
) -> f64;
}
extern "C" {
#[doc = " Queue a method for recompilation with updated profile data.\n\n The method is added to the recompilation queue. A background\n compilation worker will pick it up, compile it with the\n current profile, and install the new version at the next\n safe point.\n\n If the method is already in the queue, this is a no-op\n (we don't queue duplicate compilations).\n\n @param recomp Recompilation monitor\n @param method_id Method to recompile\n @param new_profile Current profile data (snapshot is taken internally)"]
pub fn vtx_sota_recomp_queue(
recomp: *mut vtx_sota_recomp_t,
method_id: u32,
new_profile: *const vtx_profile_global_t,
);
}
extern "C" {
#[doc = " Dequeue the next method to recompile.\n\n Returns the method_id of the next unprocessed entry, or\n VTX_PHASE_NONE if the queue is empty.\n\n @param recomp Recompilation monitor\n @return Method ID to recompile, or VTX_PHASE_NONE"]
pub fn vtx_sota_recomp_dequeue(recomp: *mut vtx_sota_recomp_t) -> u32;
}
extern "C" {
#[doc = " Check if the recompilation queue has pending entries."]
pub fn vtx_sota_recomp_has_pending(recomp: *const vtx_sota_recomp_t) -> bool;
}
extern "C" {
#[doc = " Hysteresis-aware recompilation check.\n\n This is the same as vtx_sota_recomp_check(), but it tracks consecutive\n divergent samples per method and only returns should_recompile=true\n after VTX_RECOMP_HYSTERESIS_CONSECUTIVE consecutive divergent checks.\n A non-divergent check resets the per-method counter.\n\n Use this in the orchestrator instead of the raw check to prevent\n recomp thrashing under oscillating workloads.\n\n @param recomp Recompilation monitor\n @param profile Current global profile data\n @param method_id Method to check\n @return Check result; should_recompile is true only if the\n hysteresis threshold has been reached"]
pub fn vtx_sota_recomp_check_hysteresis(
recomp: *mut vtx_sota_recomp_t,
profile: *const vtx_profile_global_t,
method_id: u32,
) -> vtx_recomp_check_t;
}
extern "C" {
#[doc = " Reset the hysteresis counter for a method (e.g., after a successful\n recompilation, so the counter doesn't immediately fire again).\n\n @param recomp Recompilation monitor\n @param method_id Method whose counter to reset"]
pub fn vtx_sota_recomp_hysteresis_reset(recomp: *mut vtx_sota_recomp_t, method_id: u32);
}
extern "C" {
#[doc = " Get the current consecutive-divergent count for a method.\n Returns 0 if no state exists for the method."]
pub fn vtx_sota_recomp_hysteresis_count(
recomp: *const vtx_sota_recomp_t,
method_id: u32,
) -> u32;
}
extern "C" {
#[doc = " Backpressure-aware queue submission.\n\n Same as vtx_sota_recomp_queue(), but enforces backpressure:\n\n - HARD CAP: if the queue is at VTX_RECOMP_QUEUE_HARD_CAP, the entry\n is rejected (returns false). The orchestrator will re-check the\n method on the next tick.\n\n - SOFT CAP: if the queue is above VTX_RECOMP_QUEUE_SOFT_CAP, the\n lowest-priority unprocessed entry (lowest KL divergence) is\n evicted before the new entry is added. This keeps the queue\n drained under sustained divergence.\n\n - COALESCE: if the same method is already queued (unprocessed) AND\n was recompiled at least VTX_RECOMP_COALESCE_MAX_DUPLICATES times\n within VTX_RECOMP_COALESCE_WINDOW_SEC, the older entry is removed\n and replaced with the newer one (with updated KL divergence).\n\n @param recomp Recompilation monitor\n @param method_id Method to recompile\n @param new_profile Current profile data\n @param now_ns Current monotonic time in nanoseconds (used for\n coalesce windowing; pass 0 to disable coalescing)\n @return true if the entry was queued, false if rejected\n by the hard cap"]
pub fn vtx_sota_recomp_queue_backpressure(
recomp: *mut vtx_sota_recomp_t,
method_id: u32,
new_profile: *const vtx_profile_global_t,
now_ns: u64,
) -> bool;
}
extern "C" {
#[doc = " Get backpressure statistics.\n\n @param recomp Recompilation monitor\n @param dropped_soft_cap Out: entries dropped because queue > soft cap\n @param dropped_hard_cap Out: entries rejected because queue >= hard cap\n @param coalesced Out: older entries merged into newer\n @param hysteresis_blocks Out: would-have-fired but blocked by hysteresis"]
pub fn vtx_sota_recomp_backpressure_stats(
recomp: *const vtx_sota_recomp_t,
dropped_soft_cap: *mut u64,
dropped_hard_cap: *mut u64,
coalesced: *mut u64,
hysteresis_blocks: *mut u64,
);
}
#[doc = " VORTEX SOTA — Feedback-Directed Inlining Recompilation\n\n Tracks inlining decision outcomes and triggers targeted recompilation\n when inlining proves unprofitable. Maintains multiple compiled versions\n with different inlining strategies, switching based on performance.\n\n When an inlined call site causes repeated deoptimizations:\n 1. Record the call site as \"unprofitable inline\"\n 2. Queue a recompilation of the method with that call site\n forced to no-inline\n 3. Install the new version at the next safe point\n 4. The old version remains active for threads still executing it\n (version coexistence via the version manager)\n\n When an un-inlined call site would benefit from inlining:\n 1. Record the call site as \"missed inline opportunity\"\n 2. Queue recompilation with that call site forced to inline\n 3. Same version management as above\n\n The FDI system works closely with the inliner feedback module,\n adding the ability to trigger recompilations based on feedback."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_fdi_method_record_t {
pub method_id: u32,
pub has_unprofitable_inlines: bool,
pub has_missed_inlines: bool,
pub unprofitable_site_count: u32,
pub missed_site_count: u32,
pub no_inline_sites: *mut u64,
pub no_inline_count: u32,
pub no_inline_capacity: u32,
pub force_inline_sites: *mut u64,
pub force_inline_count: u32,
pub force_inline_capacity: u32,
pub current_version_id: u32,
pub recompilation_count: u32,
pub deopt_count_at_inlined_sites: u64,
pub total_executions: u64,
pub spill_rate: f64,
pub deopt_rate: f64,
pub spill_count: u64,
pub total_instructions: u64,
pub alternative_versions: *mut u32,
pub alternative_version_count: u32,
pub alternative_version_capacity: u32,
pub best_version_id: u32,
pub best_version_score: f64,
}
impl Default for vtx_fdi_method_record_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_sota_fdi_t {
pub records: *mut vtx_fdi_method_record_t,
pub record_count: u32,
pub record_capacity: u32,
pub feedback: *mut vtx_inline_feedback_t,
pub total_recompilations: u32,
pub total_methods_improved: u32,
pub total_methods_worse: u32,
}
impl Default for vtx_sota_fdi_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the FDI system.\n\n @param fdi FDI state to initialize\n @param feedback Inline feedback tracker (not owned, must outlive FDI)\n @return 0 on success, -1 on failure"]
pub fn vtx_sota_fdi_init(
fdi: *mut vtx_sota_fdi_t,
feedback: *mut vtx_inline_feedback_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the FDI system and free memory."]
pub fn vtx_sota_fdi_destroy(fdi: *mut vtx_sota_fdi_t);
}
extern "C" {
#[doc = " Evaluate whether a method should be recompiled with different\n inlining decisions based on feedback.\n\n Checks:\n 1. Are any inlined call sites in this method marked as unprofitable?\n 2. Are any non-inlined call sites in this method now good inline candidates?\n 3. Has the method's deopt rate exceeded VTX_INLINE_DEOPT_THRESHOLD?\n\n @param fdi FDI state\n @param method_id Method to evaluate\n @return true if recompilation is recommended"]
pub fn vtx_sota_fdi_evaluate(fdi: *mut vtx_sota_fdi_t, method_id: u32) -> bool;
}
extern "C" {
#[doc = " Get the recompilation directive for a method.\n Returns the set of call sites to force no-inline and force inline.\n\n @param fdi FDI state\n @param method_id Method to get directives for\n @param[out] no_inline Array of call site IDs to force no-inline (arena-allocated)\n @param[out] no_inline_count Number of no-inline sites\n @param[out] force_inline Array of call site IDs to force inline (arena-allocated)\n @param[out] force_inline_count Number of force-inline sites\n @return 0 on success, -1 on failure"]
pub fn vtx_sota_fdi_get_directives(
fdi: *mut vtx_sota_fdi_t,
method_id: u32,
arena: *mut vtx_arena_t,
no_inline: *mut *mut u64,
no_inline_count: *mut u32,
force_inline: *mut *mut u64,
force_inline_count: *mut u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Record that a deoptimization occurred at an inlined call site.\n This may trigger a recompilation recommendation.\n\n @param fdi FDI state\n @param method_id Method containing the inlined call site\n @param call_site_id Call site where deopt occurred"]
pub fn vtx_sota_fdi_record_deopt(fdi: *mut vtx_sota_fdi_t, method_id: u32, call_site_id: u64);
}
extern "C" {
#[doc = " Record that a method execution completed successfully.\n Used to compute deopt rates and detect when inlining is profitable.\n\n @param fdi FDI state\n @param method_id Method that executed"]
pub fn vtx_sota_fdi_record_execution(fdi: *mut vtx_sota_fdi_t, method_id: u32);
}
extern "C" {
#[doc = " Record that a recompilation was completed for a method.\n Updates the current version tracking.\n\n @param fdi FDI state\n @param method_id Method that was recompiled\n @param new_version New version ID"]
pub fn vtx_sota_fdi_record_recompilation(
fdi: *mut vtx_sota_fdi_t,
method_id: u32,
new_version: u32,
);
}
extern "C" {
#[doc = " Record performance metrics for a compiled method.\n\n Tracks spill rate and deopt rate to detect when inlining is\n unprofitable. When either rate exceeds its threshold:\n - spill_rate > VTX_SPILL_THRESHOLD (10%): inlining increased register\n pressure beyond available registers, causing excessive spills\n - deopt_rate > VTX_INLINE_DEOPT_THRESHOLD (5%): inlined guards are\n failing too often, making the inlined code path useless\n\n If either threshold is exceeded, the method is flagged for\n recompilation with different inlining decisions.\n\n This also feeds back to the ML model immediately: the feature\n vector and outcome are recorded for the next training cycle.\n\n @param fdi FDI state\n @param method_id Method to record performance for\n @param spill_rate Register spill rate (0.0 to 1.0)\n @param deopt_rate Deoptimization rate (0.0 to 1.0)"]
pub fn vtx_sota_fdi_record_performance(
fdi: *mut vtx_sota_fdi_t,
method_id: u32,
spill_rate: f64,
deopt_rate: f64,
);
}
extern "C" {
#[doc = " Get the best replacement version for a method.\n\n If a method has multiple compiled versions with different inlining\n decisions, this function returns the version that has the best\n performance so far. This enables dynamic switching between\n compiled versions at safe points.\n\n If no better version exists, returns the current version ID.\n\n @param fdi FDI state\n @param method_id Method to query\n @return Version ID of the best-performing version"]
pub fn vtx_sota_fdi_get_replacement_version(fdi: *mut vtx_sota_fdi_t, method_id: u32) -> u32;
}
extern "C" {
#[doc = " Register an alternative compiled version for a method.\n\n When a recompilation produces a new version with different inlining\n decisions, it is registered here. The FDI system tracks multiple\n versions and can switch between them based on performance.\n\n @param fdi FDI state\n @param method_id Method that has a new alternative version\n @param version_id New version ID"]
pub fn vtx_sota_fdi_register_version(fdi: *mut vtx_sota_fdi_t, method_id: u32, version_id: u32);
}
extern "C" {
#[doc = " Update the performance score of a specific version.\n\n The score is computed as:\n score = (1 - spill_rate) * (1 - deopt_rate) * execution_speedup\n Higher is better. This is used to determine which version to use.\n\n @param fdi FDI state\n @param method_id Method\n @param version_id Version to update\n @param score Performance score (higher is better)"]
pub fn vtx_sota_fdi_update_version_score(
fdi: *mut vtx_sota_fdi_t,
method_id: u32,
version_id: u32,
score: f64,
);
}
extern "C" {
#[doc = " Get the next method that FDI recommends for recompilation.\n\n Iterates over all tracked methods and returns the method_id of\n the next method that vtx_sota_fdi_evaluate() recommends for\n recompilation. Returns VTX_PHASE_NONE if no more candidates exist.\n\n Each call advances an internal cursor so that repeated calls\n enumerate all candidates without duplication.\n\n @param fdi FDI state\n @return Method ID of the next recompilation candidate,\n or VTX_PHASE_NONE if no more candidates"]
pub fn vtx_sota_fdi_next_recompile_candidate(fdi: *mut vtx_sota_fdi_t) -> u32;
}
#[doc = " A phase hash: identifies a specific execution phase.\n Computed from the call stack's type signature at the time\n of compilation. Same phase hash = same type behavior expected.\n\n The hash is computed using FNV-1a over the type feedback for a method,\n capturing the dominant type at each call site and the shape at each\n field access site. This is similar to vtx_profile_compute_hash() in\n deoptless.c but focuses on the current phase's type distribution rather\n than the full profile history."]
pub type vtx_phase_hash_t = u64;
#[doc = " Phase-version entry: maps a phase hash to a parked version.\n\n Each entry records the phase hash that the version was compiled for,\n a pointer to the parked code version, and metadata for LRU eviction\n (park time) and reactivation statistics.\n\n An entry becomes invalid when its parked version is freed due to\n memory pressure. The entry slot is then available for reuse."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_phase_version_entry_t {
pub phase_hash: vtx_phase_hash_t,
pub parked_version: *mut vtx_code_version_t,
pub method_id: u32,
pub park_time_ns: u64,
pub reactivate_count: u64,
pub is_valid: bool,
}
impl Default for vtx_phase_version_entry_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Per-method phase-version registry.\n Tracks parked versions for each execution phase of a single method.\n\n The entries array is a fixed-size open-addressing table with linear\n probing. Phase hash collisions are handled by chaining to the next\n free slot. The table is deliberately small (16 entries) because:\n 1. Most methods have 2-4 distinct phases\n 2. Parked versions consume memory, so we cap the total\n 3. Linear scan over 16 entries is faster than a hash table for\n these sizes"]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_phase_version_registry_t {
pub method_id: u32,
pub entries: [vtx_phase_version_entry_t; 16usize],
pub entry_count: u32,
pub current_phase_hash: vtx_phase_hash_t,
pub total_reactivations: u32,
pub total_recompilations: u32,
pub total_evictions: u32,
}
impl Default for vtx_phase_version_registry_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Global phase-reactive version manager.\n\n Manages per-method registries and enforces a global code budget for\n parked versions. When the budget is exceeded, the least recently parked\n versions are evicted first (LRU policy based on park_time_ns).\n\n Thread safety: all operations on the manager are protected by the\n manager_mutex. Individual version state transitions are additionally\n protected by the version manager's per-method mutex."]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct vtx_phase_react_manager_t {
pub registries: *mut vtx_phase_version_registry_t,
pub registry_count: u32,
pub registry_capacity: u32,
pub parked_code_budget: usize,
pub parked_code_used: usize,
pub manager_mutex: pthread_mutex_t,
pub total_parked_versions: u32,
pub total_reactivated_versions: u32,
pub total_evicted_versions: u32,
}
impl Default for vtx_phase_react_manager_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the phase-reactive version manager.\n\n @param mgr Manager to initialize\n @param code_budget Total bytes of code that may be parked before\n eviction kicks in. Use VTX_PHASE_REACT_DEFAULT_CODE_BUDGET\n for the default (8 MB).\n @return 0 on success, -1 on failure"]
pub fn vtx_phase_react_manager_init(
mgr: *mut vtx_phase_react_manager_t,
code_budget: usize,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the phase-reactive version manager and release all resources.\n Does NOT free the parked code versions themselves — those are owned\n by the version manager (compile/version.h). This only frees the\n registry structures.\n\n @param mgr Manager to destroy"]
pub fn vtx_phase_react_manager_destroy(mgr: *mut vtx_phase_react_manager_t);
}
extern "C" {
#[doc = " Get or create a phase-version registry for a method.\n\n The registry is created on first access for a method_id.\n Subsequent calls with the same method_id return the existing registry.\n\n Thread safety: caller must NOT hold manager_mutex (this function\n acquires it internally).\n\n @param mgr Phase-reactive manager\n @param method_id Method ID\n @return Pointer to the registry, or NULL on failure"]
pub fn vtx_phase_react_get_registry(
mgr: *mut vtx_phase_react_manager_t,
method_id: u32,
) -> *mut vtx_phase_version_registry_t;
}
extern "C" {
#[doc = " Park the current active version for a method's current phase.\n\n Called when:\n 1. A phase transition is detected (the method is about to switch\n to a different execution phase)\n 2. A newer version is installed (the current version becomes deprecated)\n\n The version's state is transitioned from Active to Parked. Its compiled\n code remains in memory and can be reactivated when the same phase recurs.\n\n If the registry is full (VTX_PHASE_REACT_MAX_PARKED entries), the\n oldest parked version (by park_time_ns) is evicted to make room.\n\n If memory pressure is high (parked_code_used > parked_code_budget),\n the oldest parked versions across all methods are evicted before\n parking the new one.\n\n @param mgr Phase-reactive manager\n @param method_id Method ID\n @param version The version to park (must be Active or Deprecated)\n @param phase_hash The phase hash this version was compiled for\n @return 0 on success, -1 on failure"]
pub fn vtx_phase_react_park(
mgr: *mut vtx_phase_react_manager_t,
method_id: u32,
version: *mut vtx_code_version_t,
phase_hash: vtx_phase_hash_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Try to reactivate a parked version for a given phase.\n\n Looks up the phase hash in the method's registry. If a valid parked\n version exists, it is transitioned from Parked → Active and returned.\n The reactivation is O(1): no recompilation, no code generation.\n\n If no parked version exists for the given phase, returns NULL.\n The caller should then trigger background compilation for the new phase.\n\n Thread safety: acquires manager_mutex internally. The caller is\n responsible for installing the reactivated version as the method's\n active code (via the version manager).\n\n @param mgr Phase-reactive manager\n @param method_id Method ID\n @param phase_hash The phase hash to look up\n @return The reactivated version, or NULL if no parked version exists"]
pub fn vtx_phase_react_try_reactivate(
mgr: *mut vtx_phase_react_manager_t,
method_id: u32,
phase_hash: vtx_phase_hash_t,
) -> *mut vtx_code_version_t;
}
extern "C" {
#[doc = " Evict the oldest parked version for a method (LRU eviction).\n\n Finds the entry with the smallest park_time_ns and frees the\n associated parked version. The entry is marked as invalid and\n the slot becomes available for reuse.\n\n Called when the per-method registry is full, or when global\n memory pressure requires eviction.\n\n @param mgr Phase-reactive manager\n @param method_id Method ID\n @return 0 on success, -1 if no valid parked version to evict"]
pub fn vtx_phase_react_evict_oldest(
mgr: *mut vtx_phase_react_manager_t,
method_id: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Evict parked versions globally until the code budget is satisfied.\n\n Iterates over all registries and evicts the oldest parked versions\n (by park_time_ns) until parked_code_used <= parked_code_budget.\n\n This is called after parking a new version to ensure the budget\n constraint is maintained.\n\n @param mgr Phase-reactive manager\n @return Number of versions evicted"]
pub fn vtx_phase_react_evict_for_budget(mgr: *mut vtx_phase_react_manager_t) -> u32;
}
extern "C" {
#[doc = " Check if memory pressure requires eviction.\n\n Returns true if the total size of parked code exceeds the budget.\n\n @param mgr Phase-reactive manager\n @return true if eviction is needed"]
pub fn vtx_phase_react_needs_eviction(mgr: *const vtx_phase_react_manager_t) -> bool;
}
extern "C" {
#[doc = " Compute a phase hash from the current execution context.\n\n The hash captures the type signature of the current call stack:\n 1. The dominant type at each call site (top type from type_freq)\n 2. The shape at each field access site\n\n This is similar to vtx_profile_compute_hash() in deoptless.c but\n focuses on the current phase's type distribution rather than the\n full profile history. The hash uses FNV-1a for robust distribution.\n\n Two execution contexts with the same phase hash are expected to\n exhibit the same type behavior, so a version compiled for one\n should work for the other without recompilation.\n\n @param type_feedback Type feedback data for the method\n @param method_id Method ID\n @return Phase hash, or VTX_PHASE_HASH_NONE on failure"]
pub fn vtx_phase_react_compute_hash(
type_feedback: *const vtx_type_feedback_t,
method_id: u32,
) -> vtx_phase_hash_t;
}
extern "C" {
#[doc = " Get global phase-reactive statistics.\n\n @param mgr Phase-reactive manager\n @param total_parked Output: total parked versions currently held\n @param total_reactivated Output: total successful reactivations\n @param total_evicted Output: total evicted versions"]
pub fn vtx_phase_react_get_stats(
mgr: *const vtx_phase_react_manager_t,
total_parked: *mut u32,
total_reactivated: *mut u32,
total_evicted: *mut u32,
);
}
extern "C" {
#[doc = " Get per-method phase-reactive statistics.\n\n @param registry Per-method registry\n @param reactivations Output: successful reactivations for this method\n @param recompilations Output: recompilations that could have been avoided\n @param evictions Output: evicted parked versions for this method"]
pub fn vtx_phase_react_get_method_stats(
registry: *const vtx_phase_version_registry_t,
reactivations: *mut u32,
recompilations: *mut u32,
evictions: *mut u32,
);
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct vtx_orchestrator_struct {
pub markov: *mut vtx_markov_t,
pub phase_detector: *mut vtx_sota_phase_t,
pub recomp: *mut vtx_sota_recomp_t,
pub fdi: *mut vtx_sota_fdi_t,
pub phase_react: *mut vtx_phase_react_manager_t,
pub threadpool: *mut vtx_threadpool_t,
pub type_feedback: *mut vtx_type_feedback_t,
pub profile: *mut vtx_profile_global_t,
pub inline_feedback: *mut vtx_inline_feedback_t,
pub phase_partition: *mut vtx_phase_partition_t,
pub deoptless_tables: *mut *mut vtx_deoptless_table_t,
pub deoptless_table_count: u32,
pub orchestrator_thread: pthread_t,
pub mutex: pthread_mutex_t,
pub wake_cond: pthread_cond_t,
pub running: bool,
pub shutdown_requested: bool,
pub check_interval_ms: u32,
pub min_profile_observations: u32,
pub proactive_compile_limit: u32,
pub total_checks: u64,
pub total_phase_predictions: u64,
pub total_proactive_compiles: u64,
pub total_recomp_triggers: u64,
pub total_fdi_recompiles: u64,
pub total_phase_reactivations: u64,
pub total_phase_partition_transitions: u64,
pub total_phase_preemptive_recompiles: u64,
pub decision_submit_counts: [u64; 8usize],
pub decision_deopt_count: u64,
}
impl Default for vtx_orchestrator_struct {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
pub type vtx_orchestrator_t = vtx_orchestrator_struct;
extern "C" {
#[doc = " Initialize the runtime orchestrator.\n\n All subsystem pointers are stored but NOT owned — the caller must\n ensure they remain valid for the lifetime of the orchestrator.\n Any pointer may be NULL to disable that particular wiring.\n\n @param orch Orchestrator to initialize\n @param markov Markov chain (may be NULL)\n @param phase Phase detector (may be NULL)\n @param recomp Recomp monitor (may be NULL)\n @param fdi FDI tracker (may be NULL)\n @param threadpool Compilation threadpool (may be NULL)\n @param phase_react Phase-reactive manager (may be NULL)\n @param type_feedback Runtime type feedback (may be NULL)\n @param profile Global profile data (may be NULL)\n @param inline_feedback Inline feedback tracker (may be NULL)\n @return 0 on success, -1 on failure"]
pub fn vtx_orchestrator_init(
orch: *mut vtx_orchestrator_t,
markov: *mut vtx_markov_t,
phase: *mut vtx_sota_phase_t,
recomp: *mut vtx_sota_recomp_t,
fdi: *mut vtx_sota_fdi_t,
threadpool: *mut vtx_threadpool_t,
phase_react: *mut vtx_phase_react_manager_t,
type_feedback: *mut vtx_type_feedback_t,
profile: *mut vtx_profile_global_t,
inline_feedback: *mut vtx_inline_feedback_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Start the orchestrator background thread.\n\n The thread wakes up periodically and on explicit events to\n perform wiring functions (proactive compilation, drift checks, etc.)\n\n @param orch Orchestrator to start\n @return 0 on success, -1 on failure"]
pub fn vtx_orchestrator_start(orch: *mut vtx_orchestrator_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Stop the orchestrator background thread and wait for it to finish.\n\n @param orch Orchestrator to stop"]
pub fn vtx_orchestrator_stop(orch: *mut vtx_orchestrator_t);
}
extern "C" {
#[doc = " Destroy the orchestrator and release resources.\n Stops the background thread if running.\n\n @param orch Orchestrator to destroy"]
pub fn vtx_orchestrator_destroy(orch: *mut vtx_orchestrator_t);
}
extern "C" {
#[doc = " Notify the orchestrator that a method entry occurred.\n\n This feeds the method entry to the Markov chain and phase detector,\n which may trigger proactive compilation for the predicted next phase.\n\n @param orch Orchestrator\n @param method_id Method that was just entered"]
pub fn vtx_orchestrator_on_method_entry(orch: *mut vtx_orchestrator_t, method_id: u32);
}
extern "C" {
#[doc = " Notify the orchestrator that a deoptimization occurred.\n\n This feeds the deopt event to FDI, which tracks unprofitable inlines\n and may recommend recompilation with different inlining decisions.\n Also records the failed guard in the guard metadata system.\n\n @param orch Orchestrator\n @param method_id Method where the deopt occurred\n @param call_site_id Call site where the deopt occurred\n @param guard_id Guard that failed (may be VTX_GUARD_ID_INVALID)"]
pub fn vtx_orchestrator_on_deopt(
orch: *mut vtx_orchestrator_t,
method_id: u32,
call_site_id: u64,
guard_id: u32,
);
}
extern "C" {
#[doc = " Notify the orchestrator that a compilation completed.\n\n This saves a profile snapshot in the recomp monitor (so we can\n detect drift later) and records the new version in FDI.\n\n @param orch Orchestrator\n @param method_id Method that was compiled\n @param version_id New version ID"]
pub fn vtx_orchestrator_on_compile_done(
orch: *mut vtx_orchestrator_t,
method_id: u32,
version_id: u32,
);
}
extern "C" {
#[doc = " Wake the orchestrator immediately (e.g., after a burst of deopts).\n\n Normally the orchestrator wakes on its timer. This forces an\n immediate check, which is useful when the system detects that\n something has changed significantly (e.g., a phase transition\n was detected by the interpreter).\n\n @param orch Orchestrator to wake"]
pub fn vtx_orchestrator_wake(orch: *mut vtx_orchestrator_t);
}
extern "C" {
#[doc = " Attach a phase-aware profile partition to the orchestrator.\n\n After this call, the orchestrator will:\n - Read from the partition's active phase profile (instead of the\n static `profile` pointer) for recomp decisions.\n - On phase transitions detected by the phase detector, call\n vtx_phase_partition_transition() to swap the active profile.\n - After a transition, preemptively recompile the new phase's hot\n methods using the new phase's profile.\n\n The orchestrator does NOT own the partition — the caller must keep it\n alive for the orchestrator's lifetime and destroy it after\n vtx_orchestrator_stop().\n\n Pass NULL to detach (revert to the single-profile mode).\n\n @param orch Orchestrator\n @param part Phase partition (may be NULL)"]
pub fn vtx_orchestrator_set_phase_partition(
orch: *mut vtx_orchestrator_t,
part: *mut vtx_phase_partition_t,
);
}
extern "C" {
#[doc = " Manually trigger a phase partition transition.\n\n Called by the interpreter/runtime when a phase transition is detected\n outside the orchestrator's periodic check (e.g., immediately when\n the phase detector fires). This swaps the active profile and queues\n preemptive recompilation of the new phase's hot methods.\n\n If no partition is attached, this is a no-op.\n\n @param orch Orchestrator\n @param new_phase_id Phase to transition to"]
pub fn vtx_orchestrator_phase_transition(orch: *mut vtx_orchestrator_t, new_phase_id: u32);
}
extern "C" {
#[doc = " Get orchestrator statistics."]
pub fn vtx_orchestrator_get_stats(
orch: *const vtx_orchestrator_t,
total_checks: *mut u64,
total_phase_predictions: *mut u64,
total_proactive_compiles: *mut u64,
total_recomp_triggers: *mut u64,
total_fdi_recompiles: *mut u64,
total_phase_reactivations: *mut u64,
);
}
extern "C" {
#[doc = " Get Sprint 2 partition statistics.\n\n @param orch Orchestrator\n @param total_partition_transitions Out: phase profile swaps\n @param total_preemptive_recompiles Out: methods recompiled on phase entry"]
pub fn vtx_orchestrator_get_partition_stats(
orch: *const vtx_orchestrator_t,
total_partition_transitions: *mut u64,
total_preemptive_recompiles: *mut u64,
);
}
#[doc = " A type signature for method versioning: the concrete types observed\n at each argument position.\n\n Named vtx_spec_type_sig_t to avoid collision with vtx_type_signature_t\n in interp/type_feedback.h, which tracks call-site receiver+result types\n for composite guard optimization. This structure tracks argument types\n for method-level versioning decisions.\n\n The signature_hash is an FNV-1a hash of arg_types, consistent with\n the hash functions used in deopt/deoptless.c and compile/phase_react.c.\n It enables O(1) signature comparison in the dispatch hot path."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_spec_type_sig_t {
pub arg_types: [u32; 4usize],
pub arg_count: u32,
pub signature_hash: u64,
}
#[doc = " A type-specialized version of a method.\n\n Each version is compiled with the assumption that arguments match\n the type signature. The guard_id identifies the DeoptGuard that\n checks the type signature at the method entry point. If the guard\n fails, execution transfers to the generic version or the interpreter.\n\n The stability metric tracks how often this version's guard succeeds:\n stability = execution_count / (execution_count + deopt_count)\n\n When stability drops below VTX_SPEC_VERSION_STABILITY_THRESHOLD,\n the version is a candidate for deactivation.\n\n Versions are stored in a prepend-based linked list (newest first)\n for O(1) insertion and preferential access to recently created versions."]
pub type vtx_spec_version_t = vtx_spec_version;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_spec_version {
pub method_id: u32,
pub signature: vtx_spec_type_sig_t,
pub code_version: *mut vtx_code_version_t,
pub execution_count: u64,
pub deopt_count: u64,
pub stability: f64,
pub is_active: bool,
pub is_compiling: bool,
pub guard_id: u32,
pub next: *mut vtx_spec_version_t,
}
impl Default for vtx_spec_version {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Per-method spec version registry.\n\n Tracks all type-specialized versions for a single method, plus\n per-argument type profiling data used to decide which type\n signatures are worth creating versions for.\n\n The arg_profiles array tracks the top 4 types observed at each\n argument position with their frequencies. This data drives the\n decision of whether to create a new specialized version:\n - If a type's frequency >= VTX_SPEC_VERSION_FREQUENCY_THRESHOLD\n and total observations >= VTX_SPEC_VERSION_MIN_OBSERVATIONS,\n that type is a candidate for specialization.\n - The combination of specialized types across arguments forms\n the signature for the new version.\n\n Statistics track the dispatch efficiency: how often calls hit a\n specialized version (direct_hits) vs. fall through to the generic\n fallback (generic_fallbacks)."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_spec_version_registry_t {
pub method_id: u32,
pub versions: *mut vtx_spec_version_t,
pub version_count: u32,
pub default_version: *mut vtx_spec_version_t,
pub hot_version: *mut vtx_spec_version_t,
pub arg_profiles: [vtx_spec_version_registry_t__bindgen_ty_1; 4usize],
pub total_dispatches: u64,
pub direct_hits: u64,
pub generic_fallbacks: u64,
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_spec_version_registry_t__bindgen_ty_1 {
pub top_type_ids: [u32; 4usize],
pub top_frequencies: [f64; 4usize],
pub total_observations: u64,
}
impl Default for vtx_spec_version_registry_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " A loop version: a clone of a loop body with specific type assumptions.\n\n The key insight is that the type guard moves OUTSIDE the loop.\n Instead of checking the type on every iteration, we check once\n before entering the loop and execute the type-specialized loop body.\n\n For a loop that iterates N times:\n - Without versioning: N type checks inside the loop\n - With versioning: 1 type check before the loop\n - Savings: (N-1) type checks eliminated\n\n The guard_id identifies the pre-loop guard that checks:\n - The loop items are all of item_type_id\n - (Optionally) the loop trip count matches the expected range\n\n If the pre-loop guard fails, execution falls through to the\n generic (unversioned) loop."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_loop_version_t {
pub method_id: u32,
pub loop_header_pc: u32,
pub item_type_id: u32,
pub code_version: *mut vtx_code_version_t,
pub guard_id: u32,
pub execution_count: u64,
pub is_active: bool,
}
impl Default for vtx_loop_version_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Per-loop version registry.\n\n Tracks all type-specialized versions for a single loop.\n The versions array is dynamically growing (unlike method registries\n which use linked lists) because the number of loop versions is\n typically small (1-3) and array access is faster for dispatch."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_loop_version_registry_t {
pub method_id: u32,
pub loop_header_pc: u32,
pub versions: *mut vtx_loop_version_t,
pub version_count: u32,
pub version_capacity: u32,
pub active_version: u32,
}
impl Default for vtx_loop_version_registry_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Global method versioning manager.\n\n Manages per-method registries for type-specialized versioning (2B)\n and per-loop registries for loop versioning (2C). The manager\n provides thread-safe access to all registries via a single mutex.\n\n Loop versioning registries are stored in a separate array indexed\n by a combined (method_id, loop_header_pc) key. In practice, most\n methods have 0-2 hot loops, so a flat array with linear scan is\n efficient. A hash table could be used if this becomes a bottleneck.\n\n The loop_versioning_stats field tracks the aggregate impact of\n loop versioning: how many loops have been versioned, how many\n type guards were hoisted out of loops, and the estimated total\n number of per-iteration type checks eliminated."]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct vtx_spec_version_manager_t {
pub registries: *mut vtx_spec_version_registry_t,
pub registry_count: u32,
pub registry_capacity: u32,
pub mutex: pthread_mutex_t,
pub loop_registries: *mut vtx_loop_version_registry_t,
pub loop_registry_count: u32,
pub loop_registry_capacity: u32,
pub loop_versioning_stats: vtx_spec_version_manager_t__bindgen_ty_1,
pub total_versions_created: u32,
pub total_versions_deopted: u32,
pub total_direct_dispatches: u32,
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_spec_version_manager_t__bindgen_ty_1 {
pub total_loops_versioned: u32,
pub guards_hoisted: u32,
pub estimated_checks_saved: u64,
}
impl Default for vtx_spec_version_manager_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the spec version manager.\n\n Allocates the registries array with VTX_SPEC_VERSION_INITIAL_CAPACITY\n entries and initializes the global mutex.\n\n @param mgr Manager to initialize\n @return 0 on success, -1 on failure"]
pub fn vtx_spec_version_manager_init(
mgr: *mut vtx_spec_version_manager_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the spec version manager and release all resources.\n\n Frees all version structures, registries, and loop registries.\n Does NOT free the vtx_code_version_t objects — those are owned\n by the version manager (compile/version.h).\n\n @param mgr Manager to destroy"]
pub fn vtx_spec_version_manager_destroy(mgr: *mut vtx_spec_version_manager_t);
}
extern "C" {
#[doc = " Get or create a spec version registry for a method.\n\n The registry is created on first access for a method_id.\n Subsequent calls with the same method_id return the existing registry.\n\n Thread safety: acquires mgr->mutex internally.\n\n @param mgr Spec version manager\n @param method_id Method ID\n @return Pointer to the registry, or NULL on failure"]
pub fn vtx_spec_version_get_registry(
mgr: *mut vtx_spec_version_manager_t,
method_id: u32,
) -> *mut vtx_spec_version_registry_t;
}
extern "C" {
#[doc = " Find a type-specialized version matching the given type signature.\n\n Searches the registry's linked list for a version whose signature\n matches. Uses signature_hash for fast O(1) rejection, then verifies\n with vtx_spec_type_sig_equal for full comparison.\n\n Thread safety: caller must hold mgr->mutex or ensure the registry\n is not being concurrently modified.\n\n @param registry Per-method registry\n @param signature Type signature to search for\n @return Matching version, or NULL if not found"]
pub fn vtx_spec_version_find(
registry: *const vtx_spec_version_registry_t,
signature: *const vtx_spec_type_sig_t,
) -> *mut vtx_spec_version_t;
}
extern "C" {
#[doc = " Create a type-specialized version for the given type signature.\n\n Allocates a new vtx_spec_version_t, initializes it with the\n signature, and prepends it to the registry's linked list.\n The version starts in is_compiling=true, is_active=false state.\n\n If the registry is at capacity (VTX_SPEC_VERSION_MAX versions),\n the least stable version is evicted to make room.\n\n Thread safety: acquires mgr->mutex internally.\n\n @param mgr Spec version manager\n @param method_id Method ID\n @param signature Type signature for the new version\n @return New version, or NULL on failure"]
pub fn vtx_spec_version_create(
mgr: *mut vtx_spec_version_manager_t,
method_id: u32,
signature: *const vtx_spec_type_sig_t,
) -> *mut vtx_spec_version_t;
}
extern "C" {
#[doc = " Check whether a type signature is worth creating a version for.\n\n A signature should be specialized when:\n 1. At least one argument position has a type with frequency\n >= VTX_SPEC_VERSION_FREQUENCY_THRESHOLD\n 2. Total dispatch observations >= VTX_SPEC_VERSION_MIN_OBSERVATIONS\n 3. The registry is not at capacity, or a less-stable version\n can be evicted\n\n Thread safety: caller must hold mgr->mutex or ensure the registry\n is not being concurrently modified.\n\n @param registry Per-method registry\n @param signature Type signature to evaluate\n @return true if specialization is recommended"]
pub fn vtx_spec_version_should_specialize(
registry: *const vtx_spec_version_registry_t,
signature: *const vtx_spec_type_sig_t,
) -> bool;
}
extern "C" {
#[doc = " Record a method dispatch with the given type signature.\n\n Updates the registry's dispatch statistics and argument type profiles.\n If the signature matches an existing specialized version, increments\n that version's execution_count. Otherwise, increments generic_fallbacks.\n\n The argument type profiles are updated for each position: the observed\n type is either inserted into the top-4 list or increments an existing\n entry's frequency.\n\n Thread safety: acquires mgr->mutex internally.\n\n @param registry Per-method registry (must be valid)\n @param signature Type signature of the dispatch arguments"]
pub fn vtx_spec_version_record_dispatch(
registry: *mut vtx_spec_version_registry_t,
signature: *const vtx_spec_type_sig_t,
);
}
extern "C" {
#[doc = " Compute the FNV-1a hash of a type signature.\n\n Uses the same FNV-1a constants as deopt/deoptless.c and\n compile/phase_react.c for consistency:\n offset_basis = 14695981039346656037ULL\n prime = 1099511628211ULL\n\n The hash is computed over arg_types[0..arg_count-1], each hashed\n byte-by-byte for robust distribution.\n\n @param sig Type signature\n @return 64-bit FNV-1a hash"]
pub fn vtx_spec_type_sig_hash(sig: *const vtx_spec_type_sig_t) -> u64;
}
extern "C" {
#[doc = " Compare two type signatures for equality.\n\n Two signatures are equal if and only if:\n - arg_count is the same\n - All arg_types[0..arg_count-1] are the same\n\n Uses signature_hash for fast rejection before full comparison.\n\n @param a First signature\n @param b Second signature\n @return true if the signatures are equal"]
pub fn vtx_spec_type_sig_equal(
a: *const vtx_spec_type_sig_t,
b: *const vtx_spec_type_sig_t,
) -> bool;
}
extern "C" {
#[doc = " Initialize a type signature from an array of argument type IDs.\n\n Sets arg_types[0..arg_count-1] from the input array, zeroes\n remaining positions, and computes the signature_hash.\n\n @param sig Signature to initialize (must not be NULL)\n @param arg_count Number of argument types (must be <= VTX_SPEC_VERSION_MAX_ARGS)\n @param arg_types Array of type IDs (may be NULL if arg_count is 0)"]
pub fn vtx_spec_type_sig_init(
sig: *mut vtx_spec_type_sig_t,
arg_count: u32,
arg_types: *const u32,
);
}
extern "C" {
#[doc = " Get or create a loop version registry for a loop.\n\n The registry is created on first access for the given\n (method_id, loop_header_pc) pair. Subsequent calls return\n the existing registry.\n\n Thread safety: acquires mgr->mutex internally.\n\n @param mgr Spec version manager\n @param method_id Method ID containing the loop\n @param loop_header_pc Bytecode PC of the loop header\n @return Pointer to the registry, or NULL on failure"]
pub fn vtx_loop_version_get_registry(
mgr: *mut vtx_spec_version_manager_t,
method_id: u32,
loop_header_pc: u32,
) -> *mut vtx_loop_version_registry_t;
}
extern "C" {
#[doc = " Create a loop version for the given item type.\n\n Allocates a new vtx_loop_version_t, initializes it, and adds it\n to the registry's versions array. The version starts in\n is_active=false state.\n\n If the registry is at capacity (VTX_LOOP_VERSION_MAX versions),\n the version with the lowest execution_count is evicted.\n\n Thread safety: acquires mgr->mutex internally.\n\n @param mgr Spec version manager\n @param method_id Method ID containing the loop\n @param loop_header_pc Bytecode PC of the loop header\n @param item_type_id Assumed type of loop items\n @return New loop version, or NULL on failure"]
pub fn vtx_loop_version_create(
mgr: *mut vtx_spec_version_manager_t,
method_id: u32,
loop_header_pc: u32,
item_type_id: u32,
) -> *mut vtx_loop_version_t;
}
extern "C" {
#[doc = " Find a loop version matching the given item type.\n\n Searches the registry's versions array for a version with\n the specified item_type_id. Returns NULL if not found.\n\n Thread safety: caller must hold mgr->mutex or ensure the registry\n is not being concurrently modified.\n\n @param registry Per-loop registry\n @param item_type_id Item type to search for\n @return Matching loop version, or NULL"]
pub fn vtx_loop_version_find(
registry: *const vtx_loop_version_registry_t,
item_type_id: u32,
) -> *mut vtx_loop_version_t;
}
extern "C" {
#[doc = " Check whether a loop should be versioned for the given item type.\n\n A loop should be versioned when:\n 1. The item type's frequency >= VTX_LOOP_VERSION_FREQUENCY_THRESHOLD\n 2. The loop has been observed at least VTX_LOOP_VERSION_MIN_OBSERVATIONS\n times\n 3. The expected trip count >= VTX_LOOP_VERSION_MIN_TRIP_COUNT\n (amortizes the pre-loop guard cost)\n\n Thread safety: caller must hold mgr->mutex or ensure the registry\n is not being concurrently modified.\n\n @param registry Per-loop registry\n @param item_type_id Item type to evaluate\n @param frequency Observed frequency of this item type (0.0-1.0)\n @return true if loop versioning is recommended"]
pub fn vtx_loop_should_version(
registry: *const vtx_loop_version_registry_t,
item_type_id: u32,
frequency: f64,
) -> bool;
}
extern "C" {
#[doc = " Get global spec versioning statistics.\n\n @param mgr Spec version manager\n @param versions_created Output: total type-specialized versions created\n @param versions_deopted Output: total versions that deopted excessively\n @param direct_dispatches Output: total dispatches hitting specialized versions"]
pub fn vtx_spec_version_get_stats(
mgr: *const vtx_spec_version_manager_t,
versions_created: *mut u32,
versions_deopted: *mut u32,
direct_dispatches: *mut u32,
);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_deopt_site_limiter_t {
pub failure_times_ns: *mut u64,
pub capacity: u32,
pub head: u32,
pub count: u32,
pub poisoned: bool,
pub total_failures: u64,
pub first_failure_ns: u64,
}
impl Default for vtx_deopt_site_limiter_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
pub fn vtx_deopt_site_init(
sl: *mut vtx_deopt_site_limiter_t,
capacity: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn vtx_deopt_site_destroy(sl: *mut vtx_deopt_site_limiter_t);
}
extern "C" {
pub fn vtx_deopt_site_record_failure(sl: *mut vtx_deopt_site_limiter_t, now_ns: u64) -> bool;
}
extern "C" {
pub fn vtx_deopt_site_is_poisoned(sl: *const vtx_deopt_site_limiter_t) -> bool;
}
extern "C" {
pub fn vtx_deopt_site_rate_per_sec(sl: *const vtx_deopt_site_limiter_t, now_ns: u64) -> f64;
}
extern "C" {
pub fn vtx_deopt_site_reset(sl: *mut vtx_deopt_site_limiter_t);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_deopt_batcher_t {
pub pending_sites: *mut u32,
pub pending_times_ns: *mut u64,
pub capacity: u32,
pub count: u32,
pub batch_start_ns: u64,
pub total_batches: u64,
pub total_deopts_coalesced: u64,
}
impl Default for vtx_deopt_batcher_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
pub fn vtx_deopt_batcher_init(
b: *mut vtx_deopt_batcher_t,
capacity: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn vtx_deopt_batcher_destroy(b: *mut vtx_deopt_batcher_t);
}
extern "C" {
pub fn vtx_deopt_batcher_add(b: *mut vtx_deopt_batcher_t, site_id: u32, now_ns: u64) -> bool;
}
extern "C" {
pub fn vtx_deopt_batcher_flush(
b: *mut vtx_deopt_batcher_t,
out_sites: *mut u32,
out_capacity: u32,
now_ns: u64,
) -> u32;
}
extern "C" {
pub fn vtx_deopt_batcher_should_flush(b: *const vtx_deopt_batcher_t, now_ns: u64) -> bool;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_deopt_budget_t {
pub deopt_times_ns: *mut u64,
pub capacity: u32,
pub head: u32,
pub count: u32,
pub budget_exceeded: bool,
pub total_deopts: u64,
pub suppress_start_ns: u64,
}
impl Default for vtx_deopt_budget_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
pub fn vtx_deopt_budget_init(
gb: *mut vtx_deopt_budget_t,
capacity: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn vtx_deopt_budget_destroy(gb: *mut vtx_deopt_budget_t);
}
extern "C" {
pub fn vtx_deopt_budget_record(gb: *mut vtx_deopt_budget_t, now_ns: u64) -> bool;
}
extern "C" {
pub fn vtx_deopt_budget_is_suppressed(gb: *const vtx_deopt_budget_t, now_ns: u64) -> bool;
}
extern "C" {
pub fn vtx_deopt_budget_rate_per_sec(gb: *const vtx_deopt_budget_t, now_ns: u64) -> f64;
}
pub const vtx_deopt_decision_t_DEOPT_COORD_POISONED: vtx_deopt_decision_t = 0;
pub const vtx_deopt_decision_t_DEOPT_COORD_BATCH: vtx_deopt_decision_t = 1;
pub const vtx_deopt_decision_t_DEOPT_COORD_DEOPTLESS: vtx_deopt_decision_t = 2;
pub const vtx_deopt_decision_t_DEOPT_COORD_FULL_DEOPT: vtx_deopt_decision_t = 3;
pub const vtx_deopt_decision_t_DEOPT_COORD_SUPPRESSED: vtx_deopt_decision_t = 4;
#[doc = " VORTEX Deopt Coordinator\n ========================\n\n Audit priority #7 (Hardening) — integration layer:\n\n \"Deopt storm resilience — the deoptless path and OSR work, but you\n need: rate limiting, deopt batching, deopt budget.\"\n\n The rate_limit.c module provides the three primitives (per-site limiter,\n batcher, global budget) as standalone, tested units. This coordinator\n WIRING them into the actual deopt path:\n\n 1. When a guard fails at runtime, the runtime calls\n vtx_deopt_coord_on_guard_fail(coord, site_id, now_ns).\n\n 2. The coordinator records the failure in:\n - the per-site limiter (poisons the site if rate > 100/sec)\n - the global budget (suppresses T2/T3 if total > 10000/sec)\n - the batcher (coalesces pending deopts into 1ms windows)\n\n 3. The coordinator returns a decision:\n - DEOPT_COORD_POISONED: site is poisoned → fall back to\n interpreter permanently for this site. Do NOT recompile.\n - DEOPT_COORD_BATCH: add to batch, defer recompilation.\n - DEOPT_COORD_DEOPTLESS: try the deoptless continuation path.\n - DEOPT_COORD_FULL_DEOPT: full deopt to interpreter (last resort).\n - DEOPT_COORD_SUPPRESSED: global budget exceeded → don't recompile,\n just fall back to interpreter for now.\n\n 4. When the batcher flushes, the coordinator triggers ONE recompilation\n for all pending sites (via a caller-provided callback).\n\n This coordinator is OPTIONAL — the runtime can call it if present, or\n fall back to the old \"always full deopt\" path if not. This allows\n incremental rollout."]
pub type vtx_deopt_decision_t = ::std::os::raw::c_uint;
pub type vtx_deopt_recompile_fn = ::std::option::Option<
unsafe extern "C" fn(site_ids: *const u32, count: u32, user_data: *mut ::std::os::raw::c_void),
>;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_deopt_coord_t {
pub sites: [vtx_deopt_site_limiter_t; 4096usize],
pub sites_inited: [bool; 4096usize],
pub site_ids: [u32; 4096usize],
pub batcher: vtx_deopt_batcher_t,
pub budget: vtx_deopt_budget_t,
pub recompile_fn: vtx_deopt_recompile_fn,
pub recompile_user_data: *mut ::std::os::raw::c_void,
pub total_guard_failures: u64,
pub total_poisoned: u64,
pub total_deoptless: u64,
pub total_full_deopts: u64,
pub total_suppressed: u64,
pub total_batches_flushed: u64,
}
impl Default for vtx_deopt_coord_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
pub fn vtx_deopt_coord_init(
coord: *mut vtx_deopt_coord_t,
recompile_fn: vtx_deopt_recompile_fn,
user_data: *mut ::std::os::raw::c_void,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn vtx_deopt_coord_destroy(coord: *mut vtx_deopt_coord_t);
}
extern "C" {
pub fn vtx_deopt_coord_on_guard_fail(
coord: *mut vtx_deopt_coord_t,
site_id: u32,
now_ns: u64,
) -> vtx_deopt_decision_t;
}
extern "C" {
pub fn vtx_deopt_coord_is_poisoned(coord: *const vtx_deopt_coord_t, site_id: u32) -> bool;
}
extern "C" {
pub fn vtx_deopt_coord_is_suppressed(coord: *const vtx_deopt_coord_t, now_ns: u64) -> bool;
}
extern "C" {
pub fn vtx_deopt_coord_flush(coord: *mut vtx_deopt_coord_t, now_ns: u64) -> u32;
}
extern "C" {
pub fn vtx_deopt_coord_stats_str(
coord: *const vtx_deopt_coord_t,
buf: *mut ::std::os::raw::c_char,
bufsize: usize,
);
}
pub type vtx_versioned_code_version_t = vtx_versioned_code_version;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_versioned_code_version {
pub method_id: u32,
pub version_number: u32,
pub code_ptr: *mut ::std::os::raw::c_void,
pub code_size: u32,
pub is_active: bool,
pub is_retired: bool,
pub on_stack_count: i32,
pub retire_time_ns: u64,
pub next: *mut vtx_versioned_code_version_t,
}
impl Default for vtx_versioned_code_version {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_versioned_cache_t {
pub cache: *mut vtx_code_cache_t,
pub versions: [*mut vtx_versioned_code_version_t; 4096usize],
pub next_version_number: [u32; 4096usize],
pub total_active: u32,
pub total_retired: u32,
pub total_compactions: u64,
pub total_force_frees: u64,
}
impl Default for vtx_versioned_cache_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
pub fn vtx_versioned_cache_init(
vc: *mut vtx_versioned_cache_t,
cache: *mut vtx_code_cache_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn vtx_versioned_cache_destroy(vc: *mut vtx_versioned_cache_t);
}
extern "C" {
pub fn vtx_versioned_cache_install(
vc: *mut vtx_versioned_cache_t,
method_id: u32,
code_ptr: *mut ::std::os::raw::c_void,
code_size: u32,
) -> u32;
}
extern "C" {
pub fn vtx_versioned_cache_get_active(
vc: *const vtx_versioned_cache_t,
method_id: u32,
) -> *mut vtx_versioned_code_version_t;
}
extern "C" {
pub fn vtx_versioned_cache_on_enter(vc: *mut vtx_versioned_cache_t, method_id: u32);
}
extern "C" {
pub fn vtx_versioned_cache_on_exit(vc: *mut vtx_versioned_cache_t, method_id: u32);
}
extern "C" {
pub fn vtx_versioned_cache_patch(
vc: *mut vtx_versioned_cache_t,
method_id: u32,
patch_offset: u32,
new_bytes: *const u8,
len: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn vtx_versioned_cache_reclaim(vc: *mut vtx_versioned_cache_t) -> u32;
}
extern "C" {
pub fn vtx_versioned_cache_compact(vc: *mut vtx_versioned_cache_t) -> u64;
}
extern "C" {
pub fn vtx_versioned_cache_stats_str(
vc: *const vtx_versioned_cache_t,
buf: *mut ::std::os::raw::c_char,
bufsize: usize,
);
}
#[doc = " Global compilation context shared between the interpreter and\n the compilation thread pool. Initialized once at startup."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_compile_context_t {
pub threadpool: *mut vtx_threadpool_t,
pub code_cache: *mut vtx_code_cache_t,
pub method_registry: *mut vtx_method_registry_t,
pub global_arena: *mut vtx_arena_t,
pub orchestrator: *mut vtx_orchestrator_t,
pub spec_version_mgr: *mut vtx_spec_version_manager_t,
pub deopt_coord: *mut vtx_deopt_coord_t,
pub versioned_cache: *mut vtx_versioned_cache_t,
pub safepoint_mgr: *mut vtx_safepoint_manager_t,
pub deoptless_tables: *mut *mut vtx_deoptless_table_t,
pub deoptless_table_count: u32,
pub deoptless_table_capacity: u32,
pub type_feedback: *const vtx_type_feedback_t,
pub markov: *mut vtx_markov_t,
pub profiler: *mut vtx_profiler_t,
pub method_lookup: ::std::option::Option<
unsafe extern "C" fn(
method_id: u32,
context: *mut ::std::os::raw::c_void,
) -> *const vtx_method_desc_t,
>,
pub method_lookup_context: *mut ::std::os::raw::c_void,
pub compilation_requested: *mut bool,
pub compilation_requested_count: u32,
pub compilation_requested_capacity: u32,
pub tier_decision:
::std::option::Option<unsafe extern "C" fn(execution_count: u64) -> vtx_compile_tier_t>,
}
impl Default for vtx_compile_context_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the compilation context.\n All pointers are stored but NOT owned.\n Returns 0 on success, -1 on failure."]
pub fn vtx_compile_context_init(ctx: *mut vtx_compile_context_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the compilation context and free internal resources."]
pub fn vtx_compile_context_destroy(ctx: *mut vtx_compile_context_t);
}
extern "C" {
#[doc = " Set the method lookup callback.\n The callback takes a method_id and returns the method descriptor."]
pub fn vtx_compile_context_set_method_lookup(
ctx: *mut vtx_compile_context_t,
lookup: ::std::option::Option<
unsafe extern "C" fn(
arg1: u32,
arg2: *mut ::std::os::raw::c_void,
) -> *const vtx_method_desc_t,
>,
context: *mut ::std::os::raw::c_void,
);
}
extern "C" {
#[doc = " Request compilation of a method.\n\n Called from the interpreter's dispatch loop when a method's\n execution count exceeds the tier-up threshold. Submits the\n method for background compilation on the thread pool.\n\n If the method has already been submitted (compilation_requested\n flag is set), this is a no-op.\n\n @param ctx Compilation context\n @param method Method that needs compilation"]
pub fn vtx_request_compilation(
ctx: *mut vtx_compile_context_t,
method: *const vtx_method_desc_t,
execution_count: u64,
);
}
extern "C" {
#[doc = " Check if a method has been submitted for compilation."]
pub fn vtx_is_compilation_requested(ctx: *const vtx_compile_context_t, method_id: u32) -> bool;
}
extern "C" {
#[doc = " Clear the compilation-requested flag for a method.\n Called after compilation completes or fails."]
pub fn vtx_clear_compilation_requested(ctx: *mut vtx_compile_context_t, method_id: u32);
}
extern "C" {
#[doc = " Wire the compile context to its threadpool.\n\n This sets the threadpool's compile_callback to a function that\n looks up the method by ID, compiles it (T1 baseline or T2+ pipeline),\n and installs the result in the code cache.\n\n Must be called after setting ctx->threadpool, ctx->code_cache,\n ctx->method_registry, and ctx->method_lookup.\n\n Returns 0 on success, -1 if ctx or ctx->threadpool is NULL."]
pub fn vtx_compile_context_wire_threadpool(
ctx: *mut vtx_compile_context_t,
) -> ::std::os::raw::c_int;
}
#[doc = " Per-method IC storage: one inline cache per bytecode position.\n Only call site PCs will actually use their ICs, but this makes\n indexing trivial (just use the call site's PC as the index)."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_method_ic_storage_t {
pub method: *const vtx_method_desc_t,
pub ics: *mut vtx_inline_cache_t,
pub count: u32,
}
impl Default for vtx_method_ic_storage_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " The interpreter state."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_interp_t {
pub frame_stack: vtx_frame_stack_t,
pub current_frame: *mut vtx_frame_t,
pub profiler: vtx_profiler_t,
pub type_feedback: vtx_type_feedback_t,
pub type_system: *mut vtx_type_system_t,
pub gc: *mut vtx_gc_t,
pub compile_ctx: *mut vtx_compile_context_t,
pub dispatch_table: *mut *mut ::std::os::raw::c_void,
pub running: bool,
pub deopt_pending: bool,
pub deopt_method_id: u32,
pub deopt_resume_pc: u32,
pub deopt_resume_pending: bool,
pub jit_reenter_pending: bool,
pub osr_pending: bool,
pub osr_loop_header_pc: u32,
pub exception: vtx_value_t,
pub method_ics: *mut vtx_method_ic_storage_t,
pub method_ic_count: u32,
pub method_ic_capacity: u32,
}
impl Default for vtx_interp_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the interpreter.\n Builds the dispatch table, initializes the frame stack,\n profiler, and type feedback collector.\n Returns 0 on success, -1 on failure."]
pub fn vtx_interp_init(
interp: *mut vtx_interp_t,
ts: *mut vtx_type_system_t,
gc: *mut vtx_gc_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the interpreter and release all resources."]
pub fn vtx_interp_destroy(interp: *mut vtx_interp_t);
}
extern "C" {
#[doc = " Set the deopt resume PC for a frame. Called by the deopt runtime\n transition after reconstructing the interpreter frame. The dispatch\n loop checks deopt_resume_pending and resumes at deopt_resume_pc."]
pub fn vtx_interp_set_deopt_pc(frame: *mut vtx_frame_t, pc: u32);
}
extern "C" {
#[doc = " Execute a method with the given arguments.\n\n Creates a new frame for the method, copies arguments into locals,\n and runs the dispatch loop until the method returns.\n\n Returns the method's return value (VTX_VALUE_UNDEFINED for void methods)."]
pub fn vtx_interp_run(
interp: *mut vtx_interp_t,
method: *const vtx_method_desc_t,
args: *mut vtx_value_t,
arg_count: u32,
) -> vtx_value_t;
}
extern "C" {
#[doc = " Get the inline cache for a specific call site in a method.\n If the IC doesn't exist yet, it is created.\n Returns the IC, or NULL on failure."]
pub fn vtx_interp_get_ic(
interp: *mut vtx_interp_t,
method: *const vtx_method_desc_t,
call_pc: u32,
) -> *mut vtx_inline_cache_t;
}
extern "C" {
#[doc = " Handle an uncaught exception: unwind all frames and return\n the exception value."]
pub fn vtx_interp_handle_uncaught(
interp: *mut vtx_interp_t,
exception: vtx_value_t,
) -> vtx_value_t;
}
extern "C" {
#[doc = " Set the compilation context on the interpreter.\n When set, the interpreter will request JIT compilation for hot\n methods via vtx_request_compilation(). This is the wiring that\n connects the interpreter's hot-code detection to the JIT pipeline.\n\n Must be called after vtx_interp_init() and before vtx_interp_run().\n The ctx pointer is stored but NOT owned by the interpreter."]
pub fn vtx_interp_set_compile_ctx(interp: *mut vtx_interp_t, ctx: *mut vtx_compile_context_t);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_runtime_t {
pub type_system: vtx_type_system_t,
pub gc: vtx_gc_t,
pub interp: *mut vtx_interp_t,
pub code_cache: vtx_code_cache_t,
pub method_registry: vtx_method_registry_t,
pub arena: vtx_arena_t,
pub orchestrator: *mut vtx_orchestrator_t,
pub threadpool: *mut vtx_threadpool_t,
pub initialized: ::std::os::raw::c_int,
}
impl Default for vtx_runtime_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
pub fn vtx_runtime_create(rt: *mut vtx_runtime_t) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn vtx_runtime_destroy(rt: *mut vtx_runtime_t);
}
extern "C" {
pub fn vtx_runtime_run(rt: *mut vtx_runtime_t, bc: *const vtx_bytecode_t) -> vtx_value_t;
}
extern "C" {
pub fn vtx_runtime_run_with_args(
rt: *mut vtx_runtime_t,
bc: *const vtx_bytecode_t,
args: *const vtx_value_t,
arg_count: u32,
) -> vtx_value_t;
}
extern "C" {
pub fn vtx_runtime_interp(rt: *mut vtx_runtime_t) -> *mut vtx_interp_t;
}
extern "C" {
pub fn vtx_runtime_type_system(rt: *mut vtx_runtime_t) -> *mut vtx_type_system_t;
}
extern "C" {
pub fn vtx_runtime_gc(rt: *mut vtx_runtime_t) -> *mut vtx_gc_t;
}
extern "C" {
pub fn vtx_runtime_code_cache(rt: *mut vtx_runtime_t) -> *mut vtx_code_cache_t;
}
extern "C" {
pub fn vtx_runtime_compile_ctx(rt: *mut vtx_runtime_t) -> *mut vtx_compile_context_t;
}
extern "C" {
pub fn vtx_runtime_start_threadpool(
rt: *mut vtx_runtime_t,
nthreads: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn vtx_runtime_stop_threadpool(rt: *mut vtx_runtime_t);
}
extern "C" {
pub fn vtx_bytecode_load(
path: *const ::std::os::raw::c_char,
arena: *mut vtx_arena_t,
) -> *mut vtx_bytecode_t;
}
extern "C" {
#[doc = " Emit code to increment the method invocation counter.\n\n Generated code:\n 1. Load profile_data pointer from [RBP + VTX_FRAME_PROFILE_DATA_OFFSET]\n 2. Increment invocation_count (saturating at UINT64_MAX)\n inc qword ptr [profile_data + VTX_PD_INVOCATION_COUNT_OFFSET]\n ; or: add qword ptr [...], 1 + jno skip + mov qword ptr [...], UINT64_MAX\n\n @param buf Code buffer to emit into\n @param profile_data If non-NULL, can be used for direct address;\n if NULL, load from frame"]
pub fn vtx_instrument_emit_invocation_increment(
buf: *mut vtx_code_buffer_t,
profile_data: *mut vtx_profile_data_t,
);
}
extern "C" {
#[doc = " Emit code to record the receiver type at a call site.\n\n This records the TypeID of the receiver in the call site's type\n profile array. The profile data is used by the T2 optimizer for\n speculative inlining and inline cache optimization.\n\n Generated code:\n 1. Load profile_data pointer from frame\n 2. Compute call_site_types[call_site_pc] address\n 3. Load the current count of type observations\n 4. If count < VTX_POLY_LIMIT, store the new TypeID at entries[count]\n 5. Increment count (saturating)\n\n @param buf Code buffer to emit into\n @param profile_data Profile data structure (may be NULL)\n @param call_site_pc Bytecode PC of the call site\n @param receiver_reg Register holding the receiver value (tagged)\n @param typeid_reg Register holding the TypeID to record\n (if VTX_REG_NONE, will extract from receiver_reg)"]
pub fn vtx_instrument_emit_call_type_record(
buf: *mut vtx_code_buffer_t,
profile_data: *mut vtx_profile_data_t,
call_site_pc: u32,
receiver_reg: vtx_reg_t,
typeid_reg: vtx_reg_t,
);
}
extern "C" {
#[doc = " Emit code to record a branch outcome.\n\n This increments both the taken count (if taken) and the total count\n for the branch at the given bytecode PC.\n\n Generated code:\n 1. Load profile_data pointer from frame\n 2. Increment branch_total_counts[branch_pc] (saturating at UINT32_MAX)\n 3. If taken, increment branch_taken_counts[branch_pc]\n\n @param buf Code buffer to emit into\n @param profile_data Profile data structure (may be NULL)\n @param branch_pc Bytecode PC of the branch instruction\n @param taken True if the branch is taken, false otherwise\n (the JIT knows this at compile time for unconditional\n branches; for conditional, emit on the taken path)"]
pub fn vtx_instrument_emit_branch_record(
buf: *mut vtx_code_buffer_t,
profile_data: *mut vtx_profile_data_t,
branch_pc: u32,
taken: bool,
);
}
extern "C" {
#[doc = " Emit code to increment the backward branch counter.\n Used at loop back-edges to track loop iteration counts.\n\n Generated code:\n 1. Load profile_data pointer from frame\n 2. Increment backward_branch_count (saturating at UINT64_MAX)\n\n @param buf Code buffer to emit into\n @param profile_data Profile data structure (may be NULL)"]
pub fn vtx_instrument_emit_backward_branch_increment(
buf: *mut vtx_code_buffer_t,
profile_data: *mut vtx_profile_data_t,
);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_code_buffer {
pub bytes: *mut u8,
pub position: u32,
pub capacity: u32,
}
impl Default for vtx_code_buffer {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize a code buffer with the given initial capacity.\n Returns 0 on success, -1 on failure."]
pub fn vtx_code_buffer_init(
buf: *mut vtx_code_buffer_t,
initial_capacity: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy a code buffer and free its memory."]
pub fn vtx_code_buffer_destroy(buf: *mut vtx_code_buffer_t);
}
extern "C" {
#[doc = " Ensure the buffer has at least `needed` bytes of free space.\n Reallocates if necessary.\n Returns 0 on success, -1 on failure."]
pub fn vtx_code_buffer_ensure_capacity(
buf: *mut vtx_code_buffer_t,
needed: u32,
) -> ::std::os::raw::c_int;
}
#[doc = " Records a forward branch that needs to be patched once the target\n position is known. Used for GOTO, IF_TRUE, IF_FALSE targets."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_branch_fixup_t {
pub patch_position: u32,
pub source_offset: u32,
pub target_bc_pc: u16,
pub is_32bit: bool,
}
#[doc = " Polymorphic inline cache for virtual/interface dispatch.\n\n Each CALL_VIRTUAL / CALL_INTERFACE site gets its own IC.\n The emitted machine code probes the type_ids array; on a hit,\n it calls the corresponding target directly. On a miss, it\n falls through to the runtime helper which updates the IC.\n\n Layout (designed for cache-friendly access from emitted code):\n offset 0: type_ids[0..3] — 4 × uint32_t = 16 bytes, contiguous\n offset 16: targets[0..3] — 4 × void* = 32 bytes, contiguous\n offset 48: count — uint32_t\n offset 52: misses — uint32_t"]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_poly_ic {
pub type_ids: [u32; 4usize],
pub targets: [*mut ::std::os::raw::c_void; 4usize],
pub count: u32,
pub misses: u32,
}
impl Default for vtx_poly_ic {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Destroy a compiled code struct and free all associated memory.\n Does NOT free the code buffer itself (that's managed by the code cache)."]
pub fn vtx_compiled_code_destroy(code: *mut vtx_compiled_code_t);
}
extern "C" {
#[doc = " Compile a method using the baseline JIT.\n\n Performs a single pass over the bytecode, emitting x86-64 machine code\n for each instruction. Guards are emitted for potentially speculative\n operations. Profiling instrumentation is inserted at key points.\n Deopt stubs are generated after the main code.\n\n If both cache and registry are non-NULL, the compiled code is installed\n into the code cache via vtx_install_method() which handles allocation,\n mprotect, and atomic code pointer updates. Otherwise, the code is\n malloc'd and the caller must handle installation.\n\n @param method The method to compile\n @param profile_data Profile data for this method (may be NULL for first compilation)\n @param arena Arena for temporary allocations during compilation\n @param cache Code cache for proper code installation (may be NULL)\n @param registry Method registry for code installation (may be NULL)\n @return Compiled code struct, or NULL on failure"]
pub fn vtx_baseline_compile(
method: *const vtx_method_desc_t,
profile_data: *mut vtx_profile_data_t,
arena: *mut vtx_arena_t,
cache: *mut vtx_code_cache_t,
registry: *mut vtx_method_registry_t,
) -> *mut vtx_compiled_code_t;
}
extern "C" {
#[doc = " Run GVN on the graph. Modifies the graph in place.\n Returns the number of nodes eliminated."]
pub fn vtx_gvn_run(graph: *mut vtx_graph_t) -> u32;
}
extern "C" {
#[doc = " Compute a hash for a node suitable for GVN.\n The hash considers: opcode, type, input value numbers, condition code,\n constant value (if Constant opcode), and other auxiliary data."]
pub fn vtx_gvn_node_hash(node: *const vtx_node_t, table: *const vtx_node_table_t) -> u32;
}
extern "C" {
#[doc = " Check if two nodes are congruent (same value number).\n Returns true if they are provably the same computation."]
pub fn vtx_gvn_nodes_congruent(
a: *const vtx_node_t,
b: *const vtx_node_t,
table: *const vtx_node_table_t,
) -> bool;
}
pub const vtx_lattice_tag_t_VTX_LATTICE_TOP: vtx_lattice_tag_t = 0;
pub const vtx_lattice_tag_t_VTX_LATTICE_CONSTANT: vtx_lattice_tag_t = 1;
pub const vtx_lattice_tag_t_VTX_LATTICE_BOTTOM: vtx_lattice_tag_t = 2;
#[doc = " VORTEX Sparse Conditional Constant Propagation (SCCP)\n\n Implements the SCCP algorithm on the Sea-of-Nodes IR.\n\n Lattice per node:\n Top — unreachable / not yet visited\n Constant — known constant value\n Bottom — overdefined (variable, multiple possible values)\n\n Propagation rules per opcode:\n - Arithmetic on constants → constant result (fold)\n - Phi with one non-Top input → that input\n - Phi with all same constant → that constant\n - CheckCast with known type → no-op (replace with input)\n - Guard with always-true condition → remove\n - Comparison of constants → constant result\n - Neg/Not on constant → constant result\n\n Conditional propagation:\n - At If nodes with a constant condition, only propagate into the\n reachable branch. Unreachable branches keep their lattice values at Top.\n\n Fixed-point iteration:\n - Worklist of nodes whose lattice value has changed.\n - Process until worklist is empty.\n - Nodes remaining at Top after convergence are unreachable (dead).\n\n The graph is modified in place: constant-folded nodes are replaced with\n Constant nodes, and unreachable nodes are marked dead."]
pub type vtx_lattice_tag_t = ::std::os::raw::c_uint;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct vtx_lattice_val_t {
pub tag: vtx_lattice_tag_t,
pub value: vtx_constval_t,
}
impl Default for vtx_lattice_val_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
pub fn vtx_lattice_meet(a: vtx_lattice_val_t, b: vtx_lattice_val_t) -> vtx_lattice_val_t;
}
extern "C" {
#[doc = " Run SCCP on the graph. Modifies the graph in place:\n - Replaces foldable expressions with Constant nodes\n - Marks unreachable nodes as dead\n - Simplifies Phis with one input\n\n Returns the number of nodes simplified or marked unreachable."]
pub fn vtx_constant_prop_run(graph: *mut vtx_graph_t) -> u32;
}
extern "C" {
#[doc = " Run DCE on the graph. Modifies the graph in place.\n Returns the number of nodes removed."]
pub fn vtx_dce_run(graph: *mut vtx_graph_t) -> u32;
}
#[doc = " VORTEX SoN → Basic Block Scheduling\n\n Converts the Sea-of-Nodes graph back into a scheduled form (basic blocks)\n suitable for lowering to machine code.\n\n Algorithm:\n 1. Identify control nodes and build the basic block skeleton.\n 2. Assign each data node to its earliest legal block:\n - Must be in a block that dominates all its uses.\n - Must respect memory dependencies (load after store).\n - Must be in a block that is dominated by all its inputs.\n 3. Hoist loop-invariant nodes out of loops.\n 4. Sink condition-dependent nodes into their target blocks.\n 5. Place guards as early as possible (fail-fast).\n 6. Place allocations as late as possible (avoid unnecessary allocation).\n\n The schedule is a list of basic blocks, each containing an ordered list\n of node IDs. The ordering respects data dependencies within the block."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_schedule_block_t {
pub nodes: *mut vtx_nodeid_t,
pub node_count: u32,
pub node_capacity: u32,
pub region_node: vtx_nodeid_t,
pub block_id: u32,
pub loop_depth: u32,
pub is_loop_header: bool,
pub is_catch: bool,
pub succ_blocks: *mut u32,
pub succ_count: u32,
pub succ_capacity: u32,
pub pred_blocks: *mut u32,
pub pred_count: u32,
pub pred_capacity: u32,
pub df_blocks: *mut u32,
pub df_count: u32,
pub df_capacity: u32,
}
impl Default for vtx_schedule_block_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_schedule_t {
pub blocks: *mut vtx_schedule_block_t,
pub count: u32,
pub capacity: u32,
pub node_block: *mut u32,
pub node_block_count: u32,
}
impl Default for vtx_schedule_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Run the scheduler on the graph. Produces a schedule structure.\n The arena is used for temporary allocations during scheduling.\n\n Returns 0 on success, -1 on failure. The caller must free the\n schedule with vtx_schedule_destroy."]
pub fn vtx_schedule_run(
graph: *mut vtx_graph_t,
arena: *mut vtx_arena_t,
schedule: *mut vtx_schedule_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy a schedule and free all memory."]
pub fn vtx_schedule_destroy(schedule: *mut vtx_schedule_t);
}
extern "C" {
#[doc = " Get the block index that a node is scheduled in.\n Returns (uint32_t)-1 if the node is not scheduled."]
pub fn vtx_schedule_node_block(schedule: *const vtx_schedule_t, node_id: vtx_nodeid_t) -> u32;
}
extern "C" {
#[doc = " Print the schedule to stderr for debugging."]
pub fn vtx_schedule_print(schedule: *const vtx_schedule_t, graph: *const vtx_graph_t);
}
extern "C" {
#[doc = " Compute dominance frontiers for each block.\n For each block b, DF(b) is the set of blocks where b's dominance ends —\n i.e., blocks that are successors of blocks dominated by b, but are not\n themselves dominated by b. This is used for SSA Phi node placement.\n\n The frontier sets are stored as arrays of block indices in each\n vtx_schedule_block_t, using the df_blocks and df_count fields."]
pub fn vtx_compute_dominance_frontiers(
blocks: *mut vtx_schedule_block_t,
count: u32,
dom: *const u32,
start_block: u32,
);
}
extern "C" {
#[doc = " VORTEX Loop-Invariant Code Motion (LICM)\n\n Moves loop-invariant computations out of loop bodies into preheaders.\n\n A node is loop-invariant if:\n 1. It is not pinned (not a Phi, Region, FrameState, etc.)\n 2. It has no side effects\n 3. It is not a control or memory node\n 4. All of its inputs are defined outside the loop OR are themselves\n loop-invariant\n\n Guard nodes can be hoisted if the guarded condition doesn't change\n inside the loop.\n\n Memory loads (Load/LoadField/LoadIndexed) can be hoisted ONLY if there\n is no potentially-aliasing store (Store/StoreField/StoreIndexed) in the\n loop body.\n\n With TBAA (Type-Based Alias Analysis), this check is refined:\n a load of one type (e.g., int[]) can be hoisted past a store of a\n different type (e.g., ref[]) because they can never alias. This\n enables 50%+ of loop-invariant load hoisting.\n\n Prerequisites: Graph must be scheduled (vtx_schedule_run already called).\n\n @param graph The SoN graph\n @param schedule The schedule (identifies loop structure)\n @param arena Arena for temporary allocations\n @return Number of nodes hoisted, or -1 on error"]
pub fn vtx_licm_run(
graph: *mut vtx_graph_t,
schedule: *const vtx_schedule_t,
arena: *mut vtx_arena_t,
) -> ::std::os::raw::c_int;
}
#[doc = " VORTEX Bounds Check Elimination\n\n Eliminates redundant array bounds check guards using range analysis\n and induction variable analysis.\n A bounds check is redundant if:\n - The index's range is provably within the array length\n - A dominating guard already proves the same condition\n - (NEW) Induction variable analysis proves the index is within\n bounds across all loop iterations\n\n Algorithm:\n 1. Run induction variable analysis to identify IVs and their ranges\n 2. Walk the schedule and find all Guard nodes that are bounds checks\n (Guard(i < len) or Guard(i >= 0 && i < len))\n 3. Build a range analysis: for each node, compute [min, max] range\n 4. After Guard(i < len), constrain i's max to len-1\n 5. After Guard(i >= 0), constrain i's min to 0\n 6. If a subsequent Guard(i < len) sees i in range [0, len-1], eliminate it\n 7. Also eliminate dominated guards: if Guard(i < len) at block B1\n dominates Guard(i < len) at block B2 with the same len, the dominated\n guard is redundant\n 8. (NEW) If the index is an IV whose range is provably within [0, len),\n eliminate the guard"]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_range_t {
pub min: i64,
pub max: i64,
pub is_const: bool,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_range_table_t {
pub ranges: *mut vtx_range_t,
pub count: u32,
}
impl Default for vtx_range_table_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Eliminate redundant bounds check guards using range analysis.\n\n @param graph The Sea-of-Nodes graph\n @param schedule The schedule (provides block order and dominance)\n @param arena Arena allocator for temporary data\n\n @return Number of guards eliminated, or -1 on error"]
pub fn vtx_bounds_check_run(
graph: *mut vtx_graph_t,
schedule: *const vtx_schedule_t,
arena: *mut vtx_arena_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Compute the range for a node based on its opcode and inputs.\n This is the transfer function for range propagation.\n\n @param node The node to compute range for\n @param table The node table\n @param ranges The current range map (indexed by node ID)"]
pub fn vtx_bounds_compute_range(
node: *const vtx_node_t,
table: *const vtx_node_table_t,
ranges: *const vtx_range_t,
range_count: u32,
) -> vtx_range_t;
}
extern "C" {
#[doc = " Check if a Guard node represents a bounds check (i < len).\n\n A Guard is a bounds check if:\n - Its condition input is a Cmp node\n - The Cmp compares an index against a length\n - The condition is LT (i < len)\n\n @param node The Guard node\n @param table The node table\n @param index [out] Set to the node ID of the index being checked\n @param length [out] Set to the node ID of the array length\n\n @return true if this is a bounds check guard"]
pub fn vtx_bounds_is_bounds_check(
node: *const vtx_node_t,
table: *const vtx_node_table_t,
index: *mut vtx_nodeid_t,
length: *mut vtx_nodeid_t,
) -> bool;
}
extern "C" {
#[doc = " Check if a Guard node represents a non-negative check (i >= 0).\n\n @param node The Guard node\n @param table The node table\n @param index [out] Set to the node ID of the index being checked\n\n @return true if this is a non-negative check guard"]
pub fn vtx_bounds_is_nonneg_check(
node: *const vtx_node_t,
table: *const vtx_node_table_t,
index: *mut vtx_nodeid_t,
) -> bool;
}
extern "C" {
#[doc = " Strength reduction pass: replaces expensive ops with cheaper equivalents\n when the divisor/multiplier is a power of two.\n\n Mul(x, 2^k) → Shl(x, k)\n Div(x, 1) → x\n Mul(x, 1) → x\n Mul(x, 0) → 0\n\n Note: Div(x, 2^k) → Shr(x, k) and Mod(x, 2^k) → And(x, 2^k-1) are\n NOT applied because C's / and % truncate toward zero, while SAR and\n AND round toward -infinity. This causes mismatches for negative\n dividends. A future fix can add range analysis to prove non-negativity.\n\n @param graph The IR graph\n @return Number of nodes replaced"]
pub fn vtx_strength_reduce_run(graph: *mut vtx_graph_t) -> u32;
}
extern "C" {
#[doc = " Unroll loops by duplicating their body.\n\n Conservative implementation: only unrolls small loops (<= 20 body nodes)\n with a single back-edge. The actual body replication is a future\n enhancement — currently just marks the loop with the unroll factor.\n\n @param graph The IR graph\n @param schedule The schedule (for loop structure)\n @param arena Arena for allocations\n @param factor Unroll factor (2, 3, or 4)\n @return Number of loops unrolled"]
pub fn vtx_loop_unroll_run(
graph: *mut vtx_graph_t,
schedule: *const vtx_schedule_t,
arena: *mut vtx_arena_t,
factor: u32,
) -> u32;
}
extern "C" {
#[doc = " SMI tag elision pass: marks straight-line arithmetic chains as RAW_INT\n so the isel skips per-op untag/retag. One untag at chain entry, one\n retag at chain exit, instead of untag+retag per op.\n\n @param graph The IR graph\n @return Number of nodes marked RAW_INT"]
pub fn vtx_smi_tag_elision_run(graph: *mut vtx_graph_t) -> u32;
}
extern "C" {
#[doc = " Run representation inference on the graph.\n\n Inserts UnboxInt nodes before arithmetic chains and BoxInt nodes at\n chain exits. Marks arithmetic nodes as RAW_INT so the isel emits\n raw arithmetic instead of per-op untag/retag.\n\n @param graph The IR graph (modified in-place)\n @param arena Arena for temporary allocations\n @return Number of UnboxInt/BoxInt nodes inserted"]
pub fn vtx_rep_infer_run(graph: *mut vtx_graph_t, arena: *mut vtx_arena_t) -> u32;
}
extern "C" {
#[doc = " Evict methods using the clock (second chance) algorithm until the\n cache is under the max size. O(1) amortized per eviction.\n\n @param cache Code cache\n @param registry Method registry\n @param current_ts Current global timestamp (monotonically increasing)\n @return Number of methods evicted, or -1 on failure"]
pub fn vtx_evict_lru(
cache: *mut vtx_code_cache_t,
registry: *mut vtx_method_registry_t,
current_ts: u64,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Update the use bit for a method (clock eviction touch).\n Called when a method is invoked. Sets the use_bit so the clock\n algorithm gives the method a \"second chance\" during eviction.\n The timestamp is also updated every VTX_LRU_UPDATE_INTERVAL calls\n for diagnostics.\n\n @param method The compiled method\n @param ts Current global timestamp"]
pub fn vtx_evict_touch(method: *mut vtx_compiled_method_t, ts: u64);
}
extern "C" {
#[doc = " Find the next eviction candidate using the clock (second chance)\n algorithm. O(1) amortized per call.\n Returns the method, or NULL if the registry is empty."]
pub fn vtx_evict_find_lru(registry: *mut vtx_method_registry_t) -> *mut vtx_compiled_method_t;
}
extern "C" {
#[doc = " Evict a specific method from the cache.\n\n @param cache Code cache\n @param registry Method registry\n @param method The method to evict\n @return 0 on success, -1 on failure"]
pub fn vtx_evict_method(
cache: *mut vtx_code_cache_t,
registry: *mut vtx_method_registry_t,
method: *mut vtx_compiled_method_t,
) -> ::std::os::raw::c_int;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_dep_set_t {
pub method_ids: *mut u32,
pub count: u32,
pub capacity: u32,
}
impl Default for vtx_dep_set_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " A guard-level dependency: maps (TypeID, guard_id) instead of just TypeID.\n This enables fine-grained invalidation that only patches affected guards\n rather than invalidating entire methods."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_guard_dep_t {
pub type_id: u32,
pub guard_id: u32,
pub method_id: u32,
pub guard_branch_offset: u32,
pub code_start: *mut u8,
}
impl Default for vtx_guard_dep_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
pub type vtx_guard_dep_entry_t = vtx_guard_dep_entry;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_guard_dep_entry {
pub type_id: u32,
pub deps: *mut vtx_guard_dep_t,
pub dep_count: u32,
pub dep_capacity: u32,
pub next: *mut vtx_guard_dep_entry_t,
}
impl Default for vtx_guard_dep_entry {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_guard_dep_index_t {
pub buckets: [*mut vtx_guard_dep_entry_t; 256usize],
pub entry_count: u32,
pub arena: *mut vtx_arena_t,
}
impl Default for vtx_guard_dep_index_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Inverted index: TypeID → set of methods.\n Implemented as a hash table for O(1) average lookup."]
pub type vtx_index_entry_t = vtx_index_entry;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_index_entry {
pub key: u64,
pub dep_set: vtx_dep_set_t,
pub next: *mut vtx_index_entry_t,
}
impl Default for vtx_index_entry {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_inverted_index_t {
pub buckets: [*mut vtx_index_entry_t; 256usize],
pub entry_count: u32,
pub arena: *mut vtx_arena_t,
}
impl Default for vtx_inverted_index_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the inverted index."]
pub fn vtx_inverted_index_init(
index: *mut vtx_inverted_index_t,
arena: *mut vtx_arena_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the inverted index."]
pub fn vtx_inverted_index_destroy(index: *mut vtx_inverted_index_t);
}
extern "C" {
#[doc = " Add a dependency: method `method_id` depends on `typeid`."]
pub fn vtx_inverted_index_add(
index: *mut vtx_inverted_index_t,
typeid_: u64,
method_id: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Add a shape dependency: method `method_id` depends on `shapeid`."]
pub fn vtx_inverted_index_add_shape(
index: *mut vtx_inverted_index_t,
shapeid: u32,
method_id: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Remove a method from all dependency sets.\n Call this when a method is uninstalled or invalidated."]
pub fn vtx_inverted_index_remove_method(
index: *mut vtx_inverted_index_t,
method_id: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Look up the set of methods that depend on `typeid`.\n Returns the dep set, or NULL if no methods depend on this type."]
pub fn vtx_inverted_index_lookup(
index: *mut vtx_inverted_index_t,
typeid_: u64,
) -> *const vtx_dep_set_t;
}
extern "C" {
#[doc = " Invalidate all methods that depend on the given TypeID.\n\n This is called when a class is loaded or redefined. All compiled\n methods whose guards reference this TypeID are found via the\n inverted index, marked as not-compiled, and their metadata is freed.\n\n @param typeid_ The TypeID that triggered invalidation\n @param cache Code cache\n @param registry Method registry\n @param index Inverted index\n @return Number of methods invalidated, or -1 on failure"]
pub fn vtx_invalidate_dependencies(
typeid_: u64,
cache: *mut vtx_code_cache_t,
registry: *mut vtx_method_registry_t,
index: *mut vtx_inverted_index_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Invalidate all methods that depend on the given ShapeID.\n\n Called when an object's shape changes (e.g., property added/removed).\n\n @param shapeid The ShapeID that triggered invalidation\n @param cache Code cache\n @param registry Method registry\n @param index Inverted index\n @return Number of methods invalidated, or -1 on failure"]
pub fn vtx_invalidate_shape(
shapeid: vtx_shapeid_t,
cache: *mut vtx_code_cache_t,
registry: *mut vtx_method_registry_t,
index: *mut vtx_inverted_index_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Register a method's dependencies in the inverted index.\n Called during method installation.\n\n @param index Inverted index\n @param method The compiled method\n @return 0 on success, -1 on failure"]
pub fn vtx_invalidate_register(
index: *mut vtx_inverted_index_t,
method: *const vtx_compiled_method_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn vtx_guard_dep_index_init(
index: *mut vtx_guard_dep_index_t,
arena: *mut vtx_arena_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn vtx_guard_dep_index_destroy(index: *mut vtx_guard_dep_index_t);
}
extern "C" {
pub fn vtx_guard_dep_index_add(
index: *mut vtx_guard_dep_index_t,
type_id: u32,
guard_id: u32,
method_id: u32,
guard_branch_offset: u32,
code_start: *mut u8,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn vtx_guard_dep_index_lookup(
index: *mut vtx_guard_dep_index_t,
type_id: u32,
out_count: *mut u32,
) -> *const vtx_guard_dep_t;
}
extern "C" {
#[doc = " Fine-grained invalidation: only patch guards that depend on the\n changed TypeID, leaving other guards in the method active.\n\n For each guard that depends on typeid_:\n 1. Patch the guard's JCC in the compiled code to jump to a deopt stub\n 2. The method's other guards remain active\n 3. No recompilation is needed unless all guards are invalidated\n\n This avoids the \"nuclear option\" of invalidating entire methods.\n\n @param typeid_ The TypeID that triggered invalidation\n @param index Guard-level dependency index\n @param cache Code cache (for deopt stub allocation)\n @return Number of guards patched, or -1 on failure"]
pub fn vtx_invalidate_guard_fine_grained(
typeid_: u32,
index: *mut vtx_guard_dep_index_t,
cache: *mut vtx_code_cache_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Compute SHA-256 hash of bytecode data for version gating.\n Implemented in sha256.c (public domain, FIPS 180-4)."]
pub fn vtx_profile_compute_bytecode_hash(bytecode: *const u8, len: usize, hash: *mut u8);
}
extern "C" {
#[doc = " Save global profile data to a binary file.\n Returns true on success, false on failure.\n The file is written atomically (write to temp, then rename).\n File permissions are set to 0600 (owner read/write only).\n\n @param global The profile data to save\n @param filename Output filename\n @param bytecode_hash SHA-256 hash of the bytecode this profile was\n collected against. Stored in the header so that\n a profile from a different bytecode version is\n automatically rejected on load. May be NULL to\n skip the hash (not recommended for production)."]
pub fn vtx_profile_save(
global: *const vtx_profile_global_t,
filename: *const ::std::os::raw::c_char,
bytecode_hash: *const u8,
) -> bool;
}
extern "C" {
#[doc = " Load global profile data from a binary file.\n If the file's version doesn't match VTX_PROFILE_VERSION, the file is ignored\n and false is returned. If the CRC32 doesn't match, false is returned.\n If expected_hash is non-NULL and the stored bytecode hash doesn't match,\n false is returned (profile is from a different bytecode version).\n On success, the loaded data is MERGED into the existing global profile\n (existing data is preserved and augmented with loaded data).\n Returns true on success, false on failure."]
pub fn vtx_profile_load(
global: *mut vtx_profile_global_t,
filename: *const ::std::os::raw::c_char,
expected_hash: *const u8,
) -> bool;
}
extern "C" {
#[doc = " Register an atexit handler that saves the profile to the given filename.\n The global pointer is captured at registration time.\n Returns 0 on success, -1 on failure."]
pub fn vtx_profile_register_atexit(
global: *mut vtx_profile_global_t,
filename: *const ::std::os::raw::c_char,
bytecode_hash: *const u8,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Unregister the atexit handler. Clears the stored global pointer\n so the atexit handler will not attempt to access a destroyed global.\n Must be called before destroying the registered global."]
pub fn vtx_profile_unregister_atexit();
}
#[doc = " A single method's persisted T1 code descriptor.\n\n This is the on-disk format. The code itself is in the code blob at\n `code_offset`."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_t1_persist_method_t {
pub method_id: u32,
pub code_offset: u32,
pub code_size: u32,
pub entry_offset: u32,
pub stack_slots: u32,
pub local_slots: u32,
pub reloc_count: u32,
}
#[doc = " A single persisted relocation entry."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_t1_persist_reloc_t {
pub kind: u32,
pub offset: u32,
pub target_offset: u32,
pub target_address: u64,
pub addend: i32,
}
extern "C" {
#[doc = " Save a collection of T1 compiled methods to a T1 cache file.\n\n @param filename Output filename\n @param bytecode_hash SHA-256 hash of the bytecode (for version gating)\n @param methods Array of compiled code pointers (T1 only)\n @param method_count Number of methods\n @return true on success, false on failure"]
pub fn vtx_t1_cache_save(
filename: *const ::std::os::raw::c_char,
bytecode_hash: *const u8,
methods: *mut *const vtx_compiled_code_t,
method_count: u32,
) -> bool;
}
#[doc = " Loaded T1 cache: an mmap'd code blob with per-method descriptors.\n\n The code blob is mmap'd as PROT_READ|PROT_EXEC. Method entry points\n are computed as (code_base + entry_offset)."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_t1_cache_t {
pub bytecode_hash: [u8; 32usize],
pub method_count: u32,
pub total_code_size: u32,
pub methods: *mut vtx_t1_persist_method_t,
pub method_reloc_offsets: *mut u32,
pub relocs: *mut vtx_t1_persist_reloc_t,
pub reloc_count: u32,
pub code_base: *mut ::std::os::raw::c_void,
pub code_map_size: usize,
pub code_fd: ::std::os::raw::c_int,
pub load_time_ns: u64,
pub relocations_applied: bool,
}
impl Default for vtx_t1_cache_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Load a T1 cache file, mmap the code, and apply relocations.\n\n If the file's bytecode hash doesn't match `expected_hash`, the load\n fails (returns false). If the CRC doesn't match, the load fails.\n\n On success, the caller can call vtx_t1_cache_get_entry() to get the\n native entry point for any method in the cache.\n\n @param cache Cache structure to populate (caller allocates)\n @param filename T1 cache file path\n @param expected_hash Expected bytecode hash (for version gating)\n @return true on success, false on failure (bad magic,\n version mismatch, CRC failure, hash mismatch,\n or relocation error)"]
pub fn vtx_t1_cache_load(
cache: *mut vtx_t1_cache_t,
filename: *const ::std::os::raw::c_char,
expected_hash: *const u8,
) -> bool;
}
extern "C" {
#[doc = " Get the native entry point for a method in the loaded T1 cache.\n\n Returns NULL if the method is not in the cache.\n\n @param cache Loaded T1 cache\n @param method_id Method to look up\n @return Native entry point, or NULL"]
pub fn vtx_t1_cache_get_entry(
cache: *const vtx_t1_cache_t,
method_id: u32,
) -> *mut ::std::os::raw::c_void;
}
extern "C" {
#[doc = " Check if a method is present in the loaded T1 cache."]
pub fn vtx_t1_cache_has_method(cache: *const vtx_t1_cache_t, method_id: u32) -> bool;
}
extern "C" {
#[doc = " Destroy a loaded T1 cache: unmap the code blob and free descriptors."]
pub fn vtx_t1_cache_destroy(cache: *mut vtx_t1_cache_t);
}
extern "C" {
#[doc = " Get T1 cache statistics.\n\n @param cache Loaded T1 cache\n @param method_count Out: number of methods in cache\n @param code_size Out: total native code size\n @param load_time_ns Out: time spent loading\n @param relocations Out: number of relocations applied"]
pub fn vtx_t1_cache_stats(
cache: *const vtx_t1_cache_t,
method_count: *mut u32,
code_size: *mut u32,
load_time_ns: *mut u64,
relocations: *mut u32,
);
}
extern "C" {
#[doc = " Build the T1 cache filename for a given bytecode hash.\n\n Format: <dir>/<hash_hex>.t1c\n\n @param dir Profile directory\n @param hash_hex Bytecode hash as 32-char hex string\n @param out Output buffer\n @param out_size Size of output buffer\n @return 0 on success, -1 on overflow"]
pub fn vtx_t1_cache_filename(
dir: *const ::std::os::raw::c_char,
hash_hex: *const ::std::os::raw::c_char,
out: *mut ::std::os::raw::c_char,
out_size: usize,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Verify the graph integrity. Returns true if all checks pass.\n\n When VORTEX_ENABLE_VERIFY is not defined, this function returns true\n without doing any work."]
pub fn vtx_verify_graph(graph: *const vtx_graph_t) -> bool;
}
extern "C" {
#[doc = " Verify the graph after DCE — additionally checks that no dead nodes\n exist (since DCE should have removed them all) and that memory chains\n are properly wired (each memory node has a memory chain input)."]
pub fn vtx_verify_graph_post_dce(graph: *const vtx_graph_t) -> bool;
}
pub const vtx_escape_state_t_VTX_ESCAPE_NONE: vtx_escape_state_t = 0;
pub const vtx_escape_state_t_VTX_ESCAPE_ARG: vtx_escape_state_t = 1;
pub const vtx_escape_state_t_VTX_ESCAPE_GLOBAL: vtx_escape_state_t = 2;
#[doc = " VORTEX Partial Escape Analysis — Flow-Sensitive Escape Analysis\n\n Determines for each allocation whether it escapes the current compilation\n unit. An allocation \"escapes\" if it can be observed outside the compiled\n method — i.e., the allocated object's identity (not just its value) is\n needed at runtime.\n\n Escape states form a lattice:\n\n NoEscape — the object is never observable outside this method\n ArgEscape — the object escapes through method arguments but not\n globally; callees may observe it but cannot store it\n into a globally-visible location\n GlobalEscape — the object is globally visible (stored into a static\n field, returned, or escapes through an unknown callee)\n\n NoEscape ≤ ArgEscape ≤ GlobalEscape\n\n The analysis is flow-sensitive: it computes per-basic-block entry/exit\n states using a standard dataflow framework. At merge points (Region/Phi\n nodes), states are joined (max over the lattice). The worklist algorithm\n iterates until a fixed point is reached.\n\n Escape triggers:\n - Stored into a field of a GlobalEscape object → GlobalEscape\n - Stored into a field of an ArgEscape object → ArgEscape\n - Passed as argument to an unknown function → ArgEscape (conservative:\n callee may store globally)\n - Returned from the current method → GlobalEscape\n - Stored into a global/static field → GlobalEscape\n - Used in a monitor enter/exit → GlobalEscape\n - Stored into an array element of escaping array → propagates array's state\n - Used as receiver of a virtual call → ArgEscape (may dispatch\n to unknown method)"]
pub type vtx_escape_state_t = ::std::os::raw::c_uint;
extern "C" {
pub fn vtx_escape_state_name(s: vtx_escape_state_t) -> *const ::std::os::raw::c_char;
}
#[doc = " Maps allocation NodeIDs to their escape states.\n Stored as a flat array indexed by NodeID for O(1) lookup.\n\n Only allocation nodes (VTX_OP_NewObject, VTX_OP_NewArray, VTX_OP_Allocate)\n have entries; non-allocation nodes have state VTX_ESCAPE_NONE (unused)."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_escape_map_t {
pub states: *mut vtx_escape_state_t,
pub state_count: u32,
pub alloc_ids: *mut vtx_nodeid_t,
pub alloc_count: u32,
pub alloc_capacity: u32,
}
impl Default for vtx_escape_map_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " The dataflow state for one basic block: a snapshot of the escape map\n at block entry and exit. The transfer function walks the block's nodes\n and updates the exit state based on how each node uses allocations."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_pea_block_state_t {
pub entry_state: *mut vtx_escape_state_t,
pub exit_state: *mut vtx_escape_state_t,
pub state_count: u32,
pub entry_changed: bool,
}
impl Default for vtx_pea_block_state_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " The result of running PEA on a graph. Contains the final escape state\n for every allocation, plus the per-block dataflow states for use by\n downstream transforms (cross-object SR, materialization, virtual objects).\n\n All memory is arena-allocated; destroy by freeing the arena."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_pea_analysis_t {
pub escape_map: vtx_escape_map_t,
pub block_states: *mut vtx_pea_block_state_t,
pub block_state_count: u32,
pub total_allocs: u32,
pub no_escape_count: u32,
pub arg_escape_count: u32,
pub global_escape_count: u32,
pub iterations: u32,
}
impl Default for vtx_pea_analysis_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Run flow-sensitive partial escape analysis on the graph.\n\n Algorithm:\n 1. Identify all allocation nodes in the graph.\n 2. Initialize all allocations to NoEscape.\n 3. Build per-block entry/exit state arrays.\n 4. Iterate using a reverse-postorder worklist:\n a. For each block, compute entry state as join of predecessor exit states.\n b. Apply the transfer function: walk each node, update escape states.\n c. If exit state changed, add successors to the worklist.\n 5. Stop at fixed point (no state changes).\n\n The analysis result is allocated from the given arena.\n Returns the analysis result, or NULL on failure.\n\n @param graph The SoN graph to analyze\n @param arena Arena for allocating the result\n @return Analysis result, or NULL on failure"]
pub fn vtx_pea_run(graph: *mut vtx_graph_t, arena: *mut vtx_arena_t)
-> *mut vtx_pea_analysis_t;
}
extern "C" {
#[doc = " Get the escape state for a node from the analysis result.\n Returns VTX_ESCAPE_GLOBAL for non-allocation nodes (conservative default)."]
pub fn vtx_pea_get_escape(
analysis: *const vtx_pea_analysis_t,
node_id: vtx_nodeid_t,
) -> vtx_escape_state_t;
}
extern "C" {
#[doc = " Check if a node is a scalar-replaceable allocation (NoEscape)."]
pub fn vtx_pea_is_scalar_replaceable(
analysis: *const vtx_pea_analysis_t,
node_id: vtx_nodeid_t,
) -> bool;
}
extern "C" {
#[doc = " Get the entry escape state for a specific allocation in a specific block."]
pub fn vtx_pea_block_entry_state(
analysis: *const vtx_pea_analysis_t,
block_idx: u32,
alloc_id: vtx_nodeid_t,
) -> vtx_escape_state_t;
}
extern "C" {
#[doc = " Get the exit escape state for a specific allocation in a specific block."]
pub fn vtx_pea_block_exit_state(
analysis: *const vtx_pea_analysis_t,
block_idx: u32,
alloc_id: vtx_nodeid_t,
) -> vtx_escape_state_t;
}
#[doc = " An edge in the allocation graph: a field store from one allocation\n to another (container.field = value)."]
pub type vtx_alloc_edge_t = vtx_alloc_edge;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_alloc_edge {
pub container_id: vtx_nodeid_t,
pub value_id: vtx_nodeid_t,
pub field_offset: u32,
pub store_node_id: vtx_nodeid_t,
pub next: *mut vtx_alloc_edge_t,
pub rev_next: *mut vtx_alloc_edge_t,
}
impl Default for vtx_alloc_edge {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " The allocation graph: maps each allocation to the list of outgoing\n edges (field stores from this allocation to other allocations)."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_alloc_graph_t {
pub alloc_edges: *mut *mut vtx_alloc_edge_t,
pub edge_array_size: u32,
pub all_edges: *mut vtx_alloc_edge_t,
pub edge_count: u32,
pub edge_capacity: u32,
pub reverse_edges: *mut *mut vtx_alloc_edge_t,
pub reverse_array_size: u32,
}
impl Default for vtx_alloc_graph_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " For each allocation, the effective escape state after cross-object\n analysis. This may be lower than the raw escape state from the\n base analysis: an ArgEscape or GlobalEscape object may have effective\n NoEscape if its only escape path goes through a container field that\n is never read at the escape point."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_effective_escape_t {
pub effective_states: *mut vtx_escape_state_t,
pub state_count: u32,
pub scalar_fields: *mut u32,
pub scalar_field_count: u32,
}
impl Default for vtx_effective_escape_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Maps a (allocation, field_offset) pair to the NodeID of the scalar\n local variable that replaces the field access. Used to rewrite\n LoadField/StoreField nodes."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_sr_mapping_t {
pub alloc_id: vtx_nodeid_t,
pub field_offset: u32,
pub local_id: vtx_nodeid_t,
}
#[doc = " The complete scalar replacement result: all mappings from\n (alloc, field) → local variable."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_cross_sr_result_t {
pub mappings: *mut vtx_sr_mapping_t,
pub mapping_count: u32,
pub mapping_capacity: u32,
pub allocs_replaced: u32,
pub field_accesses_rewritten: u32,
pub edges_analyzed: u32,
}
impl Default for vtx_cross_sr_result_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Run cross-object scalar replacement on the graph.\n\n This transforms the graph in place:\n - Creates scalar local variable nodes for each field of\n scalar-replaceable allocations\n - Rewrites LoadField/StoreField accesses to use the locals\n - Removes allocation nodes for fully scalar-replaced objects\n\n @param graph The SoN graph (modified in place)\n @param analysis The escape analysis result from vtx_pea_run()\n @param arena Arena for allocating temporary data\n @return Result structure, or NULL on failure"]
pub fn vtx_cross_object_sr_run(
graph: *mut vtx_graph_t,
analysis: *const vtx_pea_analysis_t,
arena: *mut vtx_arena_t,
) -> *mut vtx_cross_sr_result_t;
}
extern "C" {
#[doc = " Get the scalar local NodeID for a given (allocation, field) pair.\n Returns VTX_NODEID_INVALID if no mapping exists."]
pub fn vtx_cross_sr_get_local(
result: *const vtx_cross_sr_result_t,
alloc_id: vtx_nodeid_t,
field_offset: u32,
) -> vtx_nodeid_t;
}
extern "C" {
#[doc = " Check if an allocation was fully scalar-replaced."]
pub fn vtx_cross_sr_is_replaced(
result: *const vtx_cross_sr_result_t,
alloc_id: vtx_nodeid_t,
) -> bool;
}
pub const vtx_virtual_state_t_VTX_VIRTUAL_UNKNOWN: vtx_virtual_state_t = 0;
pub const vtx_virtual_state_t_VTX_VIRTUAL_YES: vtx_virtual_state_t = 1;
pub const vtx_virtual_state_t_VTX_VIRTUAL_NO: vtx_virtual_state_t = 2;
#[doc = " VORTEX Virtual Object Tracking\n\n Non-escaping objects are marked as \"virtual\" — no allocation code is\n generated for them. All field accesses to virtual objects are rewritten\n to local variable accesses. Virtual objects exist only in the compiler's\n analysis; at runtime, they are just a collection of local variables.\n\n Key properties:\n - Virtual objects never cause heap allocation\n - Field accesses to virtual objects are zero-cost (register/stack access)\n - Virtual objects are tracked through Phi nodes: a Phi of virtual\n objects is virtual if both inputs are virtual with the same type\n - If a Phi merges objects of different types or one virtual and one\n non-virtual, all inputs must be materialized\n\n This pass runs after the base escape analysis and cross-object SR.\n It finalizes the virtual/non-virtual classification and rewrites\n all field accesses."]
pub type vtx_virtual_state_t = ::std::os::raw::c_uint;
#[doc = " Information about a single virtual object: its type and the mapping\n from field offsets to the NodeIDs that produce the current field values."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_virtual_obj_t {
pub alloc_id: vtx_nodeid_t,
pub type_id: u32,
pub state: vtx_virtual_state_t,
pub field_offsets: *mut u32,
pub field_values: *mut vtx_nodeid_t,
pub field_count: u32,
pub field_capacity: u32,
}
impl Default for vtx_virtual_obj_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_virtual_result_t {
pub virtual_states: *mut vtx_virtual_state_t,
pub state_count: u32,
pub virtual_objs: *mut vtx_virtual_obj_t,
pub virtual_obj_count: u32,
pub virtual_obj_capacity: u32,
pub total_allocs: u32,
pub virtual_count: u32,
pub non_virtual_count: u32,
pub phis_resolved: u32,
pub field_accesses_rewritten: u32,
}
impl Default for vtx_virtual_result_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Run virtual object tracking on the graph.\n\n This pass:\n 1. Classifies each NoEscape allocation as virtual\n 2. Tracks virtual objects through Phi nodes\n 3. Rewrites all field accesses to virtual objects as local variable access\n 4. Eliminates allocation nodes for virtual objects\n\n Must run after escape analysis and before materialization (materialization\n handles objects that need to become non-virtual at escape/deopt points).\n\n @param graph The SoN graph (modified in place)\n @param analysis The escape analysis result\n @param arena Arena for allocating temporary data\n @return Virtual tracking result, or NULL on failure"]
pub fn vtx_virtual_run(
graph: *mut vtx_graph_t,
analysis: *const vtx_pea_analysis_t,
arena: *mut vtx_arena_t,
) -> *mut vtx_virtual_result_t;
}
extern "C" {
#[doc = " Check if an allocation is virtual."]
pub fn vtx_virtual_is_virtual(
result: *const vtx_virtual_result_t,
alloc_id: vtx_nodeid_t,
) -> bool;
}
extern "C" {
#[doc = " Get the current value NodeID for a field of a virtual object.\n Returns VTX_NODEID_INVALID if the object is not virtual or the\n field is not tracked."]
pub fn vtx_virtual_get_field(
result: *const vtx_virtual_result_t,
alloc_id: vtx_nodeid_t,
field_offset: u32,
) -> vtx_nodeid_t;
}
extern "C" {
#[doc = " Get the virtual object info for an allocation.\n Returns NULL if the allocation is not virtual."]
pub fn vtx_virtual_get_obj(
result: *const vtx_virtual_result_t,
alloc_id: vtx_nodeid_t,
) -> *const vtx_virtual_obj_t;
}
#[doc = " Describes a single point where a scalar-replaced object must be\n materialized. Contains the node where materialization is inserted\n and the list of fields to store."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_materialize_point_t {
pub escape_node_id: vtx_nodeid_t,
pub alloc_id: vtx_nodeid_t,
pub type_id: u32,
pub field_offsets: *mut u32,
pub field_local_ids: *mut vtx_nodeid_t,
pub field_count: u32,
pub materialized_obj_id: vtx_nodeid_t,
pub predecessor_control: vtx_nodeid_t,
}
impl Default for vtx_materialize_point_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_materialize_result_t {
pub points: *mut vtx_materialize_point_t,
pub point_count: u32,
pub point_capacity: u32,
pub objects_materialized: u32,
pub fields_stored: u32,
pub deopt_points_handled: u32,
}
impl Default for vtx_materialize_result_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Run the materialization pass on the graph.\n\n Scans for deopt points and escape points that reference scalar-replaced\n objects, and inserts NewObject + StoreField nodes to reify those objects.\n\n This pass must run AFTER cross-object scalar replacement, so it can\n identify which objects were scalar-replaced and what their field values\n are.\n\n @param graph The SoN graph (modified in place — new nodes inserted)\n @param analysis The escape analysis result\n @param virtual_result The virtual object tracking result (may be NULL if\n virtual pass was not run; when provided, field values\n are read from virtual field maps instead of dead\n StoreField nodes)\n @param arena Arena for allocating temporary data\n @return Materialization result, or NULL on failure"]
pub fn vtx_materialize_run(
graph: *mut vtx_graph_t,
analysis: *const vtx_pea_analysis_t,
virtual_result: *const vtx_virtual_result_t,
arena: *mut vtx_arena_t,
) -> *mut vtx_materialize_result_t;
}
extern "C" {
#[doc = " Get the materialized object NodeID for a given allocation at a given\n escape point. Returns VTX_NODEID_INVALID if the object was not\n materialized at that point."]
pub fn vtx_materialize_get_obj(
result: *const vtx_materialize_result_t,
alloc_id: vtx_nodeid_t,
escape_node_id: vtx_nodeid_t,
) -> vtx_nodeid_t;
}
extern "C" {
#[doc = " Check if an allocation was materialized at any point."]
pub fn vtx_materialize_is_materialized(
result: *const vtx_materialize_result_t,
alloc_id: vtx_nodeid_t,
) -> bool;
}
#[doc = " A single node in a GBDT tree. Internal nodes test a feature against\n a threshold; leaf nodes contribute a value to the prediction sum.\n\n Types are chosen for compactness:\n uint16_t feature_index: 15 features, 0xFFFF = leaf marker\n float threshold: sufficient precision for normalized [0,1] features\n int16_t left_child: indices within a tree (< 32768 nodes per tree)\n int16_t right_child: same\n float leaf_value: small values summed across trees"]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_gbdt_node_t {
pub feature_index: u16,
pub threshold: f32,
pub left_child: i32,
pub right_child: i32,
pub leaf_value: f32,
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_gbdt_tree_desc_t {
pub root_index: u32,
pub node_count: u32,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_gbdt_model_t {
pub nodes: *mut vtx_gbdt_node_t,
pub node_count: u32,
pub node_capacity: u32,
pub trees: [vtx_gbdt_tree_desc_t; 100usize],
pub tree_count: u32,
pub max_depth: u32,
pub init_score: f64,
pub owns_nodes: bool,
}
impl Default for vtx_gbdt_model_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize an empty GBDT model.\n Returns 0 on success, -1 on failure."]
pub fn vtx_gbdt_model_init(model: *mut vtx_gbdt_model_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy a GBDT model and free owned memory."]
pub fn vtx_gbdt_model_destroy(model: *mut vtx_gbdt_model_t);
}
extern "C" {
#[doc = " Load a GBDT model from a flat data array.\n\n The data array layout:\n [0] : init_score (double)\n [1] : tree_count (uint32_t cast to double)\n [2] : max_depth (uint32_t cast to double)\n [3..] : for each tree:\n node_count (uint32_t as double)\n then node_count * 5 doubles:\n feature_index, threshold, left_child, right_child, leaf_value\n\n @param model Model to load into\n @param data Flat array of doubles\n @param count Number of doubles in the data array\n @return 0 on success, -1 on failure"]
pub fn vtx_gbdt_load_model(
model: *mut vtx_gbdt_model_t,
data: *const f64,
count: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Load the default conservative model.\n This model uses 30 trees of depth 3 with simple heuristics:\n - Inline if callee is small (normalized size < 0.15)\n - Inline if receiver type is certain (> 0.8)\n - Inline if call frequency is high\n - Don't inline if call depth is too deep\n - Don't inline if callee deopt rate is high\n - Positive for constant arguments\n - Positive for hot callees\n - Negative for try/catch and virtual calls in some contexts\n\n The default model is always available and can be used until\n a real model is trained from production data.\n\n @param model Model to load into\n @return 0 on success, -1 on failure"]
pub fn vtx_gbdt_load_default_model(model: *mut vtx_gbdt_model_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Run GBDT inference on a feature vector.\n\n Traverses each tree from root to leaf, summing leaf values.\n Applies sigmoid transformation to produce output in [0, 1].\n\n @param model Trained GBDT model\n @param features Feature vector for a call site\n @return Score in [0, 1]. Above VTX_INLINE_THRESHOLD → inline."]
pub fn vtx_gbdt_infer(
model: *const vtx_gbdt_model_t,
features: *const vtx_inline_features_t,
) -> f64;
}
pub type vtx_callee_lookup_fn = ::std::option::Option<
unsafe extern "C" fn(
method_index: u32,
context: *mut ::std::os::raw::c_void,
) -> *const vtx_graph_t,
>;
#[doc = " VORTEX ML Inliner — Inlining Transform\n\n Performs the actual inlining of a callee graph into a caller graph\n at a specific call site. The transform follows the Sea-of-Nodes\n inlining algorithm:\n\n 1. Clone the callee's SoN subgraph into the caller's node table\n 2. Replace Parameter nodes in the clone with the call's argument nodes\n 3. Replace Return nodes in the clone with Phi nodes merging into the caller\n 4. Thread the callee's memory chain into the caller's memory chain\n 5. Add FrameState at the inlined entry point for deoptimization\n 6. Run GVN on the inlined subgraph to eliminate redundancies\n\n The caller graph is modified in place. The callee graph is NOT modified.\n\n Important: After inlining, the caller may need DCE and re-scheduling.\n The transform does NOT run these passes automatically — the caller\n must schedule them."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_inline_result_t {
pub success: bool,
pub nodes_added: u32,
pub nodes_removed: u32,
pub phis_created: u32,
pub return_value_node: vtx_nodeid_t,
pub new_memory_node: vtx_nodeid_t,
}
#[doc = " Result of a chain inlining operation.\n Tracks the cumulative statistics across all levels of inlining."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_chain_inline_result_t {
pub chain_depth: u32,
pub cumulative_node_count: u32,
pub sites_inlined: u32,
pub budget_exhausted: bool,
pub depth_exhausted: bool,
}
extern "C" {
#[doc = " Inline a callee graph into a caller graph at a specific call site.\n\n @param caller_graph The caller's SoN graph (modified in place)\n @param call_node The call node (CallStatic/CallVirtual/CallInterface) NodeID\n @param callee_graph The callee's SoN graph (NOT modified, treated as read-only)\n @param arena Arena for temporary allocations during inlining\n @return Result structure indicating success/failure and metrics"]
pub fn vtx_inline_transform(
caller_graph: *mut vtx_graph_t,
call_node: vtx_nodeid_t,
callee_graph: *const vtx_graph_t,
arena: *mut vtx_arena_t,
) -> vtx_inline_result_t;
}
extern "C" {
#[doc = " Check whether a call node can be inlined.\n\n A call can be inlined if:\n - The call node exists and is not dead\n - The callee graph is non-empty\n - The callee is not too large (node count < VTX_INLINE_SIZE_LIMIT)\n - The inlining depth has not been exceeded\n - The call is not recursive (callee == caller)\n\n @param caller_graph The caller's SoN graph\n @param call_node The call node to check\n @param callee_graph The callee's SoN graph\n @param current_depth Current inlining depth\n @return true if the call can be inlined"]
pub fn vtx_inline_can_inline(
caller_graph: *const vtx_graph_t,
call_node: vtx_nodeid_t,
callee_graph: *const vtx_graph_t,
current_depth: u32,
) -> bool;
}
extern "C" {
#[doc = " Perform chain inlining for a hyper-stable call site.\n\n Recursively inlines the callee and scans the inlined subgraph for\n further hyper-stable call sites. The chain terminates when:\n (a) a call site is not hyper-stable\n (b) cumulative inlined size exceeds VTX_CHAIN_INLINE_BUDGET\n (c) chain depth exceeds VTX_MAX_CHAIN_DEPTH\n\n Each level receives a composite guard (from Proposal #2), so the total\n guard cost for a 4-deep chain is 4 compares regardless of argument count.\n\n @param graph The SoN graph (modified in place)\n @param call_node The initial call site NodeID to start chaining from\n @param type_feedback Type feedback for checking hyper-stability\n @param callee_lookup Function to look up callee graphs by method_index\n @param lookup_context Context for callee_lookup\n @param arena Arena for temporary allocations\n @return Chain inline result with depth and statistics"]
pub fn vtx_inline_chain(
graph: *mut vtx_graph_t,
call_node: vtx_nodeid_t,
type_feedback: *const vtx_type_feedback_t,
callee_lookup: vtx_callee_lookup_fn,
lookup_context: *mut ::std::os::raw::c_void,
arena: *mut vtx_arena_t,
) -> vtx_chain_inline_result_t;
}
pub const vtx_loop_vectorize_t_VTX_LOOP_CANT_VECTORIZE: vtx_loop_vectorize_t = 0;
pub const vtx_loop_vectorize_t_VTX_LOOP_MAYBE_VECTORIZE: vtx_loop_vectorize_t = 1;
pub const vtx_loop_vectorize_t_VTX_LOOP_CAN_VECTORIZE_SSE2: vtx_loop_vectorize_t = 2;
pub const vtx_loop_vectorize_t_VTX_LOOP_CAN_VECTORIZE_AVX2: vtx_loop_vectorize_t = 3;
pub type vtx_loop_vectorize_t = ::std::os::raw::c_uint;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_loop_spec_result_t {
pub vectorizability: vtx_loop_vectorize_t,
pub mean_trip_count: f64,
pub cv_trip_count: f64,
pub profiled_iterations: u64,
pub has_loop_carried_dep: bool,
pub has_aliased_access: bool,
pub has_unknown_call: bool,
pub is_stride1: bool,
pub stride: u32,
pub element_size: u32,
pub tbaa_proves_no_alias: bool,
pub needs_xor_checksum_guard: bool,
pub xor_checksum_expected: u64,
pub vector_width: u32,
pub peel_count: u32,
}
impl Default for vtx_loop_spec_result_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_sota_loop_spec_t {
pub loops_checked: u32,
pub loops_vectorized: u32,
pub vectorization_attempts_failed: u32,
}
extern "C" {
#[doc = " Initialize the loop speculation module."]
pub fn vtx_sota_loop_spec_init(spec: *mut vtx_sota_loop_spec_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the loop speculation module."]
pub fn vtx_sota_loop_spec_destroy(spec: *mut vtx_sota_loop_spec_t);
}
extern "C" {
#[doc = " Check if a loop can be speculatively vectorized.\n\n Analyzes the loop body for:\n - Predictable trip count (from profile data)\n - Stride-1 access pattern\n - No loop-carried dependencies\n - No aliasing between array accesses\n - No calls to unknown functions\n\n @param spec Loop spec module\n @param profile Global profile data (for trip count statistics)\n @param graph The SoN graph\n @param loop_node The LoopBegin node ID\n @return Analysis result with vectorizability and parameters"]
pub fn vtx_sota_loop_spec_check(
spec: *mut vtx_sota_loop_spec_t,
profile: *const vtx_profile_global_t,
graph: *const vtx_graph_t,
loop_node: vtx_nodeid_t,
) -> vtx_loop_spec_result_t;
}
extern "C" {
#[doc = " Transform a loop by emitting speculative SIMD code.\n\n The transformation:\n 1. Computes the vector width based on CPU features and element size\n 2. Emits a pre-loop for alignment (peel iterations)\n 3. Emits the vectorized loop body with SIMD operations\n 4. Emits a post-loop for remaining iterations\n 5. Adds guards for: alignment, aliasing, trip count\n 6. On guard failure → deopt to the original scalar loop\n\n @param graph The SoN graph (modified in place)\n @param loop_node The LoopBegin node ID\n @param cpu_features CPU feature flags (VTX_CPU_SSE2, VTX_CPU_AVX2, etc.)\n @param spec_result Result from vtx_sota_loop_spec_check\n @param arena Arena for temporary allocations\n @return true if transformation was applied, false if not"]
pub fn vtx_sota_loop_spec_transform(
graph: *mut vtx_graph_t,
loop_node: vtx_nodeid_t,
cpu_features: u32,
spec_result: *const vtx_loop_spec_result_t,
arena: *mut vtx_arena_t,
) -> bool;
}
#[doc = " Result of a loop unrolling analysis."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_loop_unroll_result_t {
pub can_unroll: bool,
pub unroll_factor: u32,
pub constant_trip_count: u64,
pub requires_guard: bool,
}
extern "C" {
#[doc = " Check if a loop can be speculatively unrolled.\n\n A loop can be unrolled when:\n - The trip count is small and constant (from profiling)\n - The CV of trip counts is below VTX_LOOP_CV_THRESHOLD\n - The loop body is small enough that unrolling won't exceed\n VTX_MAX_NATIVE_SIZE\n\n Unrolling is beneficial when the loop overhead (branch, induction\n variable update) is significant relative to the loop body.\n\n @param spec Loop spec module\n @param profile Global profile data\n @param graph The SoN graph\n @param loop_node The LoopBegin node ID\n @return Unroll analysis result"]
pub fn vtx_sota_loop_unroll_check(
spec: *mut vtx_sota_loop_spec_t,
profile: *const vtx_profile_global_t,
graph: *const vtx_graph_t,
loop_node: vtx_nodeid_t,
) -> vtx_loop_unroll_result_t;
}
extern "C" {
#[doc = " Transform a loop by unrolling it with a trip count guard.\n\n The transformation:\n 1. Emits a DeoptGuard that the trip count equals the expected value\n 2. Copies the loop body N times (where N = unroll_factor)\n 3. Removes the loop back-edge (since the trip count is known)\n 4. On guard failure → deopt to the original loop\n\n @param graph The SoN graph (modified in place)\n @param loop_node The LoopBegin node ID\n @param unroll_result Result from vtx_sota_loop_unroll_check\n @param arena Arena for temporary allocations\n @return true if transformation was applied"]
pub fn vtx_sota_loop_unroll_transform(
graph: *mut vtx_graph_t,
loop_node: vtx_nodeid_t,
unroll_result: *const vtx_loop_unroll_result_t,
arena: *mut vtx_arena_t,
) -> bool;
}
extern "C" {
#[doc = " Compute the coefficient of variation from a set of trip count observations.\n CV = stddev / mean. A low CV (< VTX_LOOP_CV_THRESHOLD) indicates\n a predictable trip count.\n\n @param trip_counts Array of observed trip counts\n @param count Number of observations\n @return Coefficient of variation, or INFINITY if mean is 0"]
pub fn vtx_loop_cv(trip_counts: *const u64, count: u32) -> f64;
}
extern "C" {
#[doc = " Compute the vector width for a given element size and CPU features.\n Returns the number of elements that fit in one vector register.\n\n SSE2: 128 bits → 4 floats, 2 doubles, 4 int32, 2 int64\n AVX2: 256 bits → 8 floats, 4 doubles, 8 int32, 4 int64"]
pub fn vtx_loop_vector_width(element_size: u32, cpu_features: u32) -> u32;
}
extern "C" {
#[doc = " Detect the CPU features available at runtime.\n Uses CPUID on x86-64."]
pub fn vtx_cpu_detect_features() -> u32;
}
extern "C" {
#[doc = " Detect CPU features at runtime (alias for vtx_cpu_detect_features).\n Returns a bitmask with VTX_CPU_SSE2, VTX_CPU_AVX2, VTX_CPU_AVX512 set\n according to what the CPU supports.\n\n SSE2 is always available on x86-64 (baseline).\n AVX2 requires CPUID leaf 7, EBX bit 5."]
pub fn vtx_sota_loop_detect_cpu_features() -> u32;
}
#[doc = " VORTEX Mid-Tier (T1.5) — Type-Specialized Compilation\n\n Between the baseline T1 and the optimizing T2, the mid-tier provides\n type-specialized compilation with minimal analysis. This reduces warmup\n time by 3-5x compared to waiting for T2 compilation.\n\n Key differences from T1 (baseline):\n - Uses type feedback to specialize operations (e.g., \"this is always int\")\n - Eliminates type checks for monomorphic call sites\n - Inline caches are pre-populated from type feedback\n\n Key differences from T2 (optimizing):\n - No PEA / escape analysis / scalar replacement\n - No inlining of non-trivial methods\n - No LICM / bounds check elimination\n - Compilation is ~10x faster than T2"]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_midtier_config_t {
pub use_type_feedback: bool,
pub inline_max_size: u32,
pub specialize_arithmetic: bool,
pub methods_compiled: u32,
pub sites_specialized: u32,
pub guards_inserted: u32,
pub compilation_time_ns: u64,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_midtier_result_t {
pub code: *mut u8,
pub code_size: u32,
pub guards_inserted: u32,
pub sites_specialized: u32,
}
impl Default for vtx_midtier_result_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
pub fn vtx_midtier_config_default() -> vtx_midtier_config_t;
}
extern "C" {
pub fn vtx_midtier_compile(
method: *const vtx_method_desc_t,
type_feedback: *const vtx_type_feedback_t,
ts: *mut vtx_type_system_t,
arena: *mut vtx_arena_t,
) -> *mut vtx_midtier_result_t;
}
extern "C" {
#[doc = " Run profile-guided block layout on the schedule.\n\n Reorders blocks so that hot paths fall through (no branch needed)\n and cold paths are pushed to the end. Uses branch probability data\n from the profiler to decide which successor is \"hot\".\n\n @param schedule The schedule to reorder (modified in-place)\n @param graph The SoN graph (for looking up If node bytecode PCs)\n @param profiler Profiler data (may be NULL — falls back to heuristic)\n @param method Method descriptor (for profiler lookup)\n @return Number of blocks reordered (0 if no change)"]
pub fn vtx_block_layout_run(
schedule: *mut vtx_schedule_t,
graph: *const vtx_graph_t,
profiler: *const vtx_profiler_t,
method: *const vtx_method_desc_t,
) -> u32;
}
pub const vtx_x86_opcode_t_VTX_X86_NOP: vtx_x86_opcode_t = 0;
pub const vtx_x86_opcode_t_VTX_X86_ADD: vtx_x86_opcode_t = 1;
pub const vtx_x86_opcode_t_VTX_X86_SUB: vtx_x86_opcode_t = 2;
pub const vtx_x86_opcode_t_VTX_X86_IMUL: vtx_x86_opcode_t = 3;
pub const vtx_x86_opcode_t_VTX_X86_IDIV: vtx_x86_opcode_t = 4;
pub const vtx_x86_opcode_t_VTX_X86_MUL: vtx_x86_opcode_t = 5;
pub const vtx_x86_opcode_t_VTX_X86_IMUL_FULL: vtx_x86_opcode_t = 6;
pub const vtx_x86_opcode_t_VTX_X86_NEG: vtx_x86_opcode_t = 7;
pub const vtx_x86_opcode_t_VTX_X86_NOT: vtx_x86_opcode_t = 8;
pub const vtx_x86_opcode_t_VTX_X86_INC: vtx_x86_opcode_t = 9;
pub const vtx_x86_opcode_t_VTX_X86_DEC: vtx_x86_opcode_t = 10;
pub const vtx_x86_opcode_t_VTX_X86_SHL: vtx_x86_opcode_t = 11;
pub const vtx_x86_opcode_t_VTX_X86_SHR: vtx_x86_opcode_t = 12;
pub const vtx_x86_opcode_t_VTX_X86_SAR: vtx_x86_opcode_t = 13;
pub const vtx_x86_opcode_t_VTX_X86_ROL: vtx_x86_opcode_t = 14;
pub const vtx_x86_opcode_t_VTX_X86_ROR: vtx_x86_opcode_t = 15;
pub const vtx_x86_opcode_t_VTX_X86_AND: vtx_x86_opcode_t = 16;
pub const vtx_x86_opcode_t_VTX_X86_OR: vtx_x86_opcode_t = 17;
pub const vtx_x86_opcode_t_VTX_X86_XOR: vtx_x86_opcode_t = 18;
pub const vtx_x86_opcode_t_VTX_X86_CMP: vtx_x86_opcode_t = 19;
pub const vtx_x86_opcode_t_VTX_X86_TEST: vtx_x86_opcode_t = 20;
pub const vtx_x86_opcode_t_VTX_X86_MOV: vtx_x86_opcode_t = 21;
pub const vtx_x86_opcode_t_VTX_X86_MOVZX: vtx_x86_opcode_t = 22;
pub const vtx_x86_opcode_t_VTX_X86_MOVSX: vtx_x86_opcode_t = 23;
pub const vtx_x86_opcode_t_VTX_X86_CMOV: vtx_x86_opcode_t = 24;
pub const vtx_x86_opcode_t_VTX_X86_XCHG: vtx_x86_opcode_t = 25;
pub const vtx_x86_opcode_t_VTX_X86_LEA: vtx_x86_opcode_t = 26;
pub const vtx_x86_opcode_t_VTX_X86_CQO: vtx_x86_opcode_t = 27;
pub const vtx_x86_opcode_t_VTX_X86_CDQ: vtx_x86_opcode_t = 28;
pub const vtx_x86_opcode_t_VTX_X86_CDQE: vtx_x86_opcode_t = 29;
pub const vtx_x86_opcode_t_VTX_X86_SETCC: vtx_x86_opcode_t = 30;
pub const vtx_x86_opcode_t_VTX_X86_BSWAP: vtx_x86_opcode_t = 31;
pub const vtx_x86_opcode_t_VTX_X86_BSF: vtx_x86_opcode_t = 32;
pub const vtx_x86_opcode_t_VTX_X86_BSR: vtx_x86_opcode_t = 33;
pub const vtx_x86_opcode_t_VTX_X86_POPCNT: vtx_x86_opcode_t = 34;
pub const vtx_x86_opcode_t_VTX_X86_BT: vtx_x86_opcode_t = 35;
pub const vtx_x86_opcode_t_VTX_X86_PUSH: vtx_x86_opcode_t = 36;
pub const vtx_x86_opcode_t_VTX_X86_POP: vtx_x86_opcode_t = 37;
pub const vtx_x86_opcode_t_VTX_X86_JMP: vtx_x86_opcode_t = 38;
pub const vtx_x86_opcode_t_VTX_X86_JCC: vtx_x86_opcode_t = 39;
pub const vtx_x86_opcode_t_VTX_X86_CALL: vtx_x86_opcode_t = 40;
pub const vtx_x86_opcode_t_VTX_X86_RET: vtx_x86_opcode_t = 41;
pub const vtx_x86_opcode_t_VTX_X86_LAHF: vtx_x86_opcode_t = 42;
pub const vtx_x86_opcode_t_VTX_X86_SAHF: vtx_x86_opcode_t = 43;
pub const vtx_x86_opcode_t_VTX_X86_UCOMISD: vtx_x86_opcode_t = 44;
pub const vtx_x86_opcode_t_VTX_X86_COMISD: vtx_x86_opcode_t = 45;
pub const vtx_x86_opcode_t_VTX_X86_ADDSD: vtx_x86_opcode_t = 46;
pub const vtx_x86_opcode_t_VTX_X86_SUBSD: vtx_x86_opcode_t = 47;
pub const vtx_x86_opcode_t_VTX_X86_MULSD: vtx_x86_opcode_t = 48;
pub const vtx_x86_opcode_t_VTX_X86_DIVSD: vtx_x86_opcode_t = 49;
pub const vtx_x86_opcode_t_VTX_X86_SQRTSD: vtx_x86_opcode_t = 50;
pub const vtx_x86_opcode_t_VTX_X86_XORPS: vtx_x86_opcode_t = 51;
pub const vtx_x86_opcode_t_VTX_X86_MOVSD: vtx_x86_opcode_t = 52;
pub const vtx_x86_opcode_t_VTX_X86_MOVSD_LOAD: vtx_x86_opcode_t = 53;
pub const vtx_x86_opcode_t_VTX_X86_MOVSD_STORE: vtx_x86_opcode_t = 54;
pub const vtx_x86_opcode_t_VTX_X86_CVTSI2SD: vtx_x86_opcode_t = 55;
pub const vtx_x86_opcode_t_VTX_X86_CVTSD2SI: vtx_x86_opcode_t = 56;
pub const vtx_x86_opcode_t_VTX_X86_CVTTSD2SI: vtx_x86_opcode_t = 57;
pub const vtx_x86_opcode_t_VTX_X86_CVTSI2SS: vtx_x86_opcode_t = 58;
pub const vtx_x86_opcode_t_VTX_X86_CVTSS2SI: vtx_x86_opcode_t = 59;
pub const vtx_x86_opcode_t_VTX_X86_CVTTSS2SI: vtx_x86_opcode_t = 60;
pub const vtx_x86_opcode_t_VTX_X86_MOVQ_XMM_R64: vtx_x86_opcode_t = 61;
pub const vtx_x86_opcode_t_VTX_X86_MOVQ_R64_XMM: vtx_x86_opcode_t = 62;
pub const vtx_x86_opcode_t_VTX_X86_SAFEPOINT_POLL: vtx_x86_opcode_t = 63;
pub const vtx_x86_opcode_t_VTX_X86_SAFEPOINT_POLL_GUARD_PAGE: vtx_x86_opcode_t = 64;
pub const vtx_x86_opcode_t_VTX_X86_MOVAPD: vtx_x86_opcode_t = 65;
pub const vtx_x86_opcode_t_VTX_X86_ADDPD: vtx_x86_opcode_t = 66;
pub const vtx_x86_opcode_t_VTX_X86_MULPD: vtx_x86_opcode_t = 67;
pub const vtx_x86_opcode_t_VTX_X86_MINPD: vtx_x86_opcode_t = 68;
pub const vtx_x86_opcode_t_VTX_X86_MAXPD: vtx_x86_opcode_t = 69;
pub const vtx_x86_opcode_t_VTX_X86_ANDPD: vtx_x86_opcode_t = 70;
pub const vtx_x86_opcode_t_VTX_X86_XORPD: vtx_x86_opcode_t = 71;
pub const vtx_x86_opcode_t_VTX_X86_SUBPD: vtx_x86_opcode_t = 72;
pub const vtx_x86_opcode_t_VTX_X86_DIVPD: vtx_x86_opcode_t = 73;
pub const vtx_x86_opcode_t_VTX_X86_MOVDQA: vtx_x86_opcode_t = 74;
pub const vtx_x86_opcode_t_VTX_X86_MOVDQU: vtx_x86_opcode_t = 75;
pub const vtx_x86_opcode_t_VTX_X86_PADDD: vtx_x86_opcode_t = 76;
pub const vtx_x86_opcode_t_VTX_X86_PSUBD: vtx_x86_opcode_t = 77;
pub const vtx_x86_opcode_t_VTX_X86_PMULLD: vtx_x86_opcode_t = 78;
pub const vtx_x86_opcode_t_VTX_X86_PXOR: vtx_x86_opcode_t = 79;
pub const vtx_x86_opcode_t_VTX_X86_PAND: vtx_x86_opcode_t = 80;
pub const vtx_x86_opcode_t_VTX_X86_POR: vtx_x86_opcode_t = 81;
pub const vtx_x86_opcode_t_VTX_X86_PCMPEQD: vtx_x86_opcode_t = 82;
pub const vtx_x86_opcode_t_VTX_X86_MOVAPS: vtx_x86_opcode_t = 83;
pub const vtx_x86_opcode_t_VTX_X86_ADDPS: vtx_x86_opcode_t = 84;
pub const vtx_x86_opcode_t_VTX_X86_MULPS: vtx_x86_opcode_t = 85;
pub const vtx_x86_opcode_t_VTX_X86_SUBPS: vtx_x86_opcode_t = 86;
pub const vtx_x86_opcode_t_VTX_X86_DIVPS: vtx_x86_opcode_t = 87;
pub const vtx_x86_opcode_t_VTX_X86_MINPS: vtx_x86_opcode_t = 88;
pub const vtx_x86_opcode_t_VTX_X86_MAXPS: vtx_x86_opcode_t = 89;
pub const vtx_x86_opcode_t_VTX_X86_CMPPS: vtx_x86_opcode_t = 90;
pub const vtx_x86_opcode_t_VTX_X86_ADDSS: vtx_x86_opcode_t = 91;
pub const vtx_x86_opcode_t_VTX_X86_SUBSS: vtx_x86_opcode_t = 92;
pub const vtx_x86_opcode_t_VTX_X86_MULSS: vtx_x86_opcode_t = 93;
pub const vtx_x86_opcode_t_VTX_X86_DIVSS: vtx_x86_opcode_t = 94;
pub const vtx_x86_opcode_t_VTX_X86_SQRTSS: vtx_x86_opcode_t = 95;
pub const vtx_x86_opcode_t_VTX_X86_UCOMISS: vtx_x86_opcode_t = 96;
pub const vtx_x86_opcode_t_VTX_X86_MOVSS: vtx_x86_opcode_t = 97;
pub const vtx_x86_opcode_t_VTX_X86_DIV: vtx_x86_opcode_t = 98;
pub const vtx_x86_opcode_t_VTX_X86_RDTSC: vtx_x86_opcode_t = 99;
pub const vtx_x86_opcode_t_VTX_X86_RDTSCP: vtx_x86_opcode_t = 100;
pub const vtx_x86_opcode_t_VTX_X86_CMPXCHG: vtx_x86_opcode_t = 101;
pub const vtx_x86_opcode_t_VTX_X86_XADD: vtx_x86_opcode_t = 102;
pub const vtx_x86_opcode_t_VTX_X86_LFENCE: vtx_x86_opcode_t = 103;
pub const vtx_x86_opcode_t_VTX_X86_MFENCE: vtx_x86_opcode_t = 104;
pub const vtx_x86_opcode_t_VTX_X86_SFENCE: vtx_x86_opcode_t = 105;
pub const vtx_x86_opcode_t_VTX_X86_ROUNDSD: vtx_x86_opcode_t = 106;
pub const vtx_x86_opcode_t_VTX_X86_ROUNDSS: vtx_x86_opcode_t = 107;
pub const vtx_x86_opcode_t_VTX_X86_MOVSD_RIP: vtx_x86_opcode_t = 108;
pub const vtx_x86_opcode_t_VTX_X86_VMOVAPD_256: vtx_x86_opcode_t = 109;
pub const vtx_x86_opcode_t_VTX_X86_VADDPD_256: vtx_x86_opcode_t = 110;
pub const vtx_x86_opcode_t_VTX_X86_VSUBPD_256: vtx_x86_opcode_t = 111;
pub const vtx_x86_opcode_t_VTX_X86_VMULPD_256: vtx_x86_opcode_t = 112;
pub const vtx_x86_opcode_t_VTX_X86_VDIVPD_256: vtx_x86_opcode_t = 113;
pub const vtx_x86_opcode_t_VTX_X86_VMINPD_256: vtx_x86_opcode_t = 114;
pub const vtx_x86_opcode_t_VTX_X86_VMAXPD_256: vtx_x86_opcode_t = 115;
pub const vtx_x86_opcode_t_VTX_X86_VXORPD_256: vtx_x86_opcode_t = 116;
pub const vtx_x86_opcode_t_VTX_X86_VANDPD_256: vtx_x86_opcode_t = 117;
pub const vtx_x86_opcode_t_VTX_X86_VCMPPD_256: vtx_x86_opcode_t = 118;
pub const vtx_x86_opcode_t_VTX_X86_VMOVAPS_256: vtx_x86_opcode_t = 119;
pub const vtx_x86_opcode_t_VTX_X86_VADDPS_256: vtx_x86_opcode_t = 120;
pub const vtx_x86_opcode_t_VTX_X86_VSUBPS_256: vtx_x86_opcode_t = 121;
pub const vtx_x86_opcode_t_VTX_X86_VMULPS_256: vtx_x86_opcode_t = 122;
pub const vtx_x86_opcode_t_VTX_X86_VDIVPS_256: vtx_x86_opcode_t = 123;
pub const vtx_x86_opcode_t_VTX_X86_VMOVDQA_256: vtx_x86_opcode_t = 124;
pub const vtx_x86_opcode_t_VTX_X86_VPADDD_256: vtx_x86_opcode_t = 125;
pub const vtx_x86_opcode_t_VTX_X86_VPSUBD_256: vtx_x86_opcode_t = 126;
pub const vtx_x86_opcode_t_VTX_X86_VPMULLD_256: vtx_x86_opcode_t = 127;
pub const vtx_x86_opcode_t_VTX_X86_VPXOR_256: vtx_x86_opcode_t = 128;
pub const vtx_x86_opcode_t_VTX_X86_VPAND_256: vtx_x86_opcode_t = 129;
pub const vtx_x86_opcode_t_VTX_X86_VPOR_256: vtx_x86_opcode_t = 130;
pub const vtx_x86_opcode_t_VTX_X86_VZEROUPPER: vtx_x86_opcode_t = 131;
pub const vtx_x86_opcode_t_VTX_X86_VZEROALL: vtx_x86_opcode_t = 132;
pub const vtx_x86_opcode_t_VTX_X86_VBROADCASTSD: vtx_x86_opcode_t = 133;
pub const vtx_x86_opcode_t_VTX_X86_VBROADCASTSS: vtx_x86_opcode_t = 134;
pub const vtx_x86_opcode_t_VTX_X86_VPERM2F128: vtx_x86_opcode_t = 135;
pub const vtx_x86_opcode_t_VTX_X86_VINSERTF128: vtx_x86_opcode_t = 136;
pub const vtx_x86_opcode_t_VTX_X86_VEXTRACTF128: vtx_x86_opcode_t = 137;
pub const vtx_x86_opcode_t_VTX_X86_OPCODE_COUNT: vtx_x86_opcode_t = 138;
pub type vtx_x86_opcode_t = ::std::os::raw::c_uint;
pub const vtx_opnd_kind_t_VTX_OPND_NONE: vtx_opnd_kind_t = 0;
pub const vtx_opnd_kind_t_VTX_OPND_VREG: vtx_opnd_kind_t = 1;
pub const vtx_opnd_kind_t_VTX_OPND_PREG: vtx_opnd_kind_t = 2;
pub const vtx_opnd_kind_t_VTX_OPND_IMM: vtx_opnd_kind_t = 3;
pub const vtx_opnd_kind_t_VTX_OPND_MEM: vtx_opnd_kind_t = 4;
pub const vtx_opnd_kind_t_VTX_OPND_LABEL: vtx_opnd_kind_t = 5;
pub const vtx_opnd_kind_t_VTX_OPND_SPILL: vtx_opnd_kind_t = 6;
pub type vtx_opnd_kind_t = ::std::os::raw::c_uint;
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_x86_memop_t {
pub base_vreg: u32,
pub index_vreg: u32,
pub base_phys: u8,
pub index_phys: u8,
pub scale: u8,
pub disp: i32,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_inst_t {
pub opcode: vtx_x86_opcode_t,
pub opnd_kinds: [vtx_opnd_kind_t; 3usize],
pub operands: [u32; 3usize],
pub imm: i64,
pub mem: vtx_x86_memop_t,
pub cond: vtx_cond_t,
pub flags: u32,
pub source_node: vtx_nodeid_t,
pub native_offset: u32,
}
impl Default for vtx_inst_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_inst_block_t {
pub insts: *mut vtx_inst_t,
pub inst_count: u32,
pub inst_capacity: u32,
pub block_id: u32,
}
impl Default for vtx_inst_block_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_inst_stream_t {
pub blocks: *mut vtx_inst_block_t,
pub block_count: u32,
pub block_capacity: u32,
pub vreg_count: u32,
pub node_to_vreg: *mut u32,
pub node_to_vreg_count: u32,
pub vreg_fixed_reg: *mut u8,
pub vreg_fixed_reg_count: u32,
pub smi_scratch_vreg: u32,
pub smi_mask_vreg: u32,
pub uses_smi: bool,
pub schedule: *const vtx_schedule_t,
}
impl Default for vtx_inst_stream_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Select x86-64 instructions from the scheduled SoN graph.\n\n Walks each block in the schedule, mapping each SoN node to x86-64\n instructions. Value-producing nodes are assigned virtual registers.\n Guard/DeoptGuard nodes emit compare + conditional jump instructions.\n\n @param schedule The scheduled SoN graph\n @param arena Arena for allocations (node_to_vreg, blocks, instructions)\n @return Instruction stream, or NULL on failure"]
pub fn vtx_isel_select(
schedule: *const vtx_schedule_t,
graph: *const vtx_graph_t,
arena: *mut vtx_arena_t,
) -> *mut vtx_inst_stream_t;
}
extern "C" {
#[doc = " Get the virtual register assigned to a node.\n Returns VTX_VREG_INVALID if the node has no vreg."]
pub fn vtx_isel_node_vreg(stream: *const vtx_inst_stream_t, node_id: vtx_nodeid_t) -> u32;
}
extern "C" {
#[doc = " Allocate a new virtual register in the stream.\n Returns the new vreg id, or VTX_VREG_INVALID on failure."]
pub fn vtx_isel_alloc_vreg(stream: *mut vtx_inst_stream_t, arena: *mut vtx_arena_t) -> u32;
}
extern "C" {
#[doc = " Allocate a new virtual register fixed to a specific physical register.\n Returns the new vreg id, or VTX_VREG_INVALID on failure."]
pub fn vtx_isel_alloc_vreg_fixed(
stream: *mut vtx_inst_stream_t,
arena: *mut vtx_arena_t,
phys_reg: u8,
) -> u32;
}
extern "C" {
#[doc = " Map a node to a virtual register (overwriting any previous mapping)."]
pub fn vtx_isel_map_node_vreg(
stream: *mut vtx_inst_stream_t,
node_id: vtx_nodeid_t,
vreg: u32,
arena: *mut vtx_arena_t,
);
}
extern "C" {
#[doc = " Append an instruction to a block.\n Returns the instruction index, or UINT32_MAX on failure."]
pub fn vtx_isel_emit_inst(
block: *mut vtx_inst_block_t,
inst: vtx_inst_t,
arena: *mut vtx_arena_t,
) -> u32;
}
extern "C" {
#[doc = " Ensure a block has capacity for at least `needed` more instructions.\n Returns 0 on success, -1 on failure."]
pub fn vtx_isel_block_ensure_capacity(
block: *mut vtx_inst_block_t,
needed: u32,
arena: *mut vtx_arena_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Get the human-readable name for an x86 opcode."]
pub fn vtx_x86_opcode_name(opcode: vtx_x86_opcode_t) -> *const ::std::os::raw::c_char;
}
pub const vtx_reg_class_t_VTX_REG_CLASS_GPR: vtx_reg_class_t = 0;
pub const vtx_reg_class_t_VTX_REG_CLASS_XMM: vtx_reg_class_t = 1;
pub const vtx_reg_class_t_VTX_REG_CLASS_COUNT: vtx_reg_class_t = 2;
#[doc = " VORTEX Linear Scan Register Allocator\n\n Assigns physical registers to virtual registers using a linear scan\n algorithm. Computes live intervals for each virtual register, sorts\n by start point, and iteratively assigns physical registers.\n\n Register allocation policy:\n - Caller-saved first: RAX, RCX, RDX, RSI, RDI, R8-R11\n - Callee-saved next: RBX, R12-R15 (with save/restore)\n - RBP/RSP reserved (never assigned)\n - Spill slots at fixed offsets from RBP\n\n When no free register is available, the interval with the furthest\n end point is evicted (spilled)."]
pub type vtx_reg_class_t = ::std::os::raw::c_uint;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_live_range {
pub start: u32,
pub end: u32,
pub phys_reg: u8,
pub spill_slot: u32,
pub next: *mut vtx_live_range,
}
impl Default for vtx_live_range {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
pub type vtx_live_range_t = vtx_live_range;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_live_interval {
pub vreg: u32,
pub first_range: *mut vtx_live_range_t,
pub last_range: *mut vtx_live_range_t,
pub start: u32,
pub end: u32,
pub phys_reg: u8,
pub spill_slot: u32,
pub is_fixed: bool,
pub fixed_reg: u8,
pub is_spilled: bool,
pub is_remat: bool,
pub use_count: u32,
pub loop_depth: u32,
pub coalesce_src: u32,
pub reg_class: vtx_reg_class_t,
pub split_parent: *mut vtx_live_interval,
pub split_child: *mut vtx_live_interval,
}
impl Default for vtx_live_interval {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
pub type vtx_live_interval_t = vtx_live_interval;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_regalloc_result_t {
pub vreg_to_phys: *mut u8,
pub vreg_to_phys_count: u32,
pub vreg_to_spill: *mut u32,
pub vreg_to_spill_count: u32,
pub vreg_is_remat: *mut bool,
pub vreg_remat_imm: *mut i64,
pub vreg_remat_count: u32,
pub spill_count: u32,
pub callee_saved_mask: u32,
pub frame_size: u32,
pub interval_count: u32,
pub intervals: *mut vtx_live_interval_t,
pub is_leaf: bool,
}
impl Default for vtx_regalloc_result_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Run the linear scan register allocator on the instruction stream.\n\n Computes live intervals, assigns physical registers, and inserts\n spill/fill code as needed.\n\n @param stream The instruction stream (with virtual registers)\n @param arena Arena for allocations\n @return Register allocation result, or NULL on failure"]
pub fn vtx_regalloc_run(
stream: *mut vtx_inst_stream_t,
arena: *mut vtx_arena_t,
) -> *mut vtx_regalloc_result_t;
}
extern "C" {
#[doc = " Apply the register allocation result to the instruction stream.\n Replaces virtual register references with physical register references.\n Inserts spill/fill instructions where needed.\n\n @param stream The instruction stream to modify\n @param result The register allocation result\n @param arena Arena for new instructions\n @return 0 on success, -1 on failure"]
pub fn vtx_regalloc_apply(
stream: *mut vtx_inst_stream_t,
result: *const vtx_regalloc_result_t,
arena: *mut vtx_arena_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Get the physical register assigned to a virtual register.\n Returns 0xFF (VTX_REG_NONE) if not assigned."]
pub fn vtx_regalloc_phys_reg(result: *const vtx_regalloc_result_t, vreg: u32) -> u8;
}
extern "C" {
#[doc = " Get the spill slot assigned to a virtual register.\n Returns VTX_NO_SPILL if not spilled."]
pub fn vtx_regalloc_spill_slot(result: *const vtx_regalloc_result_t, vreg: u32) -> u32;
}
extern "C" {
#[doc = " Split a live interval at the given position.\n\n The interval is divided into two parts:\n - First half: [start, position) — keeps the current register assignment\n - Second half: [position, end) — becomes a new interval needing a register\n\n If the second half can get a free register, it does; otherwise it's spilled.\n At the split point, spill/reload code is inserted as needed.\n\n @param interval The interval to split (modified in place to become first half)\n @param position The split position (must be within the interval's range)\n @param arena Arena for allocations\n @return The new second-half interval, or NULL on failure"]
pub fn vtx_regalloc_split_interval(
interval: *mut vtx_live_interval_t,
position: u32,
arena: *mut vtx_arena_t,
) -> *mut vtx_live_interval_t;
}
extern "C" {
#[doc = " Find the NodeID that is currently in a given physical register at a\n given instruction position.\n\n Uses the register allocator's live interval data to determine which\n vreg (and thus which SoN node) occupies the physical register at\n the specified instruction position.\n\n @param result Register allocation result\n @param stream Instruction stream (for vreg → NodeID reverse mapping)\n @param position Instruction position (sequential instruction index)\n @param phys_reg Physical register number to look up\n @return NodeID occupying the register, or VTX_NODEID_INVALID"]
pub fn vtx_regalloc_node_at_position(
result: *const vtx_regalloc_result_t,
stream: *const vtx_inst_stream_t,
position: u32,
phys_reg: u8,
) -> vtx_nodeid_t;
}
extern "C" {
#[doc = " Get the set of physical registers that are live at a given instruction\n position, along with their defining NodeIDs.\n\n @param result Register allocation result\n @param position Instruction position (sequential instruction index)\n @param out_regs Output array of physical register numbers (caller-allocated)\n @param out_nodeids Output array of NodeIDs (caller-allocated, parallel to out_regs)\n @param max_entries Maximum number of entries the output arrays can hold\n @return Number of live register entries written"]
pub fn vtx_regalloc_live_regs_at_position(
result: *const vtx_regalloc_result_t,
position: u32,
out_regs: *mut u8,
out_nodeids: *mut vtx_nodeid_t,
max_entries: u32,
) -> u32;
}
extern "C" {
#[doc = " Split live intervals at loop boundaries.\n\n Audit priority #5: \"Split live ranges at loop boundaries.\"\n\n When a live interval spans a loop boundary (enters or exits a loop),\n splitting it at the boundary allows the loop body to use a different\n register than the loop preheader/postheader. This reduces register\n pressure inside the loop, which is where it matters most.\n\n This function scans all live intervals and splits any that cross a\n loop boundary. The loop boundaries are determined from the schedule's\n loop header information.\n\n @param result Register allocation result (intervals will be modified)\n @param stream Instruction stream (for loop boundary positions)\n @param arena Arena for new interval allocations\n @return Number of intervals split"]
pub fn vtx_regalloc_split_at_loop_boundaries(
result: *mut vtx_regalloc_result_t,
stream: *const vtx_inst_stream_t,
arena: *mut vtx_arena_t,
) -> u32;
}
extern "C" {
#[doc = " Check if a vreg is a candidate for rematerialization.\n\n Audit priority #5: \"Rematerialization of constants instead of spilling.\"\n\n Instead of spilling a value to memory and reloading it, we can\n sometimes just recompute it. This is cheaper for:\n - Constants: `mov reg, imm` is 1 instruction, vs. spill+reload = 2+\n - Simple arithmetic: `lea reg, [base+disp]` is 1 instruction\n\n This function checks if the vreg's defining instruction is a simple\n constant load or LEA that can be rematerialized.\n\n @param stream Instruction stream\n @param vreg Virtual register to check\n @return true if the vreg can be rematerialized"]
pub fn vtx_regalloc_can_rematerialize(stream: *const vtx_inst_stream_t, vreg: u32) -> bool;
}
extern "C" {
#[doc = " Get the rematerialization cost for a vreg.\n\n Returns the number of instructions needed to rematerialize the value.\n Lower is better. Returns UINT32_MAX if rematerialization is not possible.\n\n @param stream Instruction stream\n @param vreg Virtual register to check\n @return Instruction count, or UINT32_MAX"]
pub fn vtx_regalloc_rematerialize_cost(stream: *const vtx_inst_stream_t, vreg: u32) -> u32;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_x86_emit_t {
pub buffer: *mut u8,
pub position: u32,
pub capacity: u32,
pub relocs: *mut vtx_reloc_table_t,
pub reloc_arena: *mut vtx_arena_t,
pub label_offsets: *mut u32,
pub label_count: u32,
pub const_pool: vtx_x86_emit_t__bindgen_ty_1,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_x86_emit_t__bindgen_ty_1 {
pub values: *mut u64,
pub ref_offsets: *mut u32,
pub count: u32,
pub capacity: u32,
}
impl Default for vtx_x86_emit_t__bindgen_ty_1 {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
impl Default for vtx_x86_emit_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the emitter with an initial buffer capacity.\n Returns 0 on success, -1 on failure."]
pub fn vtx_x86_emit_init(
emit: *mut vtx_x86_emit_t,
initial_capacity: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the emitter and free the code buffer."]
pub fn vtx_x86_emit_destroy(emit: *mut vtx_x86_emit_t);
}
extern "C" {
#[doc = " Ensure the buffer has at least `needed` bytes of free space.\n Returns 0 on success, -1 on failure."]
pub fn vtx_x86_emit_ensure(emit: *mut vtx_x86_emit_t, needed: u32) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Emit a REX.W + opcode + ModR/M for register-register instructions.\n For example: add r64, r64 → REX.W 01 ModR/M\n @param e Emitter\n @param opcode Primary opcode byte\n @param opcode2 Secondary opcode byte (0 = none, e.g. 0F prefix)\n @param reg Destination or source register (goes in reg field)\n @param rm Source or destination register (goes in r/m field)\n @param direction 0=reg is r/m, rm is reg (opcode /r); 1=reg is reg, rm is r/m"]
pub fn vtx_x86_emit_rr(e: *mut vtx_x86_emit_t, opcode: u8, opcode2: u8, reg: u8, rm: u8);
}
extern "C" {
#[doc = " Emit a REX.W + opcode + ModR/M for register-immediate instructions.\n The immediate is sign-extended from 32 bits to 64 bits.\n @param e Emitter\n @param opcode Primary opcode byte (e.g. 81 for imm32, 83 for imm8)\n @param reg_ext Opcode extension in ModR/M reg field (e.g. 0=ADD, 5=SUB)\n @param rm Target register\n @param imm Immediate value\n @param imm_size 4 for imm32, 1 for imm8"]
pub fn vtx_x86_emit_ri(
e: *mut vtx_x86_emit_t,
opcode: u8,
reg_ext: u8,
rm: u8,
imm: i64,
imm_size: ::std::os::raw::c_int,
);
}
extern "C" {
#[doc = " Emit a REX.W + opcode + ModR/M for register-memory instructions.\n Memory is [base + disp].\n @param e Emitter\n @param opcode Primary opcode byte\n @param opcode2 Secondary opcode byte (0 = none)\n @param reg Register operand\n @param base Base register\n @param disp Displacement\n @param is_load true=load (reg ← mem), false=store (mem ← reg)"]
pub fn vtx_x86_emit_rm(
e: *mut vtx_x86_emit_t,
opcode: u8,
opcode2: u8,
reg: u8,
base: u8,
disp: i32,
is_load: bool,
);
}
extern "C" {
#[doc = " Emit a REX.W + opcode + ModR/M + SIB for [base + index*scale + disp].\n @param e Emitter\n @param opcode Primary opcode byte\n @param opcode2 Secondary opcode byte (0 = none)\n @param reg Register operand\n @param base Base register\n @param index Index register\n @param scale Scale (1, 2, 4, 8)\n @param disp Displacement\n @param is_load true=load (reg ← mem), false=store (mem ← reg)"]
pub fn vtx_x86_emit_sib_mem(
e: *mut vtx_x86_emit_t,
opcode: u8,
opcode2: u8,
reg: u8,
base: u8,
index: u8,
scale: u8,
disp: i32,
is_load: bool,
);
}
extern "C" {
#[doc = " Emit mov r64, imm64 (movabs). Uses the B8+rd encoding with REX.W."]
pub fn vtx_x86_emit_mov_imm64(e: *mut vtx_x86_emit_t, reg: u8, imm: u64);
}
extern "C" {
#[doc = " Emit mov r/m64, imm32 (sign-extended to 64 bits).\n Uses C7 /0 encoding with REX.W."]
pub fn vtx_x86_emit_mov_imm32(e: *mut vtx_x86_emit_t, reg: u8, imm: i32);
}
extern "C" {
pub fn vtx_x86_emit_add_rr(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_add_ri(e: *mut vtx_x86_emit_t, dst: u8, imm: i32);
}
extern "C" {
pub fn vtx_x86_emit_sub_rr(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_sub_ri(e: *mut vtx_x86_emit_t, dst: u8, imm: i32);
}
extern "C" {
pub fn vtx_x86_emit_imul_rr(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_imul_ri(e: *mut vtx_x86_emit_t, dst: u8, imm: i32);
}
extern "C" {
pub fn vtx_x86_emit_idiv_r(e: *mut vtx_x86_emit_t, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_imul_full_r(e: *mut vtx_x86_emit_t, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_shl_ri(e: *mut vtx_x86_emit_t, dst: u8, count: u8);
}
extern "C" {
pub fn vtx_x86_emit_shl_cl(e: *mut vtx_x86_emit_t, dst: u8);
}
extern "C" {
pub fn vtx_x86_emit_shr_ri(e: *mut vtx_x86_emit_t, dst: u8, count: u8);
}
extern "C" {
pub fn vtx_x86_emit_shr_cl(e: *mut vtx_x86_emit_t, dst: u8);
}
extern "C" {
pub fn vtx_x86_emit_sar_ri(e: *mut vtx_x86_emit_t, dst: u8, count: u8);
}
extern "C" {
pub fn vtx_x86_emit_sar_cl(e: *mut vtx_x86_emit_t, dst: u8);
}
extern "C" {
pub fn vtx_x86_emit_and_rr(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_and_ri(e: *mut vtx_x86_emit_t, dst: u8, imm: i32);
}
extern "C" {
pub fn vtx_x86_emit_or_rr(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_or_ri(e: *mut vtx_x86_emit_t, dst: u8, imm: i32);
}
extern "C" {
pub fn vtx_x86_emit_xor_rr(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_xor_ri(e: *mut vtx_x86_emit_t, dst: u8, imm: i32);
}
extern "C" {
pub fn vtx_x86_emit_cmp_rr(e: *mut vtx_x86_emit_t, a: u8, b: u8);
}
extern "C" {
pub fn vtx_x86_emit_cmp_ri(e: *mut vtx_x86_emit_t, reg: u8, imm: i32);
}
extern "C" {
pub fn vtx_x86_emit_test_rr(e: *mut vtx_x86_emit_t, a: u8, b: u8);
}
extern "C" {
pub fn vtx_x86_emit_test_ri(e: *mut vtx_x86_emit_t, reg: u8, imm: i32);
}
extern "C" {
pub fn vtx_x86_emit_mov_rr(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_mov_rmem(e: *mut vtx_x86_emit_t, dst: u8, base: u8, disp: i32);
}
extern "C" {
pub fn vtx_x86_emit_mov_memr(e: *mut vtx_x86_emit_t, base: u8, disp: i32, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_lea_rmem(e: *mut vtx_x86_emit_t, dst: u8, base: u8, disp: i32);
}
extern "C" {
pub fn vtx_x86_emit_neg_r(e: *mut vtx_x86_emit_t, reg: u8);
}
extern "C" {
pub fn vtx_x86_emit_not_r(e: *mut vtx_x86_emit_t, reg: u8);
}
extern "C" {
pub fn vtx_x86_emit_cqo(e: *mut vtx_x86_emit_t);
}
extern "C" {
pub fn vtx_x86_emit_setcc(e: *mut vtx_x86_emit_t, cond: u8, reg: u8);
}
extern "C" {
pub fn vtx_x86_emit_cmovcc(e: *mut vtx_x86_emit_t, cond: u8, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_push_r(e: *mut vtx_x86_emit_t, reg: u8);
}
extern "C" {
pub fn vtx_x86_emit_pop_r(e: *mut vtx_x86_emit_t, reg: u8);
}
extern "C" {
pub fn vtx_x86_emit_jmp_rel32(e: *mut vtx_x86_emit_t, offset: i32);
}
extern "C" {
pub fn vtx_x86_emit_jcc_rel32(e: *mut vtx_x86_emit_t, cond: u8, offset: i32);
}
extern "C" {
pub fn vtx_x86_emit_call_rel32(e: *mut vtx_x86_emit_t, offset: i32);
}
extern "C" {
pub fn vtx_x86_emit_ret(e: *mut vtx_x86_emit_t);
}
extern "C" {
pub fn vtx_x86_emit_nop(e: *mut vtx_x86_emit_t);
}
extern "C" {
#[doc = " Emit UCOMISD xmm, xmm — unordered compare scalar double.\n Sets EFLAGS for floating-point comparison."]
pub fn vtx_x86_emit_ucomisd(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
#[doc = " Emit ADDSD xmm, xmm — scalar double-precision add.\n Encoding: F2 0F 58 /r"]
pub fn vtx_x86_emit_addsd(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
#[doc = " Emit SUBSD xmm, xmm — scalar double-precision subtract.\n Encoding: F2 0F 5C /r"]
pub fn vtx_x86_emit_subsd(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
#[doc = " Emit MULSD xmm, xmm — scalar double-precision multiply.\n Encoding: F2 0F 59 /r"]
pub fn vtx_x86_emit_mulsd(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
#[doc = " Emit DIVSD xmm, xmm — scalar double-precision divide.\n Encoding: F2 0F 5E /r"]
pub fn vtx_x86_emit_divsd(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
#[doc = " Emit XORPS xmm, xmm — bitwise XOR of 128-bit operands.\n Used for float negation by XORing with a sign-bit mask.\n Encoding: 0F 57 /r"]
pub fn vtx_x86_emit_xorps(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
#[doc = " Emit MOVSD xmm, xmm — move scalar double between XMM registers.\n Encoding: F2 0F 10 /r (load) or F2 0F 11 /r (store).\n For reg-reg move: F2 0F 10 ModR/M(mod=11)"]
pub fn vtx_x86_emit_movsd(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_addss(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_subss(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_mulss(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_divss(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_sqrtss(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_ucomiss(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_movss(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_cvtsi2sd(e: *mut vtx_x86_emit_t, dst_xmm: u8, src_gpr: u8);
}
extern "C" {
pub fn vtx_x86_emit_cvtsd2si(e: *mut vtx_x86_emit_t, dst_gpr: u8, src_xmm: u8);
}
extern "C" {
pub fn vtx_x86_emit_cvttsd2si(e: *mut vtx_x86_emit_t, dst_gpr: u8, src_xmm: u8);
}
extern "C" {
pub fn vtx_x86_emit_cvtsi2ss(e: *mut vtx_x86_emit_t, dst_xmm: u8, src_gpr: u8);
}
extern "C" {
pub fn vtx_x86_emit_cvtss2si(e: *mut vtx_x86_emit_t, dst_gpr: u8, src_xmm: u8);
}
extern "C" {
pub fn vtx_x86_emit_cvttss2si(e: *mut vtx_x86_emit_t, dst_gpr: u8, src_xmm: u8);
}
extern "C" {
pub fn vtx_x86_emit_movq_xmm_r64(e: *mut vtx_x86_emit_t, dst_xmm: u8, src_gpr: u8);
}
extern "C" {
pub fn vtx_x86_emit_movq_r64_xmm(e: *mut vtx_x86_emit_t, dst_gpr: u8, src_xmm: u8);
}
extern "C" {
pub fn vtx_x86_emit_comisd(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_sqrtsd(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_movsd_load(e: *mut vtx_x86_emit_t, dst_xmm: u8, base: u8, disp: i32);
}
extern "C" {
pub fn vtx_x86_emit_movsd_store(e: *mut vtx_x86_emit_t, base: u8, disp: i32, src_xmm: u8);
}
extern "C" {
pub fn vtx_x86_emit_bswap(e: *mut vtx_x86_emit_t, reg: u8);
}
extern "C" {
pub fn vtx_x86_emit_bsf(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_bsr(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_popcnt(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_rol_ri(e: *mut vtx_x86_emit_t, dst: u8, count: u8);
}
extern "C" {
pub fn vtx_x86_emit_rol_cl(e: *mut vtx_x86_emit_t, dst: u8);
}
extern "C" {
pub fn vtx_x86_emit_ror_ri(e: *mut vtx_x86_emit_t, dst: u8, count: u8);
}
extern "C" {
pub fn vtx_x86_emit_ror_cl(e: *mut vtx_x86_emit_t, dst: u8);
}
extern "C" {
pub fn vtx_x86_emit_cdqe(e: *mut vtx_x86_emit_t);
}
extern "C" {
pub fn vtx_x86_emit_div_r(e: *mut vtx_x86_emit_t, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_rdtsc(e: *mut vtx_x86_emit_t);
}
extern "C" {
pub fn vtx_x86_emit_rdtscp(e: *mut vtx_x86_emit_t);
}
extern "C" {
pub fn vtx_x86_emit_cmpxchg(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_xadd(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_lfence(e: *mut vtx_x86_emit_t);
}
extern "C" {
pub fn vtx_x86_emit_mfence(e: *mut vtx_x86_emit_t);
}
extern "C" {
pub fn vtx_x86_emit_sfence(e: *mut vtx_x86_emit_t);
}
extern "C" {
pub fn vtx_x86_emit_roundsd(e: *mut vtx_x86_emit_t, dst: u8, src: u8, mode: u8);
}
extern "C" {
pub fn vtx_x86_emit_roundss(e: *mut vtx_x86_emit_t, dst: u8, src: u8, mode: u8);
}
extern "C" {
pub fn vtx_x86_emit_movsd_rip(e: *mut vtx_x86_emit_t, dst_xmm: u8, double_bits: u64);
}
extern "C" {
pub fn vtx_x86_emit_vmovapd_256(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_vaddpd_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8);
}
extern "C" {
pub fn vtx_x86_emit_vsubpd_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8);
}
extern "C" {
pub fn vtx_x86_emit_vmulpd_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8);
}
extern "C" {
pub fn vtx_x86_emit_vdivpd_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8);
}
extern "C" {
pub fn vtx_x86_emit_vminpd_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8);
}
extern "C" {
pub fn vtx_x86_emit_vmaxpd_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8);
}
extern "C" {
pub fn vtx_x86_emit_vxorpd_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8);
}
extern "C" {
pub fn vtx_x86_emit_vandpd_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8);
}
extern "C" {
pub fn vtx_x86_emit_vcmppd_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8, pred: u8);
}
extern "C" {
pub fn vtx_x86_emit_vmovaps_256(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_vaddps_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8);
}
extern "C" {
pub fn vtx_x86_emit_vsubps_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8);
}
extern "C" {
pub fn vtx_x86_emit_vmulps_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8);
}
extern "C" {
pub fn vtx_x86_emit_vdivps_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8);
}
extern "C" {
pub fn vtx_x86_emit_vmovdqa_256(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_vpaddd_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8);
}
extern "C" {
pub fn vtx_x86_emit_vpsubd_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8);
}
extern "C" {
pub fn vtx_x86_emit_vpmulld_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8);
}
extern "C" {
pub fn vtx_x86_emit_vpxor_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8);
}
extern "C" {
pub fn vtx_x86_emit_vpand_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8);
}
extern "C" {
pub fn vtx_x86_emit_vpor_256(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8);
}
extern "C" {
pub fn vtx_x86_emit_vzeroupper(e: *mut vtx_x86_emit_t);
}
extern "C" {
pub fn vtx_x86_emit_vzeroall(e: *mut vtx_x86_emit_t);
}
extern "C" {
pub fn vtx_x86_emit_vbroadcastsd(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_vbroadcastss(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_vperm2f128(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8, ctrl: u8);
}
extern "C" {
pub fn vtx_x86_emit_vinsertf128(e: *mut vtx_x86_emit_t, dst: u8, src1: u8, src2: u8, imm8: u8);
}
extern "C" {
pub fn vtx_x86_emit_vextractf128(e: *mut vtx_x86_emit_t, dst: u8, src: u8, imm8: u8);
}
extern "C" {
pub fn vtx_x86_emit_subpd(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_divpd(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_movdqa(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_movdqu(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_paddd(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_psubd(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_pmulld(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_pxor(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_pand(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_por(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_pcmpeqd(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_movaps(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_addps(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_mulps(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_subps(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_divps(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_minps(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_maxps(e: *mut vtx_x86_emit_t, dst: u8, src: u8);
}
extern "C" {
pub fn vtx_x86_emit_cmpps(e: *mut vtx_x86_emit_t, dst: u8, src: u8, pred: u8);
}
extern "C" {
#[doc = " Emit safepoint poll at a loop back-edge.\n Emits:\n cmpq [vtx_safepoint_flag], 0 (RIP-relative, 8 bytes)\n jne deopt_stub (rel32, 6 bytes)\n\n The CMP uses RIP-relative addressing to access the global\n vtx_safepoint_flag. A VTX_RELOC_RIP_REL32 external relocation is\n recorded so the displacement is patched at code install time.\n\n The JNE has its displacement set to 0 (placeholder). It is marked\n with VTX_INST_FLAG_IS_GUARD in the instruction stream and will be\n patched by the guard emission pipeline to jump to a deopt stub.\n\n @param e Emitter context (must have relocs initialized)\n @return 0 on success, -1 on failure"]
pub fn vtx_x86_emit_safepoint_poll(e: *mut vtx_x86_emit_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Emit a zero-cost guard page safepoint poll at a loop back-edge.\n Replaces the CMP+JCC approach with a single MOV load.\n\n When the guard page is readable (normal operation), the MOV completes\n silently — zero overhead beyond a single load instruction. When a\n safepoint is requested, the page is mprotected to PROT_NONE, causing\n the MOV to SIGSEGV. The signal handler catches the fault, processes\n the safepoint, re-arms the page, and returns.\n\n Emitted code:\n movq rax, [rip + disp32] ; 7 bytes (REX.W + 8B + ModR/M + disp32)\n ; loaded value is discarded — rax is a scratch register\n\n Total: 7 bytes (vs. 14 bytes for CMP+JCC). No compare, no branch,\n no branch-prediction entry consumed.\n\n A VTX_RELOC_RIP_REL32 external relocation is recorded so the\n displacement is patched at code install time to point to the\n guard page. The special stub_id -6 is used to mark this as a\n guard page relocation (distinct from -5 which is the flag-based\n safepoint poll).\n\n @param e Emitter context (must have relocs initialized)\n @return 0 on success, -1 on failure"]
pub fn vtx_x86_emit_safepoint_poll_guard_page(e: *mut vtx_x86_emit_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Emit function prologue:\n push rbp\n mov rbp, rsp\n sub rsp, frame_size\n push callee-saved registers (for each bit set in callee_saved_mask)\n\n @param e Emitter\n @param frame_size Frame size in bytes (locals + spills, aligned)\n @param callee_saved_mask Bitmask of callee-saved registers to save"]
pub fn vtx_x86_emit_prologue(
e: *mut vtx_x86_emit_t,
frame_size: u32,
callee_saved_mask: u32,
arg_count: u32,
max_locals: u32,
is_leaf: bool,
);
}
extern "C" {
#[doc = " Emit SMI constant initialization in the prologue.\n Loads R10 = VTX_NAN_BOX_HEADER and R11 = VTX_NAN_DATA_MASK once.\n Called after vtx_x86_emit_prologue() if the function uses SMI arithmetic."]
pub fn vtx_x86_emit_smi_constants(e: *mut vtx_x86_emit_t);
}
extern "C" {
#[doc = " Emit function epilogue:\n pop callee-saved registers\n mov rsp, rbp\n pop rbp\n ret\n is_leaf must match the value passed to vtx_x86_emit_prologue()."]
pub fn vtx_x86_emit_epilogue(e: *mut vtx_x86_emit_t, callee_saved_mask: u32, is_leaf: bool);
}
extern "C" {
#[doc = " Emit the entire instruction stream into the code buffer.\n Uses the register allocation result to resolve physical registers.\n\n @param emit Emitter context\n @param stream Instruction stream (after register allocation)\n @param result Register allocation result\n @param arena Arena for temporary allocations\n @return 0 on success, -1 on failure"]
pub fn vtx_x86_emit_function(
emit: *mut vtx_x86_emit_t,
stream: *mut vtx_inst_stream_t,
result: *const vtx_regalloc_result_t,
arena: *mut vtx_arena_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Apply peephole optimizations to the instruction stream.\n Must be called after register allocation (physical registers resolved).\n Optimizations applied:\n - Eliminate redundant MOV reg, reg (src == dst)\n - CMP reg, 0 → TEST reg, reg (1 byte shorter)\n - Fold ADD/SUB with 0 into NOP\n - Eliminate dead code (write to unused register)\n\n @param stream Instruction stream (modified in place)\n @param result Register allocation result\n @return Number of instructions eliminated"]
pub fn vtx_peephole_optimize(
stream: *mut vtx_inst_stream_t,
result: *const vtx_regalloc_result_t,
) -> u32;
}
extern "C" {
#[doc = " Optimize branch layout in the instruction stream.\n Must be called after peephole optimization and before emission.\n Optimizations applied:\n - Invert JCC + JMP to fall-through where possible\n - Use short jumps (2 bytes) when target is within ±127 bytes\n - Align loop headers to 16-byte boundaries for I-cache performance\n\n @param stream Instruction stream (modified in place)\n @param emit Emitter context (for position tracking)\n @param result Register allocation result\n @return 0 on success, -1 on failure"]
pub fn vtx_branch_optimize(
stream: *mut vtx_inst_stream_t,
emit: *mut vtx_x86_emit_t,
result: *const vtx_regalloc_result_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Map VTX condition code to x86-64 condition code byte.\n Returns the x86 condition code (0-15) for JCC/SETCC/CMOVcc."]
pub fn vtx_cond_to_x86(cond: vtx_cond_t) -> u8;
}
#[doc = " VORTEX Guard Emission for JIT-compiled Code\n\n Emits guard checks and deoptimization stubs from SoN Guard/DeoptGuard\n nodes. For each guard:\n 1. Emit a compare + conditional jump in the main code stream\n 2. If the guard fails, jump to a deopt stub\n 3. Record a side table entry (native PC, live registers, frame_state_index)\n\n Deopt stubs are emitted after the main code and perform:\n 1. Save all live registers to the frame\n 2. Load the deopt handler address\n 3. Jump to the deopt runtime"]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_guard_desc_t {
pub guard_node: vtx_nodeid_t,
pub cond: vtx_cond_t,
pub bytecode_pc: u32,
pub frame_state_index: u32,
pub type_id: u32,
pub shape_id: u32,
pub jcc_native_offset: u32,
pub deopt_stub_offset: u32,
pub is_implicit_null: bool,
pub is_value_guard: bool,
pub expected_value: u64,
}
impl Default for vtx_guard_desc_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_guard_desc_array_t {
pub guards: *mut vtx_guard_desc_t,
pub count: u32,
pub capacity: u32,
}
impl Default for vtx_guard_desc_array_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize a guard descriptor array."]
pub fn vtx_guard_desc_array_init(
arr: *mut vtx_guard_desc_array_t,
arena: *mut vtx_arena_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Add a guard descriptor."]
pub fn vtx_guard_desc_array_add(
arr: *mut vtx_guard_desc_array_t,
guard: vtx_guard_desc_t,
arena: *mut vtx_arena_t,
) -> u32;
}
extern "C" {
#[doc = " Lower guard nodes into x86-64 instructions and record side table entries.\n\n For each guard in the guard array:\n 1. Emits a compare + conditional jump into the emit buffer\n 2. Records a side table entry with the native PC, live registers,\n and frame state index\n 3. The deopt stubs are emitted after the main code by emit_deopt_stubs\n\n @param guards Array of guard descriptors\n @param inst_stream Instruction stream (for finding live registers at guard points)\n @param emit x86-64 code emitter (main code section)\n @param side_table Side table to record deopt entries\n @param arena Arena for allocations\n @return Number of guards lowered, or -1 on failure"]
pub fn vtx_guard_emit_lower(
guards: *mut vtx_guard_desc_array_t,
inst_stream: *mut vtx_inst_stream_t,
emit: *mut vtx_x86_emit_t,
side_table: *mut vtx_side_table_t,
arena: *mut vtx_arena_t,
ra: *const vtx_regalloc_result_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Emit deopt stubs after the main code.\n\n For each guard, emits a deopt stub that:\n 1. Pushes all callee-saved registers\n 2. Stores the frame state index in RDI\n 3. Loads the deopt handler address\n 4. Jumps to the deopt runtime\n\n @param guards Array of guard descriptors\n @param emit x86-64 code emitter (will append stubs)\n @param side_table Side table for recording native PCs\n @param code_start Start address of the compiled code (for offset calculation)\n @param arena Arena for allocations\n @return Number of stubs emitted, or -1 on failure"]
pub fn vtx_guard_emit_deopt_stubs(
guards: *mut vtx_guard_desc_array_t,
emit: *mut vtx_x86_emit_t,
side_table: *mut vtx_side_table_t,
code_start: *mut u8,
arena: *mut vtx_arena_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Patch guard conditional jumps to point to their deopt stubs.\n\n After both main code and deopt stubs are emitted, this function\n patches the 32-bit displacement in each guard's JCC instruction\n to point to the corresponding deopt stub.\n\n @param guards Array of guard descriptors\n @param emit x86-64 code emitter (code buffer to patch)\n @param code_start Start of the compiled code\n @param arena Arena for allocations\n @return 0 on success, -1 on failure"]
pub fn vtx_guard_emit_patch(
guards: *mut vtx_guard_desc_array_t,
emit: *mut vtx_x86_emit_t,
code_start: *mut u8,
arena: *mut vtx_arena_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Set the global deopt handler function pointer.\n\n The deopt handler is called when a guard fails. It receives:\n - RDI = frame_state_index (which FrameState to use for reconstitution)\n - RSI = native_pc_offset (where in the compiled code the failure occurred)\n\n If no handler is set, a default stub is used that prints diagnostic\n information and calls abort().\n\n @param handler Function pointer for the deopt handler"]
pub fn vtx_guard_emit_set_deopt_handler(handler: *mut ::std::os::raw::c_void);
}
extern "C" {
#[doc = " Get the current deopt handler function pointer.\n Returns NULL if no handler has been set (the default stub will be used)."]
pub fn vtx_guard_emit_get_deopt_handler() -> *mut ::std::os::raw::c_void;
}
extern "C" {
#[doc = " Emit a predicated guard using CMOVCC + conditional INT3.\n Used for guards with very low failure rates where branch\n misprediction penalty exceeds the cost of always-decoded deopt path.\n\n The emission strategy:\n 1. Evaluate the guard condition into a register\n 2. CMOVCC: conditionally set a flag byte to 0xCC (INT3 opcode)\n 3. The flag byte is placed right after the CMOVCC\n 4. If the condition fails, the flag becomes 0xCC → INT3 fires → deopt handler\n 5. If the condition passes, the flag remains 0x90 (NOP) → no trap\n\n @param guard Guard descriptor\n @param code_buf Output code buffer\n @param buf_size Size of code buffer\n @return Number of bytes emitted, or -1 on failure"]
pub fn vtx_guard_emit_predicated(
guard: *const vtx_guard_desc_t,
code_buf: *mut u8,
buf_size: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Emit an implicit null check — no code emitted.\n\n When the guard page / SIGSEGV mechanism is available, null checks\n can be made implicit: instead of emitting TEST reg,reg + JCC, we\n simply let the next memory load from that register trigger SIGSEGV\n if the pointer is null. The signal handler catches the fault and\n performs deoptimization.\n\n This function marks the guard as implicit_null and sets jcc_native_offset\n to UINT32_MAX (no JCC to patch). The actual \"guard\" is the subsequent\n load instruction from the checked register, which will SIGSEGV on null.\n\n The side table entry is recorded so the SIGSEGV handler can find the\n deopt metadata for this code location.\n\n Hot-path cost: 0 instructions (the load was going to happen anyway).\n Cold-path cost: SIGSEGV signal delivery + handler (~1-2 microseconds).\n\n Prerequisites:\n - vtx_guard_page_init() must have been called (guard page available)\n - The checked register must be used by a subsequent load instruction\n - The load must be at an offset < VTX_NULL_PAGE_LIMIT (64KB) from null\n\n @param guard Guard descriptor (is_implicit_null will be set to true)\n @param code_buf Output code buffer (unused, but required for API consistency)\n @param buf_size Size of code buffer\n @return 0 bytes emitted (always succeeds if guard != NULL)"]
pub fn vtx_guard_emit_implicit_null(
guard: *mut vtx_guard_desc_t,
code_buf: *mut u8,
buf_size: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Emit a value speculation guard — CMP + JCC for now, guard-page in future.\n\n Value speculation guards verify that a loaded value matches a previously\n observed constant. When the guard passes, all downstream uses of the\n value can be constant-folded, enabling:\n - Dead code elimination of branches that depend on the constant\n - Loop unrolling with known trip counts\n - Strength reduction (e.g., multiply by constant → shifts)\n\n Current emission (CMP+JCC, same as type guard):\n mov rax, [obj + field_offset] ; load the field\n cmp rax, <expected_value> ; is it the expected constant?\n jne deopt_stub ; if not, deopt\n ; rax is now \"proven\" constant → replace all uses with <expected_value>\n\n Future emission (guard page, zero-cost):\n mov rax, [obj + field_offset] ; load the field\n mov rbx, [value_check_page + rax*8] ; trap if wrong value\n ; rax is \"proven\" to be <expected_value> → constant fold\n\n @param guard Guard descriptor (is_value_guard must be true,\n expected_value must be set)\n @param code_buf Output code buffer\n @param buf_size Size of code buffer\n @return Number of bytes emitted, or -1 on failure"]
pub fn vtx_guard_emit_value_guard(
guard: *const vtx_guard_desc_t,
code_buf: *mut u8,
buf_size: u32,
) -> ::std::os::raw::c_int;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_pipeline_config_t {
pub run_gvn: bool,
pub run_sccp: bool,
pub run_dce: bool,
pub run_licm: bool,
pub run_bounds_check: bool,
pub run_pea: bool,
pub run_inlining: bool,
pub run_verify: bool,
pub run_speculative: bool,
pub run_loop_spec: bool,
pub run_vectorize: bool,
pub run_midtier: bool,
pub run_block_layout: bool,
pub run_rep_infer: bool,
pub gvn_iterations: ::std::os::raw::c_int,
pub sccp_iterations: ::std::os::raw::c_int,
pub dce_iterations: ::std::os::raw::c_int,
pub inline_size_limit: ::std::os::raw::c_int,
pub callee_lookup: vtx_callee_lookup_fn,
pub callee_lookup_context: *mut ::std::os::raw::c_void,
pub type_feedback: *const vtx_type_feedback_t,
pub shared_gbdt_model: *mut vtx_gbdt_model_t,
pub owns_gbdt_model: bool,
pub markov: *mut vtx_markov_t,
pub profiler: *const vtx_profiler_t,
pub code_cache: *mut vtx_code_cache,
pub method_registry: *mut vtx_method_registry,
pub method: *const vtx_method_desc_t,
pub install_arena: *mut vtx_arena_t,
pub orchestrator: *mut vtx_orchestrator_t,
pub versioned_cache: *mut vtx_versioned_cache_t,
pub deoptless_tables: *mut *mut vtx_deoptless_table_t,
pub deoptless_table_count: u32,
pub deoptless_table_capacity: u32,
}
impl Default for vtx_pipeline_config_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_pipeline_stats_t {
pub gvn_nodes_merged: u32,
pub sccp_constants_propagated: u32,
pub dce_nodes_removed: u32,
pub licm_nodes_hoisted: u32,
pub bounds_checks_eliminated: u32,
pub pea_allocs_eliminated: u32,
pub inlining_decisions: u32,
pub inlines_performed: u32,
pub loops_vectorized: u32,
pub total_pipeline_time_ns: i64,
pub gvn_time_ns: i64,
pub sccp_time_ns: i64,
pub dce_time_ns: i64,
pub licm_time_ns: i64,
pub bounds_check_time_ns: i64,
pub pea_time_ns: i64,
pub inlining_time_ns: i64,
pub loop_spec_time_ns: i64,
pub schedule_time_ns: i64,
pub block_layout_time_ns: i64,
pub lowering_time_ns: i64,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_compile_result_t {
pub success: bool,
pub graph: *mut vtx_graph_t,
pub schedule: *mut vtx_schedule_t,
pub stats: vtx_pipeline_stats_t,
pub native_code: *mut u8,
pub native_size: u32,
pub side_table: *mut vtx_side_table_t,
pub reloc_table: *mut vtx_reloc_table_t,
}
impl Default for vtx_compile_result_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
pub fn vtx_pipeline_config_t1() -> vtx_pipeline_config_t;
}
extern "C" {
pub fn vtx_pipeline_config_t1_5() -> vtx_pipeline_config_t;
}
extern "C" {
pub fn vtx_pipeline_config_t2() -> vtx_pipeline_config_t;
}
extern "C" {
pub fn vtx_pipeline_config_t3() -> vtx_pipeline_config_t;
}
extern "C" {
#[doc = " Initialize the shared GBDT model on a pipeline config.\n Call this once before the first compilation to avoid creating\n a new model on every compilation. The model is reused across\n all subsequent compilations with this config.\n\n @param config Pipeline configuration (must not be NULL)\n @return 0 on success, -1 on failure"]
pub fn vtx_pipeline_config_init_shared_model(
config: *mut vtx_pipeline_config_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy a pipeline config's shared resources (GBDT model).\n Call this when the config is no longer needed.\n\n @param config Pipeline configuration (must not be NULL)"]
pub fn vtx_pipeline_config_destroy(config: *mut vtx_pipeline_config_t);
}
extern "C" {
#[doc = " Compute heat-adapted speculation thresholds for a method.\n The hotter a method, the more aggressive the speculation:\n - Very hot methods (E > 10M): lower inline threshold, stronger guards, more deoptless\n - Cold methods (E < 1000): default conservative thresholds\n\n Uses logarithmic scaling to avoid extreme values.\n\n @param execution_count Method execution count from profile\n @return Dynamically adapted pipeline config"]
pub fn vtx_pipeline_config_heat_adapted(execution_count: u64) -> vtx_pipeline_config_t;
}
extern "C" {
pub fn vtx_pipeline_run(
graph: *mut vtx_graph_t,
config: *const vtx_pipeline_config_t,
arena: *mut vtx_arena_t,
result: *mut vtx_compile_result_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn vtx_compile_result_destroy(result: *mut vtx_compile_result_t);
}
pub const vtx_decision_reason_t_VTX_DECISION_REASON_PROACTIVE: vtx_decision_reason_t = 0;
pub const vtx_decision_reason_t_VTX_DECISION_REASON_DRIFT: vtx_decision_reason_t = 1;
pub const vtx_decision_reason_t_VTX_DECISION_REASON_FDI: vtx_decision_reason_t = 2;
pub const vtx_decision_reason_t_VTX_DECISION_REASON_DEOPTLESS: vtx_decision_reason_t = 3;
pub const vtx_decision_reason_t_VTX_DECISION_REASON_DEOPT: vtx_decision_reason_t = 4;
pub const vtx_decision_reason_t_VTX_DECISION_REASON_PHASE: vtx_decision_reason_t = 5;
pub const vtx_decision_reason_t_VTX_DECISION_REASON_COUNT: vtx_decision_reason_t = 6;
pub type vtx_decision_reason_t = ::std::os::raw::c_uint;
extern "C" {
pub fn vtx_decision_record_deopt(
orch: *mut vtx_orchestrator_t,
method_id: u32,
call_site_id: u64,
guard_id: u32,
);
}
extern "C" {
pub fn vtx_decision_submit_compile(
orch: *mut vtx_orchestrator_t,
task: *mut vtx_compile_task_t,
reason: vtx_decision_reason_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn vtx_decision_submit_counts(orch: *const vtx_orchestrator_t, counts_out: *mut u64);
}
extern "C" {
pub fn vtx_decision_deopt_count(orch: *const vtx_orchestrator_t) -> u64;
}
extern "C" {
#[doc = " Merge all data from `source` into `target`. Target is modified in place.\n Source is not modified.\n\n After this call, target contains the union of both profiles."]
pub fn vtx_profile_merge_into(
target: *mut vtx_profile_global_t,
source: *const vtx_profile_global_t,
);
}
extern "C" {
#[doc = " Merge a single method profile into the global target.\n If the method does not exist in target, it is added.\n If it exists, its data is merged.\n\n This is the function called by the persistence loader for each method."]
pub fn vtx_profile_merge_method(
target: *mut vtx_profile_global_t,
source_method: *const vtx_profile_method_t,
);
}
extern "C" {
#[doc = " Merge a single callsite profile: union the type observations from source\n into target. If the combined type count exceeds VTX_POLY_LIMIT, target\n becomes megamorphic."]
pub fn vtx_profile_merge_callsite(
target: *mut vtx_callsite_profile_t,
source: *const vtx_callsite_profile_t,
);
}
extern "C" {
#[doc = " Merge branch profiles: add source counts into target (saturating).\n This is equivalent to weight-averaging since the counts are additive."]
pub fn vtx_profile_merge_branch(
target: *mut vtx_branch_profile_t,
source: *const vtx_branch_profile_t,
);
}
extern "C" {
#[doc = " Merge field access profiles: union the shape observations from source\n into target. Same rule as callsite merging."]
pub fn vtx_profile_merge_field(
target: *mut vtx_field_profile_t,
source: *const vtx_field_profile_t,
);
}
extern "C" {
#[doc = " Merge loop profiles: sum the back-edge counts (saturating)."]
pub fn vtx_profile_merge_loop(
target: *mut vtx_loop_profile_t,
source: *const vtx_loop_profile_t,
);
}
pub const vtx_confidence_level_t_VTX_CONFIDENCE_LOW: vtx_confidence_level_t = 0;
pub const vtx_confidence_level_t_VTX_CONFIDENCE_MEDIUM: vtx_confidence_level_t = 1;
pub const vtx_confidence_level_t_VTX_CONFIDENCE_HIGH: vtx_confidence_level_t = 2;
#[doc = " Confidence classification for a single profile datum.\n\n LOW — below the promotion gate (T1 only, no speculation)\n MEDIUM — meets the T2 gate (T2 speculation OK, T3 not yet)\n HIGH — meets the T3/T4 gate (full speculation OK)"]
pub type vtx_confidence_level_t = ::std::os::raw::c_uint;
extern "C" {
#[doc = " Branch-direction confidence in [0.0, 1.0].\n\n Based on the total observation count (taken + not_taken) relative to\n VTX_CONFIDENCE_THRESHOLD_BRANCH. A branch with 100 samples has confidence\n 1.0; a branch with 50 samples has confidence 0.5; a branch with 0 samples\n has confidence 0.0.\n\n @param branch Branch profile (may be NULL → returns 0.0)\n @return Confidence in [0.0, 1.0]"]
pub fn vtx_confidence_branch(branch: *const vtx_branch_profile_t) -> f64;
}
extern "C" {
#[doc = " Call-target (monomorphic) confidence in [0.0, 1.0].\n\n Based on the invocation count observed at the call site relative to\n VTX_CONFIDENCE_THRESHOLD_CALL_TARGET. A megamorphic site is always\n confidence 0.0 (we cannot speculate on a single target).\n\n @param callsite Call-site profile (may be NULL → returns 0.0)\n @return Confidence in [0.0, 1.0]"]
pub fn vtx_confidence_call_target(callsite: *const vtx_callsite_profile_t) -> f64;
}
extern "C" {
#[doc = " Type-distribution confidence in [0.0, 1.0].\n\n Based on the total observation count across all observed types at the\n call site relative to VTX_CONFIDENCE_THRESHOLD_TYPE_DIST. Megamorphic\n sites are confidence 0.0 (we cannot speculate on a stable distribution).\n\n @param callsite Call-site profile (may be NULL → returns 0.0)\n @return Confidence in [0.0, 1.0]"]
pub fn vtx_confidence_type_dist(callsite: *const vtx_callsite_profile_t) -> f64;
}
extern "C" {
#[doc = " Loop trip-count confidence in [0.0, 1.0].\n\n Based on the backedge count relative to VTX_CONFIDENCE_THRESHOLD_LOOP_TRIP.\n A trip-stable loop with sufficient samples is confidence 1.0; an unstable\n loop is confidence 0.0.\n\n @param loop Loop profile (may be NULL → returns 0.0)\n @return Confidence in [0.0, 1.0]"]
pub fn vtx_confidence_loop_trip(loop_: *const vtx_loop_profile_t) -> f64;
}
extern "C" {
#[doc = " Field-shape confidence in [0.0, 1.0].\n\n Based on the observation count at the field site relative to\n VTX_CONFIDENCE_THRESHOLD_FIELD_SHAPE. Megamorphic sites are confidence 0.0.\n\n @param field Field-access profile (may be NULL → returns 0.0)\n @return Confidence in [0.0, 1.0]"]
pub fn vtx_confidence_field_shape(field: *const vtx_field_profile_t) -> f64;
}
extern "C" {
#[doc = " Aggregate confidence for a single method.\n\n The aggregate is the MINIMUM of:\n - branch confidence averaged across all profiled branches (weighted\n by sample count, so a branch with 0 samples doesn't drag the average\n down)\n - call-site type-distribution confidence (same weighting)\n - loop trip-count confidence\n - field-shape confidence\n\n The minimum (not the mean) is used because speculation is only as safe\n as its weakest link: if any one feature is low-confidence, the whole\n method's speculation is low-confidence.\n\n @param method Method profile (may be NULL → returns 0.0)\n @return Aggregate confidence in [0.0, 1.0]"]
pub fn vtx_confidence_method(method: *const vtx_profile_method_t) -> f64;
}
extern "C" {
#[doc = " Classify a confidence value into a tier-promotion level.\n\n < VTX_PROMOTION_CONFIDENCE_T2 → LOW (T1 only)\n < VTX_PROMOTION_CONFIDENCE_T3 → MEDIUM (T2 OK)\n else → HIGH (T3/T4 OK)\n\n @param confidence Confidence in [0.0, 1.0]\n @return Classification"]
pub fn vtx_confidence_classify(confidence: f64) -> vtx_confidence_level_t;
}
extern "C" {
#[doc = " Check whether a method is eligible for promotion to a given tier,\n considering BOTH heat and confidence.\n\n tier 1 (T1) — always eligible (T1 is non-speculative)\n tier 2 (T2) — hot AND confidence >= VTX_PROMOTION_CONFIDENCE_T2\n tier 3 (T3) — hot AND confidence >= VTX_PROMOTION_CONFIDENCE_T3\n tier 4 (T4) — hot AND confidence >= VTX_PROMOTION_CONFIDENCE_T4\n\n @param method Method profile\n @param hot_thresh Heat threshold (invocation count) — caller passes the\n tier's own heat threshold\n @param tier Target tier (1..4)\n @return true if eligible for promotion"]
pub fn vtx_confidence_eligible_for_tier(
method: *const vtx_profile_method_t,
hot_thresh: u64,
tier: u32,
) -> bool;
}
extern "C" {
#[doc = " Probe VORTEX_DETERMINISTIC at startup and cache the result.\n\n This is called once during JIT initialization (vortex_main). Subsequent\n calls to vtx_deterministic_enabled() return the cached value without\n re-reading the environment.\n\n The env var is checked as:\n VORTEX_DETERMINISTIC=1 → enabled\n VORTEX_DETERMINISTIC=0 → disabled (explicit)\n VORTEX_DETERMINISTIC= → disabled (empty)\n VORTEX_DETERMINISTIC unset → disabled\n\n Any other value (e.g. \"true\", \"yes\") is treated as enabled for\n convenience — only \"0\" and \"\" explicitly disable."]
pub fn vtx_deterministic_init();
}
extern "C" {
#[doc = " Returns true if deterministic mode is enabled.\n\n Callers should consult this before making any decision that could\n introduce nondeterminism:\n - Threadpool size selection\n - Orchestrator sleep interval\n - Adaptive guard decay rate\n - Profile persistence enable/disable\n - Compilation priority tie-breaking"]
pub fn vtx_deterministic_enabled() -> bool;
}
extern "C" {
#[doc = " Returns the deterministic-mode threadpool size (1 if enabled, 0 otherwise).\n\n Use this when sizing the compilation threadpool:\n uint32_t nthreads = vtx_deterministic_threads();\n if (nthreads == 0) nthreads = VORTEX_COMPILE_THREADS; // default"]
pub fn vtx_deterministic_threads() -> u32;
}
extern "C" {
#[doc = " Returns the deterministic-mode orchestrator check interval in milliseconds.\n\n When deterministic mode is enabled, this is a fixed 100ms (no jitter).\n When disabled, returns 0 (use the default VTX_ORCHESTRATOR_CHECK_INTERVAL_MS)."]
pub fn vtx_deterministic_check_interval_ms() -> u32;
}
extern "C" {
#[doc = " Returns true if profile persistence should be disabled.\n\n In deterministic mode, we disable profile load/save so that each run\n starts from a clean slate and produces identical compilation decisions."]
pub fn vtx_deterministic_disable_persistence() -> bool;
}
extern "C" {
#[doc = " Returns true if adaptive guard EWMA decay should be frozen.\n\n In deterministic mode, time-based decay introduces nondeterminism because\n it depends on wall-clock time. Freezing the EWMA means guards either fire\n or don't based purely on observed failure counts, which is reproducible."]
pub fn vtx_deterministic_freeze_guard_ewma() -> bool;
}
extern "C" {
#[doc = " Build the filename for a specific phase's profile.\n\n Format: <dir>/<hash_hex>.<phase_label>.prof\n where phase_label is \"default\" for VTX_PHASE_NONE, else the decimal\n phase ID.\n\n @param dir Profile directory (NUL-terminated)\n @param hash_hex Bytecode hash as 32-char hex string (NUL-terminated)\n @param phase_id Phase ID (VTX_PHASE_NONE for default)\n @param out Output buffer\n @param out_size Size of output buffer (recommended: 600+)\n @return 0 on success, -1 on buffer overflow"]
pub fn vtx_phase_partition_filename(
dir: *const ::std::os::raw::c_char,
hash_hex: *const ::std::os::raw::c_char,
phase_id: u32,
out: *mut ::std::os::raw::c_char,
out_size: usize,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Save all phases' profiles to a directory.\n\n For each valid phase entry in `part`, saves its profile to:\n <dir>/<hash_hex>.<phase_label>.prof\n\n The bytecode hash is included in each file's header so that a stale\n profile from a different bytecode version is automatically rejected\n on load.\n\n @param part Partition manager\n @param dir Profile directory (must exist)\n @param hash_hex Bytecode hash as 32-char hex string\n @param bytecode_hash Raw 32-byte bytecode hash (passed to vtx_profile_save)\n @return Number of phases saved, or -1 on error"]
pub fn vtx_phase_partition_save_all(
part: *mut vtx_phase_partition_t,
dir: *const ::std::os::raw::c_char,
hash_hex: *const ::std::os::raw::c_char,
bytecode_hash: *const u8,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Load all phase profiles from a directory.\n\n Scans the directory for files matching <hash_hex>.*.prof, parses each\n one, and adds the corresponding phase entry to `part`. The active\n phase is set to the default (VTX_PHASE_NONE) after loading.\n\n Files that fail to load (bad magic, version mismatch, CRC failure,\n hash mismatch) are silently skipped.\n\n @param part Partition manager (must be initialized)\n @param dir Profile directory\n @param hash_hex Bytecode hash as 32-char hex string\n @param expected_hash Raw 32-byte bytecode hash for version gating\n @return Number of phases loaded, or -1 on error"]
pub fn vtx_phase_partition_load_all(
part: *mut vtx_phase_partition_t,
dir: *const ::std::os::raw::c_char,
hash_hex: *const ::std::os::raw::c_char,
expected_hash: *const u8,
) -> ::std::os::raw::c_int;
}
#[doc = " Metadata for a single run's profile.\n\n This is what gets stored alongside each profile snapshot in the\n ensemble. The quality score is derived from these fields."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_ensemble_run_meta_t {
pub sample_count: u64,
pub deopt_count: u64,
pub deopt_rate: f64,
pub runtime_duration_s: f64,
pub timestamp_ns: u64,
pub quality: f64,
pub demoted: bool,
}
#[doc = " A single entry in the ensemble: a profile snapshot + its metadata."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_ensemble_entry_t {
pub profile: vtx_profile_global_t,
pub meta: vtx_ensemble_run_meta_t,
pub valid: bool,
}
impl Default for vtx_ensemble_entry_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Ensemble profile manager.\n\n Stores the last K runs and computes a robust aggregate. The aggregate\n is stored in `working_profile` — this is what the JIT reads from.\n\n The `previous_aggregate` is kept so that rollback can restore it."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_ensemble_t {
pub runs: [vtx_ensemble_entry_t; 5usize],
pub run_count: u32,
pub next_slot: u32,
pub working_profile: *mut vtx_profile_global_t,
pub previous_aggregate: *mut vtx_profile_global_t,
pub owned_working: *mut vtx_profile_global_t,
pub owned_previous: *mut vtx_profile_global_t,
pub pending_validation: bool,
pub validation_start_ns: u64,
pub total_aggregates_computed: u64,
pub total_rollbacks: u64,
pub total_demotions: u64,
}
impl Default for vtx_ensemble_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the ensemble manager.\n\n Does NOT allocate the working profile — that happens on the first\n call to compute_aggregate().\n\n Returns 0 on success, -1 on failure."]
pub fn vtx_ensemble_init(ens: *mut vtx_ensemble_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the ensemble and free all owned profiles."]
pub fn vtx_ensemble_destroy(ens: *mut vtx_ensemble_t);
}
extern "C" {
#[doc = " Add a completed run's profile to the ensemble.\n\n The run's profile is COPIED into the ensemble (the caller retains\n ownership of the original). The metadata is stored alongside it.\n\n If the ensemble is full (K runs), the OLDEST run is evicted (FIFO).\n\n After adding, the run's quality score is computed automatically.\n Runs below the quality threshold are marked as demoted and excluded\n from future aggregates.\n\n @param ens Ensemble manager\n @param profile The run's profile data (copied)\n @param meta Run metadata (quality field is computed internally)\n @return 0 on success, -1 on failure"]
pub fn vtx_ensemble_add_run(
ens: *mut vtx_ensemble_t,
profile: *const vtx_profile_global_t,
meta: vtx_ensemble_run_meta_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Compute the quality score for a run given its metadata.\n\n quality = (sample_count / MIN_SAMPLES) * (1.0 - deopt_rate) * (duration / MIN_DURATION)\n clamped to [0, 1]\n\n A run with 1000+ samples, 0% deopt rate, and 1+ second duration has\n quality 1.0. A run with 100 samples, 50% deopt rate, and 0.5s duration\n has quality = 0.1 * 0.5 * 0.5 = 0.025 — demoted.\n\n @param meta Run metadata (quality field is updated)"]
pub fn vtx_ensemble_compute_quality(meta: *mut vtx_ensemble_run_meta_t);
}
extern "C" {
#[doc = " Check if a run is demoted (quality below threshold)."]
pub fn vtx_ensemble_run_is_demoted(meta: *const vtx_ensemble_run_meta_t) -> bool;
}
extern "C" {
#[doc = " Compute the robust aggregate from the non-demoted runs.\n\n The aggregate is stored in the ensemble's working_profile (allocated\n if needed). The previous working_profile is moved to\n previous_aggregate for potential rollback.\n\n Aggregate rules:\n - Branch probabilities: median P(taken) across non-demoted runs\n - Type distributions: mode — types seen in >50% of runs\n - Shape sets: intersection — shapes seen in ALL non-demoted runs\n - Loop backedge counts: median across runs\n - Invocation counts: median across runs\n\n If fewer than VTX_ENSEMBLE_MIN_RUNS non-demoted runs exist, the\n aggregate is just the most recent non-demoted run (no robustness\n benefit, but still usable).\n\n After computing, the working_profile is marked as \"pending\n validation.\" Call vtx_ensemble_validate() after\n VTX_ENSEMBLE_VALIDATION_WINDOW_S seconds to confirm it.\n\n @param ens Ensemble manager\n @return The working profile, or NULL on failure"]
pub fn vtx_ensemble_compute_aggregate(ens: *mut vtx_ensemble_t) -> *mut vtx_profile_global_t;
}
extern "C" {
#[doc = " Get the current working profile (the aggregate the JIT should use).\n Returns NULL if no aggregate has been computed yet."]
pub fn vtx_ensemble_get_working(ens: *mut vtx_ensemble_t) -> *mut vtx_profile_global_t;
}
extern "C" {
#[doc = " Validate the current working profile.\n\n Called after VTX_ENSEMBLE_VALIDATION_WINDOW_S seconds of use. If the\n observed deopt rate is below the rollback threshold, the working\n profile is marked as validated. If it exceeds the threshold, the\n ensemble rolls back to the previous validated aggregate.\n\n @param ens Ensemble manager\n @param observed_deopt_rate Deopt rate observed during the validation window\n @return true if validated, false if rolled back"]
pub fn vtx_ensemble_validate(ens: *mut vtx_ensemble_t, observed_deopt_rate: f64) -> bool;
}
extern "C" {
#[doc = " Force an immediate rollback to the previous validated aggregate.\n\n Called when the system detects that the current aggregate is bad\n (e.g., a burst of deopts before the validation window expires).\n\n @param ens Ensemble manager\n @return true if rolled back, false if no previous aggregate exists"]
pub fn vtx_ensemble_rollback(ens: *mut vtx_ensemble_t) -> bool;
}
extern "C" {
#[doc = " Check if the current working profile is pending validation."]
pub fn vtx_ensemble_is_pending_validation(ens: *const vtx_ensemble_t) -> bool;
}
extern "C" {
#[doc = " Get ensemble statistics.\n\n @param ens Ensemble manager\n @param run_count Out: number of runs stored\n @param demoted_count Out: number of demoted runs\n @param total_aggregates Out: total aggregates computed\n @param total_rollbacks Out: total rollbacks performed\n @param total_demotions Out: total runs demoted"]
pub fn vtx_ensemble_stats(
ens: *const vtx_ensemble_t,
run_count: *mut u32,
demoted_count: *mut u32,
total_aggregates: *mut u64,
total_rollbacks: *mut u64,
total_demotions: *mut u64,
);
}
pub const vtx_size_bin_t_VTX_SIZE_BIN_EMPTY: vtx_size_bin_t = 0;
pub const vtx_size_bin_t_VTX_SIZE_BIN_ONE: vtx_size_bin_t = 1;
pub const vtx_size_bin_t_VTX_SIZE_BIN_TINY: vtx_size_bin_t = 2;
pub const vtx_size_bin_t_VTX_SIZE_BIN_SMALL: vtx_size_bin_t = 3;
pub const vtx_size_bin_t_VTX_SIZE_BIN_MEDIUM: vtx_size_bin_t = 4;
pub const vtx_size_bin_t_VTX_SIZE_BIN_LARGE: vtx_size_bin_t = 5;
pub const vtx_size_bin_t_VTX_SIZE_BIN_COUNT: vtx_size_bin_t = 6;
#[doc = " Coarse bins for collection sizes and loop trip counts.\n\n The bins are chosen so that optimization decisions don't change within\n a bin:\n - BIN_EMPTY (0): no elements → skip the loop entirely\n - BIN_ONE (1): exactly 1 → no loop, direct access\n - BIN_TINY (2): 2-4 → unroll fully\n - BIN_SMALL (3): 5-16 → unroll partially\n - BIN_MEDIUM (4): 17-256 → vectorize\n - BIN_LARGE (5): 257+ → don't unroll, streaming\n\n 6 bins captures >99% of real-world workloads without shape explosion."]
pub type vtx_size_bin_t = ::std::os::raw::c_uint;
extern "C" {
#[doc = " Bin a collection size or loop trip count.\n\n @param count The size/trip count to bin\n @return The bin enum value"]
pub fn vtx_size_bin(count: u64) -> vtx_size_bin_t;
}
extern "C" {
#[doc = " Get a human-readable name for a size bin."]
pub fn vtx_size_bin_name(bin: vtx_size_bin_t) -> *const ::std::os::raw::c_char;
}
#[doc = " A 64-bit input shape signature.\n\n VTX_INPUT_SHAPE_DEFAULT is the \"no shape\" / \"shapeless\" value — used\n for methods that haven't been shape-profiled yet, or for methods where\n shape-keying is disabled."]
pub type vtx_input_shape_t = u64;
extern "C" {
#[doc = " Compute an input shape signature from the observed input characteristics.\n\n @param arg_type_fingerprint XOR of argument type IDs (8 bits used)\n @param receiver_type_fingerprint XOR of receiver type IDs (8 bits used)\n @param dominant_size_bin Dominant collection size bin (0-5)\n @param dominant_trip_bin Dominant loop trip count bin (0-5)\n @param call_site_count Number of distinct call sites (8 bits used)\n @param field_shape_fingerprint XOR of field shape IDs (8 bits used)\n @return 64-bit shape signature"]
pub fn vtx_input_shape_make(
arg_type_fingerprint: u8,
receiver_type_fingerprint: u8,
dominant_size_bin: vtx_size_bin_t,
dominant_trip_bin: vtx_size_bin_t,
call_site_count: u8,
field_shape_fingerprint: u8,
) -> vtx_input_shape_t;
}
extern "C" {
#[doc = " Check if two input shapes are equivalent (same signature)."]
pub fn vtx_input_shape_equals(a: vtx_input_shape_t, b: vtx_input_shape_t) -> bool;
}
extern "C" {
#[doc = " Decode the dominant size bin from a shape signature."]
pub fn vtx_input_shape_size_bin(shape: vtx_input_shape_t) -> vtx_size_bin_t;
}
extern "C" {
#[doc = " Decode the dominant trip count bin from a shape signature."]
pub fn vtx_input_shape_trip_bin(shape: vtx_input_shape_t) -> vtx_size_bin_t;
}
#[doc = " A per-shape profile entry: one method's profile data for one input shape.\n\n This wraps vtx_profile_method_t with shape-specific metadata. The\n underlying profile data (branches, call sites, loops, fields) is\n stored in the embedded vtx_profile_method_t."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_shape_profile_entry_t {
pub shape: vtx_input_shape_t,
pub method: vtx_profile_method_t,
pub sample_count: u64,
pub first_seen_ns: u64,
pub last_seen_ns: u64,
pub valid: bool,
}
impl Default for vtx_shape_profile_entry_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Per-method input-shape-keyed profile table.\n\n Holds up to VTX_INPUT_SHAPE_MAX_PER_METHOD shape-specific profile\n entries. When a new shape is observed and the table is full, the\n least-recently-used shape is evicted (its data is merged into the\n default shape).\n\n The table also maintains a \"default\" entry (shape == VTX_INPUT_SHAPE_DEFAULT)\n for observations that don't match any tracked shape, or for methods\n where shape-keying is disabled."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_input_shape_table_t {
pub method_id: u32,
pub entries: [vtx_shape_profile_entry_t; 8usize],
pub entry_count: u32,
pub total_observations: u64,
pub shape_transitions: u64,
pub shape_evictions: u64,
}
impl Default for vtx_input_shape_table_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize a shape-keyed profile table for a method.\n\n Creates a default-shape entry (VTX_INPUT_SHAPE_DEFAULT) so that\n observations can be recorded even before shape-keying kicks in.\n\n @param table Table to initialize\n @param method_id Method ID this table is for\n @return 0 on success, -1 on failure"]
pub fn vtx_input_shape_table_init(
table: *mut vtx_input_shape_table_t,
method_id: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy a shape-keyed profile table and free all per-shape profiles."]
pub fn vtx_input_shape_table_destroy(table: *mut vtx_input_shape_table_t);
}
extern "C" {
#[doc = " Get or create the profile entry for a specific input shape.\n\n If the shape doesn't exist in the table:\n - If the table is full, evict the LRU shape (merge into default)\n - Create a new entry for the requested shape\n\n Returns a pointer to the shape's profile method, or NULL on failure.\n\n @param table Shape table\n @param shape Input shape signature\n @param now_ns Current monotonic time (0 to use internal clock)\n @return Pointer to the shape's vtx_profile_method_t, or NULL"]
pub fn vtx_input_shape_table_get_or_create(
table: *mut vtx_input_shape_table_t,
shape: vtx_input_shape_t,
now_ns: u64,
) -> *mut vtx_profile_method_t;
}
extern "C" {
#[doc = " Get the profile entry for the default shape (VTX_INPUT_SHAPE_DEFAULT).\n\n This is the \"catch-all\" shape for methods that haven't been shape-\n profiled, or for observations that don't match any tracked shape."]
pub fn vtx_input_shape_table_get_default(
table: *mut vtx_input_shape_table_t,
) -> *mut vtx_profile_method_t;
}
extern "C" {
#[doc = " Get the profile entry for a specific shape, or NULL if it doesn't exist.\n\n Does NOT create a new entry — use get_or_create for that."]
pub fn vtx_input_shape_table_get(
table: *mut vtx_input_shape_table_t,
shape: vtx_input_shape_t,
) -> *mut vtx_profile_method_t;
}
extern "C" {
#[doc = " Record an observation of a specific input shape.\n\n Updates the sample count and last_seen timestamp. Called by the\n interpreter when it detects a shape transition.\n\n @param table Shape table\n @param shape Input shape that was observed\n @param now_ns Current monotonic time (0 to use internal clock)"]
pub fn vtx_input_shape_table_record_observation(
table: *mut vtx_input_shape_table_t,
shape: vtx_input_shape_t,
now_ns: u64,
);
}
extern "C" {
#[doc = " Number of distinct shapes tracked (including the default shape)."]
pub fn vtx_input_shape_table_shape_count(table: *const vtx_input_shape_table_t) -> u32;
}
extern "C" {
#[doc = " Get the dominant (most-observed) input shape for a method.\n\n Returns VTX_INPUT_SHAPE_DEFAULT if the table is empty or all shapes\n have equal sample counts.\n\n @param table Shape table\n @return The dominant shape signature"]
pub fn vtx_input_shape_table_dominant_shape(
table: *const vtx_input_shape_table_t,
) -> vtx_input_shape_t;
}
extern "C" {
#[doc = " Check if a method has multiple distinct input shapes that would\n benefit from multi-version compilation.\n\n Returns true if there are 2+ shapes with sample_count above\n VTX_INPUT_SHAPE_MIN_SAMPLES_FOR_MULTI_VERSION."]
pub fn vtx_input_shape_table_needs_multi_version(table: *const vtx_input_shape_table_t)
-> bool;
}
extern "C" {
#[doc = " Get shape table statistics.\n\n @param table Shape table\n @param shape_count Out: number of distinct shapes\n @param total_observations Out: total observations across all shapes\n @param transitions Out: shape transitions\n @param evictions Out: LRU evictions\n @param dominant_shape Out: dominant shape signature"]
pub fn vtx_input_shape_table_stats(
table: *const vtx_input_shape_table_t,
shape_count: *mut u32,
total_observations: *mut u64,
transitions: *mut u64,
evictions: *mut u64,
dominant_shape: *mut vtx_input_shape_t,
);
}
#[doc = " Global manager holding per-method shape tables.\n\n This sits above vtx_profile_global_t. The orchestrator queries this\n manager to get the shape-specific profile for a method when making\n compilation decisions."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_input_shape_manager_t {
pub tables: *mut *mut vtx_input_shape_table_t,
pub table_count: u32,
pub table_capacity: u32,
pub total_shape_observations: u64,
pub total_multi_version_methods: u64,
}
impl Default for vtx_input_shape_manager_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the global shape manager."]
pub fn vtx_input_shape_manager_init(
mgr: *mut vtx_input_shape_manager_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the global shape manager and all per-method tables."]
pub fn vtx_input_shape_manager_destroy(mgr: *mut vtx_input_shape_manager_t);
}
extern "C" {
#[doc = " Get or create the shape table for a method.\n\n @param mgr Shape manager\n @param method_id Method ID\n @return Pointer to the method's shape table, or NULL on failure"]
pub fn vtx_input_shape_manager_get_or_create(
mgr: *mut vtx_input_shape_manager_t,
method_id: u32,
) -> *mut vtx_input_shape_table_t;
}
extern "C" {
#[doc = " Get the shape table for a method, or NULL if it doesn't exist."]
pub fn vtx_input_shape_manager_get(
mgr: *mut vtx_input_shape_manager_t,
method_id: u32,
) -> *mut vtx_input_shape_table_t;
}
extern "C" {
#[doc = " Get the shape-specific profile for a method + shape combination.\n\n This is the primary query for the JIT: \"give me the profile data for\n method M when called with input shape S\". Returns the default shape's\n profile if the specific shape doesn't exist.\n\n @param mgr Shape manager\n @param method_id Method ID\n @param shape Input shape\n @return Pointer to the shape's profile method, or NULL"]
pub fn vtx_input_shape_manager_get_profile(
mgr: *mut vtx_input_shape_manager_t,
method_id: u32,
shape: vtx_input_shape_t,
) -> *mut vtx_profile_method_t;
}
extern "C" {
#[doc = " Get manager statistics."]
pub fn vtx_input_shape_manager_stats(
mgr: *const vtx_input_shape_manager_t,
total_observations: *mut u64,
multi_version_methods: *mut u64,
table_count: *mut u32,
);
}
#[doc = " A single (shape → compiled_code) mapping.\n\n The compiled_code pointer is opaque — the dispatch table doesn't know\n the details of the compiled code, it just stores the entry point."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_shape_version_t {
pub shape: vtx_input_shape_t,
pub compiled_code: *mut ::std::os::raw::c_void,
pub code_metadata: *mut ::std::os::raw::c_void,
pub compile_time_ns: u64,
pub call_count: u64,
pub valid: bool,
}
impl Default for vtx_shape_version_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Per-method shape dispatch table.\n\n Holds up to VTX_SHAPE_DISPATCH_MAX_VERSIONS shape-specific compiled\n versions. The first entry (index 0) is always the \"default\" version\n (shape == VTX_INPUT_SHAPE_DEFAULT) — the fallback when no shape-\n specific version matches."]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct vtx_shape_dispatch_t {
pub method_id: u32,
pub versions: [vtx_shape_version_t; 8usize],
pub version_count: u32,
pub mutex: pthread_mutex_t,
}
impl Default for vtx_shape_dispatch_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Global shape dispatch manager.\n\n Holds per-method dispatch tables. The interpreter queries this at\n call time to find the right compiled version for the current input shape."]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct vtx_shape_dispatch_mgr_t {
pub tables: *mut *mut vtx_shape_dispatch_t,
pub table_count: u32,
pub table_capacity: u32,
pub global_mutex: pthread_mutex_t,
pub total_dispatches: u64,
pub total_default_fallbacks: u64,
pub total_versions_compiled: u64,
}
impl Default for vtx_shape_dispatch_mgr_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Initialize the global shape dispatch manager."]
pub fn vtx_shape_dispatch_mgr_init(mgr: *mut vtx_shape_dispatch_mgr_t)
-> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy the global shape dispatch manager."]
pub fn vtx_shape_dispatch_mgr_destroy(mgr: *mut vtx_shape_dispatch_mgr_t);
}
extern "C" {
#[doc = " Install a shape-specific compiled version for a method.\n\n Called by the JIT compiler after compiling a version specialized for\n a particular input shape. If the table is full, the LRU shape-version\n is evicted.\n\n @param mgr Dispatch manager\n @param method_id Method ID\n @param shape Input shape this version is specialized for\n @param compiled_code Entry point of the compiled code\n @param code_metadata Optional metadata (may be NULL)\n @return 0 on success, -1 on failure"]
pub fn vtx_shape_dispatch_install(
mgr: *mut vtx_shape_dispatch_mgr_t,
method_id: u32,
shape: vtx_input_shape_t,
compiled_code: *mut ::std::os::raw::c_void,
code_metadata: *mut ::std::os::raw::c_void,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Install the default (shapeless) compiled version for a method.\n\n This is the fallback version used when no shape-specific version\n matches. Every method that participates in shape dispatch must have\n a default version installed.\n\n @param mgr Dispatch manager\n @param method_id Method ID\n @param compiled_code Entry point of the compiled code\n @param code_metadata Optional metadata (may be NULL)\n @return 0 on success, -1 on failure"]
pub fn vtx_shape_dispatch_install_default(
mgr: *mut vtx_shape_dispatch_mgr_t,
method_id: u32,
compiled_code: *mut ::std::os::raw::c_void,
code_metadata: *mut ::std::os::raw::c_void,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Look up the compiled version for a method + input shape.\n\n This is the hot-path call-time query. It's lock-free: the caller\n reads the versions array without acquiring the mutex. Writes\n (installs) use atomic swaps to ensure readers never see a torn\n pointer.\n\n If a shape-specific version exists, it's returned. Otherwise, the\n default version is returned. If no default exists either, NULL is\n returned (the caller should use the interpreter).\n\n @param mgr Dispatch manager\n @param method_id Method ID\n @param shape Current input shape\n @return Compiled code entry point, or NULL"]
pub fn vtx_shape_dispatch_lookup(
mgr: *mut vtx_shape_dispatch_mgr_t,
method_id: u32,
shape: vtx_input_shape_t,
) -> *mut ::std::os::raw::c_void;
}
extern "C" {
#[doc = " Record a dispatch (for statistics).\n\n Called by the interpreter after a successful lookup to track whether\n the shape-specific version or the default was used.\n\n @param mgr Dispatch manager\n @param shape_specific true if a shape-specific version was used,\n false if the default was used"]
pub fn vtx_shape_dispatch_record(mgr: *mut vtx_shape_dispatch_mgr_t, shape_specific: bool);
}
extern "C" {
#[doc = " Check if a method has multiple shape-specific versions installed.\n\n Returns the number of shape-specific versions (excluding the default).\n If >0, the method benefits from shape-keyed dispatch."]
pub fn vtx_shape_dispatch_version_count(
mgr: *mut vtx_shape_dispatch_mgr_t,
method_id: u32,
) -> u32;
}
extern "C" {
#[doc = " Get the dispatch table for a method (for introspection).\n Returns NULL if the method has no dispatch table."]
pub fn vtx_shape_dispatch_get_table(
mgr: *mut vtx_shape_dispatch_mgr_t,
method_id: u32,
) -> *mut vtx_shape_dispatch_t;
}
extern "C" {
#[doc = " Get dispatch statistics.\n\n @param mgr Dispatch manager\n @param total_dispatches Out: total shape-specific calls\n @param total_default_fallbacks Out: calls that fell back to default\n @param total_versions_compiled Out: shape-specific versions compiled\n @param table_count Out: number of methods with dispatch tables"]
pub fn vtx_shape_dispatch_stats(
mgr: *const vtx_shape_dispatch_mgr_t,
total_dispatches: *mut u64,
total_default_fallbacks: *mut u64,
total_versions_compiled: *mut u64,
table_count: *mut u32,
);
}
pub const vtx_patch_entry_type_t_VTX_PATCH_METHOD_SNAPSHOT: vtx_patch_entry_type_t = 1;
pub const vtx_patch_entry_type_t_VTX_PATCH_BRANCH_UPDATE: vtx_patch_entry_type_t = 2;
pub const vtx_patch_entry_type_t_VTX_PATCH_CALLSITE_UPDATE: vtx_patch_entry_type_t = 3;
pub const vtx_patch_entry_type_t_VTX_PATCH_LOOP_UPDATE: vtx_patch_entry_type_t = 4;
pub const vtx_patch_entry_type_t_VTX_PATCH_FIELD_UPDATE: vtx_patch_entry_type_t = 5;
pub const vtx_patch_entry_type_t_VTX_PATCH_INVOCATION_COUNT: vtx_patch_entry_type_t = 6;
pub const vtx_patch_entry_type_t_VTX_PATCH_COMPACTION_MARKER: vtx_patch_entry_type_t = 7;
#[doc = " Entry types."]
pub type vtx_patch_entry_type_t = ::std::os::raw::c_uint;
#[doc = " Append-only patch log handle.\n\n The log is opened for appending (O_APPEND) so writes are atomic at\n the OS level. Multiple processes can't safely share a log (use the\n profile directory's per-hash files)."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_patch_log_t {
pub fd: ::std::os::raw::c_int,
pub filename: [::std::os::raw::c_char; 512usize],
pub entry_count: u32,
pub bytes_written: u64,
pub writable: bool,
}
impl Default for vtx_patch_log_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Open a patch log for appending (writing).\n\n Creates the file if it doesn't exist, with 0600 permissions. If the\n file exists, validates the header (magic, version, bytecode hash).\n If the header is invalid, the file is truncated and re-created.\n\n @param log Log handle (caller allocates)\n @param filename Path to the .vpl file\n @param bytecode_hash SHA-256 hash of the bytecode (for version gating)\n @return 0 on success, -1 on failure"]
pub fn vtx_patch_log_open(
log: *mut vtx_patch_log_t,
filename: *const ::std::os::raw::c_char,
bytecode_hash: *const u8,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Open a patch log for reading (replay).\n\n Validates the header. The caller then calls vtx_patch_log_replay()\n to apply the deltas to a profile.\n\n @param log Log handle (caller allocates)\n @param filename Path to the .vpl file\n @param expected_hash Expected bytecode hash (NULL to skip check)\n @return 0 on success, -1 on failure"]
pub fn vtx_patch_log_open_read(
log: *mut vtx_patch_log_t,
filename: *const ::std::os::raw::c_char,
expected_hash: *const u8,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Close the patch log."]
pub fn vtx_patch_log_close(log: *mut vtx_patch_log_t);
}
extern "C" {
#[doc = " Append a full method snapshot to the log.\n\n This is the \"compaction\" entry — it captures the complete current\n state of a method's profile. Used during background compaction and\n as the initial entry when saving a profile for the first time.\n\n @param log Log handle (must be open for writing)\n @param method Method profile to snapshot\n @return 0 on success, -1 on failure"]
pub fn vtx_patch_log_append_snapshot(
log: *mut vtx_patch_log_t,
method: *const vtx_profile_method_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Append a branch update delta.\n\n @param log Log handle\n @param method_id Method ID\n @param bytecode_pc Branch bytecode PC\n @param taken Taken count\n @param not_taken Not-taken count\n @return 0 on success, -1 on failure"]
pub fn vtx_patch_log_append_branch(
log: *mut vtx_patch_log_t,
method_id: u32,
bytecode_pc: u32,
taken: u64,
not_taken: u64,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Append a callsite type update delta.\n\n @param log Log handle\n @param method_id Method ID\n @param callsite_index Call site index\n @param type_id Observed type ID\n @return 0 on success, -1 on failure"]
pub fn vtx_patch_log_append_callsite(
log: *mut vtx_patch_log_t,
method_id: u32,
callsite_index: u32,
type_id: vtx_typeid_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Append a loop backedge update delta.\n\n @param log Log handle\n @param method_id Method ID\n @param loop_header_pc Loop header bytecode PC\n @param backedge_count Backedge count\n @return 0 on success, -1 on failure"]
pub fn vtx_patch_log_append_loop(
log: *mut vtx_patch_log_t,
method_id: u32,
loop_header_pc: u32,
backedge_count: u64,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Append a field shape update delta.\n\n @param log Log handle\n @param method_id Method ID\n @param field_offset Field offset\n @param shape_id Observed shape ID\n @return 0 on success, -1 on failure"]
pub fn vtx_patch_log_append_field(
log: *mut vtx_patch_log_t,
method_id: u32,
field_offset: u32,
shape_id: vtx_shapeid_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Append an invocation count update delta.\n\n @param log Log handle\n @param method_id Method ID\n @param count_delta Invocation count delta to add\n @return 0 on success, -1 on failure"]
pub fn vtx_patch_log_append_invocation(
log: *mut vtx_patch_log_t,
method_id: u32,
count_delta: u64,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Append a compaction marker.\n\n This marks the point where all prior entries have been subsumed by\n a snapshot. On replay, entries before the last compaction marker\n can be skipped (the snapshot captures their state).\n\n @param log Log handle\n @return 0 on success, -1 on failure"]
pub fn vtx_patch_log_append_compaction_marker(
log: *mut vtx_patch_log_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Replay the patch log, applying all deltas to a profile.\n\n Reads each entry in order, validates its CRC, and applies the delta\n to the given profile. Entries with bad CRCs are skipped (crash\n recovery). Entries before the last compaction marker are skipped\n (they're subsumed by the snapshot).\n\n @param log Log handle (must be open for reading)\n @param profile Profile to apply deltas to\n @return Number of entries applied, or -1 on fatal error"]
pub fn vtx_patch_log_replay(
log: *mut vtx_patch_log_t,
profile: *mut vtx_profile_global_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Compact the patch log.\n\n Reads the current log, computes the final profile state for each\n method, writes a new log containing just METHOD_SNAPSHOT entries +\n a COMPACTION_MARKER, then atomically replaces the old log.\n\n After compaction, the log is small (one snapshot per method) and\n replay is fast.\n\n @param log Log handle (must be open for writing)\n @param profile Current profile state (the source of truth for\n the snapshots). If NULL, the log is replayed\n first to build the profile, then compacted.\n @return 0 on success, -1 on failure"]
pub fn vtx_patch_log_compact(
log: *mut vtx_patch_log_t,
profile: *const vtx_profile_global_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Get patch log statistics.\n\n @param log Log handle\n @param entry_count Out: entries written since open\n @param bytes_written Out: bytes appended since open\n @param fd Out: file descriptor (-1 if closed)"]
pub fn vtx_patch_log_stats(
log: *const vtx_patch_log_t,
entry_count: *mut u32,
bytes_written: *mut u64,
fd: *mut ::std::os::raw::c_int,
);
}
extern "C" {
#[doc = " Build the patch log filename for a given bytecode hash.\n\n Format: <dir>/<hash_hex>.vpl"]
pub fn vtx_patch_log_filename(
dir: *const ::std::os::raw::c_char,
hash_hex: *const ::std::os::raw::c_char,
out: *mut ::std::os::raw::c_char,
out_size: usize,
) -> ::std::os::raw::c_int;
}
pub const vtx_frame_kind_t_VTX_FRAME_INTERPRETED: vtx_frame_kind_t = 0;
pub const vtx_frame_kind_t_VTX_FRAME_COMPILED: vtx_frame_kind_t = 1;
pub const vtx_frame_kind_t_VTX_FRAME_NATIVE: vtx_frame_kind_t = 2;
pub const vtx_frame_kind_t_VTX_FRAME_DEOPTLESS: vtx_frame_kind_t = 3;
pub const vtx_frame_kind_t_VTX_FRAME_STUB: vtx_frame_kind_t = 4;
#[doc = " The kind of a frame encountered during stack walking."]
pub type vtx_frame_kind_t = ::std::os::raw::c_uint;
#[doc = " A single reconstructed interpreter frame. This is the output of stack\n walking: for each physical or logical frame on the compiled stack,\n we produce one of these with the interpreter-visible state."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_reconstructed_frame_t {
pub method_id: u32,
pub bytecode_pc: u32,
pub locals: *mut vtx_value_t,
pub local_count: u32,
pub stack: *mut vtx_value_t,
pub stack_count: u32,
pub original_kind: vtx_frame_kind_t,
pub is_inlined: bool,
pub is_materialized: bool,
pub compressed_snapshot: *mut u8,
pub snapshot_size: u32,
}
impl Default for vtx_reconstructed_frame_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " The result of stack walking: an array of reconstructed interpreter frames."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_reconstructed_stack_t {
pub frames: *mut vtx_reconstructed_frame_t,
pub frame_count: u32,
pub frame_capacity: u32,
}
impl Default for vtx_reconstructed_stack_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Maps a code entry point to its side table.\n Used during stack walking to look up the side table for each compiled frame."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_code_descriptor_t {
pub code_start: *mut ::std::os::raw::c_void,
pub code_size: u32,
pub side_table: *mut vtx_side_table_t,
}
impl Default for vtx_code_descriptor_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Registry of all compiled code descriptors, used for side table lookup."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_side_table_registry_t {
pub descriptors: *mut vtx_code_descriptor_t,
pub descriptor_count: u32,
pub descriptor_capacity: u32,
}
impl Default for vtx_side_table_registry_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Configuration for a stack walk operation."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_stack_walk_config_t {
pub start_fp: *mut ::std::os::raw::c_void,
pub registry: *mut vtx_side_table_registry_t,
pub node_table: *const vtx_node_table_t,
pub frame_states: *mut *mut vtx_frame_state_t,
pub frame_state_count: u32,
pub max_depth: u32,
}
impl Default for vtx_stack_walk_config_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Walk the compiled frame stack starting from the given frame pointer.\n\n For each compiled frame:\n 1. Look up the side table from the registry using the frame's code pointer.\n 2. Determine the native PC (from the saved return address minus 1).\n 3. Look up the FrameState from the side table.\n 4. For inlined methods, the FrameState chain contains multiple logical frames.\n 5. Reconstruct each logical frame as an interpreter frame.\n\n For each interpreter frame:\n 1. Read the method pointer, PC, locals, and stack directly.\n 2. Add to the reconstructed stack.\n\n Returns a newly allocated reconstructed stack (caller must free with\n vtx_reconstructed_stack_destroy), or NULL on failure."]
pub fn vtx_stack_walk(config: *const vtx_stack_walk_config_t)
-> *mut vtx_reconstructed_stack_t;
}
extern "C" {
#[doc = " Create an empty reconstructed stack."]
pub fn vtx_reconstructed_stack_create() -> *mut vtx_reconstructed_stack_t;
}
extern "C" {
#[doc = " Destroy a reconstructed stack and free all frame memory."]
pub fn vtx_reconstructed_stack_destroy(stack: *mut vtx_reconstructed_stack_t);
}
extern "C" {
#[doc = " Add a reconstructed frame to the stack.\n Returns 0 on success, -1 on failure."]
pub fn vtx_reconstructed_stack_add_frame(
stack: *mut vtx_reconstructed_stack_t,
frame: *const vtx_reconstructed_frame_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Initialize a side table registry."]
pub fn vtx_side_table_registry_init(
registry: *mut vtx_side_table_registry_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Destroy a side table registry."]
pub fn vtx_side_table_registry_destroy(registry: *mut vtx_side_table_registry_t);
}
extern "C" {
#[doc = " Register a compiled code range with its side table."]
pub fn vtx_side_table_registry_add(
registry: *mut vtx_side_table_registry_t,
code_start: *mut ::std::os::raw::c_void,
code_size: u32,
side_table: *mut vtx_side_table_t,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Look up the side table for a code address.\n Returns the side table, or NULL if not found."]
pub fn vtx_side_table_registry_lookup(
registry: *const vtx_side_table_registry_t,
code_addr: *const ::std::os::raw::c_void,
) -> *mut vtx_side_table_t;
}
extern "C" {
#[doc = " Read the saved frame pointer from a compiled frame.\n On x86-64, this is the value at [fp + 0].\n Returns 0 on success, -1 on failure (e.g., invalid fp)."]
pub fn vtx_stack_walk_read_caller_fp(
fp: *mut ::std::os::raw::c_void,
out_caller_fp: *mut *mut ::std::os::raw::c_void,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Read the return address from a compiled frame.\n On x86-64, this is the value at [fp + 8].\n Returns 0 on success, -1 on failure."]
pub fn vtx_stack_walk_read_return_addr(
fp: *mut ::std::os::raw::c_void,
out_return_addr: *mut *mut ::std::os::raw::c_void,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Determine the kind of frame at the given frame pointer.\n Uses heuristics: if the code at the return address falls within a known\n compiled code range, it's a compiled frame. Otherwise it's native or\n interpreted."]
pub fn vtx_stack_walk_classify_frame(
registry: *const vtx_side_table_registry_t,
fp: *mut ::std::os::raw::c_void,
) -> vtx_frame_kind_t;
}
extern "C" {
#[doc = " Compress a frame's locals and operand stack into a compact snapshot.\n Uses run-length encoding: consecutive identical values are stored as\n (value, count). For typical interpreter frames (many nulls and zeros),\n this achieves 3-5x compression.\n\n @param frame The frame to compress (must have locals/stack populated)\n @return Newly allocated compressed buffer, or NULL on failure.\n Caller must free() the returned buffer."]
pub fn vtx_frame_compress(frame: *const vtx_reconstructed_frame_t) -> *mut u8;
}
extern "C" {
#[doc = " Decompress a snapshot and populate the frame's locals/stack.\n This is called on demand when the interpreter needs to return into\n a frame that was lazily materialized.\n\n @param frame The frame to decompress into (must have compressed_snapshot set)\n @return 0 on success, -1 on failure"]
pub fn vtx_frame_decompress(frame: *mut vtx_reconstructed_frame_t) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " Materialize a single frame on demand.\n If the frame is already materialized, this is a no-op.\n If the frame has a compressed snapshot, decompress it.\n\n @param frame The frame to materialize\n @return 0 on success, -1 on failure"]
pub fn vtx_frame_materialize_on_demand(
frame: *mut vtx_reconstructed_frame_t,
) -> ::std::os::raw::c_int;
}
#[doc = " Monitor state entry: tracks which objects are locked by this frame.\n Each entry records the local variable index holding the locked object\n and the object value itself (resolved at deopt time)."]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct vtx_osr_monitor_entry_t {
pub local_index: u32,
pub object: vtx_value_t,
}
#[doc = " Enhanced representation of an interpreter frame for OSR transitions.\n Matches the real interpreter frame from src/interp/frame.h more closely,\n including monitor state, exception handlers, return address, and frame kind."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_interp_frame_t {
pub method_id: u32,
pub bytecode_pc: u32,
pub locals: *mut vtx_value_t,
pub local_count: u32,
pub stack: *mut vtx_value_t,
pub stack_top: u32,
pub stack_capacity: u32,
pub caller: *mut vtx_frame_state_t,
pub osr_active: bool,
pub monitors: *mut vtx_osr_monitor_entry_t,
pub monitor_count: u32,
pub monitor_capacity: u32,
pub catch_handler_pc: u32,
pub return_pc: u32,
pub frame_kind: vtx_frame_kind_t,
}
impl Default for vtx_interp_frame_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[doc = " Information provided when a guard fails and OSR down is needed.\n This is populated by the deopt stub before calling vtx_osr_down.\n This is distinct from vtx_deopt_info_t (which is the static per-method\n deopt metadata) — this struct contains the dynamic runtime state\n at the point of deoptimization."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct vtx_osr_deopt_context_t {
pub method_id: u32,
pub native_pc: u32,
pub frame_state: *mut vtx_frame_state_t,
pub side_table: *mut vtx_side_table_t,
pub frame_pointer: *mut ::std::os::raw::c_void,
pub register_map: *mut vtx_value_t,
pub register_count: u32,
}
impl Default for vtx_osr_deopt_context_t {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
extern "C" {
#[doc = " Perform OSR up: replace the interpreter frame with a compiled frame\n and transfer control to the compiled code.\n\n Steps:\n 1. Verify the compiled code exists for the method at the loop header.\n 2. Build a FrameState from the interpreter's current local/stack state.\n 3. Set up the JIT frame: copy locals and stack into the JIT frame layout.\n 4. Patch the return address to point into the compiled code.\n 5. Transfer execution to the compiled code's entry point.\n\n @param interp Current interpreter frame\n @param method_id Method being executed\n @param compiled_code Compiled code descriptor for the method\n @param loop_header_pc Bytecode PC of the loop header (OSR entry point)\n @return true if OSR up was successful, false if not"]
pub fn vtx_osr_up(
interp: *mut vtx_interp_frame_t,
method_id: u32,
compiled_code: *const vtx_compiled_code_t,
loop_header_pc: u32,
) -> bool;
}
extern "C" {
#[doc = " Perform OSR down: replace the compiled frame with an interpreter frame\n and resume execution in the interpreter.\n\n Steps:\n 1. Look up the FrameState from the side table using the native PC.\n 2. Reconstruct the interpreter operand stack from the FrameState:\n - For each NodeID in the FrameState, evaluate the node to get a value.\n - Map NodeIDs to values using the register map and frame state.\n 3. Reconstruct the interpreter local variables similarly.\n 4. Handle monitors: relock any monitors that were held in compiled code.\n 5. Handle exception handlers: set up the active handler from FrameState.\n 6. Walk the caller chain and reconstruct caller interpreter frames.\n 7. Transfer execution to the interpreter dispatch loop at the deopt PC.\n\n @param interp Interpreter state to resume (output: populated with frame)\n @param deopt_info Information about the deoptimization point\n @return The interpreter resume frame, or NULL on failure"]
pub fn vtx_osr_down(
interp: *mut vtx_interp_frame_t,
deopt_ctx: *const vtx_osr_deopt_context_t,
) -> *mut vtx_interp_frame_t;
}
extern "C" {
#[doc = " Build an interpreter frame from a FrameState and a value resolution function.\n\n @param fs The FrameState to convert\n @param node_to_value Function that maps a NodeID to its current vtx_value_t\n @param context Opaque context passed to node_to_value\n @return A newly allocated interpreter frame, or NULL on failure"]
pub fn vtx_osr_build_interp_frame(
fs: *const vtx_frame_state_t,
node_to_value: ::std::option::Option<
unsafe extern "C" fn(
arg1: vtx_nodeid_t,
arg2: *mut ::std::os::raw::c_void,
) -> vtx_value_t,
>,
context: *mut ::std::os::raw::c_void,
) -> *mut vtx_interp_frame_t;
}
extern "C" {
#[doc = " Resolve a NodeID to its value at deopt time.\n Uses the register map and frame state to look up the value.\n\n @param node_id The NodeID to resolve\n @param register_map Array of values indexed by NodeID (from side table)\n @param map_size Size of the register map array\n @return The resolved value, or VTX_VALUE_UNDEFINED if not found"]
pub fn vtx_osr_resolve_node(
node_id: vtx_nodeid_t,
register_map: *const vtx_value_t,
map_size: u32,
) -> vtx_value_t;
}