Skip to content

Commit e5c5f8b

Browse files
committed
Pass hard-heap-limit to MMTk
1 parent f75a27a commit e5c5f8b

File tree

1 file changed

+39
-34
lines changed

1 file changed

+39
-34
lines changed

src/gc-mmtk.c

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -104,36 +104,46 @@ void jl_gc_init(void) {
104104
// MMTK_MIN_HSIZE and MMTK_MAX_HSIZE environment variables
105105
long long min_heap_size;
106106
long long max_heap_size;
107-
char* min_size_def = getenv("MMTK_MIN_HSIZE");
108-
char* min_size_gb = getenv("MMTK_MIN_HSIZE_G");
109-
110-
char* max_size_def = getenv("MMTK_MAX_HSIZE");
111-
char* max_size_gb = getenv("MMTK_MAX_HSIZE_G");
112-
113-
// If min and max values are not specified, set them to 0 here
114-
// and use stock heuristics as defined in the binding
115-
if (min_size_def != NULL) {
116-
char *p;
117-
double min_size = strtod(min_size_def, &p);
118-
min_heap_size = (long) 1024 * 1024 * min_size;
119-
} else if (min_size_gb != NULL) {
120-
char *p;
121-
double min_size = strtod(min_size_gb, &p);
122-
min_heap_size = (long) 1024 * 1024 * 1024 * min_size;
123-
} else {
124-
min_heap_size = 0;
125-
}
126107

127-
if (max_size_def != NULL) {
128-
char *p;
129-
double max_size = strtod(max_size_def, &p);
130-
max_heap_size = (long) 1024 * 1024 * max_size;
131-
} else if (max_size_gb != NULL) {
132-
char *p;
133-
double max_size = strtod(max_size_gb, &p);
134-
max_heap_size = (long) 1024 * 1024 * 1024 * max_size;
108+
if (jl_options.hard_heap_limit != 0) {
109+
min_heap_size = jl_options.hard_heap_limit;
110+
max_heap_size = jl_options.hard_heap_limit;
135111
} else {
136-
max_heap_size = 0;
112+
char* min_size_def = getenv("MMTK_MIN_HSIZE");
113+
char* min_size_gb = getenv("MMTK_MIN_HSIZE_G");
114+
char* max_size_def = getenv("MMTK_MAX_HSIZE");
115+
char* max_size_gb = getenv("MMTK_MAX_HSIZE_G");
116+
117+
// If min and max values are not specified, set them to 0 here
118+
// and use stock heuristics as defined in the binding
119+
if (min_size_def != NULL) {
120+
char *p;
121+
double min_size = strtod(min_size_def, &p);
122+
min_heap_size = (long) 1024 * 1024 * min_size;
123+
} else if (min_size_gb != NULL) {
124+
char *p;
125+
double min_size = strtod(min_size_gb, &p);
126+
min_heap_size = (long) 1024 * 1024 * 1024 * min_size;
127+
} else {
128+
min_heap_size = 0;
129+
}
130+
131+
if (max_size_def != NULL) {
132+
char *p;
133+
double max_size = strtod(max_size_def, &p);
134+
max_heap_size = (long) 1024 * 1024 * max_size;
135+
} else if (max_size_gb != NULL) {
136+
char *p;
137+
double max_size = strtod(max_size_gb, &p);
138+
max_heap_size = (long) 1024 * 1024 * 1024 * max_size;
139+
} else {
140+
max_heap_size = 0;
141+
}
142+
143+
// if only max size is specified initialize MMTk with a fixed size heap
144+
if (max_size_def != NULL || (max_size_gb != NULL && (min_size_def == NULL && min_size_gb == NULL))) {
145+
min_heap_size = 0;
146+
}
137147
}
138148

139149
// Assert that the number of stock GC threads is 0; MMTK uses the number of threads in jl_options.ngcthreads
@@ -150,15 +160,10 @@ void jl_gc_init(void) {
150160

151161
mmtk_julia_copy_stack_check(copy_stacks);
152162

153-
// if only max size is specified initialize MMTk with a fixed size heap
154163
// TODO: We just assume mark threads means GC threads, and ignore the number of concurrent sweep threads.
155164
// If the two values are the same, we can use either. Otherwise, we need to be careful.
156165
uintptr_t gcthreads = jl_options.nmarkthreads;
157-
if (max_size_def != NULL || (max_size_gb != NULL && (min_size_def == NULL && min_size_gb == NULL))) {
158-
mmtk_gc_init(0, max_heap_size, gcthreads, (sizeof(jl_taggedvalue_t)), jl_buff_tag);
159-
} else {
160-
mmtk_gc_init(min_heap_size, max_heap_size, gcthreads, (sizeof(jl_taggedvalue_t)), jl_buff_tag);
161-
}
166+
mmtk_gc_init(min_heap_size, max_heap_size, gcthreads, (sizeof(jl_taggedvalue_t)), jl_buff_tag);
162167
}
163168

164169
void jl_start_gc_threads(void) {

0 commit comments

Comments
 (0)