Commit f314b3cd authored by hpayer's avatar hpayer Committed by Commit Bot

[api] Add an API function to set the GetExternallyAllocatedMemoryInBytesCallback.

BUG=chromium:727569

Review-Url: https://codereview.chromium.org/2910203002
Cr-Commit-Position: refs/heads/master@{#45599}
parent fb6a094d
......@@ -7147,6 +7147,17 @@ class V8_EXPORT Isolate {
*/
void RemoveGCEpilogueCallback(GCCallback callback);
typedef size_t (*GetExternallyAllocatedMemoryInBytesCallback)();
/**
* Set the callback that tells V8 how much memory is currently allocated
* externally of the V8 heap. Ideally this memory is somehow connected to V8
* objects and may get freed-up when the corresponding V8 objects get
* collected by a V8 garbage collection.
*/
void SetGetExternallyAllocatedMemoryInBytesCallback(
GetExternallyAllocatedMemoryInBytesCallback callback);
/**
* Forcefully terminate the current thread of JavaScript execution
* in the given isolate.
......
......@@ -8260,6 +8260,12 @@ void Isolate::SetEmbedderHeapTracer(EmbedderHeapTracer* tracer) {
isolate->heap()->SetEmbedderHeapTracer(tracer);
}
void Isolate::SetGetExternallyAllocatedMemoryInBytesCallback(
GetExternallyAllocatedMemoryInBytesCallback callback) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->heap()->SetGetExternallyAllocatedMemoryInBytesCallback(callback);
}
void Isolate::TerminateExecution() {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->stack_guard()->RequestTerminateExecution();
......
......@@ -381,6 +381,8 @@ void Heap::PrintShortHeapStatistics() {
this->CommittedMemory() / KB);
PrintIsolate(isolate_, "External memory reported: %6" PRId64 " KB\n",
external_memory_ / KB);
PrintIsolate(isolate_, "External memory global %zu KB\n",
external_memory_callback_() / KB);
PrintIsolate(isolate_, "Total time spent in GC : %.1f ms\n",
total_gc_time_ms_);
}
......@@ -964,7 +966,6 @@ void Heap::ReportExternalMemoryPressure() {
}
}
void Heap::EnsureFillerObjectAtTop() {
// There may be an allocation memento behind objects in new space. Upon
// evacuation of a non-full new space (or if we are on the last page) there
......@@ -5743,6 +5744,9 @@ bool Heap::SetUp() {
*this, ScavengeJob::kBytesAllocatedBeforeNextIdleTask);
new_space()->AddAllocationObserver(idle_scavenge_observer_);
SetGetExternallyAllocatedMemoryInBytesCallback(
DefaultGetExternallyAllocatedMemoryInBytesCallback);
return true;
}
......
......@@ -1175,6 +1175,14 @@ class Heap {
// completes incremental marking in order to free external resources.
void ReportExternalMemoryPressure();
typedef v8::Isolate::GetExternallyAllocatedMemoryInBytesCallback
GetExternallyAllocatedMemoryInBytesCallback;
void SetGetExternallyAllocatedMemoryInBytesCallback(
GetExternallyAllocatedMemoryInBytesCallback callback) {
external_memory_callback_ = callback;
}
// Invoked when GC was requested via the stack guard.
void HandleGCRequest();
......@@ -1664,6 +1672,10 @@ class Heap {
return (pretenure == TENURED) ? OLD_SPACE : NEW_SPACE;
}
static size_t DefaultGetExternallyAllocatedMemoryInBytesCallback() {
return 0;
}
#define ROOT_ACCESSOR(type, name, camel_name) \
inline void set_##name(type* value);
ROOT_LIST(ROOT_ACCESSOR)
......@@ -2282,6 +2294,8 @@ class Heap {
List<GCCallbackPair> gc_epilogue_callbacks_;
List<GCCallbackPair> gc_prologue_callbacks_;
GetExternallyAllocatedMemoryInBytesCallback external_memory_callback_;
int deferred_counters_[v8::Isolate::kUseCounterFeatureCount];
GCTracer* tracer_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment