reduce ram usage of stack

This commit is contained in:
pikastech 2022-10-02 00:00:53 +08:00
parent a29fa66117
commit d8698d5cac
17 changed files with 53 additions and 28 deletions

View File

@ -11,7 +11,7 @@
"program": "${workspaceFolder}/build/test/pikascript_test",
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
"args": [
"--gtest_filter=str.big_slice"
"--gtest_filter=vm.*"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",

View File

@ -1,3 +1,3 @@
#define PIKA_STACK_BUFF_SIZE 1024 * 1024
#define PIKA_STACK_BUFF_SIZE 1024 * 4
#define PIKA_ASSERT_ENABLE 1
#define PIKA_MATH_ENABLE 1

View File

@ -1,4 +1,4 @@
#define PIKA_STACK_BUFF_SIZE 1024 * 1024
#define PIKA_STACK_BUFF_SIZE 1024 * 4
#define PIKA_ASSERT_ENABLE 1
#define PIKA_MATH_ENABLE 1
#define PIKA_FLOAT_TYPE_DOUBLE 0

View File

@ -1,3 +1,3 @@
#define PIKA_OPTIMIZE PIKA_OPTIMIZE_SPEED
#define PIKA_STACK_BUFF_SIZE 1024 * 1024
#define PIKA_STACK_BUFF_SIZE 1024 * 4
#define PIKA_ASSERT_ENABLE 1

View File

@ -1,4 +1,4 @@
#define PIKA_STACK_BUFF_SIZE 1024 * 10
#define PIKA_STACK_BUFF_SIZE 1024 * 4
#define PIKA_POOL_ENABLE 1
#define PIKA_POOL_SIZE 1024 * 1024 * 10
#define PIKA_ASSERT_ENABLE 1

View File

@ -1,3 +1,3 @@
#define PIKA_NANO_ENABLE 1
#define PIKA_STACK_BUFF_SIZE 1024 * 1024
#define PIKA_STACK_BUFF_SIZE 1024 * 4
#define PIKA_ASSERT_ENABLE 1

View File

@ -2,4 +2,4 @@
#define PIKA_VERSION_MINOR 11
#define PIKA_VERSION_MICRO 2
#define PIKA_EDIT_TIME "2022/10/01 14:03:55"
#define PIKA_EDIT_TIME "2022/10/02 00:00:51"

View File

@ -275,7 +275,14 @@ pika_float arg_getFloat(Arg* self) {
}
Arg* arg_setPtr(Arg* self, char* name, ArgType type, void* pointer) {
return arg_init(name, type, (uint8_t*)&pointer, sizeof(uintptr_t), NULL);
if (NULL == self) {
return arg_init(name, type, (uint8_t*)&pointer, sizeof(uintptr_t),
NULL);
}
self = arg_setContent(self, (uint8_t*)&pointer, sizeof(pointer));
self = arg_setType(self, type);
self = arg_setName(self, name);
return self;
}
Arg* arg_setStr(Arg* self, char* name, char* string) {

View File

@ -40,6 +40,7 @@ typedef enum {
ARG_TYPE_STRING,
ARG_TYPE_BYTES,
ARG_TYPE_POINTER,
ARG_TYPE_BIG_ARG_PTR,
ARG_TYPE_OBJECT,
ARG_TYPE_OBJECT_META,
ARG_TYPE_OBJECT_NEW,

View File

@ -92,9 +92,10 @@ uint8_t* stack_popPyload(Stack* stack, size_t size) {
}
static int32_t _stack_pushArg(Stack* stack, Arg* arg, PIKA_BOOL is_alloc) {
PIKA_BOOL is_big_arg = PIKA_FALSE;
arg_newReg(big_arg_ref, PIKA_ARG_BUFF_SIZE);
stack->top++;
size_t size = arg_getTotleSize(arg);
//! if you unsure about the __impl_pikaMalloc, uncomment this to force alignment
#if PIKA_ARG_ALIGN_ENABLE
/* force alignment to avoid unaligned access */
@ -104,13 +105,25 @@ static int32_t _stack_pushArg(Stack* stack, Arg* arg, PIKA_BOOL is_alloc) {
if (argType_isObject(arg_getType(arg))) {
obj_refcntInc((PikaObj*)arg_getPtr(arg));
}
if (arg_getSerialized(arg) && size > PIKA_BIG_ARG_SIZE) {
is_big_arg = PIKA_TRUE;
arg_setPtr(&big_arg_ref, "", ARG_TYPE_BIG_ARG_PTR, arg);
arg = &big_arg_ref;
size = arg_getTotleSize(arg);
}
stack_pushSize(stack, size);
stack_pushPyload(stack, arg, size);
if (is_big_arg) {
return 0;
}
if (is_alloc) {
arg_deinit(arg);
} else {
arg_deinitHeap(arg);
return 0;
}
arg_deinitHeap(arg);
return 0;
}
@ -134,18 +147,27 @@ Arg* _stack_popArg(Stack* stack, Arg* arg_dict, PIKA_BOOL is_alloc) {
stack->top--;
int32_t size = stack_popSize(stack);
Arg* arg = NULL;
Arg* arg_res = NULL;
if (is_alloc) {
arg = arg_copy((Arg*)stack_popPyload(stack, size));
} else {
arg = arg_copy_noalloc((Arg*)stack_popPyload(stack, size), arg_dict);
}
ArgType type = arg_getType(arg);
arg_res = arg;
if (type == ARG_TYPE_BIG_ARG_PTR) {
arg_res = arg_getPtr(arg);
if (is_alloc) {
arg_deinit(arg);
}
type = arg_getType(arg_res);
}
/* decrase ref_cnt */
if (argType_isObject(type)) {
obj_refcntDec((PikaObj*)arg_getPtr(arg));
obj_refcntDec((PikaObj*)arg_getPtr(arg_res));
}
pika_assert(arg->flag < ARG_FLAG_MAX);
return arg;
pika_assert(arg_res->flag < ARG_FLAG_MAX);
return arg_res;
}
Arg* stack_popArg_alloc(Stack* stack) {

View File

@ -309,6 +309,10 @@
#define PIKA_FLOAT_TYPE_DOUBLE 1
#endif
#ifndef PIKA_BIG_ARG_SIZE
#define PIKA_BIG_ARG_SIZE 64
#endif
/* configuration validation */
#endif

View File

@ -1,7 +1,6 @@
#include "test_common.h"
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && (!PIKA_POOL_ENABLE) && \
(PIKA_STACK_BUFF_SIZE > 0x1000)
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && (!PIKA_POOL_ENABLE)
TEST(PikaCV, test1) {
/* init */
pikaMemInfo.heapUsedMax = 0;

View File

@ -1,7 +1,6 @@
#include "test_common.h"
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && (!PIKA_POOL_ENABLE) && \
(PIKA_STACK_BUFF_SIZE > 0x6000)
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && (!PIKA_POOL_ENABLE)
TEST(PikaNN, test1) {
/* init */

View File

@ -54,8 +54,7 @@ TEST(builtin, seek) {
}
#endif
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && \
(PIKA_STACK_BUFF_SIZE >= 0x1000)
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL)
TEST(builtin, file2) {
/* init */
pikaMemInfo.heapUsedMax = 0;
@ -89,8 +88,7 @@ TEST(builtin, file3) {
}
#endif
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && !PIKA_POOL_ENABLE && \
(PIKA_STACK_BUFF_SIZE >= 0x1000)
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && !PIKA_POOL_ENABLE
TEST(builtin, bigfile) {
/* init */
pikaMemInfo.heapUsedMax = 0;

View File

@ -1,6 +1,5 @@
#include "test_common.h"
#if PIKA_STACK_BUFF_SIZE >= 0x1000
TEST(cJSON, parse_print) {
/* init */
pikaMemInfo.heapUsedMax = 0;
@ -455,5 +454,3 @@ TEST(cJSON, module) {
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
#endif

View File

@ -1,5 +1,4 @@
#include "test_common.h"
#if PIKA_STACK_BUFF_SIZE >= 0x1000
#if PIKA_SYNTAX_SLICE_ENABLE
TEST(configparser, test1) {
char* s =
@ -54,4 +53,3 @@ TEST(configparser, test2) {
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
#endif

View File

@ -85,7 +85,7 @@ TEST(stddata, encode_decode) {
}
#endif
#if PIKA_FILEIO_ENABLE && PIKA_STACK_BUFF_SIZE > 0x1000
#if PIKA_FILEIO_ENABLE
TEST(stddata, fileio) {
/* init */
pikaMemInfo.heapUsedMax = 0;