| OLD | NEW |
| 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(TARGET_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 defined(TARGET_OS_IOS) | 18 #if TARGET_OS_IOS |
| 19 #include <sys/sysctl.h> | 19 #include <sys/sysctl.h> |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 #include "platform/utils.h" | 22 #include "platform/utils.h" |
| 23 #include "vm/isolate.h" | 23 #include "vm/isolate.h" |
| 24 #include "vm/zone.h" | 24 #include "vm/zone.h" |
| 25 | 25 |
| 26 namespace dart { | 26 namespace dart { |
| 27 | 27 |
| 28 const char* OS::Name() { | 28 const char* OS::Name() { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 struct timeval tv; | 79 struct timeval tv; |
| 80 if (gettimeofday(&tv, NULL) < 0) { | 80 if (gettimeofday(&tv, NULL) < 0) { |
| 81 UNREACHABLE(); | 81 UNREACHABLE(); |
| 82 return 0; | 82 return 0; |
| 83 } | 83 } |
| 84 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec; | 84 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec; |
| 85 } | 85 } |
| 86 | 86 |
| 87 | 87 |
| 88 int64_t OS::GetCurrentTraceMicros() { | 88 int64_t OS::GetCurrentTraceMicros() { |
| 89 #if defined(TARGET_OS_IOS) | 89 #if TARGET_OS_IOS |
| 90 // On iOS mach_absolute_time stops while the device is sleeping. Instead use | 90 // On iOS mach_absolute_time stops while the device is sleeping. Instead use |
| 91 // now - KERN_BOOTTIME to get a time difference that is not impacted by clock | 91 // now - KERN_BOOTTIME to get a time difference that is not impacted by clock |
| 92 // changes. KERN_BOOTTIME will be updated by the system whenever the system | 92 // changes. KERN_BOOTTIME will be updated by the system whenever the system |
| 93 // clock change. | 93 // clock change. |
| 94 struct timeval boottime; | 94 struct timeval boottime; |
| 95 int mib[2] = {CTL_KERN, KERN_BOOTTIME}; | 95 int mib[2] = {CTL_KERN, KERN_BOOTTIME}; |
| 96 size_t size = sizeof(boottime); | 96 size_t size = sizeof(boottime); |
| 97 int kr = sysctl(mib, sizeof(mib) / sizeof(mib[0]), &boottime, &size, NULL, 0); | 97 int kr = sysctl(mib, sizeof(mib) / sizeof(mib[0]), &boottime, &size, NULL, 0); |
| 98 ASSERT(KERN_SUCCESS == kr); | 98 ASSERT(KERN_SUCCESS == kr); |
| 99 int64_t now = GetCurrentTimeMicros(); | 99 int64_t now = GetCurrentTimeMicros(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 111 kern_return_t kr = mach_timebase_info(&timebase_info); | 111 kern_return_t kr = mach_timebase_info(&timebase_info); |
| 112 ASSERT(KERN_SUCCESS == kr); | 112 ASSERT(KERN_SUCCESS == kr); |
| 113 } | 113 } |
| 114 | 114 |
| 115 // timebase_info converts absolute time tick units into nanoseconds. Convert | 115 // timebase_info converts absolute time tick units into nanoseconds. Convert |
| 116 // to microseconds. | 116 // to microseconds. |
| 117 int64_t result = mach_absolute_time() / kNanosecondsPerMicrosecond; | 117 int64_t result = mach_absolute_time() / kNanosecondsPerMicrosecond; |
| 118 result *= timebase_info.numer; | 118 result *= timebase_info.numer; |
| 119 result /= timebase_info.denom; | 119 result /= timebase_info.denom; |
| 120 return result; | 120 return result; |
| 121 #endif // defined(TARGET_OS_IOS) | 121 #endif // TARGET_OS_IOS |
| 122 } | 122 } |
| 123 | 123 |
| 124 | 124 |
| 125 void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) { | 125 void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) { |
| 126 const int kMinimumAlignment = 16; | 126 const int kMinimumAlignment = 16; |
| 127 ASSERT(Utils::IsPowerOfTwo(alignment)); | 127 ASSERT(Utils::IsPowerOfTwo(alignment)); |
| 128 ASSERT(alignment >= kMinimumAlignment); | 128 ASSERT(alignment >= kMinimumAlignment); |
| 129 // Temporary workaround until xcode is upgraded. | 129 // Temporary workaround until xcode is upgraded. |
| 130 // Mac guarantees malloc returns a 16 byte aligned memory chunk. | 130 // Mac guarantees malloc returns a 16 byte aligned memory chunk. |
| 131 // Currently we only allocate with 16-bye alignment. | 131 // Currently we only allocate with 16-bye alignment. |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 } | 338 } |
| 339 | 339 |
| 340 | 340 |
| 341 void OS::Exit(int code) { | 341 void OS::Exit(int code) { |
| 342 exit(code); | 342 exit(code); |
| 343 } | 343 } |
| 344 | 344 |
| 345 } // namespace dart | 345 } // namespace dart |
| 346 | 346 |
| 347 #endif // defined(TARGET_OS_MACOS) | 347 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |