OLD | NEW |
---|---|
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 #include "vm-state-inl.h" | 70 #include "vm-state-inl.h" |
71 | 71 |
72 | 72 |
73 namespace v8 { | 73 namespace v8 { |
74 namespace internal { | 74 namespace internal { |
75 | 75 |
76 // 0 is never a valid thread id on Linux since tids and pids share a | 76 // 0 is never a valid thread id on Linux since tids and pids share a |
77 // name space and pid 0 is reserved (see man 2 kill). | 77 // name space and pid 0 is reserved (see man 2 kill). |
78 static const pthread_t kNoThread = (pthread_t) 0; | 78 static const pthread_t kNoThread = (pthread_t) 0; |
79 | 79 |
80 static void (*g_old_signal_handler)(int, siginfo_t *, void *) = NULL; | |
danno
2012/10/19 07:43:16
I don't think you need to store this separately. A
| |
80 | 81 |
81 double ceiling(double x) { | 82 double ceiling(double x) { |
82 return ceil(x); | 83 return ceil(x); |
83 } | 84 } |
84 | 85 |
85 | 86 |
86 static Mutex* limit_mutex = NULL; | 87 static Mutex* limit_mutex = NULL; |
87 | 88 |
88 | 89 |
89 void OS::PostSetUp() { | 90 void OS::PostSetUp() { |
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1013 #else | 1014 #else |
1014 // Glibc doesn't provide a wrapper for gettid(2). | 1015 // Glibc doesn't provide a wrapper for gettid(2). |
1015 return syscall(SYS_gettid); | 1016 return syscall(SYS_gettid); |
1016 #endif | 1017 #endif |
1017 } | 1018 } |
1018 | 1019 |
1019 | 1020 |
1020 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { | 1021 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { |
1021 USE(info); | 1022 USE(info); |
1022 if (signal != SIGPROF) return; | 1023 if (signal != SIGPROF) return; |
1024 if (g_old_signal_handler) g_old_signal_handler(signal, info, context); | |
1023 Isolate* isolate = Isolate::UncheckedCurrent(); | 1025 Isolate* isolate = Isolate::UncheckedCurrent(); |
1024 if (isolate == NULL || !isolate->IsInitialized() || !isolate->IsInUse()) { | 1026 if (isolate == NULL || !isolate->IsInitialized() || !isolate->IsInUse()) { |
1025 // We require a fully initialized and entered isolate. | 1027 // We require a fully initialized and entered isolate. |
1026 return; | 1028 return; |
1027 } | 1029 } |
1028 if (v8::Locker::IsActive() && | 1030 if (v8::Locker::IsActive() && |
1029 !isolate->thread_manager()->IsLockedByCurrentThread()) { | 1031 !isolate->thread_manager()->IsLockedByCurrentThread()) { |
1030 return; | 1032 return; |
1031 } | 1033 } |
1032 | 1034 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1101 static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } | 1103 static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } |
1102 static void TearDown() { delete mutex_; } | 1104 static void TearDown() { delete mutex_; } |
1103 | 1105 |
1104 static void InstallSignalHandler() { | 1106 static void InstallSignalHandler() { |
1105 struct sigaction sa; | 1107 struct sigaction sa; |
1106 sa.sa_sigaction = ProfilerSignalHandler; | 1108 sa.sa_sigaction = ProfilerSignalHandler; |
1107 sigemptyset(&sa.sa_mask); | 1109 sigemptyset(&sa.sa_mask); |
1108 sa.sa_flags = SA_RESTART | SA_SIGINFO; | 1110 sa.sa_flags = SA_RESTART | SA_SIGINFO; |
1109 signal_handler_installed_ = | 1111 signal_handler_installed_ = |
1110 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); | 1112 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); |
1113 if (signal_handler_installed_) | |
1114 g_old_signal_handler = old_signal_handler_.sa_sigaction; | |
1111 } | 1115 } |
1112 | 1116 |
1113 static void RestoreSignalHandler() { | 1117 static void RestoreSignalHandler() { |
1114 if (signal_handler_installed_) { | 1118 if (signal_handler_installed_) { |
1115 sigaction(SIGPROF, &old_signal_handler_, 0); | 1119 sigaction(SIGPROF, &old_signal_handler_, 0); |
1120 g_old_signal_handler = NULL; | |
1116 signal_handler_installed_ = false; | 1121 signal_handler_installed_ = false; |
1117 } | 1122 } |
1118 } | 1123 } |
1119 | 1124 |
1120 static void AddActiveSampler(Sampler* sampler) { | 1125 static void AddActiveSampler(Sampler* sampler) { |
1121 ScopedLock lock(mutex_); | 1126 ScopedLock lock(mutex_); |
1122 SamplerRegistry::AddActiveSampler(sampler); | 1127 SamplerRegistry::AddActiveSampler(sampler); |
1123 if (instance_ == NULL) { | 1128 if (instance_ == NULL) { |
1124 // Start a thread that will send SIGPROF signal to VM threads, | 1129 // Start a thread that will send SIGPROF signal to VM threads, |
1125 // when CPU profiling will be enabled. | 1130 // when CPU profiling will be enabled. |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1308 | 1313 |
1309 | 1314 |
1310 void Sampler::Stop() { | 1315 void Sampler::Stop() { |
1311 ASSERT(IsActive()); | 1316 ASSERT(IsActive()); |
1312 SignalSender::RemoveActiveSampler(this); | 1317 SignalSender::RemoveActiveSampler(this); |
1313 SetActive(false); | 1318 SetActive(false); |
1314 } | 1319 } |
1315 | 1320 |
1316 | 1321 |
1317 } } // namespace v8::internal | 1322 } } // namespace v8::internal |
OLD | NEW |