File tree Expand file tree Collapse file tree 2 files changed +24
-19
lines changed
java/org/truffleruby/core Expand file tree Collapse file tree 2 files changed +24
-19
lines changed Original file line number Diff line number Diff line change 14
14
import java .lang .management .MemoryPoolMXBean ;
15
15
import java .lang .management .MemoryUsage ;
16
16
import java .time .Duration ;
17
+ import java .util .Arrays ;
17
18
18
19
import com .oracle .truffle .api .dsl .Cached ;
19
20
import org .jcodings .specific .UTF8Encoding ;
@@ -178,6 +179,8 @@ protected RubyArray stat(
178
179
179
180
// Get memory usage values from relevant memory pools (2-3 / ~8 are relevant)
180
181
memoryPools = new Object [memoryPoolNames .length ];
182
+ // On Native Image, ManagementFactory.getMemoryPoolMXBeans() is empty
183
+ Arrays .fill (memoryPools , nil );
181
184
for (int i = 0 ; i < memoryPoolNames .length ; i ++) {
182
185
String memoryPoolName = memoryPoolNames [i ];
183
186
for (MemoryPoolMXBean bean : ManagementFactory .getMemoryPoolMXBeans ()) {
Original file line number Diff line number Diff line change @@ -102,27 +102,29 @@ def self.stat(option = nil)
102
102
heap_free_slots : committed - used ,
103
103
}
104
104
105
- ( 0 ... memory_pool_names . length ) . each do |i |
105
+ memory_pool_names . each_with_index do |memory_pool_name , i |
106
106
# Populate memory pool specific stats
107
107
info = memory_pool_info [ i ]
108
- stat [ memory_pool_names [ i ] ] = {
109
- committed : info [ 0 ] ,
110
- init : info [ 1 ] ,
111
- max : info [ 2 ] ,
112
- used : info [ 3 ] ,
113
- peak_committed : info [ 4 ] ,
114
- peak_init : info [ 5 ] ,
115
- peak_max : info [ 6 ] ,
116
- peak_used : info [ 7 ] ,
117
- last_committed : info [ 8 ] ,
118
- last_init : info [ 9 ] ,
119
- last_max : info [ 10 ] ,
120
- last_used : info [ 11 ] ,
121
- }
122
-
123
- # Calculate stats across memory pools
124
- stat [ memory_pool_names [ i ] ] . each_pair do |key , value |
125
- stat [ key ] += value
108
+ if info
109
+ 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 ] ,
122
+ }
123
+
124
+ # Calculate stats across memory pools
125
+ data . each_pair do |key , value |
126
+ stat [ key ] += value
127
+ end
126
128
end
127
129
end
128
130
You can’t perform that action at this time.
0 commit comments