Class: Heapviz::Slot

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/heapviz/slot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Slot

Returns a new instance of Slot.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/heapviz/slot.rb', line 10

def initialize(json)
  attrs = JSON.parse(json)

  @type = attrs.fetch("type")
  if !gc_root?
      @address  = attrs.fetch("address").to_i(16)
      @size     = attrs.fetch("slot_size")
  end
  @flags    = attrs.fetch("flags", {})

  @page_body_address = @address & ~Heap::HEAP_PAGE_ALIGN_MASK
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



8
9
10
# File 'lib/heapviz/slot.rb', line 8

def address
  @address
end

#flagsObject (readonly)

Returns the value of attribute flags.



8
9
10
# File 'lib/heapviz/slot.rb', line 8

def flags
  @flags
end

#page_body_addressObject (readonly)

Returns the value of attribute page_body_address.



8
9
10
# File 'lib/heapviz/slot.rb', line 8

def page_body_address
  @page_body_address
end

#sizeObject (readonly)

Returns the value of attribute size.



8
9
10
# File 'lib/heapviz/slot.rb', line 8

def size
  @size
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/heapviz/slot.rb', line 8

def type
  @type
end

Instance Method Details

#<=>(o) ⇒ Object



35
36
37
# File 'lib/heapviz/slot.rb', line 35

def <=>(o)
  address <=> o.address
end

#gc_root?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/heapviz/slot.rb', line 23

def gc_root?
  @type == "ROOT"
end

#has_flags?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/heapviz/slot.rb', line 31

def has_flags?
  !gc_root?
end

#pinned?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/heapviz/slot.rb', line 27

def pinned?
  @flags.fetch('pinned', false)
end

#to_sObject



39
40
41
# File 'lib/heapviz/slot.rb', line 39

def to_s
  "{address: 0x#{address.to_s(16)}, type: #{type}, flags: #{flags}}"
end