@@ -138,26 +138,22 @@ protected long time() {
138
138
@ Primitive (name = "gc_stat" )
139
139
public abstract static class GCStatPrimitiveNode extends PrimitiveArrayArgumentsNode {
140
140
141
- @ TruffleBoundary
142
141
@ Specialization
143
- protected RubyArray stat (
144
- @ Cached StringNodes .MakeStringNode makeStringNode ) {
142
+ protected RubyArray stat () {
143
+ final long [] data = getGCData ();
144
+ return createArray (data );
145
+ }
146
+
147
+ @ TruffleBoundary
148
+ private long [] getGCData () {
145
149
long time = 0 ;
146
- int count = 0 ;
147
- int minorCount = 0 ;
148
- int majorCount = 0 ;
149
- int unknownCount = 0 ;
150
- String [] memoryPoolNames = new String [0 ];
151
- Object [] memoryPools ;
150
+ long count = 0 ;
151
+ long minorCount = 0 ;
152
+ long majorCount = 0 ;
153
+ long unknownCount = 0 ;
152
154
153
155
// Get GC time and counts from GarbageCollectorMXBean
154
156
for (GarbageCollectorMXBean bean : ManagementFactory .getGarbageCollectorMXBeans ()) {
155
- // Get MemoryPoolName relevant to GC
156
- if (bean .getMemoryPoolNames ().length > memoryPoolNames .length ) {
157
- // Since old generation memory pools are a superset of young generation memory pools,
158
- // it suffices to check that we have the longer list of memory pools
159
- memoryPoolNames = bean .getMemoryPoolNames ();
160
- }
161
157
time += bean .getCollectionTime ();
162
158
count += bean .getCollectionCount ();
163
159
switch (bean .getName ()) {
@@ -177,6 +173,43 @@ protected RubyArray stat(
177
173
}
178
174
}
179
175
176
+ final MemoryUsage total = ManagementFactory .getMemoryMXBean ().getHeapMemoryUsage ();
177
+
178
+ return new long []{
179
+ time ,
180
+ count ,
181
+ minorCount ,
182
+ majorCount ,
183
+ unknownCount ,
184
+ total .getUsed (),
185
+ total .getCommitted (),
186
+ total .getInit (),
187
+ total .getMax (),
188
+ };
189
+ }
190
+
191
+ }
192
+
193
+ @ Primitive (name = "gc_heap_stats" )
194
+ public abstract static class GCHeapStatsNode extends PrimitiveArrayArgumentsNode {
195
+
196
+ @ TruffleBoundary
197
+ @ Specialization
198
+ protected RubyArray heapStats (
199
+ @ Cached StringNodes .MakeStringNode makeStringNode ) {
200
+ String [] memoryPoolNames = new String [0 ];
201
+ Object [] memoryPools ;
202
+
203
+ // Get GC time and counts from GarbageCollectorMXBean
204
+ for (GarbageCollectorMXBean bean : ManagementFactory .getGarbageCollectorMXBeans ()) {
205
+ // Get MemoryPoolName relevant to GC
206
+ if (bean .getMemoryPoolNames ().length > memoryPoolNames .length ) {
207
+ // Since old generation memory pools are a superset of young generation memory pools,
208
+ // it suffices to check that we have the longer list of memory pools
209
+ memoryPoolNames = bean .getMemoryPoolNames ();
210
+ }
211
+ }
212
+
180
213
// Get memory usage values from relevant memory pools (2-3 / ~8 are relevant)
181
214
memoryPools = new Object [memoryPoolNames .length ];
182
215
// On Native Image, ManagementFactory.getMemoryPoolMXBeans() is empty
@@ -190,33 +223,19 @@ protected RubyArray stat(
190
223
}
191
224
}
192
225
193
- MemoryUsage total = ManagementFactory .getMemoryMXBean ().getHeapMemoryUsage ();
194
-
195
226
Object [] memoryPoolNamesCast = new Object [memoryPoolNames .length ];
196
227
for (int i = 0 ; i < memoryPoolNames .length ; i ++) {
197
228
memoryPoolNamesCast [i ] = makeStringNode
198
229
.executeMake (memoryPoolNames [i ], UTF8Encoding .INSTANCE , CodeRange .CR_UNKNOWN );
199
230
}
200
231
201
232
202
- return createArray (
203
- new Object []{
204
- time ,
205
- count ,
206
- minorCount ,
207
- majorCount ,
208
- unknownCount ,
209
- createArray (new long []{
210
- total .getUsed (),
211
- total .getCommitted (),
212
- total .getInit (),
213
- total .getMax (),
214
- }),
215
- createArray (memoryPoolNamesCast ),
216
- createArray (memoryPools ) });
233
+ return createArray (new Object []{
234
+ createArray (memoryPoolNamesCast ),
235
+ createArray (memoryPools ) });
217
236
}
218
237
219
- protected RubyArray beanToArray (MemoryPoolMXBean bean ) {
238
+ private RubyArray beanToArray (MemoryPoolMXBean bean ) {
220
239
MemoryUsage usage = bean .getUsage ();
221
240
MemoryUsage peak = bean .getPeakUsage ();
222
241
MemoryUsage last = bean .getCollectionUsage ();
0 commit comments