File tree 6 files changed +320
-87
lines changed
6 files changed +320
-87
lines changed Original file line number Diff line number Diff line change 15
15
*/
16
16
17
17
pub struct AgentController < ' a > {
18
+ #[ allow( dead_code) ] // TODO: revisit this once port is complete
18
19
jvmti : :: env:: JvmTiEnv ,
19
20
heuristic : Box < super :: Heuristic + ' a > ,
20
21
actions : Vec < Box < super :: Action > >
@@ -126,9 +127,9 @@ mod tests {
126
127
ac. on_oom ( dummy_jni_env ( ) , 0 ) ;
127
128
}
128
129
129
- unsafe extern "C" fn test_get_env ( vm : * mut :: jvmti:: JavaVM ,
130
- penv : * mut * mut :: std:: os:: raw:: c_void ,
131
- version : :: jvmti:: jint )
130
+ unsafe extern "C" fn test_get_env ( _ : * mut :: jvmti:: JavaVM ,
131
+ _ : * mut * mut :: std:: os:: raw:: c_void ,
132
+ _ : :: jvmti:: jint )
132
133
-> :: jvmti:: jint {
133
134
0
134
135
}
Original file line number Diff line number Diff line change 14
14
* limitations under the License.
15
15
*/
16
16
17
+ use env:: JvmTI ;
18
+ use std:: io:: Write ;
19
+ use std:: io:: stdout;
20
+ use heap:: Tagger ;
21
+ use heap:: Tag ;
22
+ use heap:: Stats ;
23
+ use heap:: Record ;
24
+ use heap:: Print ;
25
+
17
26
pub struct HeapHistogram {
18
27
jvmti : :: env:: JvmTiEnv ,
19
28
}
20
29
21
30
impl HeapHistogram {
22
- pub fn new ( jvmti : :: env:: JvmTiEnv ) -> Result < Self , :: jvmti:: jint > {
31
+ pub fn new ( mut jvmti : :: env:: JvmTiEnv ) -> Result < Self , :: jvmti:: jint > {
32
+ jvmti. enable_object_tagging ( ) ?;
23
33
Ok ( Self {
24
- jvmti : jvmti
34
+ jvmti : jvmti,
25
35
} )
26
36
}
37
+
38
+ pub fn print ( & self , writer : & mut Write ) {
39
+ let mut tagger = Tagger :: new ( ) ;
40
+
41
+ // Tag all loaded classes so we can determine each object's class signature during heap traversal.
42
+ self . jvmti . tag_loaded_classes ( & mut tagger) ;
43
+
44
+ let mut heap_stats = Stats :: new ( ) ;
45
+
46
+ // Traverse the live heap and add objects to the heap stats.
47
+ self . jvmti . traverse_live_heap ( |class_tag : :: jvmti:: jlong , size : :: jvmti:: jlong | {
48
+ if let Some ( sig) = tagger. class_signature ( class_tag) {
49
+ heap_stats. recordObject ( sig, size) ;
50
+ }
51
+ } ) ;
52
+
53
+ heap_stats. print ( writer) ;
54
+ }
27
55
}
28
56
29
57
impl super :: Action for HeapHistogram {
30
- fn on_oom ( & self , jni_env : :: env:: JniEnv , resource_exhaustion_flags : :: jvmti:: jint ) {
58
+ fn on_oom ( & self , _: :: env:: JniEnv , _: :: jvmti:: jint ) {
59
+ self . print ( & mut stdout ( ) ) ;
31
60
}
32
61
}
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ impl Kill {
30
30
}
31
31
}
32
32
33
+ #[ cfg( test) ]
33
34
pub fn setSignal ( & mut self , signal : c_int ) {
34
35
self . signal = signal;
35
36
}
@@ -93,7 +94,7 @@ mod tests {
93
94
signal:: SaFlags :: empty ( ) ,
94
95
signal:: SigSet :: empty ( ) ) ;
95
96
unsafe {
96
- signal:: sigaction ( signal:: SIGUSR1 , & sig_action) ;
97
+ signal:: sigaction ( signal:: SIGUSR1 , & sig_action) . unwrap ( ) ;
97
98
}
98
99
}
99
100
}
You can’t perform that action at this time.
0 commit comments