From c80433f97fd1e4cf273959ad1e4ea9e1b749074a Mon Sep 17 00:00:00 2001 From: hinus Date: Fri, 17 Jul 2020 20:28:11 +0800 Subject: [PATCH] =?UTF-8?q?Summary:=20=E5=BC=95=E5=85=A5Safepoint=E7=82=B9?= =?UTF-8?q?=20Issue:=20https://gitee.com/hinus/HiLang/issues/I1O87L=20Desc?= =?UTF-8?q?ription:=201.=20=E6=80=82=E4=BA=86=EF=BC=8C=E5=BC=95=E5=85=A5Sa?= =?UTF-8?q?fepoint=E7=82=B9=20LLT:=20datas.hi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/vm/memory/heap.cpp | 1 + src/main/vm/memory/heap.hpp | 3 +++ src/main/vm/runtime/interpreter.cpp | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/src/main/vm/memory/heap.cpp b/src/main/vm/memory/heap.cpp index 53889b8..83b3f1b 100644 --- a/src/main/vm/memory/heap.cpp +++ b/src/main/vm/memory/heap.cpp @@ -117,6 +117,7 @@ void* Space::allocate(size_t size) { char* start = _top; _top += size; _capacity -= size; + _rate = _capacity * 1.0 / _size; //printf("after allocate %lx, _top is %p\n", size, _top); return start; } diff --git a/src/main/vm/memory/heap.hpp b/src/main/vm/memory/heap.hpp index 2e9a32d..e408742 100644 --- a/src/main/vm/memory/heap.hpp +++ b/src/main/vm/memory/heap.hpp @@ -13,6 +13,7 @@ private: char* _end; size_t _size; size_t _capacity; + double _rate; Space(size_t size); ~Space(); @@ -22,6 +23,7 @@ public: void clear(); bool can_alloc(size_t size); bool has_obj(char* obj); + double rate() { return _rate; } }; class Heap { @@ -46,6 +48,7 @@ public: void* allocate(size_t size); void* allocate_meta(size_t size); void copy_live_objects(); + double rate() { return eden->rate(); } void gc(); }; diff --git a/src/main/vm/runtime/interpreter.cpp b/src/main/vm/runtime/interpreter.cpp index 70c3854..722c6e4 100644 --- a/src/main/vm/runtime/interpreter.cpp +++ b/src/main/vm/runtime/interpreter.cpp @@ -238,6 +238,10 @@ void Interpreter::eval_frame() { //printf("%d %d\n", op_code, op_arg); + if (Universe::heap->rate() < 0.05) { + Universe::heap->gc(); + } + switch (op_code) { case ByteCode::POP_TOP: POP(); -- Gitee