Skip to content

Commit 6d9d89b

Browse files
committed
[Optimize] count outer memory size
trig gc when outer_size > OUTER_HEAP_SIZE_LIMIT issue: f-6326513073
1 parent 7c207ea commit 6d9d89b

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

src/gc/allocator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct malloc_state {
9393
size_t footprint;
9494
size_t max_footprint;
9595
size_t footprint_limit;
96+
size_t outer_heap_size;
9697
flag_t mflags;
9798
#if USE_LOCKS
9899
MLOCK_T mutex;

src/interpreter/quickjs/include/quickjs-inner.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3216,6 +3216,8 @@ void get_caller_string(JSFunctionDef *s);
32163216

32173217
void SetObjectCtxCheckStatus(LEPUSContext *ctx, bool enable);
32183218

3219+
void trig_gc(JSMallocState *s, size_t size, bool is_outer = false);
3220+
32193221
#ifdef ENABLE_QUICKJS_DEBUGGER
32203222
QJS_HIDE pid_t get_tid();
32213223
QJS_HIDE void CheckObjectCtx(LEPUSContext *ctx, LEPUSValue obj);

src/interpreter/quickjs/include/quickjs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,8 @@ void LEPUS_SetFuncFileName(LEPUSContext *, LEPUSValue, const char *);
16051605
void InitLynxTraceEnv(void *(*)(const char *), void (*)(void *));
16061606

16071607
void SetObjectCtxCheckStatus(LEPUSContext *ctx, bool enable);
1608+
1609+
void UpdateOuterObjSize(LEPUSRuntime *rt, int size);
16081610
// <Primjs end>
16091611

16101612
#undef lepus_unlikely

src/interpreter/quickjs/source/quickjs.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ int64_t HEAP_TAG_INNER = 0;
183183

184184
// <primjs begin>
185185

186+
static const int OUTER_HEAP_SIZE_LIMIT = 32 * MB;
187+
186188
#if defined(ENABLE_PRIMJS_SNAPSHOT)
187189
static const int NUM_OF_TOS_STATES = 3;
188190
#endif
@@ -56122,6 +56124,19 @@ void SetObjectCtxCheckStatus(LEPUSContext *ctx, bool enable) {
5612256124
return;
5612356125
}
5612456126

56127+
void UpdateOuterObjSize(LEPUSRuntime *rt, int size) {
56128+
#ifdef ENABLE_COMPATIBLE_MM
56129+
if (rt->gc_enable) {
56130+
JSMallocState *s = &rt->malloc_state;
56131+
s->allocate_state.outer_heap_size += size;
56132+
if (s->allocate_state.outer_heap_size > OUTER_HEAP_SIZE_LIMIT) {
56133+
trig_gc(s, size, true);
56134+
s->allocate_state.outer_heap_size = 0;
56135+
}
56136+
}
56137+
#endif
56138+
}
56139+
5612556140
#ifdef ENABLE_QUICKJS_DEBUGGER
5612656141
pid_t get_tid() {
5612756142
#if defined(ANDROID) || defined(__ANDROID__)

src/interpreter/quickjs/source/quickjs_gc.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,12 +850,16 @@ bool switch_local_idx(struct malloc_state *m, size_t size) {
850850
return false;
851851
}
852852

853-
void trig_gc(JSMallocState *s, size_t size) {
853+
void trig_gc(JSMallocState *s, size_t size, bool is_outer) {
854854
struct malloc_state *m = &s->allocate_state;
855+
LEPUSRuntime *rt = static_cast<LEPUSRuntime *>(m->runtime);
856+
if (is_outer) {
857+
rt->gc->CollectGarbage(size);
858+
return;
859+
}
855860
if (switch_local_idx(m, size)) {
856861
return;
857862
}
858-
LEPUSRuntime *rt = static_cast<LEPUSRuntime *>(m->runtime);
859863
// gc pause suppression mode
860864
if (rt->gc->GetGCPauseSuppressionMode() && rt->is_lepusng &&
861865
m->footprint < 240 * MB) {

0 commit comments

Comments
 (0)