* Removed all Id tags.
[cacao.git] / src / vmcore / statistics.c
index 9d6a67b32ca4fad35c9439f3ac1b401b055f7f32..3f4810115d5e3369541cb873e57b09d5d9a76124 100644 (file)
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: statistics.c 7551 2007-03-21 14:26:09Z twisti $
-
 */
 
 
 #include "config.h"
 
 #include <string.h> 
-#include <sys/time.h>
-#include <sys/resource.h>
+
+#if defined(HAVE_TIME_H)
+# include <time.h>
+#endif
+
+#if defined(HAVE_SYS_TIME_H)
+# include <sys/time.h>
+#endif
+
+#if defined(HAVE_SYS_RESOURCE_H)
+# include <sys/resource.h>
+#endif
 
 #include "vm/types.h"
 
@@ -82,15 +90,22 @@ s4 size_methodinfo       = 0;
 s4 size_lineinfo         = 0;
 s4 size_codeinfo         = 0;
 
+s4 size_stub_native      = 0;
+
 s4 size_stack_map        = 0;
 s4 size_string           = 0;
 
 s4 size_threadobject     = 0;
 
-s4 size_lock_record_pool = 0;
+s4 size_lock_record      = 0;
 s4 size_lock_hashtable   = 0;
 s4 size_lock_waiter      = 0;
 
+s4 size_patchref         = 0;
+
+u8 count_calls_java_to_native = 0;
+u8 count_calls_native_to_java = 0;
+
 int count_const_pool_len = 0;
 int count_classref_len = 0;
 int count_parsed_desc_len = 0;
@@ -125,8 +140,12 @@ int count_mov_mem_mem = 0;
 
 int count_jit_calls = 0;
 int count_methods = 0;
-int count_spills = 0;
-int count_spills_read = 0;
+int count_spills_read_ila = 0;
+int count_spills_read_flt = 0;
+int count_spills_read_dbl = 0;
+int count_spills_write_ila = 0;
+int count_spills_write_flt = 0;
+int count_spills_write_dbl = 0;
 int count_pcmd_activ = 0;
 int count_pcmd_drop = 0;
 int count_pcmd_zero = 0;
@@ -159,14 +178,18 @@ int count_tryblocks = 0;
 int count_code_len = 0;
 int count_data_len = 0;
 int count_cstub_len = 0;
-int count_nstub_len = 0;
 int count_max_new_stack = 0;
 int count_upper_bound_new_stack = 0;
 
+int count_emit_branch = 0;
+int count_emit_branch_8bit = 0;
+int count_emit_branch_16bit = 0;
+int count_emit_branch_32bit = 0;
+int count_emit_branch_64bit = 0;
+
 s4 count_branches_resolved   = 0;
 s4 count_branches_unresolved = 0;
 
-u8 count_native_function_calls=0;
 u8 count_jni_callXmethod_calls=0;
 u8 count_jni_calls=0;
 
@@ -218,19 +241,6 @@ s4 count_schedule_max_leaders = 0;
 s4 count_schedule_critical_path = 0;
 
 
-/* nativeinvokation ***********************************************************
-
-   increments the native invokation count by one
-       
-*******************************************************************************/
-
-void nativeinvokation(void)
-{
-       /* XXX do locking here */
-       count_native_function_calls++;
-}
-
-
 /* jnicallXmethodinvokation ***************************************************
 
    increments the jni CallXMethod invokation count by one
@@ -265,14 +275,21 @@ void jniinvokation(void)
 
 s8 getcputime(void)
 {
+#if defined(HAVE_GETRUSAGE)
        struct rusage ru;
        int sec, usec;
 
        getrusage(RUSAGE_SELF, &ru);
-       sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
+
+       sec  = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
        usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
 
        return sec * 1000000 + usec;
+#else
+       /* If we don't have getrusage, simply return 0. */
+
+       return 0;
+#endif
 }
 
 
@@ -398,8 +415,12 @@ void print_stats(void)
 
        dolog("Size of compiled Exception Tables:      %d", count_javaexcsize);
        dolog("Number of Machine-Instructions: %d", count_code_len >> 2);
