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

Side by Side Diff: runtime/vm/os_macos.cc

Issue 2750843003: Rename TARGET_OS_* to HOST_OS_*. (Closed)
Patch Set: DEPS Created 3 years, 9 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
« no previous file with comments | « runtime/vm/os_linux.cc ('k') | runtime/vm/os_thread.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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/globals.h" 5 #include "vm/globals.h"
6 #if defined(TARGET_OS_MACOS) 6 #if defined(HOST_OS_MACOS)
7 7
8 #include "vm/os.h" 8 #include "vm/os.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
11 #include <limits.h> // NOLINT 11 #include <limits.h> // NOLINT
12 #include <mach/mach.h> // NOLINT 12 #include <mach/mach.h> // NOLINT
13 #include <mach/clock.h> // NOLINT 13 #include <mach/clock.h> // NOLINT
14 #include <mach/mach_time.h> // NOLINT 14 #include <mach/mach_time.h> // NOLINT
15 #include <sys/time.h> // NOLINT 15 #include <sys/time.h> // NOLINT
16 #include <sys/resource.h> // NOLINT 16 #include <sys/resource.h> // NOLINT
17 #include <unistd.h> // NOLINT 17 #include <unistd.h> // NOLINT
18 #if TARGET_OS_IOS 18 #if HOST_OS_IOS
19 #include <sys/sysctl.h> // NOLINT 19 #include <sys/sysctl.h> // NOLINT
20 #include <syslog.h> // NOLINT 20 #include <syslog.h> // NOLINT
21 #endif 21 #endif
22 22
23 #include "platform/utils.h" 23 #include "platform/utils.h"
24 #include "vm/isolate.h" 24 #include "vm/isolate.h"
25 #include "vm/zone.h" 25 #include "vm/zone.h"
26 26
27 namespace dart { 27 namespace dart {
28 28
29 const char* OS::Name() { 29 const char* OS::Name() {
30 #if TARGET_OS_IOS 30 #if HOST_OS_IOS
31 return "ios"; 31 return "ios";
32 #else 32 #else
33 return "macos"; 33 return "macos";
34 #endif 34 #endif
35 } 35 }
36 36
37 37
38 intptr_t OS::ProcessId() { 38 intptr_t OS::ProcessId() {
39 return static_cast<intptr_t>(getpid()); 39 return static_cast<intptr_t>(getpid());
40 } 40 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // gettimeofday has microsecond resolution. 83 // gettimeofday has microsecond resolution.
84 struct timeval tv; 84 struct timeval tv;
85 if (gettimeofday(&tv, NULL) < 0) { 85 if (gettimeofday(&tv, NULL) < 0) {
86 UNREACHABLE(); 86 UNREACHABLE();
87 return 0; 87 return 0;
88 } 88 }
89 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec; 89 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec;
90 } 90 }
91 91
92 92
93 #if !TARGET_OS_IOS 93 #if !HOST_OS_IOS
94 static mach_timebase_info_data_t timebase_info; 94 static mach_timebase_info_data_t timebase_info;
95 #endif 95 #endif
96 96
97 97
98 int64_t OS::GetCurrentMonotonicTicks() { 98 int64_t OS::GetCurrentMonotonicTicks() {
99 #if TARGET_OS_IOS 99 #if HOST_OS_IOS
100 // On iOS mach_absolute_time stops while the device is sleeping. Instead use 100 // On iOS mach_absolute_time stops while the device is sleeping. Instead use
101 // now - KERN_BOOTTIME to get a time difference that is not impacted by clock 101 // now - KERN_BOOTTIME to get a time difference that is not impacted by clock
102 // changes. KERN_BOOTTIME will be updated by the system whenever the system 102 // changes. KERN_BOOTTIME will be updated by the system whenever the system
103 // clock change. 103 // clock change.
104 struct timeval boottime; 104 struct timeval boottime;
105 int mib[2] = {CTL_KERN, KERN_BOOTTIME}; 105 int mib[2] = {CTL_KERN, KERN_BOOTTIME};
106 size_t size = sizeof(boottime); 106 size_t size = sizeof(boottime);
107 int kr = sysctl(mib, sizeof(mib) / sizeof(mib[0]), &boottime, &size, NULL, 0); 107 int kr = sysctl(mib, sizeof(mib) / sizeof(mib[0]), &boottime, &size, NULL, 0);
108 ASSERT(KERN_SUCCESS == kr); 108 ASSERT(KERN_SUCCESS == kr);
109 int64_t now = GetCurrentTimeMicros(); 109 int64_t now = GetCurrentTimeMicros();
110 int64_t origin = boottime.tv_sec * kMicrosecondsPerSecond; 110 int64_t origin = boottime.tv_sec * kMicrosecondsPerSecond;
111 origin += boottime.tv_usec; 111 origin += boottime.tv_usec;
112 return now - origin; 112 return now - origin;
113 #else 113 #else
114 if (timebase_info.denom == 0) { 114 if (timebase_info.denom == 0) {
115 kern_return_t kr = mach_timebase_info(&timebase_info); 115 kern_return_t kr = mach_timebase_info(&timebase_info);
116 ASSERT(KERN_SUCCESS == kr); 116 ASSERT(KERN_SUCCESS == kr);
117 } 117 }
118 ASSERT(timebase_info.denom != 0); 118 ASSERT(timebase_info.denom != 0);
119 // timebase_info converts absolute time tick units into nanoseconds. 119 // timebase_info converts absolute time tick units into nanoseconds.
120 int64_t result = mach_absolute_time(); 120 int64_t result = mach_absolute_time();
121 result *= timebase_info.numer; 121 result *= timebase_info.numer;
122 result /= timebase_info.denom; 122 result /= timebase_info.denom;
123 return result; 123 return result;
124 #endif // TARGET_OS_IOS 124 #endif // HOST_OS_IOS
125 } 125 }
126 126
127 127
128 int64_t OS::GetCurrentMonotonicFrequency() { 128 int64_t OS::GetCurrentMonotonicFrequency() {
129 #if TARGET_OS_IOS 129 #if HOST_OS_IOS
130 return kMicrosecondsPerSecond; 130 return kMicrosecondsPerSecond;
131 #else 131 #else
132 return kNanosecondsPerSecond; 132 return kNanosecondsPerSecond;
133 #endif // TARGET_OS_IOS 133 #endif // HOST_OS_IOS
134 } 134 }
135 135
136 136
137 int64_t OS::GetCurrentMonotonicMicros() { 137 int64_t OS::GetCurrentMonotonicMicros() {
138 #if TARGET_OS_IOS 138 #if HOST_OS_IOS
139 ASSERT(GetCurrentMonotonicFrequency() == kMicrosecondsPerSecond); 139 ASSERT(GetCurrentMonotonicFrequency() == kMicrosecondsPerSecond);
140 return GetCurrentMonotonicTicks(); 140 return GetCurrentMonotonicTicks();
141 #else 141 #else
142 ASSERT(GetCurrentMonotonicFrequency() == kNanosecondsPerSecond); 142 ASSERT(GetCurrentMonotonicFrequency() == kNanosecondsPerSecond);
143 return GetCurrentMonotonicTicks() / kNanosecondsPerMicrosecond; 143 return GetCurrentMonotonicTicks() / kNanosecondsPerMicrosecond;
144 #endif // TARGET_OS_IOS 144 #endif // HOST_OS_IOS
145 } 145 }
146 146
147 147
148 int64_t OS::GetCurrentThreadCPUMicros() { 148 int64_t OS::GetCurrentThreadCPUMicros() {
149 mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT; 149 mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
150 thread_basic_info_data_t info_data; 150 thread_basic_info_data_t info_data;
151 thread_basic_info_t info = &info_data; 151 thread_basic_info_t info = &info_data;
152 mach_port_t thread_port = mach_thread_self(); 152 mach_port_t thread_port = mach_thread_self();
153 if (thread_port == MACH_PORT_NULL) { 153 if (thread_port == MACH_PORT_NULL) {
154 return -1; 154 return -1;
155 } 155 }
156 kern_return_t r = 156 kern_return_t r =
157 thread_info(thread_port, THREAD_BASIC_INFO, (thread_info_t)info, &count); 157 thread_info(thread_port, THREAD_BASIC_INFO, (thread_info_t)info, &count);
158 mach_port_deallocate(mach_task_self(), thread_port); 158 mach_port_deallocate(mach_task_self(), thread_port);
159 ASSERT(r == KERN_SUCCESS); 159 ASSERT(r == KERN_SUCCESS);
160 int64_t thread_cpu_micros = 160 int64_t thread_cpu_micros =
161 (info->system_time.seconds + info->user_time.seconds); 161 (info->system_time.seconds + info->user_time.seconds);
162 thread_cpu_micros *= kMicrosecondsPerSecond; 162 thread_cpu_micros *= kMicrosecondsPerSecond;
163 thread_cpu_micros += info->user_time.microseconds; 163 thread_cpu_micros += info->user_time.microseconds;
164 thread_cpu_micros += info->system_time.microseconds; 164 thread_cpu_micros += info->system_time.microseconds;
165 return thread_cpu_micros; 165 return thread_cpu_micros;
166 } 166 }
167 167
168 168
169 intptr_t OS::ActivationFrameAlignment() { 169 intptr_t OS::ActivationFrameAlignment() {
170 #if TARGET_OS_IOS 170 #if HOST_OS_IOS
171 #if TARGET_ARCH_ARM 171 #if TARGET_ARCH_ARM
172 // Even if we generate code that maintains a stronger alignment, we cannot 172 // Even if we generate code that maintains a stronger alignment, we cannot
173 // assert the stronger stack alignment because C++ code will not maintain it. 173 // assert the stronger stack alignment because C++ code will not maintain it.
174 return 8; 174 return 8;
175 #elif TARGET_ARCH_ARM64 175 #elif TARGET_ARCH_ARM64
176 return 16; 176 return 16;
177 #elif TARGET_ARCH_IA32 177 #elif TARGET_ARCH_IA32
178 return 16; // iOS simulator 178 return 16; // iOS simulator
179 #elif TARGET_ARCH_X64 179 #elif TARGET_ARCH_X64
180 return 16; // iOS simulator 180 return 16; // iOS simulator
181 #elif TARGET_ARCH_DBC 181 #elif TARGET_ARCH_DBC
182 return 16; 182 return 16;
183 #else 183 #else
184 #error Unimplemented 184 #error Unimplemented
185 #endif 185 #endif
186 #else // TARGET_OS_IOS 186 #else // HOST_OS_IOS
187 // OS X activation frames must be 16 byte-aligned; see "Mac OS X ABI 187 // OS X activation frames must be 16 byte-aligned; see "Mac OS X ABI
188 // Function Call Guide". 188 // Function Call Guide".
189 return 16; 189 return 16;
190 #endif // TARGET_OS_IOS 190 #endif // HOST_OS_IOS
191 } 191 }
192 192
193 193
194 intptr_t OS::PreferredCodeAlignment() { 194 intptr_t OS::PreferredCodeAlignment() {
195 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) || \ 195 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) || \
196 defined(TARGET_ARCH_ARM64) || defined(TARGET_ARCH_DBC) 196 defined(TARGET_ARCH_ARM64) || defined(TARGET_ARCH_DBC)
197 const int kMinimumAlignment = 32; 197 const int kMinimumAlignment = 32;
198 #elif defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_MIPS) 198 #elif defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_MIPS)
199 const int kMinimumAlignment = 16; 199 const int kMinimumAlignment = 16;
200 #else 200 #else
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 len++; 307 len++;
308 } 308 }
309 return len; 309 return len;
310 #else // !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || ... 310 #else // !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || ...
311 return strnlen(s, n); 311 return strnlen(s, n);
312 #endif // !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || ... 312 #endif // !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || ...
313 } 313 }
314 314
315 315
316 void OS::Print(const char* format, ...) { 316 void OS::Print(const char* format, ...) {
317 #if TARGET_OS_IOS 317 #if HOST_OS_IOS
318 va_list args; 318 va_list args;
319 va_start(args, format); 319 va_start(args, format);
320 vsyslog(LOG_INFO, format, args); 320 vsyslog(LOG_INFO, format, args);
321 va_end(args); 321 va_end(args);
322 #else 322 #else
323 va_list args; 323 va_list args;
324 va_start(args, format); 324 va_start(args, format);
325 VFPrint(stdout, format, args); 325 VFPrint(stdout, format, args);
326 va_end(args); 326 va_end(args);
327 #endif 327 #endif
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 errno = 0; 400 errno = 0;
401 *value = strtoll(str, &endptr, base); 401 *value = strtoll(str, &endptr, base);
402 return ((errno == 0) && (endptr != str) && (*endptr == 0)); 402 return ((errno == 0) && (endptr != str) && (*endptr == 0));
403 } 403 }
404 404
405 405
406 void OS::RegisterCodeObservers() {} 406 void OS::RegisterCodeObservers() {}
407 407
408 408
409 void OS::PrintErr(const char* format, ...) { 409 void OS::PrintErr(const char* format, ...) {
410 #if TARGET_OS_IOS 410 #if HOST_OS_IOS
411 va_list args; 411 va_list args;
412 va_start(args, format); 412 va_start(args, format);
413 vsyslog(LOG_ERR, format, args); 413 vsyslog(LOG_ERR, format, args);
414 va_end(args); 414 va_end(args);
415 #else 415 #else
416 va_list args; 416 va_list args;
417 va_start(args, format); 417 va_start(args, format);
418 VFPrint(stderr, format, args); 418 VFPrint(stderr, format, args);
419 va_end(args); 419 va_end(args);
420 #endif 420 #endif
(...skipping 17 matching lines...) Expand all
438 abort(); 438 abort();
439 } 439 }
440 440
441 441
442 void OS::Exit(int code) { 442 void OS::Exit(int code) {
443 exit(code); 443 exit(code);
444 } 444 }
445 445
446 } // namespace dart 446 } // namespace dart
447 447
448 #endif // defined(TARGET_OS_MACOS) 448 #endif // defined(HOST_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/vm/os_linux.cc ('k') | runtime/vm/os_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698