Class: Heapviz::Page
- Inherits:
-
Object
- Object
- Heapviz::Page
- Defined in:
- lib/heapviz/page.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#live_objects ⇒ Object
readonly
Returns the value of attribute live_objects.
-
#slot_size ⇒ Object
readonly
Returns the value of attribute slot_size.
Instance Method Summary collapse
- #each_slot ⇒ Object
- #fill_slot(slot) ⇒ Object
- #fragmented? ⇒ Boolean
- #full? ⇒ Boolean
-
#initialize(address, obj_start_address, capacity, slot_size) ⇒ Page
constructor
A new instance of Page.
- #live_object_count ⇒ Object
- #pinned_count ⇒ Object
- #sorted_objects ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(address, obj_start_address, capacity, slot_size) ⇒ Page
Returns a new instance of Page.
5 6 7 8 9 10 11 12 |
# File 'lib/heapviz/page.rb', line 5 def initialize(address, obj_start_address, capacity, slot_size) @address = address @obj_start_address = obj_start_address @capacity = capacity @slot_size = slot_size @live_objects = [] end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
3 4 5 |
# File 'lib/heapviz/page.rb', line 3 def address @address end |
#live_objects ⇒ Object (readonly)
Returns the value of attribute live_objects.
3 4 5 |
# File 'lib/heapviz/page.rb', line 3 def live_objects @live_objects end |
#slot_size ⇒ Object (readonly)
Returns the value of attribute slot_size.
3 4 5 |
# File 'lib/heapviz/page.rb', line 3 def slot_size @slot_size end |
Instance Method Details
#each_slot ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/heapviz/page.rb', line 19 def each_slot return enum_for(:each_slot) unless block_given? objs = sorted_objects @capacity.times do |i| expected = @obj_start_address + (i * slot_size) if objs.any? && objs.first.address == expected yield objs.shift else yield nil end end end |
#fill_slot(slot) ⇒ Object
14 15 16 17 |
# File 'lib/heapviz/page.rb', line 14 def fill_slot(slot) fail "slot size mismatch" if slot.size != @slot_size @live_objects << slot end |
#fragmented? ⇒ Boolean
50 51 52 |
# File 'lib/heapviz/page.rb', line 50 def fragmented? !full? end |
#full? ⇒ Boolean
38 39 40 |
# File 'lib/heapviz/page.rb', line 38 def full? @live_objects.count == @capacity end |
#live_object_count ⇒ Object
46 47 48 |
# File 'lib/heapviz/page.rb', line 46 def live_object_count @live_objects.count end |
#pinned_count ⇒ Object
42 43 44 |
# File 'lib/heapviz/page.rb', line 42 def pinned_count @pinned_count ||= live_objects.find_all { |lo| lo.dig("flags", "pinned") }.count end |
#sorted_objects ⇒ Object
34 35 36 |
# File 'lib/heapviz/page.rb', line 34 def sorted_objects @live_objects.sort end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/heapviz/page.rb', line 54 def to_s "{page: #{address.to_s(16)}, slot_size: #{slot_size}, full: #{full?}}" end |