34 #include <mach/mach_init.h>
35 #include <mach-o/dyld.h>
36 #include <mach-o/getsect.h>
38 #include <AvailabilityMacros.h>
43 #include <libkern/OSAtomic.h>
44 #include <mach/mach.h>
45 #include <mach/semaphore.h>
46 #include <mach/task.h>
47 #include <mach/vm_statistics.h>
49 #include <sys/resource.h>
50 #include <sys/types.h>
51 #include <sys/sysctl.h>
74 static const int kMmapFd = VM_MAKE_TAG(255);
75 static const off_t kMmapFdOffset = 0;
81 const size_t msize =
RoundUp(requested, getpagesize());
82 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
86 MAP_PRIVATE | MAP_ANON,
89 if (mbase == MAP_FAILED) {
90 LOG(Isolate::Current(), StringEvent(
"OS::Allocate",
"mmap failed"));
98 class PosixMemoryMappedFile :
public OS::MemoryMappedFile {
101 : file_(file), memory_(memory), size_(size) { }
103 virtual void*
memory() {
return memory_; }
104 virtual int size() {
return size_; }
113 FILE* file = fopen(name,
"r+");
116 fseek(file, 0, SEEK_END);
117 int size = ftell(file);
122 PROT_READ | PROT_WRITE,
126 return new PosixMemoryMappedFile(file, memory, size);
132 FILE* file = fopen(name,
"w+");
134 int result = fwrite(initial, size, 1, file);
142 PROT_READ | PROT_WRITE,
146 return new PosixMemoryMappedFile(file, memory, size);
151 if (memory_)
OS::Free(memory_, size_);
157 unsigned int images_count = _dyld_image_count();
158 for (
unsigned int i = 0; i < images_count; ++i) {
159 const mach_header* header = _dyld_get_image_header(i);
160 if (header ==
NULL)
continue;
163 char* code_ptr = getsectdatafromheader_64(
164 reinterpret_cast<const mach_header_64*>(header),
170 char* code_ptr = getsectdatafromheader(header, SEG_TEXT, SECT_TEXT, &size);
172 if (code_ptr ==
NULL)
continue;
173 const uintptr_t slide = _dyld_get_image_vmaddr_slide(i);
174 const uintptr_t start =
reinterpret_cast<uintptr_t
>(code_ptr) + slide;
176 SharedLibraryEvent(_dyld_get_image_name(i), start, start + size));
187 time_t tv =
static_cast<time_t
>(std::floor(time/msPerSecond));
188 struct tm* t = localtime(&tv);
189 if (
NULL == t)
return "";
195 time_t tv = time(
NULL);
196 struct tm* t = localtime(&tv);
198 return static_cast<double>(t->tm_gmtoff * msPerSecond -
199 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
207 : address_(ReserveRegion(size)), size_(size) { }
211 : address_(
NULL), size_(0) {
213 size_t request_size =
RoundUp(size + alignment,
218 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE,
221 if (reservation == MAP_FAILED)
return;
228 if (aligned_base != base) {
229 size_t prefix_size =
static_cast<size_t>(aligned_base - base);
231 request_size -= prefix_size;
237 if (aligned_size != request_size) {
238 size_t suffix_size = request_size - aligned_size;
239 OS::Free(aligned_base + aligned_size, suffix_size);
240 request_size -= suffix_size;
243 ASSERT(aligned_size == request_size);
245 address_ =
static_cast<void*
>(aligned_base);
246 size_ = aligned_size;
260 return address_ !=
NULL;
290 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE,
294 if (result == MAP_FAILED)
return NULL;
302 bool is_executable) {
303 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
304 if (MAP_FAILED == mmap(address,
307 MAP_PRIVATE | MAP_ANON | MAP_FIXED,
320 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | MAP_FIXED,
322 kMmapFdOffset) != MAP_FAILED;
327 return munmap(address, size) == 0;
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 Free(void *address, const size_t size)
static void LogSharedLibraryAddresses(Isolate *isolate)
#define LOG(isolate, Call)
static void SignalCodeMovingGC()
static void * GetRandomMmapAddr()
static void * ReserveRegion(size_t size)
PosixMemoryMappedFile(FILE *file, void *memory, int size)
#define ASSERT(condition)
static MemoryMappedFile * open(const char *name)
static bool HasLazyCommits()
virtual void * memory()=0
bool Guard(void *address)
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
bool IsAligned(T value, U alignment)
static MemoryMappedFile * create(const char *name, int size, void *initial)
bool Commit(void *address, size_t size, bool is_executable)
static void Guard(void *address, const size_t size)
T RoundUp(T x, intptr_t m)
#define ASSERT_LE(v1, v2)
static const char * LocalTimezone(double time, TimezoneCache *cache)
static bool ReleaseRegion(void *base, size_t size)
static bool CommitRegion(void *base, size_t size, bool is_executable)
static void * Allocate(const size_t requested, size_t *allocated, bool is_executable)
static bool UncommitRegion(void *base, size_t size)
virtual ~PosixMemoryMappedFile()
static size_t AllocateAlignment()
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 double LocalTimeOffset(TimezoneCache *cache)
bool Uncommit(void *address, size_t size)