Commit defd75b9 authored by Brett Wilson's avatar Brett Wilson Committed by Commit Bot

Hook Oilpan to OOP memory logging.

Plumbs the oilpan hooks to the out-of-process memory allocation log.

Change two loops in ChromeContentRendererClient to use C++11.

Bug: 763173
Change-Id: I7fc2b27fcc84c6f1298130096e584936042b9763
Reviewed-on: https://chromium-review.googlesource.com/671418Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Brett Wilson <brettw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#504413}
parent 319dbf61
......@@ -36,6 +36,12 @@ constexpr int kSendBufferSize = 65536;
// to provide sufficient parallelism to avoid lock overhead in ad-hoc testing.
constexpr int kNumSendBuffers = 17;
// Functions set by a callback if the GC heap exists in the current process.
// This function pointers can be used to hook or unhook the oilpan allocations.
// It will be null in the browser process.
SetGCAllocHookFunction g_hook_gc_alloc = nullptr;
SetGCFreeHookFunction g_hook_gc_free = nullptr;
class SendBuffer {
public:
SendBuffer() : buffer_(new char[kSendBufferSize]) {}
......@@ -182,6 +188,14 @@ void HookPartitionFree(void* address) {
AllocatorShimLogFree(address);
}
void HookGCAlloc(uint8_t* address, size_t size, const char* type) {
AllocatorShimLogAlloc(AllocatorType::kOilpan, address, size, type);
}
void HookGCFree(uint8_t* address) {
AllocatorShimLogFree(address);
}
} // namespace
void InitAllocatorShim(MemlogSenderPipe* sender_pipe) {
......@@ -199,12 +213,23 @@ void InitAllocatorShim(MemlogSenderPipe* sender_pipe) {
// PartitionAlloc allocator shim.
base::PartitionAllocHooks::SetAllocationHook(&HookPartitionAlloc);
base::PartitionAllocHooks::SetFreeHook(&HookPartitionFree);
// GC (Oilpan) allocator shim.
if (g_hook_gc_alloc && g_hook_gc_free) {
g_hook_gc_alloc(&HookGCAlloc);
g_hook_gc_free(&HookGCFree);
}
}
void StopAllocatorShimDangerous() {
g_send_buffers = nullptr;
base::PartitionAllocHooks::SetAllocationHook(nullptr);
base::PartitionAllocHooks::SetFreeHook(nullptr);
if (g_hook_gc_alloc && g_hook_gc_free) {
g_hook_gc_alloc(nullptr);
g_hook_gc_free(nullptr);
}
}
void AllocatorShimLogAlloc(AllocatorType type,
......@@ -275,4 +300,17 @@ void AllocatorShimLogFree(void* address) {
}
}
void SetGCHeapAllocationHookFunctions(SetGCAllocHookFunction hook_alloc,
SetGCFreeHookFunction hook_free) {
g_hook_gc_alloc = hook_alloc;
g_hook_gc_free = hook_free;
if (g_sender_pipe) {
// If starting the memlog pipe beat Blink initialization, hook the
// functions now.
g_hook_gc_alloc(&HookGCAlloc);
g_hook_gc_free(&HookGCFree);
}
}
} // namespace profiling
......@@ -8,12 +8,6 @@
#include "chrome/common/profiling/memlog_sender_pipe.h"
#include "chrome/common/profiling/memlog_stream.h"
// This is a temporary allocator shim for testing out-of-process heap
// profiling.
//
// TODO(brettw) replace this with the base allocator shim, plus a way to get
// the events at the Chrome layer.
namespace profiling {
// Begin profiling all allocations in the process. Send the results to
......@@ -40,6 +34,17 @@ void AllocatorShimLogAlloc(AllocatorType type,
void AllocatorShimLogFree(void* address);
// Sets the functions that can be called to hook GC heap allocations. These
// must be set externally since GC heap only exists in renderer processes. If
// set, these functions functions will be called to enable logging of the GC
// heap.
using SetGCAllocHookFunction = void (*)(void (*)(uint8_t*,
size_t,
const char*));
using SetGCFreeHookFunction = void (*)(void (*)(uint8_t*));
void SetGCHeapAllocationHookFunctions(SetGCAllocHookFunction hook_alloc,
SetGCFreeHookFunction hook_free);
} // namespace profiling
#endif // CHROME_COMMON_PROFILING_MEMLOG_ALLOCATOR_SHIM_H_
......@@ -35,6 +35,7 @@
#include "chrome/common/pepper_permission_util.h"
#include "chrome/common/plugin.mojom.h"
#include "chrome/common/prerender_types.h"
#include "chrome/common/profiling/memlog_allocator_shim.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/secure_origin_whitelist.h"
#include "chrome/common/url_constants.h"
......@@ -128,6 +129,7 @@
#include "third_party/WebKit/public/platform/scheduler/renderer_process_type.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebElement.h"
#include "third_party/WebKit/public/web/WebHeap.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebPluginContainer.h"
#include "third_party/WebKit/public/web/WebPluginParams.h"
......@@ -377,15 +379,17 @@ ChromeContentRendererClient::ChromeContentRendererClient()
ChromeExtensionsRendererClient::GetInstance());
#endif
#if BUILDFLAG(ENABLE_PLUGINS)
for (size_t i = 0; i < arraysize(kPredefinedAllowedCameraDeviceOrigins); ++i)
allowed_camera_device_origins_.insert(
kPredefinedAllowedCameraDeviceOrigins[i]);
for (size_t i = 0; i < arraysize(kPredefinedAllowedCompositorOrigins); ++i)
allowed_compositor_origins_.insert(kPredefinedAllowedCompositorOrigins[i]);
for (const char* origin : kPredefinedAllowedCameraDeviceOrigins)
allowed_camera_device_origins_.insert(origin);
for (const char* origin : kPredefinedAllowedCompositorOrigins)
allowed_compositor_origins_.insert(origin);
#endif
#if BUILDFLAG(ENABLE_PRINTING)
printing::SetAgent(GetUserAgent());
#endif
profiling::SetGCHeapAllocationHookFunctions(
&blink::WebHeap::SetAllocationHook, &blink::WebHeap::SetFreeHook);
}
ChromeContentRendererClient::~ChromeContentRendererClient() = default;
......
......@@ -31,6 +31,7 @@
#include "public/web/WebHeap.h"
#include "platform/heap/Handle.h"
#include "platform/heap/Heap.h"
namespace blink {
......@@ -43,4 +44,12 @@ void WebHeap::CollectAllGarbageForTesting() {
ThreadState::Current()->CollectAllGarbage();
}
void WebHeap::SetAllocationHook(AllocationHook alloc_hook) {
HeapAllocHooks::SetAllocationHook(alloc_hook);
}
void WebHeap::SetFreeHook(FreeHook free_hook) {
HeapAllocHooks::SetFreeHook(free_hook);
}
} // namespace blink
......@@ -37,10 +37,17 @@ namespace blink {
class WebHeap {
public:
using AllocationHook = void (*)(uint8_t*, size_t, const char*);
using FreeHook = void (*)(uint8_t*);
// These APIs are only for testing purposes and should not be used
// outside of tests.
BLINK_EXPORT static void CollectGarbageForTesting();
BLINK_EXPORT static void CollectAllGarbageForTesting();
// These functions allow hooking the GC allocator.
BLINK_EXPORT static void SetAllocationHook(AllocationHook);
BLINK_EXPORT static void SetFreeHook(FreeHook);
};
} // namespace blink
......
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