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:
@@ -16,6 +16,7 @@
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-lcache.h"
|
||||
#include "globals.h"
|
||||
#include "mem-poolman.h"
|
||||
|
||||
@@ -59,26 +60,9 @@ JERRY_STATIC_ASSERT (sizeof (ecma_label_descriptor_t) == sizeof (uint64_t));
|
||||
{ \
|
||||
ecma_ ## ecma_type ## _t *p ## ecma_type = (ecma_ ## ecma_type ## _t *) mem_pools_alloc (); \
|
||||
\
|
||||
if (likely (p ## ecma_type != NULL)) \
|
||||
{ \
|
||||
return p ## ecma_type; \
|
||||
} \
|
||||
JERRY_ASSERT (p ## ecma_type != NULL); \
|
||||
\
|
||||
for (ecma_gc_gen_t gen_id = ECMA_GC_GEN_0; \
|
||||
gen_id < ECMA_GC_GEN_COUNT; \
|
||||
gen_id++) \
|
||||
{ \
|
||||
ecma_gc_run (gen_id); \
|
||||
\
|
||||
p ## ecma_type = (ecma_ ## ecma_type ## _t *) mem_pools_alloc (); \
|
||||
\
|
||||
if (likely (p ## ecma_type != NULL)) \
|
||||
{ \
|
||||
return p ## ecma_type; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
jerry_exit (ERR_OUT_OF_MEMORY); \
|
||||
return p ## ecma_type; \
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#define ECMA_GC_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "mem-allocator.h"
|
||||
|
||||
/**
|
||||
* GC generation identifier
|
||||
@@ -43,6 +44,7 @@ extern void ecma_deref_object (ecma_object_t *object_p);
|
||||
extern void ecma_gc_update_may_ref_younger_object_flag_by_value (ecma_object_t *obj_p, ecma_value_t value);
|
||||
extern void ecma_gc_update_may_ref_younger_object_flag_by_object (ecma_object_t *obj_p, ecma_object_t *ref_obj_p);
|
||||
extern void ecma_gc_run (ecma_gc_gen_t max_gen_to_collect);
|
||||
extern void ecma_try_to_give_back_some_memory (mem_try_give_memory_back_severity_t severity);
|
||||
|
||||
#endif /* !ECMA_GC_H */
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-lcache.h"
|
||||
#include "globals.h"
|
||||
#include "jerry-libc.h"
|
||||
#include "interpreter.h"
|
||||
@@ -688,6 +689,7 @@ ecma_copy_or_ref_ecma_string (ecma_string_t *string_desc_p) /**< string descript
|
||||
uint32_t current_refs = string_desc_p->refs;
|
||||
|
||||
/* First trying to free unreachable objects that maybe refer to the string */
|
||||
ecma_lcache_invalidate_all ();
|
||||
ecma_gc_run (ECMA_GC_GEN_COUNT - 1);
|
||||
|
||||
if (current_refs == string_desc_p->refs)
|
||||
|
||||
Reference in New Issue
Block a user