diff options
Diffstat (limited to 'deps/v8/src/platform-linux.cc')
-rw-r--r-- | deps/v8/src/platform-linux.cc | 304 |
1 files changed, 1 insertions, 303 deletions
diff --git a/deps/v8/src/platform-linux.cc b/deps/v8/src/platform-linux.cc index 885683398e..b8b96025e1 100644 --- a/deps/v8/src/platform-linux.cc +++ b/deps/v8/src/platform-linux.cc @@ -76,143 +76,7 @@ namespace v8 { namespace internal { -static Mutex* limit_mutex = NULL; - - #ifdef __arm__ -static bool CPUInfoContainsString(const char * search_string) { - const char* file_name = "/proc/cpuinfo"; - // This is written as a straight shot one pass parser - // and not using STL string and ifstream because, - // on Linux, it's reading from a (non-mmap-able) - // character special device. - FILE* f = NULL; - const char* what = search_string; - - if (NULL == (f = fopen(file_name, "r"))) { - OS::PrintError("Failed to open /proc/cpuinfo\n"); - return false; - } - - int k; - while (EOF != (k = fgetc(f))) { - if (k == *what) { - ++what; - while ((*what != '\0') && (*what == fgetc(f))) { - ++what; - } - if (*what == '\0') { - fclose(f); - return true; - } else { - what = search_string; - } - } - } - fclose(f); - - // Did not find string in the proc file. - return false; -} - - -bool OS::ArmCpuHasFeature(CpuFeature feature) { - const char* search_string = NULL; - // Simple detection of VFP at runtime for Linux. - // It is based on /proc/cpuinfo, which reveals hardware configuration - // to user-space applications. According to ARM (mid 2009), no similar - // facility is universally available on the ARM architectures, - // so it's up to individual OSes to provide such. - switch (feature) { - case VFP3: - search_string = "vfpv3"; - break; - case NEON: - search_string = "neon"; - break; - case ARMv7: - search_string = "ARMv7"; - break; - case SUDIV: - search_string = "idiva"; - break; - case VFP32DREGS: - // This case is handled specially below. - break; - default: - UNREACHABLE(); - } - - if (feature == VFP32DREGS) { - return ArmCpuHasFeature(VFP3) && !CPUInfoContainsString("d16"); - } - - if (CPUInfoContainsString(search_string)) { - return true; - } - - if (feature == VFP3) { - // Some old kernels will report vfp not vfpv3. Here we make a last attempt - // to detect vfpv3 by checking for vfp *and* neon, since neon is only - // available on architectures with vfpv3. - // Checking neon on its own is not enough as it is possible to have neon - // without vfp. - if (CPUInfoContainsString("vfp") && CPUInfoContainsString("neon")) { - return true; - } - } - - return false; -} - - -CpuImplementer OS::GetCpuImplementer() { - static bool use_cached_value = false; - static CpuImplementer cached_value = UNKNOWN_IMPLEMENTER; - if (use_cached_value) { - return cached_value; - } - if (CPUInfoContainsString("CPU implementer\t: 0x41")) { - cached_value = ARM_IMPLEMENTER; - } else if (CPUInfoContainsString("CPU implementer\t: 0x51")) { - cached_value = QUALCOMM_IMPLEMENTER; - } else { - cached_value = UNKNOWN_IMPLEMENTER; - } - use_cached_value = true; - return cached_value; -} - - -CpuPart OS::GetCpuPart(CpuImplementer implementer) { - static bool use_cached_value = false; - static CpuPart cached_value = CPU_UNKNOWN; - if (use_cached_value) { - return cached_value; - } - if (implementer == ARM_IMPLEMENTER) { - if (CPUInfoContainsString("CPU part\t: 0xc0f")) { - cached_value = CORTEX_A15; - } else if (CPUInfoContainsString("CPU part\t: 0xc0c")) { - cached_value = CORTEX_A12; - } else if (CPUInfoContainsString("CPU part\t: 0xc09")) { - cached_value = CORTEX_A9; - } else if (CPUInfoContainsString("CPU part\t: 0xc08")) { - cached_value = CORTEX_A8; - } else if (CPUInfoContainsString("CPU part\t: 0xc07")) { - cached_value = CORTEX_A7; - } else if (CPUInfoContainsString("CPU part\t: 0xc05")) { - cached_value = CORTEX_A5; - } else { - cached_value = CPU_UNKNOWN; - } - } else { - cached_value = CPU_UNKNOWN; - } - use_cached_value = true; - return cached_value; -} - bool OS::ArmUsingHardFloat() { // GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify @@ -255,60 +119,6 @@ bool OS::ArmUsingHardFloat() { #endif // def __arm__ -#ifdef __mips__ -bool OS::MipsCpuHasFeature(CpuFeature feature) { - const char* search_string = NULL; - const char* file_name = "/proc/cpuinfo"; - // Simple detection of FPU at runtime for Linux. - // It is based on /proc/cpuinfo, which reveals hardware configuration - // to user-space applications. According to MIPS (early 2010), no similar - // facility is universally available on the MIPS architectures, - // so it's up to individual OSes to provide such. - // - // This is written as a straight shot one pass parser - // and not using STL string and ifstream because, - // on Linux, it's reading from a (non-mmap-able) - // character special device. - - switch (feature) { - case FPU: - search_string = "FPU"; - break; - default: - UNREACHABLE(); - } - - FILE* f = NULL; - const char* what = search_string; - - if (NULL == (f = fopen(file_name, "r"))) { - OS::PrintError("Failed to open /proc/cpuinfo\n"); - return false; - } - - int k; - while (EOF != (k = fgetc(f))) { - if (k == *what) { - ++what; - while ((*what != '\0') && (*what == fgetc(f))) { - ++what; - } - if (*what == '\0') { - fclose(f); - return true; - } else { - what = search_string; - } - } - } - fclose(f); - - // Did not find string in the proc file. - return false; -} -#endif // def __mips__ - - const char* OS::LocalTimezone(double time) { if (std::isnan(time)) return ""; time_t tv = static_cast<time_t>(floor(time/msPerSecond)); @@ -327,31 +137,6 @@ double OS::LocalTimeOffset() { } -// 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 -// 'allocated' space are actually allocated to our heap. The range is -// [lowest, highest), inclusive on the low and and exclusive on the high end. -static void* lowest_ever_allocated = reinterpret_cast<void*>(-1); -static void* highest_ever_allocated = reinterpret_cast<void*>(0); - - -static void UpdateAllocatedSpaceLimits(void* address, int size) { - ASSERT(limit_mutex != NULL); - ScopedLock lock(limit_mutex); - - lowest_ever_allocated = Min(lowest_ever_allocated, address); - highest_ever_allocated = - Max(highest_ever_allocated, - reinterpret_cast<void*>(reinterpret_cast<char*>(address) + size)); -} - - -bool OS::IsOutsideAllocatedSpace(void* address) { - return address < lowest_ever_allocated || address >= highest_ever_allocated; -} - - void* OS::Allocate(const size_t requested, size_t* allocated, bool is_executable) { @@ -365,7 +150,6 @@ void* OS::Allocate(const size_t requested, return NULL; } *allocated = msize; - UpdateAllocatedSpaceLimits(mbase, msize); return mbase; } @@ -436,7 +220,7 @@ PosixMemoryMappedFile::~PosixMemoryMappedFile() { } -void OS::LogSharedLibraryAddresses() { +void OS::LogSharedLibraryAddresses(Isolate* isolate) { // This function assumes that the layout of the file is as follows: // hex_start_addr-hex_end_addr rwxp <unused data> [binary_file_name] // If we encounter an unexpected situation we abort scanning further entries. @@ -447,7 +231,6 @@ void OS::LogSharedLibraryAddresses() { const int kLibNameLen = FILENAME_MAX + 1; char* lib_name = reinterpret_cast<char*>(malloc(kLibNameLen)); - i::Isolate* isolate = ISOLATE; // This loop will terminate once the scanning hits an EOF. while (true) { uintptr_t start, end; @@ -659,7 +442,6 @@ bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) { return false; } - UpdateAllocatedSpaceLimits(base, size); return true; } @@ -683,88 +465,4 @@ bool VirtualMemory::HasLazyCommits() { return true; } - -class LinuxSemaphore : public Semaphore { - public: - explicit LinuxSemaphore(int count) { sem_init(&sem_, 0, count); } - virtual ~LinuxSemaphore() { sem_destroy(&sem_); } - - virtual void Wait(); - virtual bool Wait(int timeout); - virtual void Signal() { sem_post(&sem_); } - private: - sem_t sem_; -}; - - -void LinuxSemaphore::Wait() { - while (true) { - int result = sem_wait(&sem_); - if (result == 0) return; // Successfully got semaphore. - CHECK(result == -1 && errno == EINTR); // Signal caused spurious wakeup. - } -} - - -#ifndef TIMEVAL_TO_TIMESPEC -#define TIMEVAL_TO_TIMESPEC(tv, ts) do { \ - (ts)->tv_sec = (tv)->tv_sec; \ - (ts)->tv_nsec = (tv)->tv_usec * 1000; \ -} while (false) -#endif - - -bool LinuxSemaphore::Wait(int timeout) { - const long kOneSecondMicros = 1000000; // NOLINT - - // Split timeout into second and nanosecond parts. - struct timeval delta; - delta.tv_usec = timeout % kOneSecondMicros; - delta.tv_sec = timeout / kOneSecondMicros; - - struct timeval current_time; - // Get the current time. - if (gettimeofday(¤t_time, NULL) == -1) { - return false; - } - - // Calculate time for end of timeout. - struct timeval end_time; - timeradd(¤t_time, &delta, &end_time); - - struct timespec ts; - TIMEVAL_TO_TIMESPEC(&end_time, &ts); - // Wait for semaphore signalled or timeout. - while (true) { - int result = sem_timedwait(&sem_, &ts); - if (result == 0) return true; // Successfully got semaphore. - if (result > 0) { - // For glibc prior to 2.3.4 sem_timedwait returns the error instead of -1. - errno = result; - result = -1; - } - if (result == -1 && errno == ETIMEDOUT) return false; // Timeout. - CHECK(result == -1 && errno == EINTR); // Signal caused spurious wakeup. - } -} - - -Semaphore* OS::CreateSemaphore(int count) { - return new LinuxSemaphore(count); -} - - -void OS::SetUp() { - // Seed the random number generator. We preserve microsecond resolution. - uint64_t seed = Ticks() ^ (getpid() << 16); - srandom(static_cast<unsigned int>(seed)); - limit_mutex = CreateMutex(); -} - - -void OS::TearDown() { - delete limit_mutex; -} - - } } // namespace v8::internal |