jvmti_rs/wrapper/jvmtifns/
thread_group.rs

1use std::ptr;
2
3use crate::{builder::*, errors::*, JThreadGroupInfo, JVMTIEnv, objects::*};
4use crate::sys;
5use crate::sys::{jthreadGroup, jvmtiThreadGroupInfo};
6
7impl<'a> JVMTIEnv<'a> {
8    pub fn get_top_thread_groups(&self) -> Result<Vec<JThreadGroupID>> {
9        let mut builder: MutAutoDeallocateObjectArrayBuilder<jthreadGroup> = MutAutoDeallocateObjectArrayBuilder::new();
10        let res = jvmti_call_result!( self.jvmti_raw(), GetTopThreadGroups,
11            &mut builder.count,
12            &mut builder.items
13        );
14        jvmti_error_code_to_result(res)?;
15        Ok(builder.build(self))
16    }
17
18    pub fn get_thread_group_info(&self, thread_group: &JThreadGroupID) -> Result<JThreadGroupInfo> {
19        let mut into_ptr: jvmtiThreadGroupInfo = jvmtiThreadGroupInfo {
20            parent: ptr::null_mut(),
21            name: ptr::null_mut(),
22            max_priority: 0,
23            is_daemon: 0,
24        };
25        let res = jvmti_call_result!(self.jvmti_raw(), GetThreadGroupInfo,
26            thread_group.into(),
27            &mut into_ptr
28        );
29        jvmti_error_code_to_result(res)?;
30        Ok(JThreadGroupInfo::new(into_ptr))
31    }
32
33    pub fn get_thread_group_children(&self, thread_group: &JThreadGroupID) -> Result<(Vec<JThreadID>, Vec<JThreadGroupID>)> {
34        let mut thread_builder: MutAutoDeallocateObjectArrayBuilder<sys::jthread> = MutAutoDeallocateObjectArrayBuilder::new();
35        let mut thread_group_builder: MutAutoDeallocateObjectArrayBuilder<jthreadGroup> = MutAutoDeallocateObjectArrayBuilder::new();
36
37        let res = jvmti_call_result!(self.jvmti_raw(), GetThreadGroupChildren,
38            thread_group.into(),
39            &mut thread_builder.count,
40            &mut thread_builder.items,
41            &mut thread_group_builder.count,
42            &mut thread_group_builder.items
43        );
44
45        jvmti_error_code_to_result(res)?;
46
47        Ok((thread_builder.build(self), thread_group_builder.build(self)))
48    }
49}