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
29 $Id: statistics.c 2211 2005-04-04 10:39:36Z christian $
35 #include <sys/resource.h>
37 #include "toolbox/logging.h"
38 #include "vm/global.h"
39 #include "vm/options.h"
40 #include "vm/statistics.h"
44 /* global variables */
46 static s8 loadingtime = 0; /* accumulated loading time */
47 static s8 loadingstarttime = 0;
48 static s8 loadingstoptime = 0;
49 static s4 loadingtime_recursion = 0;
51 static s8 compilingtime = 0; /* accumulated compile time */
52 static s8 compilingstarttime = 0;
53 static s8 compilingstoptime = 0;
54 static s4 compilingtime_recursion = 0;
60 s4 globalallocateddumpsize = 0;
61 s4 globaluseddumpsize = 0;
63 int count_class_infos = 0; /* variables for measurements */
64 int count_const_pool_len = 0;
65 int count_classref_len = 0;
66 int count_parsed_desc_len = 0;
67 int count_vftbl_len = 0;
68 int count_all_methods = 0;
69 int count_methods_marked_used = 0; /* RTA */
71 int count_vmcode_len = 0;
72 int count_extable_len = 0;
73 int count_class_loads = 0;
74 int count_class_inits = 0;
76 int count_utf_len = 0; /* size of utf hash */
77 int count_utf_new = 0; /* calls of utf_new */
78 int count_utf_new_found = 0; /* calls of utf_new with fast return */
80 int count_locals_conflicts = 0; /* register allocator statistics */
81 int count_locals_spilled = 0;
82 int count_locals_register = 0;
83 int count_ss_spilled = 0;
84 int count_ss_register = 0;
85 int count_methods_allocated_by_lsra = 0;
86 int count_mem_move_bb = 0;
87 int count_interface_size = 0;
88 int count_argument_mem_ss = 0;
89 int count_argument_reg_ss = 0;
90 int count_method_in_register = 0;
91 int count_mov_reg_reg = 0;
92 int count_mov_mem_reg = 0;
93 int count_mov_reg_mem = 0;
94 int count_mov_mem_mem = 0;
96 int count_jit_calls = 0;
97 int count_methods = 0;
99 int count_spills_read = 0;
100 int count_pcmd_activ = 0;
101 int count_pcmd_drop = 0;
102 int count_pcmd_zero = 0;
103 int count_pcmd_const_store = 0;
104 int count_pcmd_const_alu = 0;
105 int count_pcmd_const_bra = 0;
106 int count_pcmd_load = 0;
107 int count_pcmd_move = 0;
108 int count_load_instruction = 0;
109 int count_pcmd_store = 0;
110 int count_pcmd_store_comb = 0;
111 int count_dup_instruction = 0;
112 int count_pcmd_op = 0;
113 int count_pcmd_mem = 0;
114 int count_pcmd_met = 0;
115 int count_pcmd_bra = 0;
116 int count_pcmd_table = 0;
117 int count_pcmd_return = 0;
118 int count_pcmd_returnx = 0;
119 int count_check_null = 0;
120 int count_check_bound = 0;
121 int count_max_basic_blocks = 0;
122 int count_basic_blocks = 0;
123 int count_javainstr = 0;
124 int count_max_javainstr = 0;
125 int count_javacodesize = 0;
126 int count_javaexcsize = 0;
128 int count_tryblocks = 0;
129 int count_code_len = 0;
130 int count_data_len = 0;
131 int count_cstub_len = 0;
132 int count_nstub_len = 0;
133 int count_max_new_stack = 0;
134 int count_upper_bound_new_stack = 0;
135 /* in_ inline statistics */
137 int count_in_uniqVirt = 0;
138 int count_in_uniqIntf = 0;
139 int count_in_rejected = 0;
140 int count_in_rejected_mult = 0;
141 int count_in_outsiders = 0;
142 int count_in_uniqueVirt_not_inlined = 0;
143 int count_in_uniqueInterface_not_inlined = 0;
144 int count_in_maxDepth = 0;
145 int count_in_maxMethods = 0;
147 u2 count_in_not [512];
149 int count_no_in[12] = {0,0,0,0, 0,0,0,0, 0,0,0,0};
154 static int count_block_stack_init[11] = {
159 int *count_block_stack = count_block_stack_init;
160 static int count_analyse_iterations_init[5] = {
163 int *count_analyse_iterations = count_analyse_iterations_init;
164 static int count_method_bb_distribution_init[9] = {
168 int *count_method_bb_distribution = count_method_bb_distribution_init;
169 static int count_block_size_distribution_init[18] = {
175 int *count_block_size_distribution = count_block_size_distribution_init;
176 static int count_store_length_init[21] = {
183 int *count_store_length = count_store_length_init;
184 static int count_store_depth_init[11] = {
189 int *count_store_depth = count_store_depth_init;
192 /* instruction scheduler statistics *******************************************/
194 s4 count_schedule_basic_blocks = 0;
195 s4 count_schedule_nodes = 0;
196 s4 count_schedule_leaders = 0;
197 s4 count_schedule_max_leaders = 0;
198 s4 count_schedule_critical_path = 0;
201 /* getcputime *********************************** ******************************
203 Returns the used CPU time in microseconds
205 *******************************************************************************/
212 getrusage(RUSAGE_SELF, &ru);
213 sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
214 usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
216 return sec * 1000000 + usec;
220 /* loadingtime_stop ************************************************************
224 *******************************************************************************/
226 void loadingtime_start()
228 loadingtime_recursion++;
230 if (loadingtime_recursion == 1)
231 loadingstarttime = getcputime();
235 /* loadingtime_stop ************************************************************
239 *******************************************************************************/
241 void loadingtime_stop()
243 if (loadingtime_recursion == 1) {
244 loadingstoptime = getcputime();
245 loadingtime += (loadingstoptime - loadingstarttime);
248 loadingtime_recursion--;
252 /* compilingtime_stop **********************************************************
256 *******************************************************************************/
258 void compilingtime_start()
260 compilingtime_recursion++;
262 if (compilingtime_recursion == 1)
263 compilingstarttime = getcputime();
267 /* compilingtime_stop **********************************************************
271 *******************************************************************************/
273 void compilingtime_stop()
275 if (compilingtime_recursion == 1) {
276 compilingstoptime = getcputime();
277 compilingtime += (compilingstoptime - compilingstarttime);
280 compilingtime_recursion--;
284 /* print_times *****************************************************************
286 Prints a summary of CPU time usage.
288 *******************************************************************************/
292 s8 totaltime = getcputime();
293 s8 runtime = totaltime - loadingtime - compilingtime;
294 char logtext[MAXLOGTEXT];
296 #if defined(__I386__) || defined(__POWERPC__)
297 sprintf(logtext, "Time for loading classes: %lld secs, %lld millis",
299 sprintf(logtext, "Time for loading classes: %ld secs, %ld millis",
301 loadingtime / 1000000, (loadingtime % 1000000) / 1000);
304 #if defined(__I386__) || defined(__POWERPC__)
305 sprintf(logtext, "Time for compiling code: %lld secs, %lld millis",
307 sprintf(logtext, "Time for compiling code: %ld secs, %ld millis",
309 compilingtime / 1000000, (compilingtime % 1000000) / 1000);
312 #if defined(__I386__) || defined(__POWERPC__)
313 sprintf(logtext, "Time for running program: %lld secs, %lld millis",
315 sprintf(logtext, "Time for running program: %ld secs, %ld millis",
317 runtime / 1000000, (runtime % 1000000) / 1000);
320 #if defined(__I386__) || defined(__POWERPC__)
321 sprintf(logtext, "Total time: %lld secs, %lld millis",
323 sprintf(logtext, "Total time: %ld secs, %ld millis",
325 totaltime / 1000000, (totaltime % 1000000) / 1000);
330 /* print_stats *****************************************************************
332 outputs detailed compiler statistics
334 *******************************************************************************/
338 char logtext[MAXLOGTEXT];
340 sprintf(logtext, "Number of JitCompiler Calls: %d", count_jit_calls);
342 sprintf(logtext, "Number of compiled Methods: %d", count_methods);
345 sprintf(logtext, "Number of Methods marked Used: %d", count_methods_marked_used);
348 sprintf(logtext, "Number of max basic blocks per method: %d", count_max_basic_blocks);
350 sprintf(logtext, "Number of compiled basic blocks: %d", count_basic_blocks);
352 sprintf(logtext, "Number of max JavaVM-Instructions per method: %d", count_max_javainstr);
354 sprintf(logtext, "Number of compiled JavaVM-Instructions: %d", count_javainstr);
356 sprintf(logtext, "Size of compiled JavaVM-Instructions: %d(%d)", count_javacodesize,
357 count_javacodesize - count_methods * 18);
359 sprintf(logtext, "Size of compiled Exception Tables: %d", count_javaexcsize);
361 sprintf(logtext, "Number of Machine-Instructions: %d", count_code_len >> 2);
363 sprintf(logtext, "Number of Spills (write to memory): %d", count_spills);
365 sprintf(logtext, "Number of Spills (read from memory): %d", count_spills_read);
367 sprintf(logtext, "Number of Activ Pseudocommands: %6d", count_pcmd_activ);
369 sprintf(logtext, "Number of Drop Pseudocommands: %6d", count_pcmd_drop);
371 sprintf(logtext, "Number of Const Pseudocommands: %6d (zero:%5d)", count_pcmd_load, count_pcmd_zero);
373 sprintf(logtext, "Number of ConstAlu Pseudocommands: %6d (cmp: %5d, store:%5d)", count_pcmd_const_alu, count_pcmd_const_bra, count_pcmd_const_store);
375 sprintf(logtext, "Number of Move Pseudocommands: %6d", count_pcmd_move);
377 sprintf(logtext, "Number of Load Pseudocommands: %6d", count_load_instruction);
379 sprintf(logtext, "Number of Store Pseudocommands: %6d (combined: %5d)", count_pcmd_store, count_pcmd_store - count_pcmd_store_comb);
381 sprintf(logtext, "Number of OP Pseudocommands: %6d", count_pcmd_op);
383 sprintf(logtext, "Number of DUP Pseudocommands: %6d", count_dup_instruction);
385 sprintf(logtext, "Number of Mem Pseudocommands: %6d", count_pcmd_mem);
387 sprintf(logtext, "Number of Method Pseudocommands: %6d", count_pcmd_met);
389 sprintf(logtext, "Number of Branch Pseudocommands: %6d (rets:%5d, Xrets: %5d)",
390 count_pcmd_bra, count_pcmd_return, count_pcmd_returnx);
392 sprintf(logtext, "Number of Table Pseudocommands: %6d", count_pcmd_table);
394 sprintf(logtext, "Number of Useful Pseudocommands: %6d", count_pcmd_table +
395 count_pcmd_bra + count_pcmd_load + count_pcmd_mem + count_pcmd_op);
397 sprintf(logtext, "Number of Null Pointer Checks: %6d", count_check_null);
399 sprintf(logtext, "Number of Array Bound Checks: %6d", count_check_bound);
401 sprintf(logtext, "Number of Try-Blocks: %d", count_tryblocks);
403 sprintf(logtext, "Maximal count of stack elements: %d", count_max_new_stack);
405 sprintf(logtext, "Upper bound of max stack elements: %d", count_upper_bound_new_stack);
407 sprintf(logtext, "Distribution of stack sizes at block boundary");
409 sprintf(logtext, " 0 1 2 3 4 5 6 7 8 9 >=10");
411 sprintf(logtext, "%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d", count_block_stack[0],
412 count_block_stack[1], count_block_stack[2], count_block_stack[3], count_block_stack[4],
413 count_block_stack[5], count_block_stack[6], count_block_stack[7], count_block_stack[8],
414 count_block_stack[9], count_block_stack[10]);
416 sprintf(logtext, "Distribution of store stack depth");
418 sprintf(logtext, " 0 1 2 3 4 5 6 7 8 9 >=10");
420 sprintf(logtext, "%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d", count_store_depth[0],
421 count_store_depth[1], count_store_depth[2], count_store_depth[3], count_store_depth[4],
422 count_store_depth[5], count_store_depth[6], count_store_depth[7], count_store_depth[8],
423 count_store_depth[9], count_store_depth[10]);
425 sprintf(logtext, "Distribution of store creator chains first part");
427 sprintf(logtext, " 0 1 2 3 4 5 6 7 8 9");
429 sprintf(logtext, "%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d", count_store_length[0],
430 count_store_length[1], count_store_length[2], count_store_length[3], count_store_length[4],
431 count_store_length[5], count_store_length[6], count_store_length[7], count_store_length[8],
432 count_store_length[9]);
434 sprintf(logtext, "Distribution of store creator chains second part");
436 sprintf(logtext, " 10 11 12 13 14 15 16 17 18 19 >=20");
438 sprintf(logtext, "%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d", count_store_length[10],
439 count_store_length[11], count_store_length[12], count_store_length[13], count_store_length[14],
440 count_store_length[15], count_store_length[16], count_store_length[17], count_store_length[18],
441 count_store_length[19], count_store_length[20]);
443 sprintf(logtext, "Distribution of analysis iterations");
445 sprintf(logtext, " 1 2 3 4 >=5");
447 sprintf(logtext, "%6d%6d%6d%6d%6d", count_analyse_iterations[0], count_analyse_iterations[1],
448 count_analyse_iterations[2], count_analyse_iterations[3], count_analyse_iterations[4]);
450 sprintf(logtext, "Distribution of basic blocks per method");
452 sprintf(logtext, " <=5 <=10 <=15 <=20 <=30 <=40 <=50 <=75 >75");
454 sprintf(logtext, "%6d%6d%6d%6d%6d%6d%6d%6d%6d", count_method_bb_distribution[0],
455 count_method_bb_distribution[1], count_method_bb_distribution[2], count_method_bb_distribution[3],
456 count_method_bb_distribution[4], count_method_bb_distribution[5], count_method_bb_distribution[6],
457 count_method_bb_distribution[7], count_method_bb_distribution[8]);
459 sprintf(logtext, "Distribution of basic block sizes");
461 sprintf(logtext, " 0 1 2 3 4 5 6 7 8 9 <13 <15 <17 <19 <21 <26 <31 >30");
463 sprintf(logtext, "%6d%6d%6d%6d%6d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d",
464 count_block_size_distribution[0], count_block_size_distribution[1], count_block_size_distribution[2],
465 count_block_size_distribution[3], count_block_size_distribution[4], count_block_size_distribution[5],
466 count_block_size_distribution[6], count_block_size_distribution[7], count_block_size_distribution[8],
467 count_block_size_distribution[9], count_block_size_distribution[10], count_block_size_distribution[11],
468 count_block_size_distribution[12], count_block_size_distribution[13], count_block_size_distribution[14],
469 count_block_size_distribution[15], count_block_size_distribution[16], count_block_size_distribution[17]);
471 sprintf(logtext, "Size of Code Area (Kb): %10.3f", (float) count_code_len / 1024);
473 sprintf(logtext, "Size of data Area (Kb): %10.3f", (float) count_data_len / 1024);
475 sprintf(logtext, "Size of Class Infos (Kb):%10.3f", (float) (count_class_infos) / 1024);
477 sprintf(logtext, "Size of Const Pool (Kb): %10.3f", (float) (count_const_pool_len + count_utf_len) / 1024);
479 sprintf(logtext, "Size of Class refs (Kb): %10.3f", (float) (count_classref_len) / 1024);
481 sprintf(logtext, "Size of descriptors(Kb): %10.3f", (float) (count_parsed_desc_len) / 1024);
483 sprintf(logtext, "Size of Vftbl (Kb): %10.3f", (float) count_vftbl_len / 1024);
485 sprintf(logtext, "Size of comp stub (Kb): %10.3f", (float) count_cstub_len / 1024);
487 sprintf(logtext, "Size of native stub (Kb):%10.3f", (float) count_nstub_len / 1024);
489 sprintf(logtext, "Size of Utf (Kb): %10.3f", (float) count_utf_len / 1024);
491 sprintf(logtext, "Size of VMCode (Kb): %10.3f(%d)", (float) count_vmcode_len / 1024,
492 count_vmcode_len - 18 * count_all_methods);
494 sprintf(logtext, "Size of ExTable (Kb): %10.3f", (float) count_extable_len / 1024);
496 sprintf(logtext, "Number of class loads: %d", count_class_loads);
498 sprintf(logtext, "Number of class inits: %d", count_class_inits);
500 sprintf(logtext, "Number of loaded Methods: %d\n", count_all_methods);
503 sprintf(logtext, "Calls of utf_new: %22d", count_utf_new);
505 sprintf(logtext, "Calls of utf_new (element found): %6d\n", count_utf_new_found);
509 /* LSRA statistics ********************************************************/
510 sprintf(logtext, "Moves reg -> reg: %6d",count_mov_reg_reg );
512 sprintf(logtext, "Moves mem -> reg: %6d",count_mov_mem_reg );
514 sprintf(logtext, "Moves reg -> mem: %6d",count_mov_reg_mem );
516 sprintf(logtext, "Moves mem -> mem: %6d",count_mov_mem_mem );
519 sprintf(logtext, "Methods allocated by LSRA: %6d", count_methods_allocated_by_lsra);
521 sprintf(logtext, "Conflicts between local Variables: %6d", count_locals_conflicts);
523 sprintf(logtext, "Local Variables held in Memory: %6d", count_locals_spilled);
525 sprintf(logtext, "Local Variables held in Registers: %6d", count_locals_register);
527 sprintf(logtext, "Stackslots held in Memory: %6d", count_ss_spilled);
529 sprintf(logtext, "Stackslots held in Registers: %6d",count_ss_register );
531 sprintf(logtext, "Memory moves at BB Boundaries: %6d",count_mem_move_bb );
533 sprintf(logtext, "Number of interface slots: %6d\n",count_interface_size );
535 sprintf(logtext, "Number of Argument stack slots in register: %6d",count_argument_reg_ss );
537 sprintf(logtext, "Number of Argument stack slots in memory: %6d\n",count_argument_mem_ss );
539 sprintf(logtext, "Number of Methods kept in registers: %6d\n",count_method_in_register );
542 /****if (useinlining) ***/
545 char * in_not_reasons[IN_MAX] = {
557 sprintf(logtext, "Number of Methods Inlined : \t%6d",count_in );
559 if (inlinevirtuals) {
560 sprintf(logtext, "Number of Unique Virtual Methods inlined: \t%6d",count_in_uniqVirt);
562 sprintf(logtext, "Number of Unique Implemented Interface Methods inlined: %6d",count_in_uniqIntf);
565 sprintf(logtext, "Number of Methods Inlines (total) rejected: \t%6d",count_in_rejected);
567 sprintf(logtext, "Number of Methods Inlined rejected for multiple reasons: \t%6d",count_in_rejected_mult);
569 sprintf(logtext, "Number of Methods where Inline max depth hit: \t%6d",count_in_maxDepth);
571 sprintf(logtext, "Number of Methods Inlined rejected for max methods \t%6d\n",count_in_maxMethods);
573 sprintf(logtext, "Number of Methods calls fom Outsider Class not inlined: \t%6d",count_in_outsiders);
576 sprintf(logtext, "Number of Unique Virtual Methods not inlined: \t%6d",count_in_uniqueVirt_not_inlined);
578 sprintf(logtext, "Number of Unique Implemented Interface Methods not inlined:%6d",count_in_uniqueInterface_not_inlined);
580 #define INLINEDETAILS
582 sprintf(logtext, "\nDetails about Not Inlined Reasons :");
584 for (ii=0;ii<512;ii++) {
585 if (count_in_not[ii]>0) {
586 char logtext2[MAXLOGTEXT]="\t";
588 if (inlinevirtuals) {
589 if (ii & IN_UNIQUEVIRT) strcat(logtext2, in_not_reasons[N_UNIQUEVIRT]);
590 if (ii & IN_UNIQUE_INTERFACE) strcat(logtext2, in_not_reasons[N_UNIQUE_INTERFACE]);
591 if (ii & IN_NOT_UNIQUE_VIRT) strcat(logtext2, in_not_reasons[N_NOT_UNIQUE_VIRT]);
592 if (ii & IN_NOT_UNIQUE_INTERFACE) strcat(logtext2, in_not_reasons[N_NOT_UNIQUE_INTERFACE]);
594 if (ii & IN_OUTSIDERS) strcat(logtext2, in_not_reasons[N_OUTSIDERS]);
595 if (ii & IN_MAXDEPTH) strcat(logtext2, in_not_reasons[N_MAXDEPTH]);
596 if (ii & IN_MAXCODE) strcat(logtext2, in_not_reasons[N_MAXCODE]);
597 if (ii & IN_JCODELENGTH) strcat(logtext2, in_not_reasons[N_JCODELENGTH]);
598 if (ii & IN_EXCEPTION) strcat(logtext2, in_not_reasons[N_EXCEPTION]);
599 sprintf(logtext, " [%X]=%6d %s",ii, count_in_not[ii], logtext2 );
607 /* instruction scheduler statistics **************************************/
609 sprintf(logtext, "Instruction scheduler statistics:");
611 sprintf(logtext, "Number of basic blocks: %7d", count_schedule_basic_blocks);
613 sprintf(logtext, "Number of nodes: %7d", count_schedule_nodes);
615 sprintf(logtext, "Number of leaders nodes: %7d", count_schedule_leaders);
617 sprintf(logtext, "Number of max. leaders nodes: %7d", count_schedule_max_leaders);
619 sprintf(logtext, "Length of critical path: %7d\n", count_schedule_critical_path);
624 /* mem_usagelog ****************************************************************
626 prints some memory related infos
628 *******************************************************************************/
630 void mem_usagelog(bool givewarnings)
632 if ((memoryusage != 0) && givewarnings) {
633 dolog("Allocated memory not returned: %d", (s4) memoryusage);
636 if ((globalallocateddumpsize != 0) && givewarnings) {
637 dolog("Dump memory not returned: %d", (s4) globalallocateddumpsize);
640 dolog("Random/Dump - max. memory usage: %dkB/%dkB",
641 (s4) ((maxmemusage + 1023) / 1024),
642 (s4) ((maxdumpsize + 1023) / 1024));
647 * These are local overrides for various environment variables in Emacs.
648 * Please do not remove this and leave it at the end of the file, where
649 * Emacs will automagically detect them.
650 * ---------------------------------------------------------------------
653 * indent-tabs-mode: t