v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
sys-info.cc
Go to the documentation of this file.
1// Copyright 2014 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "src/base/sys-info.h"
6
7#if V8_OS_POSIX
8#include <sys/stat.h>
9#include <sys/time.h>
10#include <sys/types.h>
11#include <unistd.h>
12#if !V8_OS_FUCHSIA
13#include <sys/resource.h>
14#endif
15#endif
16
17#if V8_OS_BSD
18#include <sys/sysctl.h>
19#endif
20
21#include <limits>
22
23#include "src/base/logging.h"
24#include "src/base/macros.h"
25#if V8_OS_WIN
26#include <windows.h>
27#endif
28
29#if V8_OS_STARBOARD
30#include "starboard/system.h"
31#endif
32
33namespace v8 {
34namespace base {
35
36// static
38#if V8_OS_OPENBSD
39 int mib[2] = {CTL_HW, HW_NCPU};
40 int ncpu = 0;
41 size_t len = sizeof(ncpu);
42 if (sysctl(mib, arraysize(mib), &ncpu, &len, nullptr, 0) != 0) {
43 return 1;
44 }
45 return ncpu;
46#elif V8_OS_ZOS
47 // This is from zoslib:
48 return __get_num_online_cpus();
49#elif V8_OS_POSIX
50 long result = sysconf(_SC_NPROCESSORS_ONLN); // NOLINT(runtime/int)
51 if (result == -1) {
52 return 1;
53 }
54 return static_cast<int>(result);
55#elif V8_OS_WIN
56 SYSTEM_INFO system_info = {};
57 ::GetNativeSystemInfo(&system_info);
58 return static_cast<int>(system_info.dwNumberOfProcessors);
59#elif V8_OS_STARBOARD
60 return SbSystemGetNumberOfProcessors();
61#endif
62}
63
64
65// static
67#if V8_OS_DARWIN
68 int mib[2] = {CTL_HW, HW_MEMSIZE};
69 int64_t memsize = 0;
70 size_t len = sizeof(memsize);
71 if (sysctl(mib, arraysize(mib), &memsize, &len, nullptr, 0) != 0) {
72 return 0;
73 }
74 return memsize;
75#elif V8_OS_FREEBSD
76 int pages, page_size;
77 size_t size = sizeof(pages);
78 sysctlbyname("vm.stats.vm.v_page_count", &pages, &size, nullptr, 0);
79 sysctlbyname("vm.stats.vm.v_page_size", &page_size, &size, nullptr, 0);
80 if (pages == -1 || page_size == -1) {
81 return 0;
82 }
83 return static_cast<int64_t>(pages) * page_size;
84#elif V8_OS_CYGWIN || V8_OS_WIN
85 MEMORYSTATUSEX memory_info;
86 memory_info.dwLength = sizeof(memory_info);
87 if (!GlobalMemoryStatusEx(&memory_info)) {
88 return 0;
89 }
90 int64_t result = static_cast<int64_t>(memory_info.ullTotalPhys);
91 if (result < 0) result = std::numeric_limits<int64_t>::max();
92 return result;
93#elif V8_OS_QNX
94 struct stat stat_buf;
95 if (stat("/proc", &stat_buf) != 0) {
96 return 0;
97 }
98 return static_cast<int64_t>(stat_buf.st_size);
99#elif V8_OS_AIX
100 int64_t result = sysconf(_SC_AIX_REALMEM);
101 return static_cast<int64_t>(result) * 1024L;
102#elif V8_OS_ZOS
103 int pages = __get_num_frames();
104 long page_size = sysconf(_SC_PAGESIZE);
105 return static_cast<uint64_t>(pages) * page_size;
106#elif V8_OS_POSIX
107 long pages = sysconf(_SC_PHYS_PAGES); // NOLINT(runtime/int)
108 long page_size = sysconf(_SC_PAGESIZE); // NOLINT(runtime/int)
109 if (pages == -1 || page_size == -1) {
110 return 0;
111 }
112 return static_cast<int64_t>(pages) * page_size;
113#elif V8_OS_STARBOARD
114 return SbSystemGetTotalCPUMemory();
115#endif
116}
117
118
119// static
121#if V8_OS_WIN || V8_OS_FUCHSIA
122 return 0;
123#elif V8_OS_POSIX
124 struct rlimit rlim;
125 int result = getrlimit(RLIMIT_DATA, &rlim);
126 if (result != 0) {
127 return 0;
128 }
129 return (rlim.rlim_cur == RLIM_INFINITY) ? 0 : rlim.rlim_cur;
130#elif V8_OS_STARBOARD
131 return 0;
132#endif
133}
134
135// static
137#if V8_OS_WIN
138 SYSTEM_INFO info;
139 GetSystemInfo(&info);
140 uintptr_t max_address =
141 reinterpret_cast<uintptr_t>(info.lpMaximumApplicationAddress);
142 return max_address + 1;
143#else
144 // We don't query POSIX rlimits here (e.g. RLIMIT_AS) as they limit the size
145 // of memory mappings, but not the address space (e.g. even with a small
146 // RLIMIT_AS, a process can still map pages at high addresses).
147 return std::numeric_limits<uintptr_t>::max();
148#endif
149}
150
151} // namespace base
152} // namespace v8
static int NumberOfProcessors()
Definition sys-info.cc:37
static uintptr_t AddressSpaceEnd()
Definition sys-info.cc:136
static int64_t AmountOfPhysicalMemory()
Definition sys-info.cc:66
static int64_t AmountOfVirtualMemory()
Definition sys-info.cc:120
Handle< SharedFunctionInfo > info
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in allocation gc speed threshold for starting incremental marking via a task in percent of available threshold for starting incremental marking immediately in percent of available Use a single schedule for determining a marking schedule between JS and C objects schedules the minor GC task with kUserVisible priority max worker number of concurrent for NumberOfWorkerThreads start background threads that allocate memory concurrent_array_buffer_sweeping use parallel threads to clear weak refs in the atomic pause trace progress of the incremental marking trace object counts and memory usage report a tick only when allocated zone memory changes by this amount TracingFlags::gc_stats TracingFlags::gc_stats track native contexts that are expected to be garbage collected verify heap pointers before and after GC memory reducer runs GC with ReduceMemoryFootprint flag Maximum number of memory reducer GCs scheduled Old gen GC speed is computed directly from gc tracer counters Perform compaction on full GCs based on V8 s default heuristics Perform compaction on every full GC Perform code space compaction when finalizing a full GC with stack Stress GC compaction to flush out bugs with moving objects flush of baseline code when it has not been executed recently Use time base code flushing instead of age Use a progress bar to scan large objects in increments when incremental marking is active force incremental marking for small heaps and run it more often force marking at random points between and force scavenge at random points between and reclaim otherwise unreachable unmodified wrapper objects when possible less compaction in non memory reducing mode use high priority threads for concurrent Marking Test mode only flag It allows an unit test to select evacuation candidates pages(requires --stress_compaction).") DEFINE_BOOL(cppheap_incremental_marking
ZoneVector< RpoNumber > & result
#define arraysize(array)
Definition macros.h:67