Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/platform-macos.cc

Issue 148153010: Synchronize with r15701. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-nullos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include <mach/task.h> 46 #include <mach/task.h>
47 #include <mach/vm_statistics.h> 47 #include <mach/vm_statistics.h>
48 #include <sys/time.h> 48 #include <sys/time.h>
49 #include <sys/resource.h> 49 #include <sys/resource.h>
50 #include <sys/types.h> 50 #include <sys/types.h>
51 #include <sys/sysctl.h> 51 #include <sys/sysctl.h>
52 #include <stdarg.h> 52 #include <stdarg.h>
53 #include <stdlib.h> 53 #include <stdlib.h>
54 #include <string.h> 54 #include <string.h>
55 #include <errno.h> 55 #include <errno.h>
56 #include <cxxabi.h>
56 57
57 #undef MAP_TYPE 58 #undef MAP_TYPE
58 59
59 #include "v8.h" 60 #include "v8.h"
60 61
61 #include "platform-posix.h" 62 #include "platform-posix.h"
62 #include "platform.h" 63 #include "platform.h"
63 #include "simulator.h" 64 #include "simulator.h"
64 #include "vm-state-inl.h" 65 #include "vm-state-inl.h"
65 66
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 abort(); 183 abort();
183 } 184 }
184 185
185 186
186 void OS::DebugBreak() { 187 void OS::DebugBreak() {
187 asm("int $3"); 188 asm("int $3");
188 } 189 }
189 190
190 191
191 void OS::DumpBacktrace() { 192 void OS::DumpBacktrace() {
192 // Currently unsupported. 193 // If weak link to execinfo lib has failed, ie because we are on 10.4, abort.
194 if (backtrace == NULL) return;
195
196 POSIXBacktraceHelper<backtrace, backtrace_symbols>::DumpBacktrace();
193 } 197 }
194 198
195 199
196 class PosixMemoryMappedFile : public OS::MemoryMappedFile { 200 class PosixMemoryMappedFile : public OS::MemoryMappedFile {
197 public: 201 public:
198 PosixMemoryMappedFile(FILE* file, void* memory, int size) 202 PosixMemoryMappedFile(FILE* file, void* memory, int size)
199 : file_(file), memory_(memory), size_(size) { } 203 : file_(file), memory_(memory), size_(size) { }
200 virtual ~PosixMemoryMappedFile(); 204 virtual ~PosixMemoryMappedFile();
201 virtual void* memory() { return memory_; } 205 virtual void* memory() { return memory_; }
202 virtual int size() { return size_; } 206 virtual int size() { return size_; }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 time_t tv = time(NULL); 312 time_t tv = time(NULL);
309 struct tm* t = localtime(&tv); 313 struct tm* t = localtime(&tv);
310 // tm_gmtoff includes any daylight savings offset, so subtract it. 314 // tm_gmtoff includes any daylight savings offset, so subtract it.
311 return static_cast<double>(t->tm_gmtoff * msPerSecond - 315 return static_cast<double>(t->tm_gmtoff * msPerSecond -
312 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); 316 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
313 } 317 }
314 318
315 319
316 int OS::StackWalk(Vector<StackFrame> frames) { 320 int OS::StackWalk(Vector<StackFrame> frames) {
317 // If weak link to execinfo lib has failed, ie because we are on 10.4, abort. 321 // If weak link to execinfo lib has failed, ie because we are on 10.4, abort.
318 if (backtrace == NULL) 322 if (backtrace == NULL) return 0;
319 return 0;
320 323
321 int frames_size = frames.length(); 324 return POSIXBacktraceHelper<backtrace, backtrace_symbols>::StackWalk(frames);
322 ScopedVector<void*> addresses(frames_size);
323
324 int frames_count = backtrace(addresses.start(), frames_size);
325
326 char** symbols = backtrace_symbols(addresses.start(), frames_count);
327 if (symbols == NULL) {
328 return kStackWalkError;
329 }
330
331 for (int i = 0; i < frames_count; i++) {
332 frames[i].address = addresses[i];
333 // Format a text representation of the frame based on the information
334 // available.
335 SNPrintF(MutableCStrVector(frames[i].text,
336 kStackWalkMaxTextLen),
337 "%s",
338 symbols[i]);
339 // Make sure line termination is in place.
340 frames[i].text[kStackWalkMaxTextLen - 1] = '\0';
341 }
342
343 free(symbols);
344
345 return frames_count;
346 } 325 }
347 326
348 327
349 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { } 328 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
350 329
351 330
352 VirtualMemory::VirtualMemory(size_t size) 331 VirtualMemory::VirtualMemory(size_t size)
353 : address_(ReserveRegion(size)), size_(size) { } 332 : address_(ReserveRegion(size)), size_(size) { }
354 333
355 334
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 return pthread_getspecific(pthread_key); 624 return pthread_getspecific(pthread_key);
646 } 625 }
647 626
648 627
649 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { 628 void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
650 pthread_key_t pthread_key = static_cast<pthread_key_t>(key); 629 pthread_key_t pthread_key = static_cast<pthread_key_t>(key);
651 pthread_setspecific(pthread_key, value); 630 pthread_setspecific(pthread_key, value);
652 } 631 }
653 632
654 633
655 void Thread::YieldCPU() {
656 sched_yield();
657 }
658
659
660 class MacOSMutex : public Mutex {
661 public:
662 MacOSMutex() {
663 pthread_mutexattr_t attr;
664 pthread_mutexattr_init(&attr);
665 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
666 pthread_mutex_init(&mutex_, &attr);
667 }
668
669 virtual ~MacOSMutex() { pthread_mutex_destroy(&mutex_); }
670
671 virtual int Lock() { return pthread_mutex_lock(&mutex_); }
672 virtual int Unlock() { return pthread_mutex_unlock(&mutex_); }
673
674 virtual bool TryLock() {
675 int result = pthread_mutex_trylock(&mutex_);
676 // Return false if the lock is busy and locking failed.
677 if (result == EBUSY) {
678 return false;
679 }
680 ASSERT(result == 0); // Verify no other errors.
681 return true;
682 }
683
684 private:
685 pthread_mutex_t mutex_;
686 };
687
688
689 Mutex* OS::CreateMutex() {
690 return new MacOSMutex();
691 }
692
693
694 class MacOSSemaphore : public Semaphore { 634 class MacOSSemaphore : public Semaphore {
695 public: 635 public:
696 explicit MacOSSemaphore(int count) { 636 explicit MacOSSemaphore(int count) {
697 int r; 637 int r;
698 r = semaphore_create(mach_task_self(), 638 r = semaphore_create(mach_task_self(),
699 &semaphore_, 639 &semaphore_,
700 SYNC_POLICY_FIFO, 640 SYNC_POLICY_FIFO,
701 count); 641 count);
702 ASSERT(r == KERN_SUCCESS); 642 ASSERT(r == KERN_SUCCESS);
703 } 643 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 limit_mutex = CreateMutex(); 685 limit_mutex = CreateMutex();
746 } 686 }
747 687
748 688
749 void OS::TearDown() { 689 void OS::TearDown() {
750 delete limit_mutex; 690 delete limit_mutex;
751 } 691 }
752 692
753 693
754 } } // namespace v8::internal 694 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-nullos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698