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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
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 <malloc.h> // NOLINT | 12 #include <malloc.h> // NOLINT |
13 #include <time.h> // NOLINT | 13 #include <time.h> // NOLINT |
14 #include <sys/resource.h> // NOLINT | 14 #include <sys/resource.h> // NOLINT |
15 #include <sys/time.h> // NOLINT | 15 #include <sys/time.h> // NOLINT |
16 #include <sys/types.h> // NOLINT | 16 #include <sys/types.h> // NOLINT |
17 #include <sys/syscall.h> // NOLINT | 17 #include <sys/syscall.h> // NOLINT |
18 #include <sys/stat.h> // NOLINT | 18 #include <sys/stat.h> // NOLINT |
19 #include <fcntl.h> // NOLINT | 19 #include <fcntl.h> // NOLINT |
20 #include <unistd.h> // NOLINT | 20 #include <unistd.h> // NOLINT |
21 | 21 |
22 #include "platform/memory_sanitizer.h" | 22 #include "platform/memory_sanitizer.h" |
23 #include "platform/utils.h" | 23 #include "platform/utils.h" |
24 #include "vm/code_observers.h" | 24 #include "vm/code_observers.h" |
25 #include "vm/dart.h" | 25 #include "vm/dart.h" |
26 #include "vm/flags.h" | 26 #include "vm/flags.h" |
27 #include "vm/isolate.h" | 27 #include "vm/isolate.h" |
28 #include "vm/lockers.h" | 28 #include "vm/lockers.h" |
29 #include "vm/os_thread.h" | 29 #include "vm/os_thread.h" |
30 #include "vm/zone.h" | 30 #include "vm/zone.h" |
31 | 31 |
32 | 32 |
33 namespace dart { | 33 namespace dart { |
34 | 34 |
35 #ifndef PRODUCT | 35 #ifndef PRODUCT |
36 | 36 |
37 DEFINE_FLAG(bool, generate_perf_events_symbols, false, | 37 DEFINE_FLAG(bool, |
38 "Generate events symbols for profiling with perf"); | 38 generate_perf_events_symbols, |
| 39 false, |
| 40 "Generate events symbols for profiling with perf"); |
39 | 41 |
40 // Linux CodeObservers. | 42 // Linux CodeObservers. |
41 class PerfCodeObserver : public CodeObserver { | 43 class PerfCodeObserver : public CodeObserver { |
42 public: | 44 public: |
43 PerfCodeObserver() : out_file_(NULL) { | 45 PerfCodeObserver() : out_file_(NULL) { |
44 Dart_FileOpenCallback file_open = Dart::file_open_callback(); | 46 Dart_FileOpenCallback file_open = Dart::file_open_callback(); |
45 if (file_open == NULL) { | 47 if (file_open == NULL) { |
46 return; | 48 return; |
47 } | 49 } |
48 intptr_t pid = getpid(); | 50 intptr_t pid = getpid(); |
(...skipping 17 matching lines...) Expand all Loading... |
66 virtual void Notify(const char* name, | 68 virtual void Notify(const char* name, |
67 uword base, | 69 uword base, |
68 uword prologue_offset, | 70 uword prologue_offset, |
69 uword size, | 71 uword size, |
70 bool optimized) { | 72 bool optimized) { |
71 Dart_FileWriteCallback file_write = Dart::file_write_callback(); | 73 Dart_FileWriteCallback file_write = Dart::file_write_callback(); |
72 if ((file_write == NULL) || (out_file_ == NULL)) { | 74 if ((file_write == NULL) || (out_file_ == NULL)) { |
73 return; | 75 return; |
74 } | 76 } |
75 const char* marker = optimized ? "*" : ""; | 77 const char* marker = optimized ? "*" : ""; |
76 char* buffer = OS::SCreate(Thread::Current()->zone(), | 78 char* buffer = |
77 "%" Px " %" Px " %s%s\n", base, size, marker, name); | 79 OS::SCreate(Thread::Current()->zone(), "%" Px " %" Px " %s%s\n", base, |
| 80 size, marker, name); |
78 { | 81 { |
79 MutexLocker ml(CodeObservers::mutex()); | 82 MutexLocker ml(CodeObservers::mutex()); |
80 (*file_write)(buffer, strlen(buffer), out_file_); | 83 (*file_write)(buffer, strlen(buffer), out_file_); |
81 } | 84 } |
82 } | 85 } |
83 | 86 |
84 private: | 87 private: |
85 void* out_file_; | 88 void* out_file_; |
86 | 89 |
87 DISALLOW_COPY_AND_ASSIGN(PerfCodeObserver); | 90 DISALLOW_COPY_AND_ASSIGN(PerfCodeObserver); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 int64_t result = ts.tv_sec; | 188 int64_t result = ts.tv_sec; |
186 result *= kMicrosecondsPerSecond; | 189 result *= kMicrosecondsPerSecond; |
187 result += (ts.tv_nsec / kNanosecondsPerMicrosecond); | 190 result += (ts.tv_nsec / kNanosecondsPerMicrosecond); |
188 return result; | 191 return result; |
189 } | 192 } |
190 | 193 |
191 | 194 |
192 // TODO(5411554): May need to hoist these architecture dependent code | 195 // TODO(5411554): May need to hoist these architecture dependent code |
193 // into a architecture specific file e.g: os_ia32_linux.cc | 196 // into a architecture specific file e.g: os_ia32_linux.cc |
194 intptr_t OS::ActivationFrameAlignment() { | 197 intptr_t OS::ActivationFrameAlignment() { |
195 #if defined(TARGET_ARCH_IA32) || \ | 198 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) || \ |
196 defined(TARGET_ARCH_X64) || \ | 199 defined(TARGET_ARCH_ARM64) || defined(TARGET_ARCH_DBC) |
197 defined(TARGET_ARCH_ARM64) || \ | |
198 defined(TARGET_ARCH_DBC) | |
199 const int kMinimumAlignment = 16; | 200 const int kMinimumAlignment = 16; |
200 #elif defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_MIPS) | 201 #elif defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_MIPS) |
201 const int kMinimumAlignment = 8; | 202 const int kMinimumAlignment = 8; |
202 #else | 203 #else |
203 #error Unsupported architecture. | 204 #error Unsupported architecture. |
204 #endif | 205 #endif |
205 intptr_t alignment = kMinimumAlignment; | 206 intptr_t alignment = kMinimumAlignment; |
206 // TODO(5411554): Allow overriding default stack alignment for | 207 // TODO(5411554): Allow overriding default stack alignment for |
207 // testing purposes. | 208 // testing purposes. |
208 // Flags::DebugIsInt("stackalign", &alignment); | 209 // Flags::DebugIsInt("stackalign", &alignment); |
209 ASSERT(Utils::IsPowerOfTwo(alignment)); | 210 ASSERT(Utils::IsPowerOfTwo(alignment)); |
210 ASSERT(alignment >= kMinimumAlignment); | 211 ASSERT(alignment >= kMinimumAlignment); |
211 return alignment; | 212 return alignment; |
212 } | 213 } |
213 | 214 |
214 | 215 |
215 intptr_t OS::PreferredCodeAlignment() { | 216 intptr_t OS::PreferredCodeAlignment() { |
216 #if defined(TARGET_ARCH_IA32) || \ | 217 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) || \ |
217 defined(TARGET_ARCH_X64) || \ | 218 defined(TARGET_ARCH_ARM64) || defined(TARGET_ARCH_DBC) |
218 defined(TARGET_ARCH_ARM64) || \ | |
219 defined(TARGET_ARCH_DBC) | |
220 const int kMinimumAlignment = 32; | 219 const int kMinimumAlignment = 32; |
221 #elif defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_MIPS) | 220 #elif defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_MIPS) |
222 const int kMinimumAlignment = 16; | 221 const int kMinimumAlignment = 16; |
223 #else | 222 #else |
224 #error Unsupported architecture. | 223 #error Unsupported architecture. |
225 #endif | 224 #endif |
226 intptr_t alignment = kMinimumAlignment; | 225 intptr_t alignment = kMinimumAlignment; |
227 // TODO(5411554): Allow overriding default code alignment for | 226 // TODO(5411554): Allow overriding default code alignment for |
228 // testing purposes. | 227 // testing purposes. |
229 // Flags::DebugIsInt("codealign", &alignment); | 228 // Flags::DebugIsInt("codealign", &alignment); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 | 364 |
366 | 365 |
367 bool OS::StringToInt64(const char* str, int64_t* value) { | 366 bool OS::StringToInt64(const char* str, int64_t* value) { |
368 ASSERT(str != NULL && strlen(str) > 0 && value != NULL); | 367 ASSERT(str != NULL && strlen(str) > 0 && value != NULL); |
369 int32_t base = 10; | 368 int32_t base = 10; |
370 char* endptr; | 369 char* endptr; |
371 int i = 0; | 370 int i = 0; |
372 if (str[0] == '-') { | 371 if (str[0] == '-') { |
373 i = 1; | 372 i = 1; |
374 } | 373 } |
375 if ((str[i] == '0') && | 374 if ((str[i] == '0') && (str[i + 1] == 'x' || str[i + 1] == 'X') && |
376 (str[i + 1] == 'x' || str[i + 1] == 'X') && | |
377 (str[i + 2] != '\0')) { | 375 (str[i + 2] != '\0')) { |
378 base = 16; | 376 base = 16; |
379 } | 377 } |
380 errno = 0; | 378 errno = 0; |
381 *value = strtoll(str, &endptr, base); | 379 *value = strtoll(str, &endptr, base); |
382 return ((errno == 0) && (endptr != str) && (*endptr == 0)); | 380 return ((errno == 0) && (endptr != str) && (*endptr == 0)); |
383 } | 381 } |
384 | 382 |
385 | 383 |
386 void OS::RegisterCodeObservers() { | 384 void OS::RegisterCodeObservers() { |
(...skipping 16 matching lines...) Expand all Loading... |
403 void OS::InitOnce() { | 401 void OS::InitOnce() { |
404 // TODO(5411554): For now we check that initonce is called only once, | 402 // TODO(5411554): For now we check that initonce is called only once, |
405 // Once there is more formal mechanism to call InitOnce we can move | 403 // Once there is more formal mechanism to call InitOnce we can move |
406 // this check there. | 404 // this check there. |
407 static bool init_once_called = false; | 405 static bool init_once_called = false; |
408 ASSERT(init_once_called == false); | 406 ASSERT(init_once_called == false); |
409 init_once_called = true; | 407 init_once_called = true; |
410 } | 408 } |
411 | 409 |
412 | 410 |
413 void OS::Shutdown() { | 411 void OS::Shutdown() {} |
414 } | |
415 | 412 |
416 | 413 |
417 void OS::Abort() { | 414 void OS::Abort() { |
418 abort(); | 415 abort(); |
419 } | 416 } |
420 | 417 |
421 | 418 |
422 void OS::Exit(int code) { | 419 void OS::Exit(int code) { |
423 exit(code); | 420 exit(code); |
424 } | 421 } |
425 | 422 |
426 } // namespace dart | 423 } // namespace dart |
427 | 424 |
428 #endif // defined(TARGET_OS_LINUX) | 425 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |