jvmti_rs/wrapper/jvmtifns/
local_variable.rs

1use std::ptr;
2use jni::sys::jobject;
3use crate::{
4    errors::*,
5    JVMTIEnv,
6    objects::*,
7    sys::*,
8};
9
10impl<'a> JVMTIEnv<'a> {
11    pub fn get_local_instance(&self, thread: &JThreadID, depth: jint) -> Result<Option<JObject>> {
12        let res = jvmti_call_ptr_result!(self.jvmti_raw(), jobject,
13            GetLocalInstance,
14            thread.into(),
15            depth
16        );
17        if res.is_null() {
18            return Ok(None);
19        }
20        Ok(Some(res.into()))
21    }
22
23    pub fn get_local_object(&self, thread: &JThreadID, depth: jint, slot: jint) -> Result<Option<JObject>> {
24        let res = jvmti_call_ptr_result!(self.jvmti_raw(), jobject,
25            GetLocalObject,
26            thread.into(),
27            depth,
28            slot
29        );
30        if res.is_null() {
31            return Ok(None);
32        }
33        Ok(Some(res.into()))
34    }
35
36    pub fn get_local_int(&self, thread: &JThreadID, depth: jint, slot: jint) -> Result<jint> {
37        Ok(jvmti_call_number_result!(self.jvmti_raw(), jint,
38            GetLocalInt,
39            thread.into(),
40            depth,
41            slot
42        ))
43    }
44
45    pub fn get_local_long(&self, thread: &JThreadID, depth: jint, slot: jint) -> Result<jlong> {
46        Ok(jvmti_call_number_result!(self.jvmti_raw(), jlong,
47            GetLocalLong,
48            thread.into(),
49            depth,
50            slot
51       ))
52    }
53
54    pub fn get_local_float(&self, thread: &JThreadID, depth: jint, slot: jint) -> Result<jfloat> {
55        Ok(jvmti_call_number_result!(self.jvmti_raw(), jfloat,
56            GetLocalFloat,
57            thread.into(),
58            depth,
59            slot
60       ))
61    }
62
63    pub fn get_local_double(&self, thread: &JThreadID, depth: jint, slot: jint) -> Result<jdouble> {
64        Ok(jvmti_call_number_result!(self.jvmti_raw(), jdouble,
65            GetLocalDouble,
66            thread.into(),
67            depth,
68            slot
69       ))
70    }
71
72    pub fn set_local_object(&self, thread: &JThreadID, depth: jint, slot: jint, obj: &Option<JObject>) -> Result<()> {
73        jvmti_call!(self.jvmti_raw(), SetLocalObject,
74            thread.into(),
75            depth,
76            slot,
77            obj.map_or_else(|| ptr::null_mut(), |e| e.into_inner())
78        )
79    }
80
81    pub fn set_local_int(&self, thread: &JThreadID, depth: jint, slot: jint, value: jint) -> Result<()> {
82        jvmti_call!(self.jvmti_raw(), SetLocalInt,
83            thread.into(),
84            depth,
85            slot,
86            value
87        )
88    }
89
90    pub fn set_local_long(&self, thread: &JThreadID, depth: jint, slot: jint, value: jlong) -> Result<()> {
91        jvmti_call!(self.jvmti_raw(), SetLocalLong,
92            thread.into(),
93            depth,
94            slot,
95            value
96        )
97    }
98
99    pub fn set_local_float(&self, thread: &JThreadID, depth: jint, slot: jint, value: jfloat) -> Result<()> {
100        jvmti_call!(self.jvmti_raw(), SetLocalFloat,
101            thread.into(),
102            depth,
103            slot,
104            value
105        )
106    }
107
108    pub fn set_local_double(&self, thread: &JThreadID, depth: jint, slot: jint, value: jdouble) -> Result<()> {
109        jvmti_call!(self.jvmti_raw(), SetLocalDouble,
110            thread.into(),
111            depth,
112            slot,
113            value
114        )
115    }
116}