From 18aeeae0e879e90fe97f59cbd32521139c3fba79 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 27 Nov 2013 18:56:31 -0600 Subject: [PATCH] Implement Runtime#{free,total}Memory() Signed-off-by: Johannes Schindelin --- include/avian/vm/heap/heap.h | 1 + src/classpath-avian.cpp | 10 ++++------ src/heap/heap.cpp | 4 ++++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/avian/vm/heap/heap.h b/include/avian/vm/heap/heap.h index 13b38dd45a..51b9808b08 100644 --- a/include/avian/vm/heap/heap.h +++ b/include/avian/vm/heap/heap.h @@ -59,6 +59,7 @@ class Heap: public Allocator { virtual void setClient(Client* client) = 0; virtual void setImmortalHeap(uintptr_t* start, unsigned sizeInWords) = 0; + virtual unsigned remaining() = 0; virtual unsigned limit() = 0; virtual bool limitExceeded(int pendingAllocation = 0) = 0; virtual void collect(CollectionType type, unsigned footprint, diff --git a/src/classpath-avian.cpp b/src/classpath-avian.cpp index 2836bd086c..b878e04006 100644 --- a/src/classpath-avian.cpp +++ b/src/classpath-avian.cpp @@ -593,18 +593,16 @@ Avian_java_lang_Runtime_gc extern "C" AVIAN_EXPORT int64_t JNICALL Avian_java_lang_Runtime_freeMemory -(Thread*, object, uintptr_t*) +(Thread* t, object, uintptr_t*) { - // todo - return 0; + return t->m->heap->remaining(); } extern "C" AVIAN_EXPORT int64_t JNICALL Avian_java_lang_Runtime_totalMemory -(Thread*, object, uintptr_t*) +(Thread* t, object, uintptr_t*) { - // todo - return 0; + return t->m->heap->limit(); } extern "C" AVIAN_EXPORT void JNICALL diff --git a/src/heap/heap.cpp b/src/heap/heap.cpp index 50bc7afd32..aaf9909f6b 100644 --- a/src/heap/heap.cpp +++ b/src/heap/heap.cpp @@ -1888,6 +1888,10 @@ class MyHeap: public Heap { c.immortalHeapEnd = start + sizeInWords; } + virtual unsigned remaining() { + return c.limit - c.count; + } + virtual unsigned limit() { return c.limit; }