Class: HeapInfo::UnsortedBin
- Defined in:
- lib/heapinfo/arena.rb
Overview
Class for record unsorted bin type chunk.
Direct Known Subclasses
Instance Attribute Summary collapse
- #bk ⇒ Integer readonly
Attributes inherited from Fastbin
Attributes inherited from Chunk
#base, #data, #prev_size, #size_t
Instance Method Summary collapse
-
#initialize ⇒ UnsortedBin
constructor
Instantiate a UnsortedBin object.
-
#inspect(size: 2) ⇒ String
Unsorted bin layouts wrapper with color codes.
-
#link_list(expand_size) ⇒ Array<Integer>
Return the double link list with bin in the center.
-
#pretty_list(list) ⇒ String
Wrapper the doubly linked list with color codes.
Methods inherited from Fastbin
Methods inherited from Chunk
#bintype, #flags, #mmapped?, #non_main_arena?, #prev_inuse?, #size, #to_s
Constructor Details
#initialize ⇒ UnsortedBin
Instantiate a HeapInfo::UnsortedBin object.
172 173 174 175 |
# File 'lib/heapinfo/arena.rb', line 172 def initialize(*, **) super @bk = Helper.unpack(size_t, @data[@size_t, @size_t]) end |
Instance Attribute Details
#bk ⇒ Integer (readonly)
167 168 169 |
# File 'lib/heapinfo/arena.rb', line 167 def bk @bk end |
Instance Method Details
#inspect(size: 2) ⇒ String
Returns Unsorted bin layouts wrapper with color codes.
180 181 182 183 184 185 |
# File 'lib/heapinfo/arena.rb', line 180 def inspect(size: 2) list = link_list(size) return '' if list.size <= 1 && Helper.class_name(self) != 'UnsortedBin' # bad.. title + pretty_list(list) + "\n" end |
#link_list(expand_size) ⇒ Array<Integer>
Return the double link list with bin in the center.
The list will like [..., bk of bk, bk of bin, bin, fd of bin, fd of fd, ...].
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/heapinfo/arena.rb', line 214 def link_list() list = [@base] # fd work = proc do |ptr, nxt, append| sz = 0 dup = {} while ptr != @base && sz < append.call(ptr) break if ptr.nil? || dup[ptr] # invalid or duplicated pointer dup[ptr] = true ptr = __send__(nxt, ptr) sz += 1 end end work.call(@fd, :fd_of, ->(ptr) { list << ptr }) work.call(@bk, :bk_of, ->(ptr) { list.unshift(ptr) }) list end |
#pretty_list(list) ⇒ String
Wrapper the doubly linked list with color codes.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/heapinfo/arena.rb', line 190 def pretty_list(list) center = nil list.map.with_index do |c, idx| next center = Helper.color('[self]', sev: :bin) if c == @base color_c = Helper.color(format('%#x', c)) fwd = fd_of(c) next "#{color_c}(invalid)" if fwd.nil? # invalid c bck = bk_of(c) if center.nil? # bk side format('%s%s', color_c, fwd == list[idx + 1] ? nil : Helper.color(format('(%#x)', fwd))) else # fd side format('%s%s', bck == list[idx - 1] ? nil : Helper.color(format('(%#x)', bck)), color_c) end end.join(' === ') end |