So IIUC, the safe thing to do should be to return a new limit that's initial_heap_limit + max_young_generation_size in the second callback. From what I can tell, there should two ways to get to the young generation size:
- Save the max_young_generation_size_in_bytes() from the resource constraints used to create the isolate.
- Do a GetHeapSpaceStatistics() in the callback, and filter out the one with the name "new_space", then use the space_size() of that particular item.
Which one would be more preferable? My guess is the first one might be larger than the second one, but probably not by lot, and it saves the filtering code and thus is more reliable.
Also, is it safe to assume that the GC triggered by snapshot generation will not invoke the NearHeapLimitCallback more than once? Or should I guard against more potential invocations?
Joyee