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:



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

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

Instance Attribute Details

#fdInteger (readonly)

Returns fd.

Returns:

  • (Integer)

    fd



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

def fd
  @fd
end

#indexInteger

Returns index.

Returns:

  • (Integer)

    index



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

def index
  @index
end

Instance Method Details

#idx_to_sizeInteger

Mapping index of fastbin to chunk size.

Returns:

  • (Integer)

    size



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

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

#inspectString

Pretty inspect.

Returns:

  • (String)

    fastbin layouts wrapper with color codes.



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

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)



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

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.



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

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