blob: edce1e85234a05a7433fd0c9bb1a7db449a3e5b8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# 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);
|