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

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

Issue 131363008: A64: Synchronize with r15922. (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.h ('k') | src/platform-freebsd.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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "platform-posix.h" 44 #include "platform-posix.h"
45 #include "platform.h" 45 #include "platform.h"
46 #include "simulator.h" 46 #include "simulator.h"
47 #include "v8threads.h" 47 #include "v8threads.h"
48 #include "vm-state-inl.h" 48 #include "vm-state-inl.h"
49 #include "win32-headers.h" 49 #include "win32-headers.h"
50 50
51 namespace v8 { 51 namespace v8 {
52 namespace internal { 52 namespace internal {
53 53
54 // 0 is never a valid thread id
55 static const pthread_t kNoThread = (pthread_t) 0;
56
57
58 double ceiling(double x) {
59 return ceil(x);
60 }
61
62 54
63 static Mutex* limit_mutex = NULL; 55 static Mutex* limit_mutex = NULL;
64 56
65 57
66 void OS::PostSetUp() {
67 POSIXPostSetUp();
68 }
69
70
71 uint64_t OS::CpuFeaturesImpliedByPlatform() {
72 return 0; // Nothing special about Cygwin.
73 }
74
75
76 int OS::ActivationFrameAlignment() {
77 // With gcc 4.4 the tree vectorization optimizer can generate code
78 // that requires 16 byte alignment such as movdqa on x86.
79 return 16;
80 }
81
82
83 const char* OS::LocalTimezone(double time) { 58 const char* OS::LocalTimezone(double time) {
84 if (std::isnan(time)) return ""; 59 if (std::isnan(time)) return "";
85 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); 60 time_t tv = static_cast<time_t>(floor(time/msPerSecond));
86 struct tm* t = localtime(&tv); 61 struct tm* t = localtime(&tv);
87 if (NULL == t) return ""; 62 if (NULL == t) return "";
88 return tzname[0]; // The location of the timezone string on Cygwin. 63 return tzname[0]; // The location of the timezone string on Cygwin.
89 } 64 }
90 65
91 66
92 double OS::LocalTimeOffset() { 67 double OS::LocalTimeOffset() {
(...skipping 26 matching lines...) Expand all
119 Max(highest_ever_allocated, 94 Max(highest_ever_allocated,
120 reinterpret_cast<void*>(reinterpret_cast<char*>(address) + size)); 95 reinterpret_cast<void*>(reinterpret_cast<char*>(address) + size));
121 } 96 }
122 97
123 98
124 bool OS::IsOutsideAllocatedSpace(void* address) { 99 bool OS::IsOutsideAllocatedSpace(void* address) {
125 return address < lowest_ever_allocated || address >= highest_ever_allocated; 100 return address < lowest_ever_allocated || address >= highest_ever_allocated;
126 } 101 }
127 102
128 103
129 size_t OS::AllocateAlignment() {
130 return sysconf(_SC_PAGESIZE);
131 }
132
133
134 void* OS::Allocate(const size_t requested, 104 void* OS::Allocate(const size_t requested,
135 size_t* allocated, 105 size_t* allocated,
136 bool is_executable) { 106 bool is_executable) {
137 const size_t msize = RoundUp(requested, sysconf(_SC_PAGESIZE)); 107 const size_t msize = RoundUp(requested, sysconf(_SC_PAGESIZE));
138 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); 108 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
139 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 109 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
140 if (mbase == MAP_FAILED) { 110 if (mbase == MAP_FAILED) {
141 LOG(ISOLATE, StringEvent("OS::Allocate", "mmap failed")); 111 LOG(ISOLATE, StringEvent("OS::Allocate", "mmap failed"));
142 return NULL; 112 return NULL;
143 } 113 }
144 *allocated = msize; 114 *allocated = msize;
145 UpdateAllocatedSpaceLimits(mbase, msize); 115 UpdateAllocatedSpaceLimits(mbase, msize);
146 return mbase; 116 return mbase;
147 } 117 }
148 118
149 119
150 void OS::Free(void* address, const size_t size) {
151 // TODO(1240712): munmap has a return value which is ignored here.
152 int result = munmap(address, size);
153 USE(result);
154 ASSERT(result == 0);
155 }
156
157
158 void OS::ProtectCode(void* address, const size_t size) {
159 DWORD old_protect;
160 VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect);
161 }
162
163
164 void OS::Guard(void* address, const size_t size) {
165 DWORD oldprotect;
166 VirtualProtect(address, size, PAGE_READONLY | PAGE_GUARD, &oldprotect);
167 }
168
169
170 void OS::Sleep(int milliseconds) {
171 unsigned int ms = static_cast<unsigned int>(milliseconds);
172 usleep(1000 * ms);
173 }
174
175
176 int OS::NumberOfCores() {
177 return sysconf(_SC_NPROCESSORS_ONLN);
178 }
179
180
181 void OS::Abort() {
182 // Redirect to std abort to signal abnormal program termination.
183 abort();
184 }
185
186
187 void OS::DebugBreak() {
188 asm("int $3");
189 }
190
191
192 void OS::DumpBacktrace() { 120 void OS::DumpBacktrace() {
193 // Currently unsupported. 121 // Currently unsupported.
194 } 122 }
195 123
196 124
197 class PosixMemoryMappedFile : public OS::MemoryMappedFile { 125 class PosixMemoryMappedFile : public OS::MemoryMappedFile {
198 public: 126 public:
199 PosixMemoryMappedFile(FILE* file, void* memory, int size) 127 PosixMemoryMappedFile(FILE* file, void* memory, int size)
200 : file_(file), memory_(memory), size_(size) { } 128 : file_(file), memory_(memory), size_(size) { }
201 virtual ~PosixMemoryMappedFile(); 129 virtual ~PosixMemoryMappedFile();
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 return VirtualFree(base, 0, MEM_RELEASE) != 0; 391 return VirtualFree(base, 0, MEM_RELEASE) != 0;
464 } 392 }
465 393
466 394
467 bool VirtualMemory::HasLazyCommits() { 395 bool VirtualMemory::HasLazyCommits() {
468 // TODO(alph): implement for the platform. 396 // TODO(alph): implement for the platform.
469 return false; 397 return false;
470 } 398 }
471 399
472 400
473 class Thread::PlatformData : public Malloced {
474 public:
475 PlatformData() : thread_(kNoThread) {}
476 pthread_t thread_; // Thread handle for pthread.
477 };
478
479
480 Thread::Thread(const Options& options)
481 : data_(new PlatformData()),
482 stack_size_(options.stack_size()),
483 start_semaphore_(NULL) {
484 set_name(options.name());
485 }
486
487
488 Thread::~Thread() {
489 delete data_;
490 }
491
492
493 static void* ThreadEntry(void* arg) {
494 Thread* thread = reinterpret_cast<Thread*>(arg);
495 // This is also initialized by the first argument to pthread_create() but we
496 // don't know which thread will run first (the original thread or the new
497 // one) so we initialize it here too.
498 thread->data()->thread_ = pthread_self();
499 ASSERT(thread->data()->thread_ != kNoThread);
500 thread->NotifyStartedAndRun();
501 return NULL;
502 }
503
504
505 void Thread::set_name(const char* name) {
506 strncpy(name_, name, sizeof(name_));
507 name_[sizeof(name_) - 1] = '\0';
508 }
509
510
511 void Thread::Start() {
512 pthread_attr_t* attr_ptr = NULL;
513 pthread_attr_t attr;
514 if (stack_size_ > 0) {
515 pthread_attr_init(&attr);
516 pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_));
517 attr_ptr = &attr;
518 }
519 pthread_create(&data_->thread_, attr_ptr, ThreadEntry, this);
520 ASSERT(data_->thread_ != kNoThread);
521 }
522
523
524 void Thread::Join() {
525 pthread_join(data_->thread_, NULL);
526 }
527
528
529 static inline Thread::LocalStorageKey PthreadKeyToLocalKey(
530 pthread_key_t pthread_key) {
531 // We need to cast pthread_key_t to Thread::LocalStorageKey in two steps
532 // because pthread_key_t is a pointer type on Cygwin. This will probably not
533 // work on 64-bit platforms, but Cygwin doesn't support 64-bit anyway.
534 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t));
535 intptr_t ptr_key = reinterpret_cast<intptr_t>(pthread_key);
536 return static_cast<Thread::LocalStorageKey>(ptr_key);
537 }
538
539
540 static inline pthread_key_t LocalKeyToPthreadKey(
541 Thread::LocalStorageKey local_key) {
542 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t));
543 intptr_t ptr_key = static_cast<intptr_t>(local_key);
544 return reinterpret_cast<pthread_key_t>(ptr_key);
545 }
546
547
548 Thread::LocalStorageKey Thread::CreateThreadLocalKey() {
549 pthread_key_t key;
550 int result = pthread_key_create(&key, NULL);
551 USE(result);
552 ASSERT(result == 0);
553 return PthreadKeyToLocalKey(key);
554 }
555
556
557 void Thread::DeleteThreadLocalKey(LocalStorageKey key) {
558 pthread_key_t pthread_key = LocalKeyToPthreadKey(key);
559 int result = pthread_key_delete(pthread_key);
560 USE(result);
561 ASSERT(result == 0);
562 }
563
564
565 void* Thread::GetThreadLocal(LocalStorageKey key) {
566 pthread_key_t pthread_key = LocalKeyToPthreadKey(key);
567 return pthread_getspecific(pthread_key);
568 }
569
570
571 void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
572 pthread_key_t pthread_key = LocalKeyToPthreadKey(key);
573 pthread_setspecific(pthread_key, value);
574 }
575
576
577 class CygwinSemaphore : public Semaphore { 401 class CygwinSemaphore : public Semaphore {
578 public: 402 public:
579 explicit CygwinSemaphore(int count) { sem_init(&sem_, 0, count); } 403 explicit CygwinSemaphore(int count) { sem_init(&sem_, 0, count); }
580 virtual ~CygwinSemaphore() { sem_destroy(&sem_); } 404 virtual ~CygwinSemaphore() { sem_destroy(&sem_); }
581 405
582 virtual void Wait(); 406 virtual void Wait();
583 virtual bool Wait(int timeout); 407 virtual bool Wait(int timeout);
584 virtual void Signal() { sem_post(&sem_); } 408 virtual void Signal() { sem_post(&sem_); }
585 private: 409 private:
586 sem_t sem_; 410 sem_t sem_;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 limit_mutex = CreateMutex(); 474 limit_mutex = CreateMutex();
651 } 475 }
652 476
653 477
654 void OS::TearDown() { 478 void OS::TearDown() {
655 delete limit_mutex; 479 delete limit_mutex;
656 } 480 }
657 481
658 482
659 } } // namespace v8::internal 483 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform.h ('k') | src/platform-freebsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698