Class: HeapInfo::Fastbin

Inherits:
Chunk
  • Object
show all
Defined in:
lib/heapinfo/arena.rb

Overview

Class for record fastbin type chunk.

Direct Known Subclasses

UnsortedBin

Instance Attribute Summary collapse

Attributes inherited from Chunk

#base, #data, #prev_size, #size_t

Instance Method Summary collapse

Methods inherited from Chunk

#bintype, #flags, #mmapped?, #non_main_arena?, #prev_inuse?, #size, #to_s

Constructor Details

#initialize(*args) ⇒ Fastbin

Instantiate a HeapInfo::Fastbin object.

Parameters:

  • args (Mixed)

    See Chunk for more information.


90
91
92
93
# File 'lib/heapinfo/arena.rb', line 90

def initialize(*args)
  super
  @fd = Helper.unpack(size_t, @data[0, @size_t])
end

Instance Attribute Details

#fdInteger (readonly)

Returns fd

Returns:

  • (Integer)

    fd


83
84
85
# File 'lib/heapinfo/arena.rb', line 83

def fd
  @fd
end

#indexInteger

Returns index

Returns:

  • (Integer)

    index


85
86
87
# File 'lib/heapinfo/arena.rb', line 85

def index
  @index
end

Instance Method Details

#bk_of(ptr) ⇒ Integer

Returns The bk.

Parameters:

  • ptr (Integer)

    Get the bk value of chunk at ptr.

Returns:

  • (Integer)

    The bk.


146
147
148
# File 'lib/heapinfo/arena.rb', line 146

def bk_of(ptr)
  addr_of(ptr, 3)
end

#fd_of(ptr) ⇒ Integer

Returns The fd.

Parameters:

  • ptr (Integer)

    Get the fd value of chunk at ptr.

Returns:

  • (Integer)

    The fd.


140
141
142
# File 'lib/heapinfo/arena.rb', line 140

def fd_of(ptr)
  addr_of(ptr, 2)
end

#idx_to_sizeInteger

Mapping index of fastbin to chunk size.

Returns:

  • (Integer)

    size


97
98
99
# File 'lib/heapinfo/arena.rb', line 97

def idx_to_size
  index * size_t * 2 + size_t * 4
end

#inspectString

Pretty inspect.

Returns:

  • (String)

    fastbin layouts wrapper with color codes.


111
112
113
114
115
116
117
# File 'lib/heapinfo/arena.rb', line 111

def inspect
  title + list.map do |ptr|
    next "(#{ptr})\n" if ptr.is_a? Symbol
    next " => (nil)\n" if ptr.nil?
    format(' => %s', Helper.color(format('%#x', ptr)))
  end.join
end

#listArray<Integer, Symbol, nil>

Returns single link list of fd chain. Last element will be:

  • :loop if loop detectded

  • :invalid invalid address detected

  • nil end with zero address (normal case)

Returns:

  • (Array<Integer, Symbol, nil>)

    single link list of fd chain. Last element will be:

    • :loop if loop detectded

    • :invalid invalid address detected

    • nil end with zero address (normal case)


124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/heapinfo/arena.rb', line 124

def list
  dup = {}
  ptr = @fd
  ret = []
  while ptr != 0
    ret << ptr
    return ret << :loop if dup[ptr]
    dup[ptr] = true
    ptr = fd_of(ptr)
    return ret << :invalid if ptr.nil?
  end
  ret << nil
end

#titleString

For pretty inspect.

Returns:

  • (String)

    Title with color codes.


103
104
105
106
107
# File 'lib/heapinfo/arena.rb', line 103

def title
  class_name = Helper.color(Helper.class_name(self), sev: :bin)
  size_str = index.nil? ? nil : "[#{Helper.color(format('%#x', idx_to_size))}]"
  "#{class_name}#{size_str}: "
end