Skip to content

Commit

Permalink
[Sampling profiler] Add ModuleCache::Module::IsNative()
Browse files Browse the repository at this point in the history
Adds a Module interface function to determine if a module is native.
This is required for the native unwinder so that it knows to stop trying
to unwind when encountering a v8 module.

Bug: 909957
Change-Id: Ic67cc7bc9ae9642664b0e0a9f6f163da8b67b969
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1566175
Auto-Submit: Mike Wittman <wittman@chromium.org>
Reviewed-by: Leonard Grey <lgrey@chromium.org>
Reviewed-by: oysteine <oysteine@chromium.org>
Commit-Queue: oysteine <oysteine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#651364}
  • Loading branch information
Mike Wittman authored and Commit Bot committed Apr 16, 2019
1 parent b30594b commit 2936278
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions base/profiler/stack_sampler_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class TestModule : public ModuleCache::Module {
std::string GetId() const override { return ""; }
FilePath GetDebugBasename() const override { return FilePath(); }
size_t GetSize() const override { return size_; }
bool IsNative() const override { return true; }

private:
const uintptr_t base_address_;
Expand Down
1 change: 1 addition & 0 deletions base/profiler/win32_stack_frame_unwinder_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class TestModule : public ModuleCache::Module {
std::string GetId() const override { return ""; }
FilePath GetDebugBasename() const override { return FilePath(); }
size_t GetSize() const override { return 0; }
bool IsNative() const override { return true; }

private:
const uintptr_t base_address_;
Expand Down
1 change: 1 addition & 0 deletions base/sampling_heap_profiler/module_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ std::vector<const ModuleCache::Module*> ModuleCache::GetModules() const {
}

void ModuleCache::AddNonNativeModule(std::unique_ptr<Module> module) {
DCHECK(!module->IsNative());
non_native_modules_.push_back(std::move(module));
}

Expand Down
3 changes: 3 additions & 0 deletions base/sampling_heap_profiler/module_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class BASE_EXPORT ModuleCache {

// Gets the size of the module.
virtual size_t GetSize() const = 0;

// True if this is a native module.
virtual bool IsNative() const = 0;
};

ModuleCache();
Expand Down
1 change: 1 addition & 0 deletions base/sampling_heap_profiler/module_cache_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class MacModule : public ModuleCache::Module {
std::string GetId() const override { return id_; }
FilePath GetDebugBasename() const override { return debug_basename_; }
size_t GetSize() const override { return size_; }
bool IsNative() const override { return true; }

private:
uintptr_t base_address_;
Expand Down
1 change: 1 addition & 0 deletions base/sampling_heap_profiler/module_cache_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class PosixModule : public ModuleCache::Module {
std::string GetId() const override { return id_; }
FilePath GetDebugBasename() const override { return debug_basename_; }
size_t GetSize() const override { return size_; }
bool IsNative() const override { return true; }

private:
uintptr_t base_address_;
Expand Down
18 changes: 12 additions & 6 deletions base/sampling_heap_profiler/module_cache_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ int AFunctionForTest() {
// heap memory.
class IsolatedModule : public ModuleCache::Module {
public:
IsolatedModule() : memory_region_(new char[kRegionSize]) {}
explicit IsolatedModule(bool is_native = true)
: is_native_(is_native), memory_region_(new char[kRegionSize]) {}

// ModuleCache::Module
uintptr_t GetBaseAddress() const override {
Expand All @@ -31,18 +32,20 @@ class IsolatedModule : public ModuleCache::Module {
std::string GetId() const override { return ""; }
FilePath GetDebugBasename() const override { return FilePath(); }
size_t GetSize() const override { return kRegionSize / 2; }
bool IsNative() const override { return is_native_; }

private:
static const int kRegionSize = 100;

bool is_native_;
std::unique_ptr<char[]> memory_region_;
};

// Provides a fake module with configurable base address and size.
class FakeModule : public ModuleCache::Module {
public:
FakeModule(uintptr_t base_address, size_t size)
: base_address_(base_address), size_(size) {}
FakeModule(uintptr_t base_address, size_t size, bool is_native = true)
: base_address_(base_address), size_(size), is_native_(is_native) {}

FakeModule(const FakeModule&) = delete;
FakeModule& operator=(const FakeModule&) = delete;
Expand All @@ -51,10 +54,12 @@ class FakeModule : public ModuleCache::Module {
std::string GetId() const override { return ""; }
FilePath GetDebugBasename() const override { return FilePath(); }
size_t GetSize() const override { return size_; }
bool IsNative() const override { return is_native_; }

private:
uintptr_t base_address_;
size_t size_;
bool is_native_;
};

#if defined(OS_POSIX) && !defined(OS_IOS) || defined(OS_WIN) || \
Expand Down Expand Up @@ -95,7 +100,7 @@ MAYBE_TEST(ModuleCacheTest, LookupRange) {

MAYBE_TEST(ModuleCacheTest, LookupNonNativeModule) {
ModuleCache cache;
auto non_native_module_to_add = std::make_unique<IsolatedModule>();
auto non_native_module_to_add = std::make_unique<IsolatedModule>(false);
const ModuleCache::Module* module = non_native_module_to_add.get();
cache.AddNonNativeModule(std::move(non_native_module_to_add));

Expand All @@ -116,8 +121,9 @@ MAYBE_TEST(ModuleCacheTest, LookupOverlaidNonNativeModule) {

// Overlay the native module with the non-native module, starting 8 bytes into
// the native modules and ending 8 bytes before the end of the module.
auto non_native_module_to_add = std::make_unique<FakeModule>(
native_module->GetBaseAddress() + 8, native_module->GetSize() - 16);
auto non_native_module_to_add =
std::make_unique<FakeModule>(native_module->GetBaseAddress() + 8,
native_module->GetSize() - 16, false);
const ModuleCache::Module* non_native_module = non_native_module_to_add.get();
cache.AddNonNativeModule(std::move(non_native_module_to_add));

Expand Down
1 change: 1 addition & 0 deletions base/sampling_heap_profiler/module_cache_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class WindowsModule : public ModuleCache::Module {
std::string GetId() const override { return id_; }
FilePath GetDebugBasename() const override { return debug_basename_; }
size_t GetSize() const override { return module_info_.SizeOfImage; }
bool IsNative() const override { return true; }

private:
ScopedModuleHandle module_handle_;
Expand Down
1 change: 1 addition & 0 deletions components/metrics/call_stack_profile_builder_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class TestModule : public base::ModuleCache::Module {
std::string GetId() const override { return id_; }
base::FilePath GetDebugBasename() const override { return debug_basename_; }
size_t GetSize() const override { return 0; }
bool IsNative() const override { return true; }

private:
uintptr_t base_address_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class TestModule : public base::ModuleCache::Module {
std::string GetId() const override { return ""; }
base::FilePath GetDebugBasename() const override { return base::FilePath(); }
size_t GetSize() const override { return 0; }
bool IsNative() const override { return true; }
};

} // namespace
Expand Down

0 comments on commit 2936278

Please sign in to comment.