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

Side by Side Diff: src/platform-freebsd.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-cygwin.cc ('k') | src/platform-linux.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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 void OS::DebugBreak() { 189 void OS::DebugBreak() {
190 #if (defined(__arm__) || defined(__thumb__)) 190 #if (defined(__arm__) || defined(__thumb__))
191 asm("bkpt 0"); 191 asm("bkpt 0");
192 #else 192 #else
193 asm("int $3"); 193 asm("int $3");
194 #endif 194 #endif
195 } 195 }
196 196
197 197
198 void OS::DumpBacktrace() { 198 void OS::DumpBacktrace() {
199 void* trace[100]; 199 POSIXBacktraceHelper<backtrace, backtrace_symbols>::DumpBacktrace();
200 int size = backtrace(trace, ARRAY_SIZE(trace));
201 char** symbols = backtrace_symbols(trace, size);
202 fprintf(stderr, "\n==== C stack trace ===============================\n\n");
203 if (size == 0) {
204 fprintf(stderr, "(empty)\n");
205 } else if (symbols == NULL) {
206 fprintf(stderr, "(no symbols)\n");
207 } else {
208 for (int i = 1; i < size; ++i) {
209 fprintf(stderr, "%2d: ", i);
210 char mangled[201];
211 if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) { // NOLINT
212 fprintf(stderr, "%s\n", mangled);
213 } else {
214 fprintf(stderr, "??\n");
215 }
216 }
217 }
218 fflush(stderr);
219 free(symbols);
220 } 200 }
221 201
222 202
223 class PosixMemoryMappedFile : public OS::MemoryMappedFile { 203 class PosixMemoryMappedFile : public OS::MemoryMappedFile {
224 public: 204 public:
225 PosixMemoryMappedFile(FILE* file, void* memory, int size) 205 PosixMemoryMappedFile(FILE* file, void* memory, int size)
226 : file_(file), memory_(memory), size_(size) { } 206 : file_(file), memory_(memory), size_(size) { }
227 virtual ~PosixMemoryMappedFile(); 207 virtual ~PosixMemoryMappedFile();
228 virtual void* memory() { return memory_; } 208 virtual void* memory() { return memory_; }
229 virtual int size() { return size_; } 209 virtual int size() { return size_; }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 291 }
312 close(fd); 292 close(fd);
313 } 293 }
314 294
315 295
316 void OS::SignalCodeMovingGC() { 296 void OS::SignalCodeMovingGC() {
317 } 297 }
318 298
319 299
320 int OS::StackWalk(Vector<OS::StackFrame> frames) { 300 int OS::StackWalk(Vector<OS::StackFrame> frames) {
321 int frames_size = frames.length(); 301 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, kStackWalkMaxTextLen),
336 "%s",
337 symbols[i]);
338 // Make sure line termination is in place.
339 frames[i].text[kStackWalkMaxTextLen - 1] = '\0';
340 }
341
342 free(symbols);
343
344 return frames_count;
345 } 302 }
346 303
347 304
348 // Constants used for mmap. 305 // Constants used for mmap.
349 static const int kMmapFd = -1; 306 static const int kMmapFd = -1;
350 static const int kMmapFdOffset = 0; 307 static const int kMmapFdOffset = 0;
351 308
352 309
353 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { } 310 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
354 311
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 return pthread_getspecific(pthread_key); 518 return pthread_getspecific(pthread_key);
562 } 519 }
563 520
564 521
565 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { 522 void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
566 pthread_key_t pthread_key = static_cast<pthread_key_t>(key); 523 pthread_key_t pthread_key = static_cast<pthread_key_t>(key);
567 pthread_setspecific(pthread_key, value); 524 pthread_setspecific(pthread_key, value);
568 } 525 }
569 526
570 527
571 void Thread::YieldCPU() {
572 sched_yield();
573 }
574
575
576 class FreeBSDMutex : public Mutex {
577 public:
578 FreeBSDMutex() {
579 pthread_mutexattr_t attrs;
580 int result = pthread_mutexattr_init(&attrs);
581 ASSERT(result == 0);
582 result = pthread_mutexattr_settype(&attrs, PTHREAD_MUTEX_RECURSIVE);
583 ASSERT(result == 0);
584 result = pthread_mutex_init(&mutex_, &attrs);
585 ASSERT(result == 0);
586 USE(result);
587 }
588
589 virtual ~FreeBSDMutex() { pthread_mutex_destroy(&mutex_); }
590
591 virtual int Lock() {
592 int result = pthread_mutex_lock(&mutex_);
593 return result;
594 }
595
596 virtual int Unlock() {
597 int result = pthread_mutex_unlock(&mutex_);
598 return result;
599 }
600
601 virtual bool TryLock() {
602 int result = pthread_mutex_trylock(&mutex_);
603 // Return false if the lock is busy and locking failed.
604 if (result == EBUSY) {
605 return false;
606 }
607 ASSERT(result == 0); // Verify no other errors.
608 return true;
609 }
610
611 private:
612 pthread_mutex_t mutex_; // Pthread mutex for POSIX platforms.
613 };
614
615
616 Mutex* OS::CreateMutex() {
617 return new FreeBSDMutex();
618 }
619
620
621 class FreeBSDSemaphore : public Semaphore { 528 class FreeBSDSemaphore : public Semaphore {
622 public: 529 public:
623 explicit FreeBSDSemaphore(int count) { sem_init(&sem_, 0, count); } 530 explicit FreeBSDSemaphore(int count) { sem_init(&sem_, 0, count); }
624 virtual ~FreeBSDSemaphore() { sem_destroy(&sem_); } 531 virtual ~FreeBSDSemaphore() { sem_destroy(&sem_); }
625 532
626 virtual void Wait(); 533 virtual void Wait();
627 virtual bool Wait(int timeout); 534 virtual bool Wait(int timeout);
628 virtual void Signal() { sem_post(&sem_); } 535 virtual void Signal() { sem_post(&sem_); }
629 private: 536 private:
630 sem_t sem_; 537 sem_t sem_;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 limit_mutex = CreateMutex(); 592 limit_mutex = CreateMutex();
686 } 593 }
687 594
688 595
689 void OS::TearDown() { 596 void OS::TearDown() {
690 delete limit_mutex; 597 delete limit_mutex;
691 } 598 }
692 599
693 600
694 } } // namespace v8::internal 601 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-cygwin.cc ('k') | src/platform-linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698