jvmti_rs/wrapper/jvmtifns/
method_static.rs

1use std::ptr;
2
3use jni::strings::JNIString;
4
5use crate::{builder::*, errors::*, JVMTIEnv, objects::*, sys::*, to_bool, Transform};
6use crate::sys;
7
8impl<'a> JVMTIEnv<'a> {
9    pub fn get_method_declaring_class_s<K, M, V>(&self, jni: &jni::JNIEnv<'a>, class: K, name: M, sig: V) -> Result<JObject>
10        where
11            K: Transform<'a, JClass<'a>>,
12            M: Into<JNIString>,
13            V: Into<JNIString> {
14        let method = self.get_static_method_id(jni, class, name, sig)?;
15
16        let mut value: jclass = ptr::null_mut();
17        let res = jvmti_call_result!(self.jvmti_raw(), GetMethodDeclaringClass,
18            method.into_inner(),
19            &mut value
20        );
21        jvmti_error_code_to_result(res)?;
22        Ok(value.into())
23    }
24
25    pub fn get_method_modifiers_s<K, M, V>(&self, jni: &jni::JNIEnv<'a>, class: K, name: M, sig: V) -> Result<jint>
26        where
27            K: Transform<'a, JClass<'a>>,
28            M: Into<JNIString>,
29            V: Into<JNIString> {
30        let method = self.get_static_method_id(jni, class, name, sig)?;
31
32        Ok(jvmti_call_number_result!(self.jvmti_raw(), jint,
33            GetMethodModifiers,
34            method.into_inner()
35        ))
36    }
37
38    pub fn get_max_locals_s<K, M, V>(&self, jni: &jni::JNIEnv<'a>, class: K, name: M, sig: V) -> Result<jint>
39        where
40            K: Transform<'a, JClass<'a>>,
41            M: Into<JNIString>,
42            V: Into<JNIString> {
43        let method = self.get_static_method_id(jni, class, name, sig)?;
44
45        Ok(jvmti_call_number_result!(self.jvmti_raw(), jint,
46            GetMaxLocals,
47            method.into_inner()
48        ))
49    }
50
51    pub fn get_arguments_size_s<K, M, V>(&self, jni: &jni::JNIEnv<'a>, class: K, name: M, sig: V) -> Result<jint>
52        where
53            K: Transform<'a, JClass<'a>>,
54            M: Into<JNIString>,
55            V: Into<JNIString> {
56        let method = self.get_static_method_id(jni, class, name, sig)?;
57
58        Ok(jvmti_call_number_result!(self.jvmti_raw(), jint,
59            GetArgumentsSize,
60            method.into_inner()
61        ))
62    }
63
64    pub fn get_line_number_table_s<K, M, V>(&self, jni: &jni::JNIEnv<'a>, class: K, name: M, sig: V) -> Result<Vec<JLineNumberEntry>>
65        where
66            K: Transform<'a, JClass<'a>>,
67            M: Into<JNIString>,
68            V: Into<JNIString> {
69        let method = self.get_static_method_id(jni, class, name, sig)?;
70
71        let mut builder: MutAutoDeallocateObjectArrayBuilder<jvmtiLineNumberEntry> = MutAutoDeallocateObjectArrayBuilder::new();
72        let res = jvmti_call_result!( self.jvmti_raw(), GetLineNumberTable,
73            method.into_inner(),
74            &mut builder.count,
75            &mut builder.items
76        );
77        jvmti_error_code_to_result(res)?;
78        Ok(builder.build(self))
79    }
80
81    pub fn get_method_location_s<K, M, V>(&self, jni: &jni::JNIEnv<'a>, class: K, name: M, sig: V) -> Result<JMethodLocation>
82        where
83            K: Transform<'a, JClass<'a>>,
84            M: Into<JNIString>,
85            V: Into<JNIString> {
86        let method = self.get_static_method_id(jni, class, name, sig)?;
87
88        let mut start_location: sys::jlocation = 0 as sys::jlocation;
89        let mut end_location: sys::jlocation = 0 as sys::jlocation;
90        let res = jvmti_call_result!(self.jvmti_raw(), GetMethodLocation,
91            method.into_inner(),
92            &mut start_location,
93            &mut end_location
94        );
95        jvmti_error_code_to_result(res)?;
96        Ok(JMethodLocation::new(start_location, end_location))
97    }
98
99    pub fn get_local_variable_table_s<K, M, V>(&self, jni: &jni::JNIEnv<'a>, class: K, name: M, sig: V) -> Result<Vec<JLocalVariableEntry>>
100        where
101            K: Transform<'a, JClass<'a>>,
102            M: Into<JNIString>,
103            V: Into<JNIString> {
104        let method = self.get_static_method_id(jni, class, name, sig)?;
105
106        let mut builder: MutAutoDeallocateObjectArrayBuilder<jvmtiLocalVariableEntry> = MutAutoDeallocateObjectArrayBuilder::new();
107        let res = jvmti_call_result!( self.jvmti_raw(), GetLocalVariableTable,
108            method.into_inner(),
109            &mut builder.count,
110            &mut builder.items
111        );
112        jvmti_error_code_to_result(res)?;
113        Ok(builder.build(self))
114    }
115
116    pub fn get_bytecodes_s<K, M, V>(&self, jni: &jni::JNIEnv<'a>, class: K, name: M, sig: V) -> Result<JMemoryAllocate>
117        where
118            K: Transform<'a, JClass<'a>>,
119            M: Into<JNIString>,
120            V: Into<JNIString> {
121        let method = self.get_static_method_id(jni, class, name, sig)?;
122
123        let mut bytecode_count: jint = 0 as jint;
124        let mut bytecodes_ptr: jmemory = ptr::null_mut();
125        let res = jvmti_call_result!(self.jvmti_raw(), GetBytecodes,
126            method.into_inner(),
127            &mut bytecode_count,
128            &mut bytecodes_ptr
129        );
130        jvmti_error_code_to_result(res)?;
131        Ok(JMemoryAllocate::new(bytecodes_ptr, bytecode_count as jlong, self))
132    }
133
134    pub fn is_method_native_s<K, M, V>(&self, jni: &jni::JNIEnv<'a>, class: K, name: M, sig: V) -> Result<bool>
135        where
136            K: Transform<'a, JClass<'a>>,
137            M: Into<JNIString>,
138            V: Into<JNIString> {
139        let method = self.get_static_method_id(jni, class, name, sig)?;
140
141        let res = jvmti_call_number_result!(self.jvmti_raw(), jboolean,
142            IsMethodNative,
143            method.into_inner()
144        );
145        Ok(to_bool(res))
146    }
147
148    pub fn is_method_synthetic_s<K, M, V>(&self, jni: &jni::JNIEnv<'a>, class: K, name: M, sig: V) -> Result<bool>
149        where
150            K: Transform<'a, JClass<'a>>,
151            M: Into<JNIString>,
152            V: Into<JNIString> {
153        let method = self.get_static_method_id(jni, class, name, sig)?;
154
155        let res = jvmti_call_number_result!(self.jvmti_raw(), jboolean,
156            IsMethodSynthetic,
157            method.into_inner()
158        );
159        Ok(to_bool(res))
160    }
161
162    pub fn is_method_obsolete_s<K, M, V>(&self, jni: &jni::JNIEnv<'a>, class: K, name: M, sig: V) -> Result<bool>
163        where
164            K: Transform<'a, JClass<'a>>,
165            M: Into<JNIString>,
166            V: Into<JNIString> {
167        let method = self.get_static_method_id(jni, class, name, sig)?;
168
169        let res = jvmti_call_number_result!(self.jvmti_raw(), jboolean,
170            IsMethodObsolete,
171            method.into_inner()
172        );
173        Ok(to_bool(res))
174    }
175}