Struct Instance

Source
pub struct Instance<'a> { /* private fields */ }
Expand description

An instance of a reference type (i.e. not a primitive).

Implementations§

Source§

impl<'a> Instance<'a>

Source

pub fn obj_id(&self) -> Id

Source

pub fn stack_trace_serial(&self) -> Serial

Source

pub fn class_obj_id(&self) -> Id

Source§

impl<'a> Instance<'a>

Source

pub fn fields(&self) -> &&'a [u8]

Instance field values, root class’s fields last.

§Example

Once you have assembled the class hierarchy and have accumulated all the field descriptors, instance fields can be parsed like so (adapted from print_field_val in the examples):

use jvm_hprof::heap_dump::{FieldDescriptor, Instance, FieldValue};
use jvm_hprof::{Hprof, IdSize, Id};
use std::collections::HashMap;

fn print_field_val(
    instance: Instance,
    field_descriptors: &[FieldDescriptor],
    id_size: IdSize,
    utf8: HashMap<Id, &str>
    ) {
   let mut field_val_input: &[u8] = instance.fields();
   for fd in field_descriptors.iter() {
       let (input, field_val) = fd
           .field_type()
           .parse_value(field_val_input, id_size)
           .unwrap();
       field_val_input = input;
       let field_name =
           utf8.get(&fd.name_id()).unwrap_or_else(|| &"missing");

       match field_val {
           FieldValue::ObjectId(Some(id)) => println!("{}: ref to obj id {}", field_name, id),
           FieldValue::ObjectId(null) => println!("{}: ref to null", field_name),
           FieldValue::Int(i) => println!("{}: int {}", field_name, i),
           _ => { /* and so forth */ }
       }
   }
}

Auto Trait Implementations§

§

impl<'a> Freeze for Instance<'a>

§

impl<'a> RefUnwindSafe for Instance<'a>

§

impl<'a> Send for Instance<'a>

§

impl<'a> Sync for Instance<'a>

§

impl<'a> Unpin for Instance<'a>

§

impl<'a> UnwindSafe for Instance<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.