-       dolog("Number of Spills (write to memory): %d", count_spills);
-       dolog("Number of Spills (read from memory): %d", count_spills_read);
+       dolog("Number of Spills (write to memory) <all [i/l/a|flt|dbl]>: %d [%d|%d|%d]",
+               count_spills_write_ila + count_spills_write_flt + count_spills_write_dbl,
+               count_spills_write_ila, count_spills_write_flt, count_spills_write_dbl);
+       dolog("Number of Spills (read from memory) <all [i/l/a|flt|dbl]>: %d [%d|%d|%d]",
+               count_spills_read_ila + count_spills_read_flt + count_spills_read_dbl,
+               count_spills_read_ila, count_spills_read_flt, count_spills_read_dbl);
        dolog("Number of Activ    Pseudocommands: %6d", count_pcmd_activ);
        dolog("Number of Drop     Pseudocommands: %6d", count_pcmd_drop);
        dolog("Number of Const    Pseudocommands: %6d (zero:%5d)",
@@ -424,6 +445,11 @@ void print_stats(void)
        dolog("Number of Null Pointer Checks:     %6d", count_check_null);
        dolog("Number of Array Bound Checks:      %6d", count_check_bound);
        dolog("Number of Try-Blocks: %d", count_tryblocks);
+
+       dolog("Number of branch_emit (total, 8bit/16bit/32bit/64bit offset): %d, %d/%d/%d/%d",
+               count_emit_branch,  count_emit_branch_8bit,  count_emit_branch_16bit, 
+                                                       count_emit_branch_32bit, count_emit_branch_64bit);
+
        dolog("Maximal count of stack elements:   %d", count_max_new_stack);
        dolog("Upper bound of max stack elements: %d", count_upper_bound_new_stack);
        dolog("Distribution of stack sizes at block boundary");
@@ -572,13 +598,14 @@ void print_stats(void)
        /* call statistics ********************************************************/
 
        dolog("Function call statistics:");
-       dolog("Number of native function invokations:           %ld",
-                 count_native_function_calls);
        dolog("Number of jni->CallXMethod function invokations: %ld",
                  count_jni_callXmethod_calls);
        dolog("Overall number of jni invokations:               %ld",
                  count_jni_calls);
 
+       log_println("java-to-native calls:   %10ld", count_calls_java_to_native);
+       log_println("native-to-java calls:   %10ld", count_calls_native_to_java);
+
 
        /* now print other statistics ********************************************/
 
@@ -588,6 +615,35 @@ void print_stats(void)
 }
 
 
