Class: HeapInfo::Fastbin

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

Overview

Class for record fastbin type chunk.

Direct Known Subclasses

TcacheEntry, 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(_size_t, base) ⇒ Fastbin

Instantiate a HeapInfo::Fastbin object.

See Also:



92
93
94
95
# File 'lib/heapinfo/arena.rb', line 92

def initialize(_size_t, base, *, **)
  super
  @fd = fd_of(base)
end

Instance Attribute Details

#fdInteger (readonly)

Returns fd.

Returns:

  • (Integer)

    fd



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

def fd
  @fd
end

#indexInteger

Returns index.

Returns:

  • (Integer)

    index



87
88
89
# File 'lib/heapinfo/arena.rb', line 87

def index
  @index
end

Instance Method Details

#idx_to_sizeInteger

Mapping index of fastbin to chunk size.

Returns:

  • (Integer)

    size



99
100
101
# File 'lib/heapinfo/arena.rb', line 99

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

#inspectString

Pretty inspect.

Returns:

  • (String)

    fastbin layouts wrapper with color codes.



113
114
115
116
117
118
119
120
# File 'lib/heapinfo/arena.rb', line 113

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)


127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/heapinfo/arena.rb', line 127

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.



105
106
107
108
109
# File 'lib/heapinfo/arena.rb', line 105

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