12 #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__)
13 #include <pthread_np.h>
20 #include <sys/resource.h>
23 #include <sys/types.h>
24 #if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || \
25 defined(__NetBSD__) || defined(__OpenBSD__)
26 #include <sys/sysctl.h>
31 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
33 #include <android/log.h>
45 #ifdef V8_FAST_TLS_SUPPORTED
54 #include <sys/prctl.h>
58 #include <sys/syscall.h>
77 #if V8_TARGET_ARCH_ARM
81 #elif V8_TARGET_ARCH_MIPS
95 static intptr_t page_size = getpagesize();
102 int result = munmap(address,
size);
112 VirtualProtect(address,
size, PAGE_EXECUTE_READ, &old_protect);
116 mprotect(address,
size, PROT_READ);
118 mprotect(address,
size, PROT_READ | PROT_EXEC);
127 VirtualProtect(address,
size, PAGE_NOACCESS, &oldprotect);
129 mprotect(address,
size, PROT_NONE);
139 const char*
const gc_fake_mmap) {
148 const char* OS::GetGCFakeMMapFile() {
160 #if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
161 defined(THREAD_SANITIZER)
168 #if V8_TARGET_ARCH_X64
174 raw_addr &= 0x3ffff000;
186 raw_addr += 0x80000000;
191 raw_addr += 0x20000000;
194 return reinterpret_cast<void*
>(raw_addr);
199 return static_cast<size_t>(sysconf(_SC_PAGESIZE));
204 useconds_t ms =
static_cast<useconds_t
>(milliseconds);
221 #elif V8_HOST_ARCH_ARM64
223 #elif V8_HOST_ARCH_MIPS
225 #elif V8_HOST_ARCH_MIPS64
227 #elif V8_HOST_ARCH_IA32
233 #elif V8_HOST_ARCH_X64
236 #error Unsupported host architecture.
251 return static_cast<int>(getpid());
257 return static_cast<int>(syscall(__NR_gettid));
258 #elif defined(SYS_gettid)
259 return static_cast<int>(syscall(SYS_gettid));
279 if (getrusage(RUSAGE_SELF, &usage) < 0)
return -1;
280 *secs = usage.ru_utime.tv_sec;
281 *usecs = usage.ru_utime.tv_usec;
288 return Time::Now().ToJsTime();
311 if (std::isnan(time))
return nan_value();
312 time_t tv =
static_cast<time_t
>(std::floor(time/
msPerSecond));
313 struct tm* t = localtime(&tv);
331 struct stat file_stat;
332 if (fstat(fileno(
file), &file_stat) != 0)
return NULL;
333 bool is_regular_file = ((file_stat.st_mode & S_IFREG) != 0);
334 if (is_regular_file)
return file;
341 return (remove(path) == 0);
355 va_start(args, format);
362 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
363 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args);
365 vprintf(format, args);
372 va_start(args, format);
379 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
380 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args);
382 vfprintf(out, format, args);
389 va_start(args, format);
396 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
397 __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, args);
399 vfprintf(stderr, format, args);
406 va_start(args, format);
407 int result =
VSNPrintF(str, length, format, args);
417 int n = vsnprintf(str, length, format, args);
418 if (n < 0 || n >= length) {
421 str[length - 1] =
'\0';
434 return strchr(str, c);
438 void OS::StrNCpy(
char* dest,
int length,
const char* src,
size_t n) {
439 strncpy(dest, src, n);
457 stack_size_(options.stack_size()),
458 start_semaphore_(
NULL) {
472 #if V8_OS_DRAGONFLYBSD || V8_OS_FREEBSD || V8_OS_OPENBSD
473 pthread_set_name_np(pthread_self(),
name);
476 pthread_setname_np(pthread_self(),
"%s",
name);
480 int (*dynamic_pthread_setname_np)(
const char*);
481 *
reinterpret_cast<void**
>(&dynamic_pthread_setname_np) =
482 dlsym(RTLD_DEFAULT,
"pthread_setname_np");
483 if (dynamic_pthread_setname_np ==
NULL)
487 static const int kMaxNameLength = 63;
489 dynamic_pthread_setname_np(
name);
490 #elif defined(PR_SET_NAME)
492 reinterpret_cast<unsigned long>(
name),
520 memset(&attr, 0,
sizeof(attr));
521 result = pthread_attr_init(&attr);
526 result = pthread_attr_setstacksize(&attr,
static_cast<size_t>(
stack_size_));
535 result = pthread_attr_destroy(&attr);
548 int result = sched_yield();
560 intptr_t ptr_key =
reinterpret_cast<intptr_t
>(pthread_key);
571 intptr_t ptr_key =
static_cast<intptr_t
>(local_key);
572 return reinterpret_cast<pthread_key_t
>(ptr_key);
574 return static_cast<pthread_key_t
>(local_key);
579 #ifdef V8_FAST_TLS_SUPPORTED
581 static Atomic32 tls_base_offset_initialized = 0;
582 intptr_t kMacTlsBaseOffset = 0;
586 static void InitializeTlsBaseOffset() {
590 int ctl_name[] = { CTL_KERN , KERN_OSRELEASE };
591 if (sysctl(ctl_name, 2, buffer, &buffer_size,
NULL, 0) != 0) {
592 V8_Fatal(__FILE__, __LINE__,
"V8 failed to get kernel version");
598 char* period_pos = strchr(buffer,
'.');
600 int kernel_version_major =
601 static_cast<int>(strtol(buffer,
NULL, 10));
604 if (kernel_version_major < 11) {
607 #if V8_HOST_ARCH_IA32
608 kMacTlsBaseOffset = 0x48;
610 kMacTlsBaseOffset = 0x60;
614 kMacTlsBaseOffset = 0;
622 void* expected =
reinterpret_cast<void*
>(0x1234CAFE);
625 if (expected != actual) {
627 "V8 failed to initialize fast TLS on current kernel");
636 #ifdef V8_FAST_TLS_SUPPORTED
637 bool check_fast_tls =
false;
638 if (tls_base_offset_initialized == 0) {
639 check_fast_tls =
true;
640 InitializeTlsBaseOffset();
644 int result = pthread_key_create(&key,
NULL);
648 #ifdef V8_FAST_TLS_SUPPORTED
650 if (check_fast_tls) CheckFastTls(local_key);
658 int result = pthread_key_delete(pthread_key);
666 return pthread_getspecific(pthread_key);
672 int result = pthread_setspecific(pthread_key, value);
static void VPrintError(const char *format, va_list args)
static double DaylightSavingsOffset(double time, TimezoneCache *cache)
static void * GetRandomMmapAddr()
static size_t AllocateAlignment()
static double nan_value()
static void VPrint(const char *format, va_list args)
static void Initialize(int64_t random_seed, bool hard_abort, const char *const gc_fake_mmap)
static intptr_t CommitPageSize()
static void ClearTimezoneCache(TimezoneCache *cache)
static const char *const LogFileOpenMode
static void Guard(void *address, const size_t size)
static void Sleep(const int milliseconds)
static int GetLastError()
static FILE * OpenTemporaryFile()
static FILE * FOpen(const char *path, const char *mode)
static int GetCurrentProcessId()
static void Print(const char *format,...)
static void StrNCpy(char *dest, int length, const char *src, size_t n)
static void PrintError(const char *format,...)
static int GetUserTime(uint32_t *secs, uint32_t *usecs)
static int GetCurrentThreadId()
static int ActivationFrameAlignment()
static char * StrChr(char *str, int c)
static void VFPrint(FILE *out, const char *format, va_list args)
static void ProtectCode(void *address, const size_t size)
static void Free(void *address, const size_t size)
static TimezoneCache * CreateTimezoneCache()
static double TimeCurrentMillis()
static void DisposeTimezoneCache(TimezoneCache *cache)
static int SNPrintF(char *str, int length, const char *format,...)
static const int msPerSecond
static int VSNPrintF(char *str, int length, const char *format, va_list args)
static void FPrint(FILE *out, const char *format,...)
static bool Remove(const char *path)
const char * name() const
Thread(const Options &options)
static void DeleteThreadLocalKey(LocalStorageKey key)
const char * name() const
static LocalStorageKey CreateThreadLocalKey()
static void * GetThreadLocal(LocalStorageKey key)
void set_name(const char *name)
static void * GetExistingThreadLocal(LocalStorageKey key)
char name_[kMaxThreadNameLength]
static const int kMaxThreadNameLength
void NotifyStartedAndRun()
static void SetThreadLocal(LocalStorageKey key, void *value)
enable harmony numeric enable harmony object literal extensions Optimize object size
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS 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 enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS 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_BOOL(enable_always_align_csp
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS 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 enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes A file to write the raw context snapshot bytes Write V8 startup blob file(mksnapshot only)") DEFINE_BOOL(profile_hydrogen_code_stub_compilation
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS 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 enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define LAZY_INSTANCE_INITIALIZER
void V8_Fatal(const char *file, int line, const char *format,...)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)
#define STATIC_ASSERT(test)
#define V8_IMMEDIATE_CRASH()
static const size_t kBufferSize
static void * ThreadEntry(void *arg)
static pthread_key_t LocalKeyToPthreadKey(Thread::LocalStorageKey local_key)
static Thread::LocalStorageKey PthreadKeyToLocalKey(pthread_key_t pthread_key)
static LazyInstance< RandomNumberGenerator >::type platform_random_number_generator
typedef DWORD(__stdcall *DLL_FUNC_TYPE(SymGetOptions))(VOID)
void Release_Store(volatile Atomic32 *ptr, Atomic32 value)
static const pthread_t kNoThread
static void SetThreadName(const char *name)
Debugger support for the V8 JavaScript engine.