+/* statistics_print_date *******************************************************
+
+   Print current date and time.
+
+*******************************************************************************/
+
+void statistics_print_date(void)
+{
+  time_t t;
+  struct tm tm;
+
+#if defined(HAVE_TIME)
+  time(&t);
+#else
+# error !HAVE_TIME
+#endif
+
+#if defined(HAVE_LOCALTIME_R)
+  localtime_r(&t, &tm);
+#else
+# error !HAVE_LOCALTIME_R
+#endif
+
+  log_println("%d-%02d-%02d %02d:%02d:%02d",
+                         1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday,
+                         tm.tm_hour, tm.tm_min, tm.tm_sec);
+}
+
+
 /* statistics_print_memory_usage ***********************************************
 
    Print current memory usage.
@@ -598,25 +654,24 @@ void statistics_print_memory_usage(void)
 {
        s4 sum;
 
-       printf("memory usage ----------------------\n\n");
-       printf("code:                   %10d\n", count_code_len);
-       printf("data:                   %10d\n", count_data_len);
-
-       printf("                         ----------\n");
+       log_println("memory usage ----------------------");
+       log_println("");
+       log_println("code:                   %10d", count_code_len);
+       log_println("data:                   %10d", count_data_len);
+       log_println("                         ----------");
 
        sum =
                count_code_len +
                count_data_len;
 
-       printf("                        %10d\n", sum);
-       printf("\n");
-
-       printf("classinfo  (%3d B):     %10d\n", sizeof(classinfo), size_classinfo);
-       printf("fieldinfo  (%3d B):     %10d\n", sizeof(fieldinfo), size_fieldinfo);
-       printf("methodinfo (%3d B):     %10d\n", sizeof(methodinfo), size_methodinfo);
-       printf("lineinfo   (%3d B):     %10d\n", sizeof(lineinfo), size_lineinfo);
-       printf("codeinfo   (%3d B):     %10d\n", sizeof(codeinfo), size_codeinfo);
-       printf("                         ----------\n");
+       log_println("                        %10d", sum);
+       log_println("");
+       log_println("classinfo  (%3d B):     %10d", (int) sizeof(classinfo), size_classinfo);
+       log_println("fieldinfo  (%3d B):     %10d", (int) sizeof(fieldinfo), size_fieldinfo);
+       log_println("methodinfo (%3d B):     %10d", (int) sizeof(methodinfo), size_methodinfo);
+       log_println("lineinfo   (%3d B):     %10d", (int) sizeof(lineinfo), size_lineinfo);
+       log_println("codeinfo   (%3d B):     %10d", (int) sizeof(codeinfo), size_codeinfo);
+       log_println("                         ----------");
 
        sum =
                size_classinfo +
@@ -625,25 +680,25 @@ void statistics_print_memory_usage(void)
                size_lineinfo +
                size_codeinfo;
 
-       printf("                        %10d\n", sum);
-       printf("\n");
-
-       printf("constant pool:          %10d\n", count_const_pool_len);
-       printf("classref:               %10d\n", count_classref_len);
-       printf("parsed descriptors:     %10d\n", count_parsed_desc_len);
-       printf("vftbl:                  %10d\n", count_vftbl_len);
-       printf("compiler stubs:         %10d\n", count_cstub_len);
-       printf("native stubs:           %10d\n", count_nstub_len);
-       printf("utf:                    %10d\n", count_utf_len);
-       printf("vmcode:                 %10d\n", count_vmcode_len);
-       printf("exception tables:       %10d\n", count_extable_len);
-       printf("stack map:              %10d\n", size_stack_map);
-       printf("string:                 %10d\n", size_string);
-       printf("threadobject:           %10d\n", size_threadobject);
-       printf("lock record pool:       %10d\n", size_lock_record_pool);
-       printf("lock hashtable:         %10d\n", size_lock_hashtable);
-       printf("lock waiter:            %10d\n", size_lock_waiter);
-       printf("                         ----------\n");
+       log_println("                        %10d", sum);
+       log_println("");
+       log_println("constant pool:          %10d", count_const_pool_len);
+       log_println("classref:               %10d", count_classref_len);
+       log_println("parsed descriptors:     %10d", count_parsed_desc_len);
+       log_println("vftbl:                  %10d", count_vftbl_len);
+       log_println("compiler stubs:         %10d", count_cstub_len);
+       log_println("native stubs:           %10d", size_stub_native);
+       log_println("utf:                    %10d", count_utf_len);
+       log_println("vmcode:                 %10d", count_vmcode_len);
+       log_println("exception tables:       %10d", count_extable_len);
+       log_println("stack map:              %10d", size_stack_map);
+       log_println("string:                 %10d", size_string);
+       log_println("threadobject:           %10d", size_threadobject);
+       log_println("lock record:            %10d", size_lock_record);
+       log_println("lock hashtable:         %10d", size_lock_hashtable);
+       log_println("lock waiter:            %10d", size_lock_waiter);
+       log_println("patcher references:     %10d", size_patchref);
+       log_println("                         ----------");
 
        sum =
                count_const_pool_len +
@@ -651,28 +706,27 @@ void statistics_print_memory_usage(void)
                count_parsed_desc_len + 
                count_vftbl_len +
                count_cstub_len +
-               count_nstub_len +
+               size_stub_native +
                count_utf_len +
                count_vmcode_len +
                count_extable_len +
                size_stack_map +
                size_string +
                size_threadobject +
-               size_lock_record_pool +
+               size_lock_record +
                size_lock_hashtable +
-               size_lock_waiter;
-
-       printf("                        %10d\n", sum);
-       printf("\n");
-
-       printf("max. memory usage:      %10d\n", maxcodememusage);
-       printf("max. heap memory usage: %10d\n", maxmemusage);
-       printf("max. dump memory usage: %10d\n", maxdumpsize);
-       printf("\n");
-                  
-       printf("heap memory not freed:  %10d\n", (s4) memoryusage);
-       printf("dump memory not freed:  %10d\n", (s4) globalallocateddumpsize);
-       printf("\n");
+               size_lock_waiter +
+               size_patchref;
+
+       log_println("                        %10d", sum);
+       log_println("");
+       log_println("max. code memory:       %10d", maxcodememusage);
+       log_println("max. heap memory:       %10d", maxmemusage);
+       log_println("max. dump memory:       %10d", maxdumpsize);
+       log_println("");
+       log_println("heap memory not freed:  %10d", (s4) memoryusage);
+       log_println("dump memory not freed:  %10d", (s4) globalallocateddumpsize);
+       log_println("");
 }
 
 
@@ -684,13 +738,44 @@ void statistics_print_memory_usage(void)
 
 void statistics_print_gc_memory_usage(void)
 {
-       log_println("GC memory usage -------------------");
-       log_println("");
-       log_println("max. heap size: %10lld", gc_get_max_heap_size());
-       log_println("");
-       log_println("heap size:      %10lld", gc_get_heap_size());
-       log_println("free:           %10lld", gc_get_free_bytes());
-       log_println("used:           %10lld", gc_get_total_bytes());
+       static int64_t count = 0;
+       int64_t max;
+       int64_t size;
+       int64_t free;
+       int64_t used;
+       int64_t total;
+
+       count++;
+
+       max   = gc_get_max_heap_size();
+       size  = gc_get_heap_size();
+       free  = gc_get_free_bytes();
+       used  = size - free;
+       total = gc_get_total_bytes();
+
+       if (opt_ProfileMemoryUsageGNUPlot) {
+               if (count == 1)
+                       fprintf(opt_ProfileMemoryUsageGNUPlot, "plot \"profile.dat\" using 1:2 with lines title \"max. Java heap size\", \"profile.dat\" using 1:3 with lines title \"Java heap size\", \"profile.dat\" using 1:4 with lines title \"used\", \"profile.dat\" using 1:5 with lines title \"free\"\n");
+
+#if SIZEOF_VOID_P == 8
+               fprintf(opt_ProfileMemoryUsageGNUPlot, "%ld %ld %ld %ld %ld\n", count, max, size, used, free);
+#else
+               fprintf(opt_ProfileMemoryUsageGNUPlot, "%lld %lld %lld %lld %lld\n", count, max, size, used, free);
+#endif
+
+               fflush(opt_ProfileMemoryUsageGNUPlot);
+       }
+       else {
+               log_println("GC memory usage -------------------");
+               log_println("");
+               log_println("max. Java heap size: %10lld", max);
+               log_println("");
+               log_println("Java heap size:      %10lld", size);
+               log_println("used:                %10lld", used);
+               log_println("free:                %10lld", free);
+               log_println("totally used:        %10lld", total);
+               log_println("");
+       }
 }