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

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

Issue 7348008: Merge up to 8597 to experimental/gc from the bleeding edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: '' Created 9 years, 5 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-solaris.cc ('k') | src/preparse-data.h » ('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-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 return mktime(timeptr); 131 return mktime(timeptr);
132 } 132 }
133 133
134 134
135 int fopen_s(FILE** pFile, const char* filename, const char* mode) { 135 int fopen_s(FILE** pFile, const char* filename, const char* mode) {
136 *pFile = fopen(filename, mode); 136 *pFile = fopen(filename, mode);
137 return *pFile != NULL ? 0 : 1; 137 return *pFile != NULL ? 0 : 1;
138 } 138 }
139 139
140 140
141 #define _TRUNCATE 0
142 #define STRUNCATE 80
143
141 int _vsnprintf_s(char* buffer, size_t sizeOfBuffer, size_t count, 144 int _vsnprintf_s(char* buffer, size_t sizeOfBuffer, size_t count,
142 const char* format, va_list argptr) { 145 const char* format, va_list argptr) {
146 ASSERT(count == _TRUNCATE);
143 return _vsnprintf(buffer, sizeOfBuffer, format, argptr); 147 return _vsnprintf(buffer, sizeOfBuffer, format, argptr);
144 } 148 }
145 #define _TRUNCATE 0
146 149
147 150
148 int strncpy_s(char* strDest, size_t numberOfElements, 151 int strncpy_s(char* dest, size_t dest_size, const char* source, size_t count) {
149 const char* strSource, size_t count) { 152 CHECK(source != NULL);
150 strncpy(strDest, strSource, count); 153 CHECK(dest != NULL);
154 CHECK_GT(dest_size, 0);
155
156 if (count == _TRUNCATE) {
157 while (dest_size > 0 && *source != 0) {
158 *(dest++) = *(source++);
159 --dest_size;
160 }
161 if (dest_size == 0) {
162 *(dest - 1) = 0;
163 return STRUNCATE;
164 }
165 } else {
166 while (dest_size > 0 && count > 0 && *source != 0) {
167 *(dest++) = *(source++);
168 --dest_size;
169 --count;
170 }
171 }
172 CHECK_GT(dest_size, 0);
173 *dest = 0;
151 return 0; 174 return 0;
152 } 175 }
153 176
154 177
155 inline void MemoryBarrier() { 178 inline void MemoryBarrier() {
156 int barrier = 0; 179 int barrier = 0;
157 __asm__ __volatile__("xchgl %%eax,%0 ":"=r" (barrier)); 180 __asm__ __volatile__("xchgl %%eax,%0 ":"=r" (barrier));
158 } 181 }
159 182
160 #endif // __MINGW32__ 183 #endif // __MINGW32__
161 184
162 // Generate a pseudo-random number in the range 0-2^31-1. Usually 185 // Generate a pseudo-random number in the range 0-2^31-1. Usually
163 // defined in stdlib.h. Missing in both Microsoft Visual Studio C++ and MinGW. 186 // defined in stdlib.h. Missing in both Microsoft Visual Studio C++ and MinGW.
164 int random() { 187 int random() {
165 return rand(); 188 return rand();
166 } 189 }
167 190
168 191
169 namespace v8 { 192 namespace v8 {
170 namespace internal { 193 namespace internal {
171 194
195 intptr_t OS::MaxVirtualMemory() {
196 return 0;
197 }
198
199
172 double ceiling(double x) { 200 double ceiling(double x) {
173 return ceil(x); 201 return ceil(x);
174 } 202 }
175 203
176 204
177 static Mutex* limit_mutex = NULL; 205 static Mutex* limit_mutex = NULL;
178 206
179 #if defined(V8_TARGET_ARCH_IA32) 207 #if defined(V8_TARGET_ARCH_IA32)
180 static OS::MemCopyFunction memcopy_function = NULL; 208 static OS::MemCopyFunction memcopy_function = NULL;
181 static Mutex* memcopy_function_mutex = OS::CreateMutex(); 209 static Mutex* memcopy_function_mutex = OS::CreateMutex();
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 tzinfo_.StandardDate.wDay = 5; 428 tzinfo_.StandardDate.wDay = 5;
401 tzinfo_.StandardDate.wHour = 3; 429 tzinfo_.StandardDate.wHour = 3;
402 tzinfo_.StandardBias = 0; 430 tzinfo_.StandardBias = 0;
403 tzinfo_.DaylightDate.wMonth = 3; 431 tzinfo_.DaylightDate.wMonth = 3;
404 tzinfo_.DaylightDate.wDay = 5; 432 tzinfo_.DaylightDate.wDay = 5;
405 tzinfo_.DaylightDate.wHour = 2; 433 tzinfo_.DaylightDate.wHour = 2;
406 tzinfo_.DaylightBias = -60; 434 tzinfo_.DaylightBias = -60;
407 } 435 }
408 436
409 // Make standard and DST timezone names. 437 // Make standard and DST timezone names.
410 OS::SNPrintF(Vector<char>(std_tz_name_, kTzNameSize), 438 WideCharToMultiByte(CP_UTF8, 0, tzinfo_.StandardName, -1,
411 "%S", 439 std_tz_name_, kTzNameSize, NULL, NULL);
412 tzinfo_.StandardName);
413 std_tz_name_[kTzNameSize - 1] = '\0'; 440 std_tz_name_[kTzNameSize - 1] = '\0';
414 OS::SNPrintF(Vector<char>(dst_tz_name_, kTzNameSize), 441 WideCharToMultiByte(CP_UTF8, 0, tzinfo_.DaylightName, -1,
415 "%S", 442 dst_tz_name_, kTzNameSize, NULL, NULL);
416 tzinfo_.DaylightName);
417 dst_tz_name_[kTzNameSize - 1] = '\0'; 443 dst_tz_name_[kTzNameSize - 1] = '\0';
418 444
419 // If OS returned empty string or resource id (like "@tzres.dll,-211") 445 // If OS returned empty string or resource id (like "@tzres.dll,-211")
420 // simply guess the name from the UTC bias of the timezone. 446 // simply guess the name from the UTC bias of the timezone.
421 // To properly resolve the resource identifier requires a library load, 447 // To properly resolve the resource identifier requires a library load,
422 // which is not possible in a sandbox. 448 // which is not possible in a sandbox.
423 if (std_tz_name_[0] == '\0' || std_tz_name_[0] == '@') { 449 if (std_tz_name_[0] == '\0' || std_tz_name_[0] == '@') {
424 OS::SNPrintF(Vector<char>(std_tz_name_, kTzNameSize - 1), 450 OS::SNPrintF(Vector<char>(std_tz_name_, kTzNameSize - 1),
425 "%s Standard Time", 451 "%s Standard Time",
426 GuessTimezoneNameFromBias(tzinfo_.Bias)); 452 GuessTimezoneNameFromBias(tzinfo_.Bias));
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 1519
1494 // Definition of invalid thread handle and id. 1520 // Definition of invalid thread handle and id.
1495 static const HANDLE kNoThread = INVALID_HANDLE_VALUE; 1521 static const HANDLE kNoThread = INVALID_HANDLE_VALUE;
1496 1522
1497 // Entry point for threads. The supplied argument is a pointer to the thread 1523 // Entry point for threads. The supplied argument is a pointer to the thread
1498 // object. The entry function dispatches to the run method in the thread 1524 // object. The entry function dispatches to the run method in the thread
1499 // object. It is important that this function has __stdcall calling 1525 // object. It is important that this function has __stdcall calling
1500 // convention. 1526 // convention.
1501 static unsigned int __stdcall ThreadEntry(void* arg) { 1527 static unsigned int __stdcall ThreadEntry(void* arg) {
1502 Thread* thread = reinterpret_cast<Thread*>(arg); 1528 Thread* thread = reinterpret_cast<Thread*>(arg);
1503 // This is also initialized by the last parameter to _beginthreadex() but we
1504 // don't know which thread will run first (the original thread or the new
1505 // one) so we initialize it here too.
1506 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
1507 thread->Run(); 1529 thread->Run();
1508 return 0; 1530 return 0;
1509 } 1531 }
1510 1532
1511 1533
1512 class Thread::PlatformData : public Malloced { 1534 class Thread::PlatformData : public Malloced {
1513 public: 1535 public:
1514 explicit PlatformData(HANDLE thread) : thread_(thread) {} 1536 explicit PlatformData(HANDLE thread) : thread_(thread) {}
1515 HANDLE thread_; 1537 HANDLE thread_;
1516 }; 1538 };
1517 1539
1518 1540
1519 // Initialize a Win32 thread object. The thread has an invalid thread 1541 // Initialize a Win32 thread object. The thread has an invalid thread
1520 // handle until it is started. 1542 // handle until it is started.
1521 1543
1522 Thread::Thread(Isolate* isolate, const Options& options) 1544 Thread::Thread(const Options& options)
1523 : isolate_(isolate), 1545 : stack_size_(options.stack_size) {
1524 stack_size_(options.stack_size) {
1525 data_ = new PlatformData(kNoThread); 1546 data_ = new PlatformData(kNoThread);
1526 set_name(options.name); 1547 set_name(options.name);
1527 } 1548 }
1528 1549
1529 1550
1530 Thread::Thread(Isolate* isolate, const char* name) 1551 Thread::Thread(const char* name)
1531 : isolate_(isolate), 1552 : stack_size_(0) {
1532 stack_size_(0) {
1533 data_ = new PlatformData(kNoThread); 1553 data_ = new PlatformData(kNoThread);
1534 set_name(name); 1554 set_name(name);
1535 } 1555 }
1536 1556
1537 1557
1538 void Thread::set_name(const char* name) { 1558 void Thread::set_name(const char* name) {
1539 OS::StrNCpy(Vector<char>(name_, sizeof(name_)), name, strlen(name)); 1559 OS::StrNCpy(Vector<char>(name_, sizeof(name_)), name, strlen(name));
1540 name_[sizeof(name_) - 1] = '\0'; 1560 name_[sizeof(name_) - 1] = '\0';
1541 } 1561 }
1542 1562
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1603 // ---------------------------------------------------------------------------- 1623 // ----------------------------------------------------------------------------
1604 // Win32 mutex support. 1624 // Win32 mutex support.
1605 // 1625 //
1606 // On Win32 mutexes are implemented using CRITICAL_SECTION objects. These are 1626 // On Win32 mutexes are implemented using CRITICAL_SECTION objects. These are
1607 // faster than Win32 Mutex objects because they are implemented using user mode 1627 // faster than Win32 Mutex objects because they are implemented using user mode
1608 // atomic instructions. Therefore we only do ring transitions if there is lock 1628 // atomic instructions. Therefore we only do ring transitions if there is lock
1609 // contention. 1629 // contention.
1610 1630
1611 class Win32Mutex : public Mutex { 1631 class Win32Mutex : public Mutex {
1612 public: 1632 public:
1613
1614 Win32Mutex() { InitializeCriticalSection(&cs_); } 1633 Win32Mutex() { InitializeCriticalSection(&cs_); }
1615 1634
1616 virtual ~Win32Mutex() { DeleteCriticalSection(&cs_); } 1635 virtual ~Win32Mutex() { DeleteCriticalSection(&cs_); }
1617 1636
1618 virtual int Lock() { 1637 virtual int Lock() {
1619 EnterCriticalSection(&cs_); 1638 EnterCriticalSection(&cs_);
1620 return 0; 1639 return 0;
1621 } 1640 }
1622 1641
1623 virtual int Unlock() { 1642 virtual int Unlock() {
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 HANDLE profiled_thread() { return profiled_thread_; } 1911 HANDLE profiled_thread() { return profiled_thread_; }
1893 1912
1894 private: 1913 private:
1895 HANDLE profiled_thread_; 1914 HANDLE profiled_thread_;
1896 }; 1915 };
1897 1916
1898 1917
1899 class SamplerThread : public Thread { 1918 class SamplerThread : public Thread {
1900 public: 1919 public:
1901 explicit SamplerThread(int interval) 1920 explicit SamplerThread(int interval)
1902 : Thread(NULL, "SamplerThread"), 1921 : Thread("SamplerThread"),
1903 interval_(interval) {} 1922 interval_(interval) {}
1904 1923
1905 static void AddActiveSampler(Sampler* sampler) { 1924 static void AddActiveSampler(Sampler* sampler) {
1906 ScopedLock lock(mutex_); 1925 ScopedLock lock(mutex_);
1907 SamplerRegistry::AddActiveSampler(sampler); 1926 SamplerRegistry::AddActiveSampler(sampler);
1908 if (instance_ == NULL) { 1927 if (instance_ == NULL) {
1909 instance_ = new SamplerThread(sampler->interval()); 1928 instance_ = new SamplerThread(sampler->interval());
1910 instance_->Start(); 1929 instance_->Start();
1911 } else { 1930 } else {
1912 ASSERT(instance_->interval_ == sampler->interval()); 1931 ASSERT(instance_->interval_ == sampler->interval());
1913 } 1932 }
1914 } 1933 }
1915 1934
1916 static void RemoveActiveSampler(Sampler* sampler) { 1935 static void RemoveActiveSampler(Sampler* sampler) {
1917 ScopedLock lock(mutex_); 1936 ScopedLock lock(mutex_);
1918 SamplerRegistry::RemoveActiveSampler(sampler); 1937 SamplerRegistry::RemoveActiveSampler(sampler);
1919 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { 1938 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
1920 RuntimeProfiler::WakeUpRuntimeProfilerThreadBeforeShutdown(); 1939 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_);
1921 instance_->Join();
1922 delete instance_; 1940 delete instance_;
1923 instance_ = NULL; 1941 instance_ = NULL;
1924 } 1942 }
1925 } 1943 }
1926 1944
1927 // Implement Thread::Run(). 1945 // Implement Thread::Run().
1928 virtual void Run() { 1946 virtual void Run() {
1929 SamplerRegistry::State state; 1947 SamplerRegistry::State state;
1930 while ((state = SamplerRegistry::GetState()) != 1948 while ((state = SamplerRegistry::GetState()) !=
1931 SamplerRegistry::HAS_NO_SAMPLERS) { 1949 SamplerRegistry::HAS_NO_SAMPLERS) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
2037 2055
2038 void Sampler::Stop() { 2056 void Sampler::Stop() {
2039 ASSERT(IsActive()); 2057 ASSERT(IsActive());
2040 SamplerThread::RemoveActiveSampler(this); 2058 SamplerThread::RemoveActiveSampler(this);
2041 SetActive(false); 2059 SetActive(false);
2042 } 2060 }
2043 2061
2044 #endif // ENABLE_LOGGING_AND_PROFILING 2062 #endif // ENABLE_LOGGING_AND_PROFILING
2045 2063
2046 } } // namespace v8::internal 2064 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-solaris.cc ('k') | src/preparse-data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698