Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
chakrashim: implement LowMemoryNotification and ifdef DEBUG -> CHAKRA…
Browse files Browse the repository at this point in the history
…_UNIMPLEMENTED

Fixes #433

PR-URL: #425

Reviewed-By: Hitesh Kanwathirtha <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
obastemur committed Nov 30, 2017
1 parent 77ab790 commit 74d08c6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 4 additions & 0 deletions deps/chakrashim/src/jsrtisolateshim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions deps/chakrashim/src/jsrtisolateshim.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
13 changes: 7 additions & 6 deletions deps/chakrashim/src/jsrtutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,22 @@ 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); }

#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.
Expand Down
4 changes: 2 additions & 2 deletions deps/chakrashim/src/v8isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -241,7 +241,7 @@ bool Isolate::IdleNotification(int idle_time_in_ms) {
}

void Isolate::LowMemoryNotification() {
CHAKRA_UNIMPLEMENTED();
jsrt::IsolateShim::GetCurrent()->CollectGarbage();
}

int Isolate::ContextDisposedNotification() {
Expand Down

0 comments on commit 74d08c6

Please sign in to comment.