1.1 --- a/src/share/vm/runtime/os.cpp Mon Feb 07 10:25:39 2011 -0800 1.2 +++ b/src/share/vm/runtime/os.cpp Mon Feb 07 10:34:39 2011 -0800 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -72,9 +72,10 @@ 1.11 size_t os::_page_sizes[os::page_sizes_max]; 1.12 1.13 #ifndef PRODUCT 1.14 -int os::num_mallocs = 0; // # of calls to malloc/realloc 1.15 -size_t os::alloc_bytes = 0; // # of bytes allocated 1.16 -int os::num_frees = 0; // # of calls to free 1.17 +julong os::num_mallocs = 0; // # of calls to malloc/realloc 1.18 +julong os::alloc_bytes = 0; // # of bytes allocated 1.19 +julong os::num_frees = 0; // # of calls to free 1.20 +julong os::free_bytes = 0; // # of bytes freed 1.21 #endif 1.22 1.23 // Fill in buffer with current local time as an ISO-8601 string. 1.24 @@ -490,9 +491,9 @@ 1.25 } 1.26 1.27 if (start_of_prev_block + space_before + size + space_after == start_of_this_block) { 1.28 - tty->print_cr("### previous object: %p (%ld bytes)", obj, size); 1.29 + tty->print_cr("### previous object: " PTR_FORMAT " (" SSIZE_FORMAT " bytes)", obj, size); 1.30 } else { 1.31 - tty->print_cr("### previous object (not sure if correct): %p (%ld bytes)", obj, size); 1.32 + tty->print_cr("### previous object (not sure if correct): " PTR_FORMAT " (" SSIZE_FORMAT " bytes)", obj, size); 1.33 } 1.34 1.35 // now find successor block 1.36 @@ -504,16 +505,16 @@ 1.37 start_of_next_block[1] == badResourceValue && 1.38 start_of_next_block[2] == badResourceValue && 1.39 start_of_next_block[3] == badResourceValue) { 1.40 - tty->print_cr("### next object: %p (%ld bytes)", next_obj, next_size); 1.41 + tty->print_cr("### next object: " PTR_FORMAT " (" SSIZE_FORMAT " bytes)", next_obj, next_size); 1.42 } else { 1.43 - tty->print_cr("### next object (not sure if correct): %p (%ld bytes)", next_obj, next_size); 1.44 + tty->print_cr("### next object (not sure if correct): " PTR_FORMAT " (" SSIZE_FORMAT " bytes)", next_obj, next_size); 1.45 } 1.46 } 1.47 1.48 1.49 void report_heap_error(void* memblock, void* bad, const char* where) { 1.50 - tty->print_cr("## nof_mallocs = %d, nof_frees = %d", os::num_mallocs, os::num_frees); 1.51 - tty->print_cr("## memory stomp: byte at %p %s object %p", bad, where, memblock); 1.52 + tty->print_cr("## nof_mallocs = " UINT64_FORMAT ", nof_frees = " UINT64_FORMAT, os::num_mallocs, os::num_frees); 1.53 + tty->print_cr("## memory stomp: byte at " PTR_FORMAT " %s object " PTR_FORMAT, bad, where, memblock); 1.54 print_neighbor_blocks(memblock); 1.55 fatal("memory stomping error"); 1.56 } 1.57 @@ -538,8 +539,8 @@ 1.58 #endif 1.59 1.60 void* os::malloc(size_t size) { 1.61 - NOT_PRODUCT(num_mallocs++); 1.62 - NOT_PRODUCT(alloc_bytes += size); 1.63 + NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1)); 1.64 + NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size)); 1.65 1.66 if (size == 0) { 1.67 // return a valid pointer if size is zero 1.68 @@ -562,26 +563,26 @@ 1.69 #endif 1.70 u_char* memblock = ptr + space_before; 1.71 if ((intptr_t)memblock == (intptr_t)MallocCatchPtr) { 1.72 - tty->print_cr("os::malloc caught, %lu bytes --> %p", size, memblock); 1.73 + tty->print_cr("os::malloc caught, " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, memblock); 1.74 breakpoint(); 1.75 } 1.76 debug_only(if (paranoid) verify_block(memblock)); 1.77 - if (PrintMalloc && tty != NULL) tty->print_cr("os::malloc %lu bytes --> %p", size, memblock); 1.78 + if (PrintMalloc && tty != NULL) tty->print_cr("os::malloc " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, memblock); 1.79 return memblock; 1.80 } 1.81 1.82 1.83 void* os::realloc(void *memblock, size_t size) { 1.84 - NOT_PRODUCT(num_mallocs++); 1.85 - NOT_PRODUCT(alloc_bytes += size); 1.86 #ifndef ASSERT 1.87 + NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1)); 1.88 + NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size)); 1.89 return ::realloc(memblock, size); 1.90 #else 1.91 if (memblock == NULL) { 1.92 - return os::malloc(size); 1.93 + return malloc(size); 1.94 } 1.95 if ((intptr_t)memblock == (intptr_t)MallocCatchPtr) { 1.96 - tty->print_cr("os::realloc caught %p", memblock); 1.97 + tty->print_cr("os::realloc caught " PTR_FORMAT, memblock); 1.98 breakpoint(); 1.99 } 1.100 verify_block(memblock); 1.101 @@ -589,13 +590,13 @@ 1.102 if (size == 0) return NULL; 1.103 // always move the block 1.104 void* ptr = malloc(size); 1.105 - if (PrintMalloc) tty->print_cr("os::remalloc %lu bytes, %p --> %p", size, memblock, ptr); 1.106 + if (PrintMalloc) tty->print_cr("os::remalloc " SIZE_FORMAT " bytes, " PTR_FORMAT " --> " PTR_FORMAT, size, memblock, ptr); 1.107 // Copy to new memory if malloc didn't fail 1.108 if ( ptr != NULL ) { 1.109 memcpy(ptr, memblock, MIN2(size, get_size(memblock))); 1.110 if (paranoid) verify_block(ptr); 1.111 if ((intptr_t)ptr == (intptr_t)MallocCatchPtr) { 1.112 - tty->print_cr("os::realloc caught, %lu bytes --> %p", size, ptr); 1.113 + tty->print_cr("os::realloc caught, " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, ptr); 1.114 breakpoint(); 1.115 } 1.116 free(memblock); 1.117 @@ -606,17 +607,14 @@ 1.118 1.119 1.120 void os::free(void *memblock) { 1.121 - NOT_PRODUCT(num_frees++); 1.122 + NOT_PRODUCT(inc_stat_counter(&num_frees, 1)); 1.123 #ifdef ASSERT 1.124 if (memblock == NULL) return; 1.125 if ((intptr_t)memblock == (intptr_t)MallocCatchPtr) { 1.126 - if (tty != NULL) tty->print_cr("os::free caught %p", memblock); 1.127 + if (tty != NULL) tty->print_cr("os::free caught " PTR_FORMAT, memblock); 1.128 breakpoint(); 1.129 } 1.130 verify_block(memblock); 1.131 - if (PrintMalloc && tty != NULL) 1.132 - // tty->print_cr("os::free %p", memblock); 1.133 - fprintf(stderr, "os::free %p\n", memblock); 1.134 NOT_PRODUCT(if (MallocVerifyInterval > 0) check_heap()); 1.135 // Added by detlefs. 1.136 if (MallocCushion) { 1.137 @@ -627,12 +625,18 @@ 1.138 *p = (u_char)freeBlockPad; 1.139 } 1.140 size_t size = get_size(memblock); 1.141 + inc_stat_counter(&free_bytes, size); 1.142 u_char* end = ptr + space_before + size; 1.143 for (u_char* q = end; q < end + MallocCushion; q++) { 1.144 guarantee(*q == badResourceValue, 1.145 "Thing freed should be malloc result."); 1.146 *q = (u_char)freeBlockPad; 1.147 } 1.148 + if (PrintMalloc && tty != NULL) 1.149 + fprintf(stderr, "os::free " SIZE_FORMAT " bytes --> " PTR_FORMAT "\n", size, memblock); 1.150 + } else if (PrintMalloc && tty != NULL) { 1.151 + // tty->print_cr("os::free %p", memblock); 1.152 + fprintf(stderr, "os::free " PTR_FORMAT "\n", memblock); 1.153 } 1.154 #endif 1.155 ::free((char*)memblock - space_before);