You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gentoo-overlay/dev-java/icedtea/files/7-cacao-dynmaxheap.patch

43 lines
1.1 KiB

# HG changeset patch
# User James Le Cuirot <chewi@gentoo.org>
# Date 1441541110 -3600
# Sun Sep 06 13:05:10 2015 +0100
# Node ID 80e5553df66e3abb3680f747cbb8e32b394b4211
# Parent 468081e3e037df27b6427aa298dfaaa20f4ba4bf
Dynamically set the maximum heap size on Linux
diff -r 468081e3e037 -r 80e5553df66e src/vm/vm.cpp
--- cacao/cacao/src/vm/vm.cpp Wed Jun 10 19:52:58 2015 +0200
+++ cacao/cacao/src/vm/vm.cpp Sun Sep 06 13:05:10 2015 +0100
@@ -32,6 +32,10 @@
#include <stdint.h>
#include <inttypes.h>
+#if defined(__LINUX__)
+#include <unistd.h>
+#endif
+
#include "md-abi.hpp"
#include "mm/codememory.hpp"
@@ -690,6 +694,19 @@
opt_heapstartsize = HEAP_STARTSIZE;
opt_stacksize = STACK_SIZE;
+#if defined(__LINUX__)
+ // Calculate 1/4 of the physical memory.
+ uint64_t qmem = sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE) / 4;
+
+ if (qmem > INT32_MAX) {
+ // More than 2GB will overflow so cap it.
+ opt_heapmaxsize = 2047 * 1024 * 1024;
+ } else if (qmem > HEAP_MAXSIZE) {
+ // Otherwise use this if greater than default (128MB).
+ opt_heapmaxsize = (s4) qmem;
+ }
+#endif
+
// First of all, parse the -XX options.
options_xx(vm_args);