Fix duplicated methods for POSIX platforms.

No need to duplicate OS::NumberOfCores() for every POSIX platform.
No need to duplicate OS::Sleep() for every POSIX platform.
No need to duplicate OS::Abort() and OS::DebugBreak() for every POSIX platform.
No need to duplicate OS::Free() for every POSIX platform.
Move #ifdef'd OS::ProtectCode() and OS::Guard() to platform-posix.cc.
No need to duplicate OS::AllocateAlignment() for every POSIX platform.
No need to duplicate OS::PostSetUp() for every POSIX platform.

R=svenpanne@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15820 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
bmeurer@chromium.org 2013-07-23 09:59:14 +00:00
parent babce318d1
commit 558c42373d
8 changed files with 62 additions and 275 deletions

View File

@ -63,11 +63,6 @@ double ceiling(double x) {
static Mutex* limit_mutex = NULL;
void OS::PostSetUp() {
POSIXPostSetUp();
}
uint64_t OS::CpuFeaturesImpliedByPlatform() {
return 0; // Nothing special about Cygwin.
}
@ -126,11 +121,6 @@ bool OS::IsOutsideAllocatedSpace(void* address) {
}
size_t OS::AllocateAlignment() {
return sysconf(_SC_PAGESIZE);
}
void* OS::Allocate(const size_t requested,
size_t* allocated,
bool is_executable) {
@ -147,48 +137,6 @@ void* OS::Allocate(const size_t requested,
}
void OS::Free(void* address, const size_t size) {
// TODO(1240712): munmap has a return value which is ignored here.
int result = munmap(address, size);
USE(result);
ASSERT(result == 0);
}
void OS::ProtectCode(void* address, const size_t size) {
DWORD old_protect;
VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect);
}
void OS::Guard(void* address, const size_t size) {
DWORD oldprotect;
VirtualProtect(address, size, PAGE_READONLY | PAGE_GUARD, &oldprotect);
}
void OS::Sleep(int milliseconds) {
unsigned int ms = static_cast<unsigned int>(milliseconds);
usleep(1000 * ms);
}
int OS::NumberOfCores() {
return sysconf(_SC_NPROCESSORS_ONLN);
}
void OS::Abort() {
// Redirect to std abort to signal abnormal program termination.
abort();
}
void OS::DebugBreak() {
asm("int $3");
}
void OS::DumpBacktrace() {
// Currently unsupported.
}

View File

@ -80,11 +80,6 @@ double ceiling(double x) {
static Mutex* limit_mutex = NULL;
void OS::PostSetUp() {
POSIXPostSetUp();
}
uint64_t OS::CpuFeaturesImpliedByPlatform() {
return 0; // FreeBSD runs on anything.
}
@ -139,11 +134,6 @@ bool OS::IsOutsideAllocatedSpace(void* address) {
}
size_t OS::AllocateAlignment() {
return getpagesize();
}
void* OS::Allocate(const size_t requested,
size_t* allocated,
bool executable) {
@ -161,40 +151,6 @@ void* OS::Allocate(const size_t requested,
}
void OS::Free(void* buf, const size_t length) {
// TODO(1240712): munmap has a return value which is ignored here.
int result = munmap(buf, length);
USE(result);
ASSERT(result == 0);
}
void OS::Sleep(int milliseconds) {
unsigned int ms = static_cast<unsigned int>(milliseconds);
usleep(1000 * ms);
}
int OS::NumberOfCores() {
return sysconf(_SC_NPROCESSORS_ONLN);
}
void OS::Abort() {
// Redirect to std abort to signal abnormal program termination.
abort();
}
void OS::DebugBreak() {
#if (defined(__arm__) || defined(__thumb__))
asm("bkpt 0");
#else
asm("int $3");
#endif
}
void OS::DumpBacktrace() {
POSIXBacktraceHelper<backtrace, backtrace_symbols>::DumpBacktrace();
}

View File

@ -88,11 +88,6 @@ double ceiling(double x) {
static Mutex* limit_mutex = NULL;
void OS::PostSetUp() {
POSIXPostSetUp();
}
uint64_t OS::CpuFeaturesImpliedByPlatform() {
return 0; // Linux runs on anything.
}
@ -384,11 +379,6 @@ bool OS::IsOutsideAllocatedSpace(void* address) {
}
size_t OS::AllocateAlignment() {
return sysconf(_SC_PAGESIZE);
}
void* OS::Allocate(const size_t requested,
size_t* allocated,
bool is_executable) {
@ -407,49 +397,6 @@ void* OS::Allocate(const size_t requested,
}
void OS::Free(void* address, const size_t size) {
// TODO(1240712): munmap has a return value which is ignored here.
int result = munmap(address, size);
USE(result);
ASSERT(result == 0);
}
void OS::Sleep(int milliseconds) {
unsigned int ms = static_cast<unsigned int>(milliseconds);
usleep(1000 * ms);
}
int OS::NumberOfCores() {
return sysconf(_SC_NPROCESSORS_ONLN);
}
void OS::Abort() {
// Redirect to std abort to signal abnormal program termination.
if (FLAG_break_on_abort) {
DebugBreak();
}
abort();
}
void OS::DebugBreak() {
// TODO(lrn): Introduce processor define for runtime system (!= V8_ARCH_x,
// which is the architecture of generated code).
#if (defined(__arm__) || defined(__thumb__))
asm("bkpt 0");
#elif defined(__mips__)
asm("break");
#elif defined(__native_client__)
asm("hlt");
#else
asm("int $3");
#endif
}
void OS::DumpBacktrace() {
// backtrace is a glibc extension.
#if defined(__GLIBC__) && !defined(__UCLIBC__)

View File

@ -96,11 +96,6 @@ double ceiling(double x) {
static Mutex* limit_mutex = NULL;
void OS::PostSetUp() {
POSIXPostSetUp();
}
// We keep the lowest and highest addresses mapped as a quick way of
// determining that pointers are outside the heap (used mostly in assertions
// and verification). The estimate is conservative, i.e., not all addresses in
@ -126,11 +121,6 @@ bool OS::IsOutsideAllocatedSpace(void* address) {
}
size_t OS::AllocateAlignment() {
return getpagesize();
}
// Constants used for mmap.
// kMmapFd is used to pass vm_alloc flags to tag the region with the user
// defined tag 255 This helps identify V8-allocated regions in memory analysis
@ -160,35 +150,6 @@ void* OS::Allocate(const size_t requested,
}
void OS::Free(void* address, const size_t size) {
// TODO(1240712): munmap has a return value which is ignored here.
int result = munmap(address, size);
USE(result);
ASSERT(result == 0);
}
void OS::Sleep(int milliseconds) {
usleep(1000 * milliseconds);
}
int OS::NumberOfCores() {
return sysconf(_SC_NPROCESSORS_ONLN);
}
void OS::Abort() {
// Redirect to std abort to signal abnormal program termination
abort();
}
void OS::DebugBreak() {
asm("int $3");
}
void OS::DumpBacktrace() {
// If weak link to execinfo lib has failed, ie because we are on 10.4, abort.
if (backtrace == NULL) return;

View File

@ -100,11 +100,6 @@ static void* GetRandomMmapAddr() {
}
void OS::PostSetUp() {
POSIXPostSetUp();
}
uint64_t OS::CpuFeaturesImpliedByPlatform() {
return 0;
}
@ -160,11 +155,6 @@ bool OS::IsOutsideAllocatedSpace(void* address) {
}
size_t OS::AllocateAlignment() {
return sysconf(_SC_PAGESIZE);
}
void* OS::Allocate(const size_t requested,
size_t* allocated,
bool is_executable) {
@ -183,36 +173,6 @@ void* OS::Allocate(const size_t requested,
}
void OS::Free(void* address, const size_t size) {
// TODO(1240712): munmap has a return value which is ignored here.
int result = munmap(address, size);
USE(result);
ASSERT(result == 0);
}
void OS::Sleep(int milliseconds) {
unsigned int ms = static_cast<unsigned int>(milliseconds);
usleep(1000 * ms);
}
int OS::NumberOfCores() {
return sysconf(_SC_NPROCESSORS_ONLN);
}
void OS::Abort() {
// Redirect to std abort to signal abnormal program termination.
abort();
}
void OS::DebugBreak() {
asm("int $3");
}
void OS::DumpBacktrace() {
// Currently unsupported.
}

View File

@ -81,10 +81,20 @@ intptr_t OS::CommitPageSize() {
}
#ifndef __CYGWIN__
void OS::Free(void* address, const size_t size) {
// TODO(1240712): munmap has a return value which is ignored here.
int result = munmap(address, size);
USE(result);
ASSERT(result == 0);
}
// Get rid of writable permission on code allocations.
void OS::ProtectCode(void* address, const size_t size) {
#if defined(__native_client__)
#if defined(__CYGWIN__)
DWORD old_protect;
VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect);
#elif defined(__native_client__)
// The Native Client port of V8 uses an interpreter, so
// code pages don't need PROT_EXEC.
mprotect(address, size, PROT_READ);
@ -96,9 +106,13 @@ void OS::ProtectCode(void* address, const size_t size) {
// Create guard pages.
void OS::Guard(void* address, const size_t size) {
#if defined(__CYGWIN__)
DWORD oldprotect;
VirtualProtect(address, size, PAGE_READONLY | PAGE_GUARD, &oldprotect);
#else
mprotect(address, size, PROT_NONE);
#endif
}
#endif // __CYGWIN__
void* OS::GetRandomMmapAddr() {
@ -135,6 +149,50 @@ void* OS::GetRandomMmapAddr() {
}
size_t OS::AllocateAlignment() {
return getpagesize();
}
void OS::Sleep(int milliseconds) {
useconds_t ms = static_cast<useconds_t>(milliseconds);
usleep(1000 * ms);
}
int OS::NumberOfCores() {
return sysconf(_SC_NPROCESSORS_ONLN);
}
void OS::Abort() {
// Redirect to std abort to signal abnormal program termination.
if (FLAG_break_on_abort) {
DebugBreak();
}
abort();
}
void OS::DebugBreak() {
#if V8_HOST_ARCH_ARM
asm("bkpt 0");
#elif V8_HOST_ARCH_MIPS
asm("break");
#elif V8_HOST_ARCH_IA32
#if defined(__native_client__)
asm("hlt");
#else
asm("int $3");
#endif // __native_client__
#elif V8_HOST_ARCH_X64
asm("int $3");
#else
#error Unsupported host architecture.
#endif
}
// ----------------------------------------------------------------------------
// Math functions
@ -371,7 +429,7 @@ OS::MemCopyUint16Uint8Function CreateMemCopyUint16Uint8Function(
#endif
void POSIXPostSetUp() {
void OS::PostSetUp() {
#if V8_TARGET_ARCH_IA32
OS::MemMoveFunction generated_memmove = CreateMemMoveFunction();
if (generated_memmove != NULL) {

View File

@ -38,9 +38,6 @@
namespace v8 {
namespace internal {
// Used by platform implementation files during OS::PostSetUp().
void POSIXPostSetUp();
// Used by platform implementation files during OS::DumpBacktrace()
// and OS::StackWalk().
template<int (*backtrace)(void**, int),

View File

@ -94,11 +94,6 @@ double ceiling(double x) {
static Mutex* limit_mutex = NULL;
void OS::PostSetUp() {
POSIXPostSetUp();
}
uint64_t OS::CpuFeaturesImpliedByPlatform() {
return 0; // Solaris runs on a lot of things.
}
@ -150,11 +145,6 @@ bool OS::IsOutsideAllocatedSpace(void* address) {
}
size_t OS::AllocateAlignment() {
return static_cast<size_t>(getpagesize());
}
void* OS::Allocate(const size_t requested,
size_t* allocated,
bool is_executable) {
@ -172,36 +162,6 @@ void* OS::Allocate(const size_t requested,
}
void OS::Free(void* address, const size_t size) {
// TODO(1240712): munmap has a return value which is ignored here.
int result = munmap(address, size);
USE(result);
ASSERT(result == 0);
}
void OS::Sleep(int milliseconds) {
useconds_t ms = static_cast<useconds_t>(milliseconds);
usleep(1000 * ms);
}
int OS::NumberOfCores() {
return sysconf(_SC_NPROCESSORS_ONLN);
}
void OS::Abort() {
// Redirect to std abort to signal abnormal program termination.
abort();
}
void OS::DebugBreak() {
asm("int $3");
}
void OS::DumpBacktrace() {
// Currently unsupported.
}