Skip to content

Commit f8b4abf

Browse files
committed
Several gems need at least some value for total_allocated_objects
1 parent 6026ead commit f8b4abf

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Compatibility:
6666
* Implemented the `Time.at` `in:` parameter.
6767
* Implemented `Kernel#raise` `cause` parameter.
6868
* Improved compatibility of `Signal.trap` and `Kernel#trap` (#2287, @chrisseaton).
69+
* Implemented `GC.stat(:total_allocated_objects)` as `0` (#2292, @chrisseaton).
6970

7071
Performance:
7172

spec/ruby/core/gc/stat_spec.rb

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
require_relative '../../spec_helper'
22

33
describe "GC.stat" do
4-
it "supports access by key" do
5-
keys = [:heap_free_slots, :total_allocated_objects, :count]
6-
keys.each do |key|
7-
GC.stat(key).should be_kind_of(Integer)
8-
end
9-
end
10-
114
it "returns hash of values" do
125
stat = GC.stat
136
stat.should be_kind_of(Hash)
147
stat.keys.should include(:count)
158
end
169

10+
it "can return a single value" do
11+
GC.stat(:count).should be_kind_of(Integer)
12+
end
13+
1714
it "increases count after GC is run" do
1815
count = GC.stat(:count)
1916
GC.start
@@ -25,4 +22,16 @@
2522
GC.start
2623
GC.stat(:major_gc_count).should > count
2724
end
25+
26+
it "provides some number for count" do
27+
GC.stat(:count).should be_kind_of(Integer)
28+
end
29+
30+
it "provides some number for heap_free_slots" do
31+
GC.stat(:heap_free_slots).should be_kind_of(Integer)
32+
end
33+
34+
it "provides some number for total_allocated_objects" do
35+
GC.stat(:total_allocated_objects).should be_kind_of(Integer)
36+
end
2837
end

src/main/ruby/truffleruby/core/gc.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ def garbage_collect
7676
end
7777

7878
def self.stat(option = nil)
79-
time, count, minor_count, major_count, unknown_count, heap, memory_pool_names, memory_pool_info = Primitive.gc_stat()
79+
time, count, minor_count, major_count, unknown_count, heap, memory_pool_names, memory_pool_info = Primitive.gc_stat
8080
used, committed, init, max = heap
8181

82-
# Initialize stat for statistics that come from memory pools, and populate it with some final stats
82+
# Initialize stat for statistics that come from memory pools, and populate it with some final stats (ordering similar to MRI)
8383
stat = {
8484
count: count,
8585
time: time,
@@ -89,6 +89,7 @@ def self.stat(option = nil)
8989
heap_available_slots: committed,
9090
heap_live_slots: used,
9191
heap_free_slots: committed - used,
92+
total_allocated_objects: 0,
9293
used: used,
9394
committed: committed,
9495
init: init,

0 commit comments

Comments
 (0)