34 #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__)
35 #include <pthread_np.h>
43 #include <sys/socket.h>
44 #include <sys/resource.h>
46 #include <sys/types.h>
48 #if defined(__linux__)
49 #include <sys/prctl.h>
51 #if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || \
52 defined(__NetBSD__) || defined(__OpenBSD__)
53 #include <sys/sysctl.h>
56 #include <arpa/inet.h>
57 #include <netinet/in.h>
62 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
64 #include <android/log.h>
77 static const pthread_t kNoThread = (pthread_t) 0;
84 const uint64_t one = 1;
85 return (one <<
SSE2) | (one <<
CMOV);
97 int result = getrlimit(RLIMIT_DATA, &limit);
98 if (result != 0)
return 0;
99 return limit.rlim_cur;
109 size_t len =
sizeof(
size);
110 if (sysctl(mib, 2, &size, &len,
NULL, 0) != 0) {
114 return static_cast<uint64_t
>(
size);
116 int pages, page_size;
117 size_t size =
sizeof(pages);
118 sysctlbyname(
"vm.stats.vm.v_page_count", &pages, &size,
NULL, 0);
119 sysctlbyname(
"vm.stats.vm.v_page_size", &page_size, &size,
NULL, 0);
120 if (pages == -1 || page_size == -1) {
124 return static_cast<uint64_t
>(pages) * page_size;
126 MEMORYSTATUS memory_info;
127 memory_info.dwLength =
sizeof(memory_info);
128 if (!GlobalMemoryStatus(&memory_info)) {
132 return static_cast<uint64_t
>(memory_info.dwTotalPhys);
134 struct stat stat_buf;
135 if (stat(
"/proc", &stat_buf) != 0) {
139 return static_cast<uint64_t
>(stat_buf.st_size);
141 intptr_t pages = sysconf(_SC_PHYS_PAGES);
142 intptr_t page_size = sysconf(_SC_PAGESIZE);
143 if (pages == -1 || page_size == -1) {
147 return static_cast<uint64_t
>(pages) * page_size;
153 #if V8_TARGET_ARCH_ARM
157 #elif V8_TARGET_ARCH_MIPS
171 static intptr_t page_size = getpagesize();
178 int result = munmap(address, size);
188 VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect);
192 mprotect(address, size, PROT_READ);
194 mprotect(address, size, PROT_READ | PROT_EXEC);
203 VirtualProtect(address, size, PAGE_NOACCESS, &oldprotect);
205 mprotect(address, size, PROT_NONE);
217 Isolate* isolate = Isolate::UncheckedCurrent();
221 if (isolate !=
NULL) {
224 #if V8_TARGET_ARCH_X64
230 raw_addr &= 0x3ffff000;
242 raw_addr += 0x80000000;
247 raw_addr += 0x20000000;
250 return reinterpret_cast<void*
>(raw_addr);
257 return static_cast<size_t>(sysconf(_SC_PAGESIZE));
262 useconds_t ms =
static_cast<useconds_t
>(milliseconds);
268 if (FLAG_hard_abort) {
279 #elif V8_HOST_ARCH_ARM64
281 #elif V8_HOST_ARCH_MIPS
283 #elif V8_HOST_ARCH_IA32
284 #if defined(__native_client__)
288 #endif // __native_client__
289 #elif V8_HOST_ARCH_X64
292 #error Unsupported host architecture.
301 return std::fmod(x, y);
305 #define UNARY_MATH_FUNCTION(name, generator) \
306 static UnaryMathFunction fast_##name##_function = NULL; \
307 void init_fast_##name##_function() { \
308 fast_##name##_function = generator; \
310 double fast_##name(double x) { \
311 return (*fast_##name##_function)(x); \
317 #undef UNARY_MATH_FUNCTION
321 if (fast_exp_function ==
NULL) {
322 init_fast_exp_function();
334 return static_cast<int>(getpid());
345 if (getrusage(RUSAGE_SELF, &usage) < 0)
return -1;
346 *secs = usage.ru_utime.tv_sec;
347 *usecs = usage.ru_utime.tv_usec;
353 return Time::Now().ToJsTime();
377 time_t tv =
static_cast<time_t
>(std::floor(time/msPerSecond));
378 struct tm* t = localtime(&tv);
380 return t->tm_isdst > 0 ? 3600 * msPerSecond : 0;
394 FILE* file = fopen(path, mode);
396 struct stat file_stat;
397 if (fstat(fileno(file), &file_stat) != 0)
return NULL;
398 bool is_regular_file = ((file_stat.st_mode & S_IFREG) != 0);
399 if (is_regular_file)
return file;
406 return (
remove(path) == 0);
420 va_start(args, format);
427 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
428 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args);
430 vprintf(format, args);
437 va_start(args, format);
444 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
445 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args);
447 vfprintf(out, format, args);
454 va_start(args, format);
461 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
462 __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, args);
464 vfprintf(stderr, format, args);
471 va_start(args, format);
472 int result =
VSNPrintF(str, format, args);
481 int n = vsnprintf(str.
start(), str.
length(), format, args);
482 if (n < 0 || n >= str.
length()) {
485 str[str.
length() - 1] =
'\0';
493 #if V8_TARGET_ARCH_IA32
494 static void MemMoveWrapper(
void* dest,
const void* src,
size_t size) {
495 memmove(dest, src, size);
500 static OS::MemMoveFunction memmove_function = &MemMoveWrapper;
503 OS::MemMoveFunction CreateMemMoveFunction();
507 if (size == 0)
return;
510 (*memmove_function)(dest, src,
size);
513 #elif defined(V8_HOST_ARCH_ARM)
514 void OS::MemCopyUint16Uint8Wrapper(
uint16_t* dest,
518 while (dest < limit) {
519 *dest++ =
static_cast<uint16_t>(*src++);
524 OS::MemCopyUint8Function OS::memcopy_uint8_function = &OS::MemCopyUint8Wrapper;
525 OS::MemCopyUint16Uint8Function OS::memcopy_uint16_uint8_function =
526 &OS::MemCopyUint16Uint8Wrapper;
528 OS::MemCopyUint8Function CreateMemCopyUint8Function(
529 OS::MemCopyUint8Function stub);
530 OS::MemCopyUint16Uint8Function CreateMemCopyUint16Uint8Function(
531 OS::MemCopyUint16Uint8Function stub);
533 #elif defined(V8_HOST_ARCH_MIPS)
534 OS::MemCopyUint8Function OS::memcopy_uint8_function = &OS::MemCopyUint8Wrapper;
536 OS::MemCopyUint8Function CreateMemCopyUint8Function(
537 OS::MemCopyUint8Function stub);
542 #if V8_TARGET_ARCH_IA32
543 OS::MemMoveFunction generated_memmove = CreateMemMoveFunction();
544 if (generated_memmove !=
NULL) {
545 memmove_function = generated_memmove;
547 #elif defined(V8_HOST_ARCH_ARM)
548 OS::memcopy_uint8_function =
549 CreateMemCopyUint8Function(&OS::MemCopyUint8Wrapper);
550 OS::memcopy_uint16_uint8_function =
551 CreateMemCopyUint16Uint8Function(&OS::MemCopyUint16Uint8Wrapper);
552 #elif defined(V8_HOST_ARCH_MIPS)
553 OS::memcopy_uint8_function =
554 CreateMemCopyUint8Function(&OS::MemCopyUint8Wrapper);
557 init_fast_sqrt_function();
566 return strchr(str, c);
571 strncpy(dest.
start(), src, n);
589 stack_size_(options.stack_size()),
590 start_semaphore_(
NULL) {
591 if (stack_size_ > 0 && stack_size_ < PTHREAD_STACK_MIN) {
592 stack_size_ = PTHREAD_STACK_MIN;
594 set_name(options.
name());
603 static void SetThreadName(
const char*
name) {
604 #if V8_OS_DRAGONFLYBSD || V8_OS_FREEBSD || V8_OS_OPENBSD
605 pthread_set_name_np(pthread_self(), name);
608 pthread_setname_np(pthread_self(),
"%s", name);
612 int (*dynamic_pthread_setname_np)(
const char*);
613 *
reinterpret_cast<void**
>(&dynamic_pthread_setname_np) =
614 dlsym(RTLD_DEFAULT,
"pthread_setname_np");
615 if (dynamic_pthread_setname_np ==
NULL)
619 static const int kMaxNameLength = 63;
621 dynamic_pthread_setname_np(name);
622 #elif defined(PR_SET_NAME)
624 reinterpret_cast<unsigned long>(name),
630 static void* ThreadEntry(
void* arg) {
631 Thread* thread =
reinterpret_cast<Thread*
>(arg);
635 { LockGuard<Mutex> lock_guard(&thread->data()->thread_creation_mutex_); }
636 SetThreadName(thread->name());
637 ASSERT(thread->data()->thread_ != kNoThread);
638 thread->NotifyStartedAndRun();
643 void Thread::set_name(
const char* name) {
644 strncpy(name_, name,
sizeof(name_));
645 name_[
sizeof(name_) - 1] =
'\0';
652 memset(&attr, 0,
sizeof(attr));
653 result = pthread_attr_init(&attr);
657 if (stack_size_ > 0) {
658 result = pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_));
664 result = pthread_create(&data_->
thread_, &attr, ThreadEntry,
this);
667 result = pthread_attr_destroy(&attr);
680 int result = sched_yield();
692 intptr_t ptr_key =
reinterpret_cast<intptr_t
>(pthread_key);
703 intptr_t ptr_key =
static_cast<intptr_t
>(local_key);
704 return reinterpret_cast<pthread_key_t
>(ptr_key);
706 return static_cast<pthread_key_t
>(local_key);
711 #ifdef V8_FAST_TLS_SUPPORTED
713 static Atomic32 tls_base_offset_initialized = 0;
714 intptr_t kMacTlsBaseOffset = 0;
718 static void InitializeTlsBaseOffset() {
719 const size_t kBufferSize = 128;
720 char buffer[kBufferSize];
721 size_t buffer_size = kBufferSize;
722 int ctl_name[] = { CTL_KERN , KERN_OSRELEASE };
723 if (sysctl(ctl_name, 2, buffer, &buffer_size,
NULL, 0) != 0) {
724 V8_Fatal(__FILE__, __LINE__,
"V8 failed to get kernel version");
729 buffer[kBufferSize - 1] =
'\0';
730 char* period_pos = strchr(buffer,
'.');
732 int kernel_version_major =
733 static_cast<int>(strtol(buffer,
NULL, 10));
736 if (kernel_version_major < 11) {
739 #if V8_HOST_ARCH_IA32
740 kMacTlsBaseOffset = 0x48;
742 kMacTlsBaseOffset = 0x60;
746 kMacTlsBaseOffset = 0;
754 void* expected =
reinterpret_cast<void*
>(0x1234CAFE);
757 if (expected != actual) {
759 "V8 failed to initialize fast TLS on current kernel");
764 #endif // V8_FAST_TLS_SUPPORTED
768 #ifdef V8_FAST_TLS_SUPPORTED
769 bool check_fast_tls =
false;
770 if (tls_base_offset_initialized == 0) {
771 check_fast_tls =
true;
772 InitializeTlsBaseOffset();
776 int result = pthread_key_create(&key,
NULL);
780 #ifdef V8_FAST_TLS_SUPPORTED
782 if (check_fast_tls) CheckFastTls(local_key);
789 pthread_key_t pthread_key = LocalKeyToPthreadKey(key);
790 int result = pthread_key_delete(pthread_key);
797 pthread_key_t pthread_key = LocalKeyToPthreadKey(key);
798 return pthread_getspecific(pthread_key);
803 pthread_key_t pthread_key = LocalKeyToPthreadKey(key);
804 int result = pthread_setspecific(pthread_key, value);
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
static void * GetThreadLocal(LocalStorageKey key)
static void Free(void *address, const size_t size)
Thread(const Options &options)
static int VSNPrintF(Vector< char > str, const char *format, va_list args)
static FILE * OpenTemporaryFile()
static void * GetRandomMmapAddr()
static double DaylightSavingsOffset(double time, TimezoneCache *cache)
static int GetUserTime(uint32_t *secs, uint32_t *usecs)
static void ClearTimezoneCache(TimezoneCache *cache)
RandomNumberGenerator * random_number_generator()
#define ASSERT(condition)
static void VFPrint(FILE *out, const char *format, va_list args)
#define V8_IMMEDIATE_CRASH()
UnaryMathFunction CreateExpFunction()
typedef DWORD(__stdcall *DLL_FUNC_TYPE(SymGetOptions))(VOID)
void V8_Fatal(const char *file, int line, const char *format,...)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long mode(MIPS only)") DEFINE_string(expose_natives_as
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object size
STATIC_ASSERT(sizeof(CPURegister)==sizeof(Register))
static void ProtectCode(void *address, const size_t size)
void lazily_initialize_fast_exp()
static LocalStorageKey CreateThreadLocalKey()
static FILE * FOpen(const char *path, const char *mode)
static void * GetExistingThreadLocal(LocalStorageKey key)
static void VPrint(const char *format, va_list args)
static void MemMove(void *dest, const void *src, size_t size)
UnaryMathFunction CreateSqrtFunction()
static void Guard(void *address, const size_t size)
static void VPrintError(const char *format, va_list args)
double modulo(double x, double y)
static int GetCurrentProcessId()
static double TimeCurrentMillis()
void Release_Store(volatile Atomic32 *ptr, Atomic32 value)
static void DeleteThreadLocalKey(LocalStorageKey key)
static void Sleep(const int milliseconds)
static void Print(const char *format,...)
static int SNPrintF(Vector< char > str, const char *format,...)
static const int kMaxThreadNameLength
static void DisposeTimezoneCache(TimezoneCache *cache)
static double nan_value()
static void SetThreadLocal(LocalStorageKey key, void *value)
static void PrintError(const char *format,...)
#define ASSERT_EQ(v1, v2)
static void StrNCpy(Vector< char > dest, const char *src, size_t n)
static int ActivationFrameAlignment()
const char * name() const
static size_t AllocateAlignment()
static TimezoneCache * CreateTimezoneCache()
static uint64_t CpuFeaturesImpliedByPlatform()
static bool Remove(const char *path)
static int GetLastError()
static intptr_t MaxVirtualMemory()
static void FPrint(FILE *out, const char *format,...)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print statistics of the maximum memory committed for the heap in name
static intptr_t CommitPageSize()
static const char *const LogFileOpenMode
static char * StrChr(char *str, int c)
static uint64_t TotalPhysicalMemory()