Commit 52640018 authored by jochen@chromium.org's avatar jochen@chromium.org

Drop dependency on Isolate* from platform.h

BUG=none
R=dcarney@chromium.org
LOG=n

Review URL: https://codereview.chromium.org/328993003

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21819 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 649057e0
...@@ -867,7 +867,12 @@ void Profiler::Engage() { ...@@ -867,7 +867,12 @@ void Profiler::Engage() {
if (engaged_) return; if (engaged_) return;
engaged_ = true; engaged_ = true;
OS::LogSharedLibraryAddresses(isolate_); std::vector<OS::SharedLibraryAddress> addresses =
OS::GetSharedLibraryAddresses();
for (size_t i = 0; i < addresses.size(); ++i) {
LOG(isolate_, SharedLibraryEvent(
addresses[i].library_path, addresses[i].start, addresses[i].end));
}
// Start thread processing the profiler buffer. // Start thread processing the profiler buffer.
running_ = true; running_ = true;
...@@ -1048,26 +1053,13 @@ void Logger::ApiNamedSecurityCheck(Object* key) { ...@@ -1048,26 +1053,13 @@ void Logger::ApiNamedSecurityCheck(Object* key) {
} }
void Logger::SharedLibraryEvent(const char* library_path, void Logger::SharedLibraryEvent(const std::string& library_path,
uintptr_t start, uintptr_t start,
uintptr_t end) { uintptr_t end) {
if (!log_->IsEnabled() || !FLAG_prof) return; if (!log_->IsEnabled() || !FLAG_prof) return;
Log::MessageBuilder msg(log_); Log::MessageBuilder msg(log_);
msg.Append("shared-library,\"%s\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR "\n", msg.Append("shared-library,\"%s\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR "\n",
library_path, library_path.c_str(),
start,
end);
msg.WriteToLogFile();
}
void Logger::SharedLibraryEvent(const wchar_t* library_path,
uintptr_t start,
uintptr_t end) {
if (!log_->IsEnabled() || !FLAG_prof) return;
Log::MessageBuilder msg(log_);
msg.Append("shared-library,\"%ls\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR "\n",
library_path,
start, start,
end); end);
msg.WriteToLogFile(); msg.WriteToLogFile();
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef V8_LOG_H_ #ifndef V8_LOG_H_
#define V8_LOG_H_ #define V8_LOG_H_
#include <string>
#include "src/allocation.h" #include "src/allocation.h"
#include "src/objects.h" #include "src/objects.h"
#include "src/platform.h" #include "src/platform.h"
...@@ -280,10 +282,7 @@ class Logger { ...@@ -280,10 +282,7 @@ class Logger {
void HeapSampleStats(const char* space, const char* kind, void HeapSampleStats(const char* space, const char* kind,
intptr_t capacity, intptr_t used); intptr_t capacity, intptr_t used);
void SharedLibraryEvent(const char* library_path, void SharedLibraryEvent(const std::string& library_path,
uintptr_t start,
uintptr_t end);
void SharedLibraryEvent(const wchar_t* library_path,
uintptr_t start, uintptr_t start,
uintptr_t end); uintptr_t end);
......
...@@ -106,12 +106,13 @@ PosixMemoryMappedFile::~PosixMemoryMappedFile() { ...@@ -106,12 +106,13 @@ PosixMemoryMappedFile::~PosixMemoryMappedFile() {
} }
void OS::LogSharedLibraryAddresses(Isolate* isolate) { std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
std::vector<SharedLibraryAddresses> result;
// This function assumes that the layout of the file is as follows: // This function assumes that the layout of the file is as follows:
// hex_start_addr-hex_end_addr rwxp <unused data> [binary_file_name] // hex_start_addr-hex_end_addr rwxp <unused data> [binary_file_name]
// If we encounter an unexpected situation we abort scanning further entries. // If we encounter an unexpected situation we abort scanning further entries.
FILE* fp = fopen("/proc/self/maps", "r"); FILE* fp = fopen("/proc/self/maps", "r");
if (fp == NULL) return; if (fp == NULL) return result;
// Allocate enough room to be able to store a full file name. // Allocate enough room to be able to store a full file name.
const int kLibNameLen = FILENAME_MAX + 1; const int kLibNameLen = FILENAME_MAX + 1;
...@@ -150,7 +151,7 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) { ...@@ -150,7 +151,7 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) {
snprintf(lib_name, kLibNameLen, snprintf(lib_name, kLibNameLen,
"%08" V8PRIxPTR "-%08" V8PRIxPTR, start, end); "%08" V8PRIxPTR "-%08" V8PRIxPTR, start, end);
} }
LOG(isolate, SharedLibraryEvent(lib_name, start, end)); result.push_back(SharedLibraryAddress(lib_name, start, end));
} else { } else {
// Entry not describing executable data. Skip to end of line to set up // Entry not describing executable data. Skip to end of line to set up
// reading the next entry. // reading the next entry.
...@@ -162,6 +163,7 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) { ...@@ -162,6 +163,7 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) {
} }
free(lib_name); free(lib_name);
fclose(fp); fclose(fp);
return result;
} }
......
...@@ -120,10 +120,11 @@ static unsigned StringToLong(char* buffer) { ...@@ -120,10 +120,11 @@ static unsigned StringToLong(char* buffer) {
} }
void OS::LogSharedLibraryAddresses(Isolate* isolate) { std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
std::vector<SharedLibraryAddress> result;
static const int MAP_LENGTH = 1024; static const int MAP_LENGTH = 1024;
int fd = open("/proc/self/maps", O_RDONLY); int fd = open("/proc/self/maps", O_RDONLY);
if (fd < 0) return; if (fd < 0) return result;
while (true) { while (true) {
char addr_buffer[11]; char addr_buffer[11];
addr_buffer[0] = '0'; addr_buffer[0] = '0';
...@@ -154,9 +155,10 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) { ...@@ -154,9 +155,10 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) {
// There may be no filename in this line. Skip to next. // There may be no filename in this line. Skip to next.
if (start_of_path == NULL) continue; if (start_of_path == NULL) continue;
buffer[bytes_read] = 0; buffer[bytes_read] = 0;
LOG(isolate, SharedLibraryEvent(start_of_path, start, end)); result.push_back(SharedLibraryAddress(start_of_path, start, end));
} }
close(fd); close(fd);
return result;
} }
......
...@@ -182,12 +182,13 @@ PosixMemoryMappedFile::~PosixMemoryMappedFile() { ...@@ -182,12 +182,13 @@ PosixMemoryMappedFile::~PosixMemoryMappedFile() {
} }
void OS::LogSharedLibraryAddresses(Isolate* isolate) { std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
std::vector<SharedLibraryAddress> result;
// This function assumes that the layout of the file is as follows: // This function assumes that the layout of the file is as follows:
// hex_start_addr-hex_end_addr rwxp <unused data> [binary_file_name] // hex_start_addr-hex_end_addr rwxp <unused data> [binary_file_name]
// If we encounter an unexpected situation we abort scanning further entries. // If we encounter an unexpected situation we abort scanning further entries.
FILE* fp = fopen("/proc/self/maps", "r"); FILE* fp = fopen("/proc/self/maps", "r");
if (fp == NULL) return; if (fp == NULL) return result;
// Allocate enough room to be able to store a full file name. // Allocate enough room to be able to store a full file name.
const int kLibNameLen = FILENAME_MAX + 1; const int kLibNameLen = FILENAME_MAX + 1;
...@@ -227,7 +228,7 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) { ...@@ -227,7 +228,7 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) {
snprintf(lib_name, kLibNameLen, snprintf(lib_name, kLibNameLen,
"%08" V8PRIxPTR "-%08" V8PRIxPTR, start, end); "%08" V8PRIxPTR "-%08" V8PRIxPTR, start, end);
} }
LOG(isolate, SharedLibraryEvent(lib_name, start, end)); result.push_back(SharedLibraryAddress(lib_name, start, end));
} else { } else {
// Entry not describing executable data. Skip to end of line to set up // Entry not describing executable data. Skip to end of line to set up
// reading the next entry. // reading the next entry.
...@@ -239,6 +240,7 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) { ...@@ -239,6 +240,7 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) {
} }
free(lib_name); free(lib_name);
fclose(fp); fclose(fp);
return result;
} }
......
...@@ -125,7 +125,8 @@ PosixMemoryMappedFile::~PosixMemoryMappedFile() { ...@@ -125,7 +125,8 @@ PosixMemoryMappedFile::~PosixMemoryMappedFile() {
} }
void OS::LogSharedLibraryAddresses(Isolate* isolate) { std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
std::vector<SharedLibraryAddress> result;
unsigned int images_count = _dyld_image_count(); unsigned int images_count = _dyld_image_count();
for (unsigned int i = 0; i < images_count; ++i) { for (unsigned int i = 0; i < images_count; ++i) {
const mach_header* header = _dyld_get_image_header(i); const mach_header* header = _dyld_get_image_header(i);
...@@ -144,9 +145,10 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) { ...@@ -144,9 +145,10 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) {
if (code_ptr == NULL) continue; if (code_ptr == NULL) continue;
const uintptr_t slide = _dyld_get_image_vmaddr_slide(i); const uintptr_t slide = _dyld_get_image_vmaddr_slide(i);
const uintptr_t start = reinterpret_cast<uintptr_t>(code_ptr) + slide; const uintptr_t start = reinterpret_cast<uintptr_t>(code_ptr) + slide;
LOG(isolate, result.push_back(
SharedLibraryEvent(_dyld_get_image_name(i), start, start + size)); SharedLibraryAddress(_dyld_get_image_name(i), start, start + size));
} }
return result;
} }
......
...@@ -113,12 +113,13 @@ PosixMemoryMappedFile::~PosixMemoryMappedFile() { ...@@ -113,12 +113,13 @@ PosixMemoryMappedFile::~PosixMemoryMappedFile() {
} }
void OS::LogSharedLibraryAddresses(Isolate* isolate) { std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
std::vector<SharedLibraryAddress> result;
// This function assumes that the layout of the file is as follows: // This function assumes that the layout of the file is as follows:
// hex_start_addr-hex_end_addr rwxp <unused data> [binary_file_name] // hex_start_addr-hex_end_addr rwxp <unused data> [binary_file_name]
// If we encounter an unexpected situation we abort scanning further entries. // If we encounter an unexpected situation we abort scanning further entries.
FILE* fp = fopen("/proc/self/maps", "r"); FILE* fp = fopen("/proc/self/maps", "r");
if (fp == NULL) return; if (fp == NULL) return result;
// Allocate enough room to be able to store a full file name. // Allocate enough room to be able to store a full file name.
const int kLibNameLen = FILENAME_MAX + 1; const int kLibNameLen = FILENAME_MAX + 1;
...@@ -157,7 +158,7 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) { ...@@ -157,7 +158,7 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) {
snprintf(lib_name, kLibNameLen, snprintf(lib_name, kLibNameLen,
"%08" V8PRIxPTR "-%08" V8PRIxPTR, start, end); "%08" V8PRIxPTR "-%08" V8PRIxPTR, start, end);
} }
LOG(isolate, SharedLibraryEvent(lib_name, start, end)); result.push_back(SharedLibraryAddress(lib_name, start, end));
} else { } else {
// Entry not describing executable data. Skip to end of line to set up // Entry not describing executable data. Skip to end of line to set up
// reading the next entry. // reading the next entry.
...@@ -169,6 +170,7 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) { ...@@ -169,6 +170,7 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) {
} }
free(lib_name); free(lib_name);
fclose(fp); fclose(fp);
return result;
} }
......
...@@ -174,7 +174,8 @@ PosixMemoryMappedFile::~PosixMemoryMappedFile() { ...@@ -174,7 +174,8 @@ PosixMemoryMappedFile::~PosixMemoryMappedFile() {
} }
void OS::LogSharedLibraryAddresses(Isolate* isolate) { std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
std::vector<SharedLibraryAddress> result;
procfs_mapinfo *mapinfos = NULL, *mapinfo; procfs_mapinfo *mapinfos = NULL, *mapinfo;
int proc_fd, num, i; int proc_fd, num, i;
...@@ -188,20 +189,20 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) { ...@@ -188,20 +189,20 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) {
if ((proc_fd = open(buf, O_RDONLY)) == -1) { if ((proc_fd = open(buf, O_RDONLY)) == -1) {
close(proc_fd); close(proc_fd);
return; return result;
} }
/* Get the number of map entries. */ /* Get the number of map entries. */
if (devctl(proc_fd, DCMD_PROC_MAPINFO, NULL, 0, &num) != EOK) { if (devctl(proc_fd, DCMD_PROC_MAPINFO, NULL, 0, &num) != EOK) {
close(proc_fd); close(proc_fd);
return; return result;
} }
mapinfos = reinterpret_cast<procfs_mapinfo *>( mapinfos = reinterpret_cast<procfs_mapinfo *>(
malloc(num * sizeof(procfs_mapinfo))); malloc(num * sizeof(procfs_mapinfo)));
if (mapinfos == NULL) { if (mapinfos == NULL) {
close(proc_fd); close(proc_fd);
return; return result;
} }
/* Fill the map entries. */ /* Fill the map entries. */
...@@ -209,7 +210,7 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) { ...@@ -209,7 +210,7 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) {
mapinfos, num * sizeof(procfs_mapinfo), &num) != EOK) { mapinfos, num * sizeof(procfs_mapinfo), &num) != EOK) {
free(mapinfos); free(mapinfos);
close(proc_fd); close(proc_fd);
return; return result;
} }
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
...@@ -219,13 +220,13 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) { ...@@ -219,13 +220,13 @@ void OS::LogSharedLibraryAddresses(Isolate* isolate) {
if (devctl(proc_fd, DCMD_PROC_MAPDEBUG, &map, sizeof(map), 0) != EOK) { if (devctl(proc_fd, DCMD_PROC_MAPDEBUG, &map, sizeof(map), 0) != EOK) {
continue; continue;
} }
LOG(isolate, SharedLibraryEvent(map.info.path, result.push_back(SharedLibraryAddress(
mapinfo->vaddr, map.info.path, mapinfo->vaddr, mapinfo->vaddr + mapinfo->size));
mapinfo->vaddr + mapinfo->size));
} }
} }
free(mapinfos); free(mapinfos);
close(proc_fd); close(proc_fd);
return result;
} }
......
...@@ -131,7 +131,8 @@ PosixMemoryMappedFile::~PosixMemoryMappedFile() { ...@@ -131,7 +131,8 @@ PosixMemoryMappedFile::~PosixMemoryMappedFile() {
} }
void OS::LogSharedLibraryAddresses(Isolate* isolate) { std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
return std::vector<SharedLibraryAddress>();
} }
......
...@@ -1058,10 +1058,13 @@ TLHELP32_FUNCTION_LIST(DLL_FUNC_LOADED) ...@@ -1058,10 +1058,13 @@ TLHELP32_FUNCTION_LIST(DLL_FUNC_LOADED)
// Load the symbols for generating stack traces. // Load the symbols for generating stack traces.
static bool LoadSymbols(Isolate* isolate, HANDLE process_handle) { static std::vector<OS::SharedLibraryAddress> LoadSymbols(
HANDLE process_handle) {
static std::vector<OS::SharedLibraryAddress> result;
static bool symbols_loaded = false; static bool symbols_loaded = false;
if (symbols_loaded) return true; if (symbols_loaded) return result;
BOOL ok; BOOL ok;
...@@ -1069,7 +1072,7 @@ static bool LoadSymbols(Isolate* isolate, HANDLE process_handle) { ...@@ -1069,7 +1072,7 @@ static bool LoadSymbols(Isolate* isolate, HANDLE process_handle) {
ok = _SymInitialize(process_handle, // hProcess ok = _SymInitialize(process_handle, // hProcess
NULL, // UserSearchPath NULL, // UserSearchPath
false); // fInvadeProcess false); // fInvadeProcess
if (!ok) return false; if (!ok) return result;
DWORD options = _SymGetOptions(); DWORD options = _SymGetOptions();
options |= SYMOPT_LOAD_LINES; options |= SYMOPT_LOAD_LINES;
...@@ -1081,13 +1084,13 @@ static bool LoadSymbols(Isolate* isolate, HANDLE process_handle) { ...@@ -1081,13 +1084,13 @@ static bool LoadSymbols(Isolate* isolate, HANDLE process_handle) {
if (!ok) { if (!ok) {
int err = GetLastError(); int err = GetLastError();
PrintF("%d\n", err); PrintF("%d\n", err);
return false; return result;
} }
HANDLE snapshot = _CreateToolhelp32Snapshot( HANDLE snapshot = _CreateToolhelp32Snapshot(
TH32CS_SNAPMODULE, // dwFlags TH32CS_SNAPMODULE, // dwFlags
GetCurrentProcessId()); // th32ProcessId GetCurrentProcessId()); // th32ProcessId
if (snapshot == INVALID_HANDLE_VALUE) return false; if (snapshot == INVALID_HANDLE_VALUE) return result;
MODULEENTRY32W module_entry; MODULEENTRY32W module_entry;
module_entry.dwSize = sizeof(module_entry); // Set the size of the structure. module_entry.dwSize = sizeof(module_entry); // Set the size of the structure.
BOOL cont = _Module32FirstW(snapshot, &module_entry); BOOL cont = _Module32FirstW(snapshot, &module_entry);
...@@ -1105,31 +1108,37 @@ static bool LoadSymbols(Isolate* isolate, HANDLE process_handle) { ...@@ -1105,31 +1108,37 @@ static bool LoadSymbols(Isolate* isolate, HANDLE process_handle) {
if (base == 0) { if (base == 0) {
int err = GetLastError(); int err = GetLastError();
if (err != ERROR_MOD_NOT_FOUND && if (err != ERROR_MOD_NOT_FOUND &&
err != ERROR_INVALID_HANDLE) return false; err != ERROR_INVALID_HANDLE) {
result.clear();
return result;
}
} }
LOG(isolate, int lib_name_length = WideCharToMultiByte(
SharedLibraryEvent( CP_UTF8, 0, module_entry.szExePath, -1, NULL, 0, NULL, NULL);
module_entry.szExePath, std::string lib_name(lib_name_length, 0);
reinterpret_cast<unsigned int>(module_entry.modBaseAddr), WideCharToMultiByte(CP_UTF8, 0, module_entry.szExePath, -1, &lib_name[0],
reinterpret_cast<unsigned int>(module_entry.modBaseAddr + lib_name_length, NULL, NULL);
module_entry.modBaseSize))); result.push_back(OS::SharedLibraryAddress(
lib_name, reinterpret_cast<unsigned int>(module_entry.modBaseAddr),
reinterpret_cast<unsigned int>(module_entry.modBaseAddr +
module_entry.modBaseSize)));
cont = _Module32NextW(snapshot, &module_entry); cont = _Module32NextW(snapshot, &module_entry);
} }
CloseHandle(snapshot); CloseHandle(snapshot);
symbols_loaded = true; symbols_loaded = true;
return true; return result;
} }
void OS::LogSharedLibraryAddresses(Isolate* isolate) { std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
// SharedLibraryEvents are logged when loading symbol information. // SharedLibraryEvents are logged when loading symbol information.
// Only the shared libraries loaded at the time of the call to // Only the shared libraries loaded at the time of the call to
// LogSharedLibraryAddresses are logged. DLLs loaded after // GetSharedLibraryAddresses are logged. DLLs loaded after
// initialization are not accounted for. // initialization are not accounted for.
if (!LoadDbgHelpAndTlHelp32()) return; if (!LoadDbgHelpAndTlHelp32()) return std::vector<OS::SharedLibraryAddress>();
HANDLE process_handle = GetCurrentProcess(); HANDLE process_handle = GetCurrentProcess();
LoadSymbols(isolate, process_handle); return LoadSymbols(process_handle);
} }
...@@ -1150,7 +1159,11 @@ uint64_t OS::TotalPhysicalMemory() { ...@@ -1150,7 +1159,11 @@ uint64_t OS::TotalPhysicalMemory() {
#else // __MINGW32__ #else // __MINGW32__
void OS::LogSharedLibraryAddresses(Isolate* isolate) { } std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
return std::vector<OS::SharedLibraryAddress>();
}
void OS::SignalCodeMovingGC() { } void OS::SignalCodeMovingGC() { }
#endif // __MINGW32__ #endif // __MINGW32__
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#define V8_PLATFORM_H_ #define V8_PLATFORM_H_
#include <stdarg.h> #include <stdarg.h>
#include <string>
#include <vector>
#include "src/base/build_config.h" #include "src/base/build_config.h"
#include "src/platform/mutex.h" #include "src/platform/mutex.h"
...@@ -255,7 +257,17 @@ class OS { ...@@ -255,7 +257,17 @@ class OS {
// Support for the profiler. Can do nothing, in which case ticks // Support for the profiler. Can do nothing, in which case ticks
// occuring in shared libraries will not be properly accounted for. // occuring in shared libraries will not be properly accounted for.
static void LogSharedLibraryAddresses(Isolate* isolate); struct SharedLibraryAddress {
SharedLibraryAddress(
const std::string& library_path, uintptr_t start, uintptr_t end)
: library_path(library_path), start(start), end(end) {}
std::string library_path;
uintptr_t start;
uintptr_t end;
};
static std::vector<SharedLibraryAddress> GetSharedLibraryAddresses();
// Support for the profiler. Notifies the external profiling // Support for the profiler. Notifies the external profiling
// process that a code moving garbage collection starts. Can do // process that a code moving garbage collection starts. Can do
......
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