jvmti_rs/wrapper/jvmtifns/
memory_management.rs1use std::ptr;
2
3use crate::{
4 errors::*,
5 JVMTIEnv,
6 objects::*,
7 sys::*,
8};
9
10impl<'a> JVMTIEnv<'a> {
11 pub fn allocate(&self, size: jlong) -> Result<Option<JMemoryAllocate>> {
12 let mut mem_ptr: jmemory = ptr::null_mut();
13 let res = jvmti_call_result!(self.jvmti_raw(), Allocate,
14 size,
15 &mut mem_ptr
16 );
17 jvmti_error_code_to_result(res)?;
18 if mem_ptr.is_null() {
19 return Ok(None);
20 }
21 Ok(Some(JMemoryAllocate::new(mem_ptr, size, &self)))
22 }
23
24 pub fn deallocate_raw(&self, memory: jmemory) -> Result<()> {
25 jvmti_call!(self.jvmti_raw(), Deallocate,
26 memory
27 );
28 }
29
30 pub fn deallocate<T>(&self, memory: &T) -> Result<()>
31 where
32 T: JDeallocate<'a> {
33 jvmti_call!(self.jvmti_raw(), Deallocate,
34 memory.as_deallocate_ptr()
35 );
36 }
37}