< prev index next >

src/hotspot/share/runtime/os.cpp

Print this page

 779   // NMT support
 780   void* membase = MemTracker::malloc_base(memblock);
 781   verify_memory(membase);
 782   // always move the block
 783   void* ptr = os::malloc(size, memflags, stack);
 784   // Copy to new memory if malloc didn't fail
 785   if (ptr != NULL ) {
 786     GuardedMemory guarded(MemTracker::malloc_base(memblock));
 787     // Guard's user data contains NMT header
 788     size_t memblock_size = guarded.get_user_size() - MemTracker::malloc_header_size(memblock);
 789     memcpy(ptr, memblock, MIN2(size, memblock_size));
 790     if (paranoid) {
 791       verify_memory(MemTracker::malloc_base(ptr));
 792     }
 793     os::free(memblock);
 794   }
 795   return ptr;
 796 #endif
 797 }
 798 
 799 
 800 void  os::free(void *memblock) {
 801   NOT_PRODUCT(inc_stat_counter(&num_frees, 1));
 802 #ifdef ASSERT
 803   if (memblock == NULL) return;
 804   if ((intptr_t)memblock == (intptr_t)MallocCatchPtr) {
 805     log_warning(malloc, free)("os::free caught " PTR_FORMAT, p2i(memblock));
 806     breakpoint();
 807   }
 808   void* membase = MemTracker::record_free(memblock);
 809   verify_memory(membase);
 810 
 811   GuardedMemory guarded(membase);
 812   size_t size = guarded.get_user_size();
 813   inc_stat_counter(&free_bytes, size);
 814   membase = guarded.release_for_freeing();
 815   ::free(membase);
 816 #else
 817   void* membase = MemTracker::record_free(memblock);
 818   ::free(membase);
 819 #endif

 779   // NMT support
 780   void* membase = MemTracker::malloc_base(memblock);
 781   verify_memory(membase);
 782   // always move the block
 783   void* ptr = os::malloc(size, memflags, stack);
 784   // Copy to new memory if malloc didn't fail
 785   if (ptr != NULL ) {
 786     GuardedMemory guarded(MemTracker::malloc_base(memblock));
 787     // Guard's user data contains NMT header
 788     size_t memblock_size = guarded.get_user_size() - MemTracker::malloc_header_size(memblock);
 789     memcpy(ptr, memblock, MIN2(size, memblock_size));
 790     if (paranoid) {
 791       verify_memory(MemTracker::malloc_base(ptr));
 792     }
 793     os::free(memblock);
 794   }
 795   return ptr;
 796 #endif
 797 }
 798 
 799 // handles NULL pointers
 800 void  os::free(void *memblock) {
 801   NOT_PRODUCT(inc_stat_counter(&num_frees, 1));
 802 #ifdef ASSERT
 803   if (memblock == NULL) return;
 804   if ((intptr_t)memblock == (intptr_t)MallocCatchPtr) {
 805     log_warning(malloc, free)("os::free caught " PTR_FORMAT, p2i(memblock));
 806     breakpoint();
 807   }
 808   void* membase = MemTracker::record_free(memblock);
 809   verify_memory(membase);
 810 
 811   GuardedMemory guarded(membase);
 812   size_t size = guarded.get_user_size();
 813   inc_stat_counter(&free_bytes, size);
 814   membase = guarded.release_for_freeing();
 815   ::free(membase);
 816 #else
 817   void* membase = MemTracker::record_free(memblock);
 818   ::free(membase);
 819 #endif
< prev index next >