src/os/linux/vm/os_linux.cpp

Print this page

        

@@ -3888,10 +3888,43 @@
   assert(rc == 0, "clock_gettime is expected to return 0 code");
 
   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
 // trampoline is used.
 // We will never set this flag, and we should