Skip to content

Commit 886e6fd

Browse files
committed
GC.stat: get total stats from getHeapMemoryUsage() rather than adding
* Since the individual memory pool stats are not available on Native Image. * Reorder fields to show used/committed (the most useful) first.
1 parent c50ccb8 commit 886e6fd

File tree

2 files changed

+36
-30
lines changed

2 files changed

+36
-30
lines changed

src/main/java/org/truffleruby/core/GCNodes.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ protected RubyArray stat(
190190
}
191191
}
192192

193-
MemoryUsage usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
193+
MemoryUsage total = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
194194

195195
Object[] memoryPoolNamesCast = new Object[memoryPoolNames.length];
196196
for (int i = 0; i < memoryPoolNames.length; i++) {
@@ -206,8 +206,12 @@ protected RubyArray stat(
206206
minorCount,
207207
majorCount,
208208
unknownCount,
209-
usage.getCommitted(),
210-
usage.getUsed(),
209+
createArray(new long[]{
210+
total.getUsed(),
211+
total.getCommitted(),
212+
total.getInit(),
213+
total.getMax(),
214+
}),
211215
createArray(memoryPoolNamesCast),
212216
createArray(memoryPools) });
213217
}
@@ -218,18 +222,19 @@ protected RubyArray beanToArray(MemoryPoolMXBean bean) {
218222
MemoryUsage last = bean.getCollectionUsage();
219223
return createArray(
220224
new long[]{
225+
usage.getUsed(),
221226
usage.getCommitted(),
222227
usage.getInit(),
223228
usage.getMax(),
224-
usage.getUsed(),
229+
peak.getUsed(),
225230
peak.getCommitted(),
226231
peak.getInit(),
227232
peak.getMax(),
228-
peak.getUsed(),
233+
last.getUsed(),
229234
last.getCommitted(),
230235
last.getInit(),
231236
last.getMax(),
232-
last.getUsed() });
237+
});
233238
}
234239

235240
}

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

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def garbage_collect
7676
end
7777

7878
def self.stat(option = nil)
79-
time, count, minor_count, major_count, unknown_count, committed, used, 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()
80+
used, committed, init, max = heap
8081

8182
# Initialize stat for statistics that come from memory pools, and populate it with some final stats
8283
stat = {
@@ -85,45 +86,45 @@ def self.stat(option = nil)
8586
minor_gc_count: minor_count,
8687
major_gc_count: major_count,
8788
unknown_count: unknown_count, # if nonzero, major or minor count needs to be updated for this GC case
88-
committed: 0,
89-
init: 0,
90-
max: 0,
91-
used: 0,
89+
heap_available_slots: committed,
90+
heap_live_slots: used,
91+
heap_free_slots: committed - used,
92+
used: used,
93+
committed: committed,
94+
init: init,
95+
max: max,
96+
peak_used: 0,
9297
peak_committed: 0,
9398
peak_init: 0,
9499
peak_max: 0,
95-
peak_used: 0,
100+
last_used: 0,
96101
last_committed: 0,
97102
last_init: 0,
98103
last_max: 0,
99-
last_used: 0,
100-
heap_available_slots: committed, # should be the same as the calculated committed
101-
heap_live_slots: used, # should be the same as the calculated used
102-
heap_free_slots: committed - used,
103104
}
104105

105106
memory_pool_names.each_with_index do |memory_pool_name, i|
106107
# Populate memory pool specific stats
107108
info = memory_pool_info[i]
108109
if info
109110
stat[memory_pool_name] = data = {
110-
committed: info[0],
111-
init: info[1],
112-
max: info[2],
113-
used: info[3],
114-
peak_committed: info[4],
115-
peak_init: info[5],
116-
peak_max: info[6],
117-
peak_used: info[7],
118-
last_committed: info[8],
119-
last_init: info[9],
120-
last_max: info[10],
121-
last_used: info[11],
111+
used: info[0],
112+
committed: info[1],
113+
init: info[2],
114+
max: info[3],
115+
peak_used: info[4],
116+
peak_committed: info[5],
117+
peak_init: info[6],
118+
peak_max: info[7],
119+
last_used: info[8],
120+
last_committed: info[9],
121+
last_init: info[10],
122+
last_max: info[11],
122123
}
123124

124-
# Calculate stats across memory pools
125+
# Calculate stats across memory pools for peak_/last_ (we already know the values for current usage)
125126
data.each_pair do |key, value|
126-
stat[key] += value
127+
stat[key] += value if key.start_with?('peak_', 'last_')
127128
end
128129
end
129130
end

0 commit comments

Comments
 (0)