v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
platform-solaris.cc
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 // Platform-specific code for Solaris 10 goes here. For the POSIX-compatible
29 // parts, the implementation is in platform-posix.cc.
30 
31 #ifdef __sparc
32 # error "V8 does not support the SPARC CPU architecture."
33 #endif
34 
35 #include <sys/stack.h> // for stack alignment
36 #include <unistd.h> // getpagesize(), usleep()
37 #include <sys/mman.h> // mmap()
38 #include <ucontext.h> // walkstack(), getcontext()
39 #include <dlfcn.h> // dladdr
40 #include <pthread.h>
41 #include <semaphore.h>
42 #include <time.h>
43 #include <sys/time.h> // gettimeofday(), timeradd()
44 #include <errno.h>
45 #include <ieeefp.h> // finite()
46 #include <signal.h> // sigemptyset(), etc
47 #include <sys/regset.h>
48 
49 
50 #undef MAP_TYPE
51 
52 #include "v8.h"
53 
54 #include "platform.h"
55 #include "v8threads.h"
56 #include "vm-state-inl.h"
57 
58 
59 // It seems there is a bug in some Solaris distributions (experienced in
60 // SunOS 5.10 Generic_141445-09) which make it difficult or impossible to
61 // access signbit() despite the availability of other C99 math functions.
62 #ifndef signbit
63 namespace std {
64 // Test sign - usually defined in math.h
65 int signbit(double x) {
66  // We need to take care of the special case of both positive and negative
67  // versions of zero.
68  if (x == 0) {
69  return fpclass(x) & FP_NZERO;
70  } else {
71  // This won't detect negative NaN but that should be okay since we don't
72  // assume that behavior.
73  return x < 0;
74  }
75 }
76 } // namespace std
77 #endif // signbit
78 
79 namespace v8 {
80 namespace internal {
81 
82 
83 const char* OS::LocalTimezone(double time, TimezoneCache* cache) {
84  if (std::isnan(time)) return "";
85  time_t tv = static_cast<time_t>(std::floor(time/msPerSecond));
86  struct tm* t = localtime(&tv);
87  if (NULL == t) return "";
88  return tzname[0]; // The location of the timezone string on Solaris.
89 }
90 
91 
92 double OS::LocalTimeOffset(TimezoneCache* cache) {
93  tzset();
94  return -static_cast<double>(timezone * msPerSecond);
95 }
96 
97 
98 void* OS::Allocate(const size_t requested,
99  size_t* allocated,
100  bool is_executable) {
101  const size_t msize = RoundUp(requested, getpagesize());
102  int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
103  void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANON, -1, 0);
104 
105  if (mbase == MAP_FAILED) {
106  LOG(Isolate::Current(), StringEvent("OS::Allocate", "mmap failed"));
107  return NULL;
108  }
109  *allocated = msize;
110  return mbase;
111 }
112 
113 
114 class PosixMemoryMappedFile : public OS::MemoryMappedFile {
115  public:
116  PosixMemoryMappedFile(FILE* file, void* memory, int size)
117  : file_(file), memory_(memory), size_(size) { }
118  virtual ~PosixMemoryMappedFile();
119  virtual void* memory() { return memory_; }
120  virtual int size() { return size_; }
121  private:
122  FILE* file_;
123  void* memory_;
124  int size_;
125 };
126 
127 
128 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
129  FILE* file = fopen(name, "r+");
130  if (file == NULL) return NULL;
131 
132  fseek(file, 0, SEEK_END);
133  int size = ftell(file);
134 
135  void* memory =
136  mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
137  return new PosixMemoryMappedFile(file, memory, size);
138 }
139 
140 
141 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
142  void* initial) {
143  FILE* file = fopen(name, "w+");
144  if (file == NULL) return NULL;
145  int result = fwrite(initial, size, 1, file);
146  if (result < 1) {
147  fclose(file);
148  return NULL;
149  }
150  void* memory =
151  mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
152  return new PosixMemoryMappedFile(file, memory, size);
153 }
154 
155 
157  if (memory_) munmap(memory_, size_);
158  fclose(file_);
159 }
160 
161 
162 void OS::LogSharedLibraryAddresses(Isolate* isolate) {
163 }
164 
165 
166 void OS::SignalCodeMovingGC() {
167 }
168 
169 
170 struct StackWalker {
172  int index;
173 };
174 
175 
176 static int StackWalkCallback(uintptr_t pc, int signo, void* data) {
177  struct StackWalker* walker = static_cast<struct StackWalker*>(data);
178  Dl_info info;
179 
180  int i = walker->index;
181 
182  walker->frames[i].address = reinterpret_cast<void*>(pc);
183 
184  // Make sure line termination is in place.
185  walker->frames[i].text[OS::kStackWalkMaxTextLen - 1] = '\0';
186 
187  Vector<char> text = MutableCStrVector(walker->frames[i].text,
189 
190  if (dladdr(reinterpret_cast<void*>(pc), &info) == 0) {
191  OS::SNPrintF(text, "[0x%p]", pc);
192  } else if ((info.dli_fname != NULL && info.dli_sname != NULL)) {
193  // We have symbol info.
194  OS::SNPrintF(text, "%s'%s+0x%x", info.dli_fname, info.dli_sname, pc);
195  } else {
196  // No local symbol info.
197  OS::SNPrintF(text,
198  "%s'0x%p [0x%p]",
199  info.dli_fname,
200  pc - reinterpret_cast<uintptr_t>(info.dli_fbase),
201  pc);
202  }
203  walker->index++;
204  return 0;
205 }
206 
207 
208 // Constants used for mmap.
209 static const int kMmapFd = -1;
210 static const int kMmapFdOffset = 0;
211 
212 
213 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
214 
215 
216 VirtualMemory::VirtualMemory(size_t size)
217  : address_(ReserveRegion(size)), size_(size) { }
218 
219 
220 VirtualMemory::VirtualMemory(size_t size, size_t alignment)
221  : address_(NULL), size_(0) {
222  ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment())));
223  size_t request_size = RoundUp(size + alignment,
224  static_cast<intptr_t>(OS::AllocateAlignment()));
225  void* reservation = mmap(OS::GetRandomMmapAddr(),
226  request_size,
227  PROT_NONE,
228  MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
229  kMmapFd,
230  kMmapFdOffset);
231  if (reservation == MAP_FAILED) return;
232 
233  Address base = static_cast<Address>(reservation);
234  Address aligned_base = RoundUp(base, alignment);
235  ASSERT_LE(base, aligned_base);
236 
237  // Unmap extra memory reserved before and after the desired block.
238  if (aligned_base != base) {
239  size_t prefix_size = static_cast<size_t>(aligned_base - base);
240  OS::Free(base, prefix_size);
241  request_size -= prefix_size;
242  }
243 
244  size_t aligned_size = RoundUp(size, OS::AllocateAlignment());
245  ASSERT_LE(aligned_size, request_size);
246 
247  if (aligned_size != request_size) {
248  size_t suffix_size = request_size - aligned_size;
249  OS::Free(aligned_base + aligned_size, suffix_size);
250  request_size -= suffix_size;
251  }
252 
253  ASSERT(aligned_size == request_size);
254 
255  address_ = static_cast<void*>(aligned_base);
256  size_ = aligned_size;
257 }
258 
259 
261  if (IsReserved()) {
262  bool result = ReleaseRegion(address(), size());
263  ASSERT(result);
264  USE(result);
265  }
266 }
267 
268 
270  return address_ != NULL;
271 }
272 
273 
274 void VirtualMemory::Reset() {
275  address_ = NULL;
276  size_ = 0;
277 }
278 
279 
280 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
281  return CommitRegion(address, size, is_executable);
282 }
283 
284 
285 bool VirtualMemory::Uncommit(void* address, size_t size) {
286  return UncommitRegion(address, size);
287 }
288 
289 
290 bool VirtualMemory::Guard(void* address) {
291  OS::Guard(address, OS::CommitPageSize());
292  return true;
293 }
294 
295 
296 void* VirtualMemory::ReserveRegion(size_t size) {
297  void* result = mmap(OS::GetRandomMmapAddr(),
298  size,
299  PROT_NONE,
300  MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
301  kMmapFd,
302  kMmapFdOffset);
303 
304  if (result == MAP_FAILED) return NULL;
305 
306  return result;
307 }
308 
309 
310 bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) {
311  int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
312  if (MAP_FAILED == mmap(base,
313  size,
314  prot,
315  MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
316  kMmapFd,
317  kMmapFdOffset)) {
318  return false;
319  }
320  return true;
321 }
322 
323 
324 bool VirtualMemory::UncommitRegion(void* base, size_t size) {
325  return mmap(base,
326  size,
327  PROT_NONE,
328  MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_FIXED,
329  kMmapFd,
330  kMmapFdOffset) != MAP_FAILED;
331 }
332 
333 
334 bool VirtualMemory::ReleaseRegion(void* base, size_t size) {
335  return munmap(base, size) == 0;
336 }
337 
338 
340  // TODO(alph): implement for the platform.
341  return false;
342 }
343 
344 } } // namespace v8::internal
byte * Address
Definition: globals.h:186
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
Definition: flags.cc:269
static void Free(void *address, const size_t size)
static void LogSharedLibraryAddresses(Isolate *isolate)
#define LOG(isolate, Call)
Definition: log.h:86
static void SignalCodeMovingGC()
static void * GetRandomMmapAddr()
static void * ReserveRegion(size_t size)
Vector< char > MutableCStrVector(char *data)
Definition: utils.h:586
static const int kStackWalkMaxTextLen
Definition: platform.h:267
PosixMemoryMappedFile(FILE *file, void *memory, int size)
#define ASSERT(condition)
Definition: checks.h:329
static MemoryMappedFile * open(const char *name)
int isnan(double x)
bool IsAligned(T value, U alignment)
Definition: utils.h:211
static MemoryMappedFile * create(const char *name, int size, void *initial)
bool Commit(void *address, size_t size, bool is_executable)
const Register pc
static void Guard(void *address, const size_t size)
T RoundUp(T x, intptr_t m)
Definition: utils.h:144
#define ASSERT_LE(v1, v2)
Definition: checks.h:334
static const char * LocalTimezone(double time, TimezoneCache *cache)
Vector< OS::StackFrame > & frames
static int SNPrintF(Vector< char > str, const char *format,...)
static bool ReleaseRegion(void *base, size_t size)
static bool CommitRegion(void *base, size_t size, bool is_executable)
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 info
Definition: flags.cc:317
static void * Allocate(const size_t requested, size_t *allocated, bool is_executable)
static bool UncommitRegion(void *base, size_t size)
void USE(T)
Definition: globals.h:341
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
Definition: flags.cc:505
static intptr_t CommitPageSize()
static double LocalTimeOffset(TimezoneCache *cache)
int signbit(double x)
bool Uncommit(void *address, size_t size)