1 /* src/vm/statistics.c - global varables for statistics
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Christian Thalinger
31 $Id: statistics.c 4001 2005-12-22 14:05:38Z twisti $
40 #include <sys/resource.h>
44 #include "toolbox/logging.h"
45 #include "vm/global.h"
46 #include "vm/options.h"
47 #include "vm/statistics.h"
50 /* global variables ***********************************************************/
52 static s8 loadingtime = 0; /* accumulated loading time */
53 static s8 loadingstarttime = 0;
54 static s8 loadingstoptime = 0;
55 static s4 loadingtime_recursion = 0;
57 static s8 compilingtime = 0; /* accumulated compile time */
58 static s8 compilingstarttime = 0;
59 static s8 compilingstoptime = 0;
60 static s4 compilingtime_recursion = 0;
63 s4 maxcodememusage = 0;
70 s4 globalallocateddumpsize = 0;
71 s4 globaluseddumpsize = 0;
73 int count_class_infos = 0; /* variables for measurements */
74 int count_const_pool_len = 0;
75 int count_classref_len = 0;
76 int count_parsed_desc_len = 0;
77 int count_vftbl_len = 0;
78 int count_all_methods = 0;
79 int count_methods_marked_used = 0; /* RTA */
81 int count_vmcode_len = 0;
82 int count_extable_len = 0;
83 int count_class_loads = 0;
84 int count_class_inits = 0;
86 int count_utf_len = 0; /* size of utf hash */
87 int count_utf_new = 0; /* calls of utf_new */
88 int count_utf_new_found = 0; /* calls of utf_new with fast return */
90 int count_locals_conflicts = 0; /* register allocator statistics */
91 int count_locals_spilled = 0;
92 int count_locals_register = 0;
93 int count_ss_spilled = 0;
94 int count_ss_register = 0;
95 int count_methods_allocated_by_lsra = 0;
96 int count_mem_move_bb = 0;
97 int count_interface_size = 0;
98 int count_argument_mem_ss = 0;
99 int count_argument_reg_ss = 0;
100 int count_method_in_register = 0;
101 int count_mov_reg_reg = 0;
102 int count_mov_mem_reg = 0;
103 int count_mov_reg_mem = 0;
104 int count_mov_mem_mem = 0;
106 int count_jit_calls = 0;
107 int count_methods = 0;
108 int count_spills = 0;
109 int count_spills_read = 0;
110 int count_pcmd_activ = 0;
111 int count_pcmd_drop = 0;
112 int count_pcmd_zero = 0;
113 int count_pcmd_const_store = 0;
114 int count_pcmd_const_alu = 0;
115 int count_pcmd_const_bra = 0;
116 int count_pcmd_load = 0;
117 int count_pcmd_move = 0;
118 int count_load_instruction = 0;
119 int count_pcmd_store = 0;
120 int count_pcmd_store_comb = 0;
121 int count_dup_instruction = 0;
122 int count_pcmd_op = 0;
123 int count_pcmd_mem = 0;
124 int count_pcmd_met = 0;
125 int count_pcmd_bra = 0;
126 int count_pcmd_table = 0;
127 int count_pcmd_return = 0;
128 int count_pcmd_returnx = 0;
129 int count_check_null = 0;
130 int count_check_bound = 0;
131 int count_max_basic_blocks = 0;
132 int count_basic_blocks = 0;
133 int count_javainstr = 0;
134 int count_max_javainstr = 0;
135 int count_javacodesize = 0;
136 int count_javaexcsize = 0;
138 int count_tryblocks = 0;
139 int count_code_len = 0;
140 int count_data_len = 0;
141 int count_cstub_len = 0;
142 int count_nstub_len = 0;
143 int count_max_new_stack = 0;
144 int count_upper_bound_new_stack = 0;
145 /* in_ inline statistics */
147 int count_in_uniqVirt = 0;
148 int count_in_uniqIntf = 0;
149 int count_in_rejected = 0;
150 int count_in_rejected_mult = 0;
151 int count_in_outsiders = 0;
152 int count_in_uniqueVirt_not_inlined = 0;
153 int count_in_uniqueInterface_not_inlined = 0;
154 int count_in_maxDepth = 0;
155 int count_in_maxMethods = 0;
157 u8 count_native_function_calls=0;
158 u8 count_compiled_function_calls=0;
159 u8 count_jni_callXmethod_calls=0;
160 u8 count_jni_calls=0;
162 u2 count_in_not [512];
164 int count_no_in[12] = {0,0,0,0, 0,0,0,0, 0,0,0,0};
169 static int count_block_stack_init[11] = {
174 int *count_block_stack = count_block_stack_init;
175 static int count_analyse_iterations_init[5] = {
178 int *count_analyse_iterations = count_analyse_iterations_init;
179 static int count_method_bb_distribution_init[9] = {
183 int *count_method_bb_distribution = count_method_bb_distribution_init;
184 static int count_block_size_distribution_init[18] = {
190 int *count_block_size_distribution = count_block_size_distribution_init;
191 static int count_store_length_init[21] = {
198 int *count_store_length = count_store_length_init;
199 static int count_store_depth_init[11] = {
204 int *count_store_depth = count_store_depth_init;
207 /* instruction scheduler statistics *******************************************/
209 s4 count_schedule_basic_blocks = 0;
210 s4 count_schedule_nodes = 0;
211 s4 count_schedule_leaders = 0;
212 s4 count_schedule_max_leaders = 0;
213 s4 count_schedule_critical_path = 0;
216 /* nativeinvokation ***********************************************************
218 increments the native invokation count by one
220 *******************************************************************************/
222 void nativeinvokation(void)
224 /* XXX do locking here */
225 count_native_function_calls++;
229 /* compiledinvokation *********************************************************
231 increments the compiled invokation count by one
233 *******************************************************************************/
235 void compiledinvokation(void)
237 /* XXX do locking here */
238 count_compiled_function_calls++;
242 /* jnicallXmethodinvokation ***************************************************
244 increments the jni CallXMethod invokation count by one
246 *******************************************************************************/
248 void jnicallXmethodnvokation(void)
250 /* XXX do locking here */
251 count_jni_callXmethod_calls++;
255 /* jniinvokation *************************************************************
257 increments the jni overall invokation count by one
259 *******************************************************************************/
261 void jniinvokation(void)
263 /* XXX do locking here */
268 /* getcputime *********************************** ******************************
270 Returns the used CPU time in microseconds
272 *******************************************************************************/
279 getrusage(RUSAGE_SELF, &ru);
280 sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
281 usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
283 return sec * 1000000 + usec;
287 /* loadingtime_stop ************************************************************
291 *******************************************************************************/
293 void loadingtime_start(void)
295 loadingtime_recursion++;
297 if (loadingtime_recursion == 1)
298 loadingstarttime = getcputime();
302 /* loadingtime_stop ************************************************************
306 *******************************************************************************/
308 void loadingtime_stop(void)
310 if (loadingtime_recursion == 1) {
311 loadingstoptime = getcputime();
312 loadingtime += (loadingstoptime - loadingstarttime);
315 loadingtime_recursion--;
319 /* compilingtime_stop **********************************************************
323 *******************************************************************************/
325 void compilingtime_start(void)
327 compilingtime_recursion++;
329 if (compilingtime_recursion == 1)
330 compilingstarttime = getcputime();
334 /* compilingtime_stop **********************************************************
338 *******************************************************************************/
340 void compilingtime_stop(void)
342 if (compilingtime_recursion == 1) {
343 compilingstoptime = getcputime();
344 compilingtime += (compilingstoptime - compilingstarttime);
347 compilingtime_recursion--;
351 /* print_times *****************************************************************
353 Prints a summary of CPU time usage.
355 *******************************************************************************/
357 void print_times(void)
362 totaltime = getcputime();
363 runtime = totaltime - loadingtime - compilingtime;
365 #if SIZEOF_VOID_P == 8
366 dolog("Time for loading classes: %6ld ms", loadingtime / 1000);
367 dolog("Time for compiling code: %6ld ms", compilingtime / 1000);
368 dolog("Time for running program: %6ld ms", runtime / 1000);
369 dolog("Total time: %6ld ms", totaltime / 1000);
371 dolog("Time for loading classes: %6lld ms", loadingtime / 1000);
372 dolog("Time for compiling code: %6lld ms", compilingtime / 1000);
373 dolog("Time for running program: %6lld ms", runtime / 1000);
374 dolog("Total time: %6lld ms", totaltime / 1000);
379 /* print_stats *****************************************************************
381 outputs detailed compiler statistics
383 *******************************************************************************/
385 void print_stats(void)
387 dolog("Number of JIT compiler calls: %6d", count_jit_calls);
388 dolog("Number of compiled methods: %6d", count_methods);
391 dolog("Number of Methods marked Used: %d", count_methods_marked_used);
393 dolog("Number of compiled basic blocks: %6d",
395 dolog("Number of max. basic blocks per method: %6d",
396 count_max_basic_blocks);
398 dolog("Number of compiled JavaVM instructions: %6d",
400 dolog("Number of max. JavaVM instructions per method: %6d",
401 count_max_javainstr);
402 dolog("Size of compiled JavaVM instructions: %6d(%d)",
403 count_javacodesize, count_javacodesize - count_methods * 18);
405 dolog("Size of compiled Exception Tables: %d", count_javaexcsize);
406 dolog("Number of Machine-Instructions: %d", count_code_len >> 2);
407 dolog("Number of Spills (write to memory): %d", count_spills);
408 dolog("Number of Spills (read from memory): %d", count_spills_read);
409 dolog("Number of Activ Pseudocommands: %6d", count_pcmd_activ);
410 dolog("Number of Drop Pseudocommands: %6d", count_pcmd_drop);
411 dolog("Number of Const Pseudocommands: %6d (zero:%5d)",
412 count_pcmd_load, count_pcmd_zero);
413 dolog("Number of ConstAlu Pseudocommands: %6d (cmp: %5d, store:%5d)",
414 count_pcmd_const_alu, count_pcmd_const_bra, count_pcmd_const_store);
415 dolog("Number of Move Pseudocommands: %6d", count_pcmd_move);
416 dolog("Number of Load Pseudocommands: %6d", count_load_instruction);
417 dolog("Number of Store Pseudocommands: %6d (combined: %5d)",
418 count_pcmd_store, count_pcmd_store - count_pcmd_store_comb);
419 dolog("Number of OP Pseudocommands: %6d", count_pcmd_op);
420 dolog("Number of DUP Pseudocommands: %6d", count_dup_instruction);
421 dolog("Number of Mem Pseudocommands: %6d", count_pcmd_mem);
422 dolog("Number of Method Pseudocommands: %6d", count_pcmd_met);
423 dolog("Number of Branch Pseudocommands: %6d (rets:%5d, Xrets: %5d)",
424 count_pcmd_bra, count_pcmd_return, count_pcmd_returnx);
425 dolog("Number of Table Pseudocommands: %6d", count_pcmd_table);
426 dolog("Number of Useful Pseudocommands: %6d", count_pcmd_table +
427 count_pcmd_bra + count_pcmd_load + count_pcmd_mem + count_pcmd_op);
428 dolog("Number of Null Pointer Checks: %6d", count_check_null);
429 dolog("Number of Array Bound Checks: %6d", count_check_bound);
430 dolog("Number of Try-Blocks: %d", count_tryblocks);
431 dolog("Maximal count of stack elements: %d", count_max_new_stack);
432 dolog("Upper bound of max stack elements: %d", count_upper_bound_new_stack);
433 dolog("Distribution of stack sizes at block boundary");
434 dolog(" 0 1 2 3 4 5 6 7 8 9 >=10");
435 dolog("%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d",
436 count_block_stack[0], count_block_stack[1], count_block_stack[2],
437 count_block_stack[3], count_block_stack[4], count_block_stack[5],
438 count_block_stack[6], count_block_stack[7], count_block_stack[8],
439 count_block_stack[9], count_block_stack[10]);
440 dolog("Distribution of store stack depth");
441 dolog(" 0 1 2 3 4 5 6 7 8 9 >=10");
442 dolog("%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d",
443 count_store_depth[0], count_store_depth[1], count_store_depth[2],
444 count_store_depth[3], count_store_depth[4], count_store_depth[5],
445 count_store_depth[6], count_store_depth[7], count_store_depth[8],
446 count_store_depth[9], count_store_depth[10]);
447 dolog("Distribution of store creator chains first part");
448 dolog(" 0 1 2 3 4 5 6 7 8 9");
449 dolog("%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d",
450 count_store_length[0], count_store_length[1], count_store_length[2],
451 count_store_length[3], count_store_length[4], count_store_length[5],
452 count_store_length[6], count_store_length[7], count_store_length[8],
453 count_store_length[9]);
454 dolog("Distribution of store creator chains second part");
455 dolog(" 10 11 12 13 14 15 16 17 18 19 >=20");
456 dolog("%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d",
457 count_store_length[10], count_store_length[11],
458 count_store_length[12], count_store_length[13],
459 count_store_length[14], count_store_length[15],
460 count_store_length[16], count_store_length[17],
461 count_store_length[18], count_store_length[19],
462 count_store_length[20]);
463 dolog("Distribution of analysis iterations");
464 dolog(" 1 2 3 4 >=5");
465 dolog("%6d%6d%6d%6d%6d",
466 count_analyse_iterations[0], count_analyse_iterations[1],
467 count_analyse_iterations[2], count_analyse_iterations[3],
468 count_analyse_iterations[4]);
469 dolog("Distribution of basic blocks per method");
470 dolog(" <=5 <=10 <=15 <=20 <=30 <=40 <=50 <=75 >75");
471 dolog("%6d%6d%6d%6d%6d%6d%6d%6d%6d",
472 count_method_bb_distribution[0], count_method_bb_distribution[1],
473 count_method_bb_distribution[2], count_method_bb_distribution[3],
474 count_method_bb_distribution[4], count_method_bb_distribution[5],
475 count_method_bb_distribution[6], count_method_bb_distribution[7],
476 count_method_bb_distribution[8]);
477 dolog("Distribution of basic block sizes");
478 dolog(" 0 1 2 3 4 5 6 7 8 9 <13 <15 <17 <19 <21 <26 <31 >30");
479 dolog("%6d%6d%6d%6d%6d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d",
480 count_block_size_distribution[0], count_block_size_distribution[1],
481 count_block_size_distribution[2], count_block_size_distribution[3],
482 count_block_size_distribution[4], count_block_size_distribution[5],
483 count_block_size_distribution[6], count_block_size_distribution[7],
484 count_block_size_distribution[8], count_block_size_distribution[9],
485 count_block_size_distribution[10], count_block_size_distribution[11],
486 count_block_size_distribution[12], count_block_size_distribution[13],
487 count_block_size_distribution[14], count_block_size_distribution[15],
488 count_block_size_distribution[16], count_block_size_distribution[17]);
489 dolog("Size of Code Area: %10.3f kB", (float) count_code_len / 1024);
490 dolog("Size of Data Area: %10.3f kB", (float) count_data_len / 1024);
491 dolog("Size of Class Infos: %10.3f kB", (float) count_class_infos / 1024);
492 dolog("Size of Const Pool: %10.3f kB", (float) (count_const_pool_len + count_utf_len) / 1024);
493 dolog("Size of Class refs: %10.3f kB", (float) count_classref_len / 1024);
494 dolog("Size of descriptors: %10.3f kB", (float) count_parsed_desc_len / 1024);
495 dolog("Size of vftbl: %10.3f kB", (float) count_vftbl_len / 1024);
496 dolog("Size of compiler stubs: %10.3f kB", (float) count_cstub_len / 1024);
497 dolog("Size of native stubs: %10.3f kB", (float) count_nstub_len / 1024);
498 dolog("Size of utf: %10.3f kB", (float) count_utf_len / 1024);
499 dolog("Size of VMCode: %10.3f kB (%d)",
500 (float) count_vmcode_len / 1024,
501 count_vmcode_len - 18 * count_all_methods);
502 dolog("Size of exception tables: %10.3f kB\n", (float) count_extable_len / 1024);
504 dolog("Number of class loads: %6d", count_class_loads);
505 dolog("Number of class inits: %6d", count_class_inits);
506 dolog("Number of loaded Methods: %6d\n", count_all_methods);
508 dolog("Calls of utf_new: %6d", count_utf_new);
509 dolog("Calls of utf_new (element found): %6d\n", count_utf_new_found);
512 /* LSRA statistics ********************************************************/
514 dolog("Moves reg -> reg: %6d", count_mov_reg_reg);
515 dolog("Moves mem -> reg: %6d", count_mov_mem_reg);
516 dolog("Moves reg -> mem: %6d", count_mov_reg_mem);
517 dolog("Moves mem -> mem: %6d", count_mov_mem_mem);
519 dolog("Methods allocated by LSRA: %6d",
520 count_methods_allocated_by_lsra);
521 dolog("Conflicts between local Variables: %6d", count_locals_conflicts);
522 dolog("Local Variables held in Memory: %6d", count_locals_spilled);
523 dolog("Local Variables held in Registers: %6d", count_locals_register);
524 dolog("Stackslots held in Memory: %6d", count_ss_spilled);
525 dolog("Stackslots held in Registers: %6d", count_ss_register);
526 dolog("Memory moves at BB Boundaries: %6d", count_mem_move_bb);
527 dolog("Number of interface slots: %6d\n", count_interface_size);
528 dolog("Number of Argument stack slots in register: %6d",
529 count_argument_reg_ss);
530 dolog("Number of Argument stack slots in memory: %6d\n",
531 count_argument_mem_ss);
532 dolog("Number of Methods kept in registers: %6d\n",
533 count_method_in_register);
536 /****if (useinlining) ***/
539 char * in_not_reasons[IN_MAX] = {
551 dolog("Number of Methods Inlined : \t%6d",
554 if (inlinevirtuals) {
555 dolog("Number of Unique Virtual Methods inlined: \t%6d",
557 dolog("Number of Unique Implemented Interface Methods inlined: %6d",
561 dolog("Number of Methods Inlines (total) rejected: \t%6d",
563 dolog("Number of Methods Inlined rejected for multiple reasons: \t%6d",
564 count_in_rejected_mult);
565 dolog("Number of Methods where Inline max depth hit: \t%6d",
567 dolog("Number of Methods Inlined rejected for max methods \t%6d\n",
568 count_in_maxMethods);
569 dolog("Number of Methods calls fom Outsider Class not inlined: \t%6d",
572 dolog("Number of Unique Virtual Methods not inlined: \t%6d",
573 count_in_uniqueVirt_not_inlined);
574 dolog("Number of Unique Implemented Interface Methods not inlined:%6d\n",
575 count_in_uniqueInterface_not_inlined);
577 #define INLINEDETAILS
579 dolog("Details about Not Inlined Reasons:");
581 for (i = 0; i < 512; i++) {
582 if (count_in_not[i] > 0) {
583 /* XXX Please reimplement me! I'm ugly and insecure! */
584 char logtext2[1024]="\t";
586 if (inlinevirtuals) {
587 if (i & IN_UNIQUEVIRT)
588 strcat(logtext2, in_not_reasons[N_UNIQUEVIRT]);
590 if (i & IN_UNIQUE_INTERFACE)
591 strcat(logtext2, in_not_reasons[N_UNIQUE_INTERFACE]);
593 if (i & IN_NOT_UNIQUE_VIRT)
594 strcat(logtext2, in_not_reasons[N_NOT_UNIQUE_VIRT]);
596 if (i & IN_NOT_UNIQUE_INTERFACE)
597 strcat(logtext2, in_not_reasons[N_NOT_UNIQUE_INTERFACE]);
600 if (i & IN_OUTSIDERS)
601 strcat(logtext2, in_not_reasons[N_OUTSIDERS]);
604 strcat(logtext2, in_not_reasons[N_MAXDEPTH]);
607 strcat(logtext2, in_not_reasons[N_MAXCODE]);
609 if (i & IN_JCODELENGTH)
610 strcat(logtext2, in_not_reasons[N_JCODELENGTH]);
612 if (i & IN_EXCEPTION)
613 strcat(logtext2, in_not_reasons[N_EXCEPTION]);
615 dolog(" [%X]=%6d %s", i, count_in_not[i], logtext2);
622 /* instruction scheduler statistics **************************************/
624 #if defined(USE_SCHEDULER)
625 dolog("Instruction scheduler statistics:");
626 dolog("Number of basic blocks: %7d", count_schedule_basic_blocks);
627 dolog("Number of nodes: %7d", count_schedule_nodes);
628 dolog("Number of leaders nodes: %7d", count_schedule_leaders);
629 dolog("Number of max. leaders nodes: %7d", count_schedule_max_leaders);
630 dolog("Length of critical path: %7d\n", count_schedule_critical_path);
634 /* call statistics ********************************************************/
636 dolog("Function call statistics:");
637 dolog("Number of native function invokations: %ld",
638 count_native_function_calls);
639 dolog("Number of compiled function invokations: %ld",
640 count_compiled_function_calls);
641 dolog("Number of jni->CallXMethod function invokations: %ld",
642 count_jni_callXmethod_calls);
643 dolog("Overall number of jni invokations: %ld",
648 /* mem_usagelog ****************************************************************
650 prints some memory related infos
652 *******************************************************************************/
654 void mem_usagelog(bool givewarnings)
656 if ((memoryusage != 0) && givewarnings) {
657 dolog("Allocated memory not returned: %9d", (s4) memoryusage);
660 if ((globalallocateddumpsize != 0) && givewarnings) {
661 dolog("Dump memory not returned: %9d",
662 (s4) globalallocateddumpsize);
665 dolog("Code - max. memory usage: %9d kB",
666 (s4) ((maxcodememusage + 1023) / 1024));
667 dolog("Random - max. memory usage: %9d kB",
668 (s4) ((maxmemusage + 1023) / 1024));
669 dolog("Dump - max. memory usage: %9d kB",
670 (s4) ((maxdumpsize + 1023) / 1024));
675 * These are local overrides for various environment variables in Emacs.
676 * Please do not remove this and leave it at the end of the file, where
677 * Emacs will automagically detect them.
678 * ---------------------------------------------------------------------
681 * indent-tabs-mode: t