From 74d08c6d47a646cf5948766ba7dc9bc16784b98d Mon Sep 17 00:00:00 2001 From: Oguz Bastemur Date: Wed, 29 Nov 2017 18:10:37 +0100 Subject: [PATCH] chakrashim: implement LowMemoryNotification and ifdef DEBUG -> CHAKRA_UNIMPLEMENTED Fixes #433 PR-URL: #425 Reviewed-By: Hitesh Kanwathirtha Reviewed-By: Anna Henningsen --- deps/chakrashim/src/jsrtisolateshim.cc | 4 ++++ deps/chakrashim/src/jsrtisolateshim.h | 1 + deps/chakrashim/src/jsrtutils.h | 13 +++++++------ deps/chakrashim/src/v8isolate.cc | 4 ++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/deps/chakrashim/src/jsrtisolateshim.cc b/deps/chakrashim/src/jsrtisolateshim.cc index ff5dbfd019d..bbe87b1164e 100644 --- a/deps/chakrashim/src/jsrtisolateshim.cc +++ b/deps/chakrashim/src/jsrtisolateshim.cc @@ -426,6 +426,10 @@ bool IsolateShim::GetMemoryUsage(size_t * memoryUsage) { return (JsGetRuntimeMemoryUsage(runtime, memoryUsage) == JsNoError); } +void IsolateShim::CollectGarbage() { + JsCollectGarbage(runtime); +} + void IsolateShim::DisposeAll() { // CHAKRA-TODO: multithread locking for s_isolateList? IsolateShim * curr = s_isolateList; diff --git a/deps/chakrashim/src/jsrtisolateshim.h b/deps/chakrashim/src/jsrtisolateshim.h index 587113a371f..a398ae54e08 100644 --- a/deps/chakrashim/src/jsrtisolateshim.h +++ b/deps/chakrashim/src/jsrtisolateshim.h @@ -62,6 +62,7 @@ class IsolateShim { bool NewContext(JsContextRef * context, bool exposeGC, bool useGlobalTTState, JsValueRef globalObjectTemplateInstance); bool GetMemoryUsage(size_t * memoryUsage); + void CollectGarbage(); bool Dispose(); bool IsDisposing(); diff --git a/deps/chakrashim/src/jsrtutils.h b/deps/chakrashim/src/jsrtutils.h index 5d02900d314..59ebd2692d4 100644 --- a/deps/chakrashim/src/jsrtutils.h +++ b/deps/chakrashim/src/jsrtutils.h @@ -78,8 +78,15 @@ inline size_t _countof(T (&)[N]) { } \ } +#ifdef DEBUG +#define CHAKRA_ASSERT(expr) assert(expr) #define CHAKRA_UNIMPLEMENTED() jsrt::Unimplemented(__FUNCTION__) #define CHAKRA_UNIMPLEMENTED_(message) jsrt::Unimplemented(message) +#else // DEBUG +#define CHAKRA_UNIMPLEMENTED() /* no-op */ +#define CHAKRA_UNIMPLEMENTED_(message) /* no-op */ +#define CHAKRA_ASSERT(expr) /* no-op */ +#endif // DEBUG #define CHAKRA_VERIFY(expr) if (!(expr)) { \ jsrt::Fatal("internal error %s(%d): %s", __FILE__, __LINE__, #expr); } @@ -87,12 +94,6 @@ inline size_t _countof(T (&)[N]) { #define CHAKRA_VERIFY_NOERROR(errorCode) if (errorCode != JsNoError) { \ jsrt::Fatal("internal error %s(%d): %x", __FILE__, __LINE__, errorCode); } -#ifdef DEBUG -#define CHAKRA_ASSERT(expr) assert(expr) -#else -#define CHAKRA_ASSERT(expr) -#endif - namespace jsrt { // Similar to v8::String::Utf8Value but only operates on JS String. diff --git a/deps/chakrashim/src/v8isolate.cc b/deps/chakrashim/src/v8isolate.cc index 71a67efe193..a5121bfd6df 100644 --- a/deps/chakrashim/src/v8isolate.cc +++ b/deps/chakrashim/src/v8isolate.cc @@ -215,7 +215,7 @@ void Isolate::TerminateExecution() { } void Isolate::RequestGarbageCollectionForTesting(GarbageCollectionType type) { - JsCollectGarbage(jsrt::IsolateShim::FromIsolate(this)->GetRuntimeHandle()); + jsrt::IsolateShim::FromIsolate(this)->CollectGarbage(); } void Isolate::SetCounterFunction(CounterLookupCallback) { @@ -241,7 +241,7 @@ bool Isolate::IdleNotification(int idle_time_in_ms) { } void Isolate::LowMemoryNotification() { - CHAKRA_UNIMPLEMENTED(); + jsrt::IsolateShim::GetCurrent()->CollectGarbage(); } int Isolate::ContextDisposedNotification() {