--- old/src/os/linux/vm/os_linux.cpp 2013-01-18 11:37:30.782863000 -0800 +++ new/src/os/linux/vm/os_linux.cpp 2013-01-18 11:37:30.686894000 -0800 @@ -3890,6 +3890,39 @@ return (tp.tv_sec * NANOSECS_PER_SEC) + tp.tv_nsec; } +// Assumes that start and len are already page-aligned. +static void deallocate_pages_raw(address start, size_t len, const char* comment) { +#ifndef PRODUCT + pid_t tid = syscall(SYS_gettid); + if (PrintMiscellaneous && Verbose) { + tty->print_cr("%d: Calling madvise(%p, %ld, MADV_DONTNEED) (%s) ", tid, + (intptr_t) start, (intptr_t) len, comment); + } +#endif + int rc = madvise(start, len, MADV_DONTNEED); +#ifndef PRODUCT + if (PrintMiscellaneous && Verbose) { + if (rc != 0) { + tty->print_cr("%d: madvise failed %d", tid, rc); + } + } +#endif +} + +void os::deallocate_pages(void* start, size_t size) { + if (!DeallocateHeapPages) { + return; + } + // Page-align + int page_size = UseLargePages ? os::large_page_size() : os::vm_page_size(); + address begin = (address) align_size_up((intptr_t) start, page_size); + address end = (address) align_size_down((intptr_t) start + size, page_size); + if (begin < end) { + size_t len = end - begin; + deallocate_pages_raw(begin, len, "heap"); + } +} + ///// // glibc on Linux platform uses non-documented flag // to indicate, that some special sort of signal