Introducing 'try to give memory back' callback for heap allocator to use upon allocation request that can not be satisfied by the allocator.

This commit is contained in:
Ruben Ayrapetyan
2014-12-18 21:20:28 +03:00
parent 8febd2bae8
commit 6bb39bb8ea
14 changed files with 308 additions and 105 deletions
+30 -2
View File
@@ -526,8 +526,6 @@ ecma_gc_sweep (ecma_object_t *object_p) /**< object to free */
void
ecma_gc_run (ecma_gc_gen_t max_gen_to_collect) /**< maximum generation to run collection on */
{
ecma_lcache_invalidate_all ();
JERRY_ASSERT(max_gen_to_collect < ECMA_GC_GEN_COUNT);
/* clearing visited flags for all objects of generations to be processed */
@@ -664,6 +662,36 @@ ecma_gc_run (ecma_gc_gen_t max_gen_to_collect) /**< maximum generation to run co
#endif /* !JERRY_NDEBUG */
} /* ecma_gc_run */
/**
* Try to free some memory (depending on severity).
*/
void
ecma_try_to_give_back_some_memory (mem_try_give_memory_back_severity_t severity) /**< severity of
* the request */
{
if (severity == MEM_TRY_GIVE_MEMORY_BACK_SEVERITY_LOW)
{
ecma_gc_run (ECMA_GC_GEN_0);
}
else if (severity == MEM_TRY_GIVE_MEMORY_BACK_SEVERITY_MEDIUM)
{
ecma_gc_run (ECMA_GC_GEN_1);
}
else if (severity == MEM_TRY_GIVE_MEMORY_BACK_SEVERITY_HIGH)
{
ecma_gc_run (ECMA_GC_GEN_2);
}
else
{
JERRY_ASSERT (severity == MEM_TRY_GIVE_MEMORY_BACK_SEVERITY_CRITICAL);
/* Freeing as much memory as we currently can */
ecma_lcache_invalidate_all ();
ecma_gc_run (ECMA_GC_GEN_COUNT - 1);
}
} /* ecma_try_to_give_back_some_memory */
/**
* @}
* @}