< prev index next >

src/share/vm/runtime/os.cpp

Print this page




 576     return NULL;
 577   }
 578 
 579   u_char* ptr = (u_char*)::malloc(alloc_size);
 580 
 581   if (ptr != NULL) {
 582     Atomic::add(((jint) (alloc_size / BytesPerWord)),
 583                 (volatile jint *) &cur_malloc_words);
 584   }
 585   return ptr;
 586 }
 587 
 588 void* os::malloc(size_t size, MEMFLAGS flags) {
 589   return os::malloc(size, flags, CALLER_PC);
 590 }
 591 
 592 void* os::malloc(size_t size, MEMFLAGS memflags, const NativeCallStack& stack) {
 593   NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1));
 594   NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size));
 595 
 596 #ifdef ASSERT
 597   // checking for the WatcherThread and crash_protection first
 598   // since os::malloc can be called when the libjvm.{dll,so} is
 599   // first loaded and we don't have a thread yet.
 600   // try to find the thread after we see that the watcher thread
 601   // exists and has crash protection.
 602   WatcherThread *wt = WatcherThread::watcher_thread();
 603   if (wt != NULL && wt->has_crash_protection()) {
 604     Thread* thread = ThreadLocalStorage::get_thread_slow();
 605     if (thread == wt) {
 606       assert(!wt->has_crash_protection(),
 607           "Can't malloc with crash protection from WatcherThread");
 608     }
 609   }
 610 #endif
 611 
 612   if (size == 0) {
 613     // return a valid pointer if size is zero
 614     // if NULL is returned the calling functions assume out of memory.
 615     size = 1;
 616   }
 617 
 618   // NMT support
 619   NMT_TrackingLevel level = MemTracker::tracking_level();
 620   size_t            nmt_header_size = MemTracker::malloc_header_size(level);
 621 
 622 #ifndef ASSERT
 623   const size_t alloc_size = size + nmt_header_size;
 624 #else
 625   const size_t alloc_size = GuardedMemory::get_total_size(size + nmt_header_size);
 626   if (size + nmt_header_size > alloc_size) { // Check for rollover.
 627     return NULL;
 628   }
 629 #endif
 630 




 576     return NULL;
 577   }
 578 
 579   u_char* ptr = (u_char*)::malloc(alloc_size);
 580 
 581   if (ptr != NULL) {
 582     Atomic::add(((jint) (alloc_size / BytesPerWord)),
 583                 (volatile jint *) &cur_malloc_words);
 584   }
 585   return ptr;
 586 }
 587 
 588 void* os::malloc(size_t size, MEMFLAGS flags) {
 589   return os::malloc(size, flags, CALLER_PC);
 590 }
 591 
 592 void* os::malloc(size_t size, MEMFLAGS memflags, const NativeCallStack& stack) {
 593   NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1));
 594   NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size));
 595 
 596   // Since os::malloc can be called when the libjvm.{dll,so} is
 597   // first loaded and we don't have a thread yet we must accept NULL also here.
 598   assert(!os::ThreadCrashProtection::is_crash_protected(ThreadLocalStorage::thread()),
 599          "malloc() not allowed when crash protection is set");











 600 
 601   if (size == 0) {
 602     // return a valid pointer if size is zero
 603     // if NULL is returned the calling functions assume out of memory.
 604     size = 1;
 605   }
 606 
 607   // NMT support
 608   NMT_TrackingLevel level = MemTracker::tracking_level();
 609   size_t            nmt_header_size = MemTracker::malloc_header_size(level);
 610 
 611 #ifndef ASSERT
 612   const size_t alloc_size = size + nmt_header_size;
 613 #else
 614   const size_t alloc_size = GuardedMemory::get_total_size(size + nmt_header_size);
 615   if (size + nmt_header_size > alloc_size) { // Check for rollover.
 616     return NULL;
 617   }
 618 #endif
 619 


< prev index next >