1 /* src/vmcore/statistics.c - global varables for statistics
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 $Id: statistics.c 7601 2007-03-28 23:02:50Z michi $
34 #include <sys/resource.h>
38 #include "mm/gc-common.h"
40 #include "toolbox/logging.h"
42 #include "vm/global.h"
44 #include "vm/jit/code.h"
46 #include "vmcore/class.h"
47 #include "vmcore/field.h"
48 #include "vmcore/method.h"
49 #include "vmcore/options.h"
50 #include "vmcore/statistics.h"
53 /* global variables ***********************************************************/
55 static s8 loadingtime = 0; /* accumulated loading time */
56 static s8 loadingstarttime = 0;
57 static s8 loadingstoptime = 0;
58 static s4 loadingtime_recursion = 0;
60 static s8 compilingtime = 0; /* accumulated compile time */
61 static s8 compilingstarttime = 0;
62 static s8 compilingstoptime = 0;
63 static s4 compilingtime_recursion = 0;
66 s4 maxcodememusage = 0;
73 s4 globalallocateddumpsize = 0;
74 s4 globaluseddumpsize = 0;
77 /* variables for measurements *************************************************/
79 s4 size_classinfo = 0;
80 s4 size_fieldinfo = 0;
81 s4 size_methodinfo = 0;
85 s4 size_stack_map = 0;
88 s4 size_threadobject = 0;
90 s4 size_lock_record_pool = 0;
91 s4 size_lock_hashtable = 0;
92 s4 size_lock_waiter = 0;
94 int count_const_pool_len = 0;
95 int count_classref_len = 0;
96 int count_parsed_desc_len = 0;
97 int count_vftbl_len = 0;
98 int count_all_methods = 0;
99 int count_methods_marked_used = 0; /* RTA */
101 int count_vmcode_len = 0;
102 int count_extable_len = 0;
103 int count_class_loads = 0;
104 int count_class_inits = 0;
106 int count_utf_len = 0; /* size of utf hash */
107 int count_utf_new = 0; /* calls of utf_new */
108 int count_utf_new_found = 0; /* calls of utf_new with fast return */
110 int count_locals_conflicts = 0; /* register allocator statistics */
111 int count_locals_spilled = 0;
112 int count_locals_register = 0;
113 int count_ss_spilled = 0;
114 int count_ss_register = 0;
115 int count_methods_allocated_by_lsra = 0;
116 int count_mem_move_bb = 0;
117 int count_interface_size = 0;
118 int count_argument_mem_ss = 0;
119 int count_argument_reg_ss = 0;
120 int count_method_in_register = 0;
121 int count_mov_reg_reg = 0;
122 int count_mov_mem_reg = 0;
123 int count_mov_reg_mem = 0;
124 int count_mov_mem_mem = 0;
126 int count_jit_calls = 0;
127 int count_methods = 0;
128 int count_spills = 0;
129 int count_spills_read = 0;
130 int count_pcmd_activ = 0;
131 int count_pcmd_drop = 0;
132 int count_pcmd_zero = 0;
133 int count_pcmd_const_store = 0;
134 int count_pcmd_const_alu = 0;
135 int count_pcmd_const_bra = 0;
136 int count_pcmd_load = 0;
137 int count_pcmd_move = 0;
138 int count_load_instruction = 0;
139 int count_pcmd_store = 0;
140 int count_pcmd_store_comb = 0;
141 int count_dup_instruction = 0;
142 int count_pcmd_op = 0;
143 int count_pcmd_mem = 0;
144 int count_pcmd_met = 0;
145 int count_pcmd_bra = 0;
146 int count_pcmd_table = 0;
147 int count_pcmd_return = 0;
148 int count_pcmd_returnx = 0;
149 int count_check_null = 0;
150 int count_check_bound = 0;
151 int count_max_basic_blocks = 0;
152 int count_basic_blocks = 0;
153 int count_javainstr = 0;
154 int count_max_javainstr = 0;
155 int count_javacodesize = 0;
156 int count_javaexcsize = 0;
158 int count_tryblocks = 0;
159 int count_code_len = 0;
160 int count_data_len = 0;
161 int count_cstub_len = 0;
162 int count_nstub_len = 0;
163 int count_max_new_stack = 0;
164 int count_upper_bound_new_stack = 0;
166 s4 count_branches_resolved = 0;
167 s4 count_branches_unresolved = 0;
169 u8 count_native_function_calls=0;
170 u8 count_jni_callXmethod_calls=0;
171 u8 count_jni_calls=0;
174 static int count_block_stack_init[11] = {
179 int *count_block_stack = count_block_stack_init;
180 static int count_analyse_iterations_init[5] = {
183 int *count_analyse_iterations = count_analyse_iterations_init;
184 static int count_method_bb_distribution_init[9] = {
188 int *count_method_bb_distribution = count_method_bb_distribution_init;
189 static int count_block_size_distribution_init[18] = {
195 int *count_block_size_distribution = count_block_size_distribution_init;
196 static int count_store_length_init[21] = {
203 int *count_store_length = count_store_length_init;
204 static int count_store_depth_init[11] = {
209 int *count_store_depth = count_store_depth_init;
212 /* instruction scheduler statistics *******************************************/
214 s4 count_schedule_basic_blocks = 0;
215 s4 count_schedule_nodes = 0;
216 s4 count_schedule_leaders = 0;
217 s4 count_schedule_max_leaders = 0;
218 s4 count_schedule_critical_path = 0;
221 /* nativeinvokation ***********************************************************
223 increments the native invokation count by one
225 *******************************************************************************/
227 void nativeinvokation(void)
229 /* XXX do locking here */
230 count_native_function_calls++;
234 /* jnicallXmethodinvokation ***************************************************
236 increments the jni CallXMethod invokation count by one
238 *******************************************************************************/
240 void jnicallXmethodnvokation(void)
242 /* XXX do locking here */
243 count_jni_callXmethod_calls++;
247 /* jniinvokation *************************************************************
249 increments the jni overall invokation count by one
251 *******************************************************************************/
253 void jniinvokation(void)
255 /* XXX do locking here */
260 /* getcputime *********************************** ******************************
262 Returns the used CPU time in microseconds
264 *******************************************************************************/
271 getrusage(RUSAGE_SELF, &ru);
272 sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
273 usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
275 return sec * 1000000 + usec;
279 /* loadingtime_stop ************************************************************
283 *******************************************************************************/
285 void loadingtime_start(void)
287 loadingtime_recursion++;
289 if (loadingtime_recursion == 1)
290 loadingstarttime = getcputime();
294 /* loadingtime_stop ************************************************************
298 *******************************************************************************/
300 void loadingtime_stop(void)
302 if (loadingtime_recursion == 1) {
303 loadingstoptime = getcputime();
304 loadingtime += (loadingstoptime - loadingstarttime);
307 loadingtime_recursion--;
311 /* compilingtime_stop **********************************************************
315 *******************************************************************************/
317 void compilingtime_start(void)
319 compilingtime_recursion++;
321 if (compilingtime_recursion == 1)
322 compilingstarttime = getcputime();
326 /* compilingtime_stop **********************************************************
330 *******************************************************************************/
332 void compilingtime_stop(void)
334 if (compilingtime_recursion == 1) {
335 compilingstoptime = getcputime();
336 compilingtime += (compilingstoptime - compilingstarttime);
339 compilingtime_recursion--;
343 /* print_times *****************************************************************
345 Prints a summary of CPU time usage.
347 *******************************************************************************/
349 void print_times(void)
354 totaltime = getcputime();
355 runtime = totaltime - loadingtime - compilingtime;
357 #if SIZEOF_VOID_P == 8
358 dolog("Time for loading classes: %6ld ms", loadingtime / 1000);
359 dolog("Time for compiling code: %6ld ms", compilingtime / 1000);
360 dolog("Time for running program: %6ld ms", runtime / 1000);
361 dolog("Total time: %6ld ms", totaltime / 1000);
363 dolog("Time for loading classes: %6lld ms", loadingtime / 1000);
364 dolog("Time for compiling code: %6lld ms", compilingtime / 1000);
365 dolog("Time for running program: %6lld ms", runtime / 1000);
366 dolog("Total time: %6lld ms", totaltime / 1000);
371 /* print_stats *****************************************************************
373 outputs detailed compiler statistics
375 *******************************************************************************/
377 void print_stats(void)
384 dolog("Number of JIT compiler calls: %6d", count_jit_calls);
385 dolog("Number of compiled methods: %6d", count_methods);
387 dolog("Number of compiled basic blocks: %6d",
389 dolog("Number of max. basic blocks per method: %6d",
390 count_max_basic_blocks);
392 dolog("Number of compiled JavaVM instructions: %6d",
394 dolog("Number of max. JavaVM instructions per method: %6d",
395 count_max_javainstr);
396 dolog("Size of compiled JavaVM instructions: %6d(%d)",
397 count_javacodesize, count_javacodesize - count_methods * 18);
399 dolog("Size of compiled Exception Tables: %d", count_javaexcsize);
400 dolog("Number of Machine-Instructions: %d", count_code_len >> 2);
401 dolog("Number of Spills (write to memory): %d", count_spills);
402 dolog("Number of Spills (read from memory): %d", count_spills_read);
403 dolog("Number of Activ Pseudocommands: %6d", count_pcmd_activ);
404 dolog("Number of Drop Pseudocommands: %6d", count_pcmd_drop);
405 dolog("Number of Const Pseudocommands: %6d (zero:%5d)",
406 count_pcmd_load, count_pcmd_zero);
407 dolog("Number of ConstAlu Pseudocommands: %6d (cmp: %5d, store:%5d)",
408 count_pcmd_const_alu, count_pcmd_const_bra, count_pcmd_const_store);
409 dolog("Number of Move Pseudocommands: %6d", count_pcmd_move);
410 dolog("Number of Load Pseudocommands: %6d", count_load_instruction);
411 dolog("Number of Store Pseudocommands: %6d (combined: %5d)",
412 count_pcmd_store, count_pcmd_store - count_pcmd_store_comb);
413 dolog("Number of OP Pseudocommands: %6d", count_pcmd_op);
414 dolog("Number of DUP Pseudocommands: %6d", count_dup_instruction);
415 dolog("Number of Mem Pseudocommands: %6d", count_pcmd_mem);
416 dolog("Number of Method Pseudocommands: %6d", count_pcmd_met);
417 dolog("Number of Branch Pseudocommands: %6d (rets:%5d, Xrets: %5d)",
418 count_pcmd_bra, count_pcmd_return, count_pcmd_returnx);
419 log_println(" resolved branches: %6d", count_branches_resolved);
420 log_println(" unresolved branches: %6d", count_branches_unresolved);
421 dolog("Number of Table Pseudocommands: %6d", count_pcmd_table);
422 dolog("Number of Useful Pseudocommands: %6d", count_pcmd_table +
423 count_pcmd_bra + count_pcmd_load + count_pcmd_mem + count_pcmd_op);
424 dolog("Number of Null Pointer Checks: %6d", count_check_null);
425 dolog("Number of Array Bound Checks: %6d", count_check_bound);
426 dolog("Number of Try-Blocks: %d", count_tryblocks);
427 dolog("Maximal count of stack elements: %d", count_max_new_stack);
428 dolog("Upper bound of max stack elements: %d", count_upper_bound_new_stack);
429 dolog("Distribution of stack sizes at block boundary");
430 dolog(" 0 1 2 3 4 5 6 7 8 9 >=10");
431 dolog("%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d",
432 count_block_stack[0], count_block_stack[1], count_block_stack[2],
433 count_block_stack[3], count_block_stack[4], count_block_stack[5],
434 count_block_stack[6], count_block_stack[7], count_block_stack[8],
435 count_block_stack[9], count_block_stack[10]);
436 dolog("Distribution of store stack depth");
437 dolog(" 0 1 2 3 4 5 6 7 8 9 >=10");
438 dolog("%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d",
439 count_store_depth[0], count_store_depth[1], count_store_depth[2],
440 count_store_depth[3], count_store_depth[4], count_store_depth[5],
441 count_store_depth[6], count_store_depth[7], count_store_depth[8],
442 count_store_depth[9], count_store_depth[10]);
443 dolog("Distribution of store creator chains first part");
444 dolog(" 0 1 2 3 4 5 6 7 8 9");
445 dolog("%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d",
446 count_store_length[0], count_store_length[1], count_store_length[2],
447 count_store_length[3], count_store_length[4], count_store_length[5],
448 count_store_length[6], count_store_length[7], count_store_length[8],
449 count_store_length[9]);
450 dolog("Distribution of store creator chains second part");
451 dolog(" 10 11 12 13 14 15 16 17 18 19 >=20");
452 dolog("%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d",
453 count_store_length[10], count_store_length[11],
454 count_store_length[12], count_store_length[13],
455 count_store_length[14], count_store_length[15],
456 count_store_length[16], count_store_length[17],
457 count_store_length[18], count_store_length[19],
458 count_store_length[20]);
459 dolog("Distribution of analysis iterations");
460 dolog(" 1 2 3 4 >=5");
461 dolog("%6d%6d%6d%6d%6d",
462 count_analyse_iterations[0], count_analyse_iterations[1],
463 count_analyse_iterations[2], count_analyse_iterations[3],
464 count_analyse_iterations[4]);
467 /* Distribution of basic blocks per method ********************************/
469 log_println("Distribution of basic blocks per method:");
470 log_println(" <=5 <=10 <=15 <=20 <=30 <=40 <=50 <=75 >75");
473 for (i = 0; i <= 8; i++)
474 log_print("%6d", count_method_bb_distribution[i]);
479 f = (float) count_methods;
482 for (i = 0; i <= 8; i++)
483 log_print("%6.2f", (float) count_method_bb_distribution[i] / f);
486 /* print cumulated ratio */
489 for (i = 0, sum = 0; i <= 8; i++) {
490 sum += count_method_bb_distribution[i];
491 log_print("%6.2f", (float) sum / f);
496 /* Distribution of basic block sizes **************************************/
498 log_println("Distribution of basic block sizes:");
499 log_println(" 0 1 2 3 4 5 6 7 8 9 <13 <15 <17 <19 <21 <26 <31 >30");
501 /* print block sizes */
504 for (i = 0; i <= 17; i++)
505 log_print("%6d", count_block_size_distribution[i]);
510 f = (float) count_basic_blocks;
513 for (i = 0; i <= 17; i++)
514 log_print("%6.2f", (float) count_block_size_distribution[i] / f);
517 /* print cumulated ratio */
520 for (i = 0, sum = 0; i <= 17; i++) {
521 sum += count_block_size_distribution[i];
522 log_print("%6.2f", (float) sum / f);
526 statistics_print_memory_usage();
528 dolog("Number of class loads: %6d", count_class_loads);
529 dolog("Number of class inits: %6d", count_class_inits);
530 dolog("Number of loaded Methods: %6d\n", count_all_methods);
532 dolog("Calls of utf_new: %6d", count_utf_new);
533 dolog("Calls of utf_new (element found): %6d\n", count_utf_new_found);
536 /* LSRA statistics ********************************************************/
538 dolog("Moves reg -> reg: %6d", count_mov_reg_reg);
539 dolog("Moves mem -> reg: %6d", count_mov_mem_reg);
540 dolog("Moves reg -> mem: %6d", count_mov_reg_mem);
541 dolog("Moves mem -> mem: %6d", count_mov_mem_mem);
543 dolog("Methods allocated by LSRA: %6d",
544 count_methods_allocated_by_lsra);
545 dolog("Conflicts between local Variables: %6d", count_locals_conflicts);
546 dolog("Local Variables held in Memory: %6d", count_locals_spilled);
547 dolog("Local Variables held in Registers: %6d", count_locals_register);
548 dolog("Stackslots held in Memory: %6d", count_ss_spilled);
549 dolog("Stackslots held in Registers: %6d", count_ss_register);
550 dolog("Memory moves at BB Boundaries: %6d", count_mem_move_bb);
551 dolog("Number of interface slots: %6d\n", count_interface_size);
552 dolog("Number of Argument stack slots in register: %6d",
553 count_argument_reg_ss);
554 dolog("Number of Argument stack slots in memory: %6d\n",
555 count_argument_mem_ss);
556 dolog("Number of Methods kept in registers: %6d\n",
557 count_method_in_register);
560 /* instruction scheduler statistics ***************************************/
562 #if defined(USE_SCHEDULER)
563 dolog("Instruction scheduler statistics:");
564 dolog("Number of basic blocks: %7d", count_schedule_basic_blocks);
565 dolog("Number of nodes: %7d", count_schedule_nodes);
566 dolog("Number of leaders nodes: %7d", count_schedule_leaders);
567 dolog("Number of max. leaders nodes: %7d", count_schedule_max_leaders);
568 dolog("Length of critical path: %7d\n", count_schedule_critical_path);
572 /* call statistics ********************************************************/
574 dolog("Function call statistics:");
575 dolog("Number of native function invokations: %ld",
576 count_native_function_calls);
577 dolog("Number of jni->CallXMethod function invokations: %ld",
578 count_jni_callXmethod_calls);
579 dolog("Overall number of jni invokations: %ld",
583 /* now print other statistics ********************************************/
585 #if defined(ENABLE_INTRP)
586 print_dynamic_super_statistics();
591 /* statistics_print_memory_usage ***********************************************
593 Print current memory usage.
595 *******************************************************************************/
597 void statistics_print_memory_usage(void)
601 printf("memory usage ----------------------\n\n");
602 printf("code: %10d\n", count_code_len);
603 printf("data: %10d\n", count_data_len);
605 printf(" ----------\n");
611 printf(" %10d\n", sum);
614 printf("classinfo (%3d B): %10d\n", sizeof(classinfo), size_classinfo);
615 printf("fieldinfo (%3d B): %10d\n", sizeof(fieldinfo), size_fieldinfo);
616 printf("methodinfo (%3d B): %10d\n", sizeof(methodinfo), size_methodinfo);
617 printf("lineinfo (%3d B): %10d\n", sizeof(lineinfo), size_lineinfo);
618 printf("codeinfo (%3d B): %10d\n", sizeof(codeinfo), size_codeinfo);
619 printf(" ----------\n");
628 printf(" %10d\n", sum);
631 printf("constant pool: %10d\n", count_const_pool_len);
632 printf("classref: %10d\n", count_classref_len);
633 printf("parsed descriptors: %10d\n", count_parsed_desc_len);
634 printf("vftbl: %10d\n", count_vftbl_len);
635 printf("compiler stubs: %10d\n", count_cstub_len);
636 printf("native stubs: %10d\n", count_nstub_len);
637 printf("utf: %10d\n", count_utf_len);
638 printf("vmcode: %10d\n", count_vmcode_len);
639 printf("exception tables: %10d\n", count_extable_len);
640 printf("stack map: %10d\n", size_stack_map);
641 printf("string: %10d\n", size_string);
642 printf("threadobject: %10d\n", size_threadobject);
643 printf("lock record pool: %10d\n", size_lock_record_pool);
644 printf("lock hashtable: %10d\n", size_lock_hashtable);
645 printf("lock waiter: %10d\n", size_lock_waiter);
646 printf(" ----------\n");
649 count_const_pool_len +
651 count_parsed_desc_len +
661 size_lock_record_pool +
662 size_lock_hashtable +
665 printf(" %10d\n", sum);
668 printf("max. memory usage: %10d\n", maxcodememusage);
669 printf("max. heap memory usage: %10d\n", maxmemusage);
670 printf("max. dump memory usage: %10d\n", maxdumpsize);
673 printf("heap memory not freed: %10d\n", (s4) memoryusage);
674 printf("dump memory not freed: %10d\n", (s4) globalallocateddumpsize);
679 /* statistics_print_gc_memory_usage ********************************************
681 Print current GC memory usage.
683 *******************************************************************************/
685 void statistics_print_gc_memory_usage(void)
687 log_println("GC memory usage -------------------");
689 log_println("max. heap size: %10lld", gc_get_max_heap_size());
691 log_println("heap size: %10lld", gc_get_heap_size());
692 log_println("free: %10lld", gc_get_free_bytes());
693 log_println("used: %10lld", gc_get_total_bytes());
698 * These are local overrides for various environment variables in Emacs.
699 * Please do not remove this and leave it at the end of the file, where
700 * Emacs will automagically detect them.
701 * ---------------------------------------------------------------------
704 * indent-tabs-mode: t
708 * vim:noexpandtab:sw=4:ts=4: