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

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

Issue 6529032: Merge 6168:6800 from bleeding_edge to experimental/gc branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: Created 9 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-posix.cc ('k') | src/platform-win32.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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 27 matching lines...) Expand all
38 #include <ucontext.h> // walkstack(), getcontext() 38 #include <ucontext.h> // walkstack(), getcontext()
39 #include <dlfcn.h> // dladdr 39 #include <dlfcn.h> // dladdr
40 #include <pthread.h> 40 #include <pthread.h>
41 #include <sched.h> // for sched_yield 41 #include <sched.h> // for sched_yield
42 #include <semaphore.h> 42 #include <semaphore.h>
43 #include <time.h> 43 #include <time.h>
44 #include <sys/time.h> // gettimeofday(), timeradd() 44 #include <sys/time.h> // gettimeofday(), timeradd()
45 #include <errno.h> 45 #include <errno.h>
46 #include <ieeefp.h> // finite() 46 #include <ieeefp.h> // finite()
47 #include <signal.h> // sigemptyset(), etc 47 #include <signal.h> // sigemptyset(), etc
48 #include <sys/kdi_regs.h>
48 49
49 50
50 #undef MAP_TYPE 51 #undef MAP_TYPE
51 52
52 #include "v8.h" 53 #include "v8.h"
53 54
54 #include "platform.h" 55 #include "platform.h"
55 #include "vm-state-inl.h" 56 #include "vm-state-inl.h"
56 57
57 58
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 asm("int $3"); 219 asm("int $3");
219 } 220 }
220 221
221 222
222 class PosixMemoryMappedFile : public OS::MemoryMappedFile { 223 class PosixMemoryMappedFile : public OS::MemoryMappedFile {
223 public: 224 public:
224 PosixMemoryMappedFile(FILE* file, void* memory, int size) 225 PosixMemoryMappedFile(FILE* file, void* memory, int size)
225 : file_(file), memory_(memory), size_(size) { } 226 : file_(file), memory_(memory), size_(size) { }
226 virtual ~PosixMemoryMappedFile(); 227 virtual ~PosixMemoryMappedFile();
227 virtual void* memory() { return memory_; } 228 virtual void* memory() { return memory_; }
229 virtual int size() { return size_; }
228 private: 230 private:
229 FILE* file_; 231 FILE* file_;
230 void* memory_; 232 void* memory_;
231 int size_; 233 int size_;
232 }; 234 };
233 235
234 236
237 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
238 FILE* file = fopen(name, "w+");
239 if (file == NULL) return NULL;
240
241 fseek(file, 0, SEEK_END);
242 int size = ftell(file);
243
244 void* memory =
245 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
246 return new PosixMemoryMappedFile(file, memory, size);
247 }
248
249
235 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, 250 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
236 void* initial) { 251 void* initial) {
237 FILE* file = fopen(name, "w+"); 252 FILE* file = fopen(name, "w+");
238 if (file == NULL) return NULL; 253 if (file == NULL) return NULL;
239 int result = fwrite(initial, size, 1, file); 254 int result = fwrite(initial, size, 1, file);
240 if (result < 1) { 255 if (result < 1) {
241 fclose(file); 256 fclose(file);
242 return NULL; 257 return NULL;
243 } 258 }
244 void* memory = 259 void* memory =
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); 501 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
487 pthread_mutex_init(&mutex_, &attr); 502 pthread_mutex_init(&mutex_, &attr);
488 } 503 }
489 504
490 ~SolarisMutex() { pthread_mutex_destroy(&mutex_); } 505 ~SolarisMutex() { pthread_mutex_destroy(&mutex_); }
491 506
492 int Lock() { return pthread_mutex_lock(&mutex_); } 507 int Lock() { return pthread_mutex_lock(&mutex_); }
493 508
494 int Unlock() { return pthread_mutex_unlock(&mutex_); } 509 int Unlock() { return pthread_mutex_unlock(&mutex_); }
495 510
511 virtual bool TryLock() {
512 int result = pthread_mutex_trylock(&mutex_);
513 // Return false if the lock is busy and locking failed.
514 if (result == EBUSY) {
515 return false;
516 }
517 ASSERT(result == 0); // Verify no other errors.
518 return true;
519 }
520
496 private: 521 private:
497 pthread_mutex_t mutex_; 522 pthread_mutex_t mutex_;
498 }; 523 };
499 524
500 525
501 Mutex* OS::CreateMutex() { 526 Mutex* OS::CreateMutex() {
502 return new SolarisMutex(); 527 return new SolarisMutex();
503 } 528 }
504 529
505 530
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 602
578 603
579 Semaphore* OS::CreateSemaphore(int count) { 604 Semaphore* OS::CreateSemaphore(int count) {
580 return new SolarisSemaphore(count); 605 return new SolarisSemaphore(count);
581 } 606 }
582 607
583 608
584 #ifdef ENABLE_LOGGING_AND_PROFILING 609 #ifdef ENABLE_LOGGING_AND_PROFILING
585 610
586 static Sampler* active_sampler_ = NULL; 611 static Sampler* active_sampler_ = NULL;
612 static pthread_t vm_tid_ = 0;
613
587 614
588 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { 615 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
589 USE(info); 616 USE(info);
590 if (signal != SIGPROF) return; 617 if (signal != SIGPROF) return;
591 if (active_sampler_ == NULL) return; 618 if (active_sampler_ == NULL || !active_sampler_->IsActive()) return;
619 if (vm_tid_ != pthread_self()) return;
592 620
593 TickSample sample; 621 TickSample sample_obj;
594 sample.pc = 0; 622 TickSample* sample = CpuProfiler::TickSampleEvent();
595 sample.sp = 0; 623 if (sample == NULL) sample = &sample_obj;
596 sample.fp = 0;
597 624
598 // We always sample the VM state. 625 // Extracting the sample from the context is extremely machine dependent.
599 sample.state = VMState::current_state(); 626 ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context);
627 mcontext_t& mcontext = ucontext->uc_mcontext;
628 sample->state = Top::current_vm_state();
600 629
601 active_sampler_->Tick(&sample); 630 #if V8_HOST_ARCH_IA32
631 sample->pc = reinterpret_cast<Address>(mcontext.gregs[KDIREG_EIP]);
632 sample->sp = reinterpret_cast<Address>(mcontext.gregs[KDIREG_ESP]);
633 sample->fp = reinterpret_cast<Address>(mcontext.gregs[KDIREG_EBP]);
634 #elif V8_HOST_ARCH_X64
635 sample->pc = reinterpret_cast<Address>(mcontext.gregs[KDIREG_RIP]);
636 sample->sp = reinterpret_cast<Address>(mcontext.gregs[KDIREG_RSP]);
637 sample->fp = reinterpret_cast<Address>(mcontext.gregs[KDIREG_RBP]);
638 #else
639 UNIMPLEMENTED();
640 #endif
641 active_sampler_->SampleStack(sample);
642 active_sampler_->Tick(sample);
602 } 643 }
603 644
604 645
605 class Sampler::PlatformData : public Malloced { 646 class Sampler::PlatformData : public Malloced {
606 public: 647 public:
607 PlatformData() { 648 PlatformData() {
608 signal_handler_installed_ = false; 649 signal_handler_installed_ = false;
609 } 650 }
610 651
611 bool signal_handler_installed_; 652 bool signal_handler_installed_;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 } 705 }
665 706
666 // This sampler is no longer the active sampler. 707 // This sampler is no longer the active sampler.
667 active_sampler_ = NULL; 708 active_sampler_ = NULL;
668 active_ = false; 709 active_ = false;
669 } 710 }
670 711
671 #endif // ENABLE_LOGGING_AND_PROFILING 712 #endif // ENABLE_LOGGING_AND_PROFILING
672 713
673 } } // namespace v8::internal 714 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-posix.cc ('k') | src/platform-win32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698