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 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1015 #if defined(__ANDROID__) | 1015 #if defined(__ANDROID__) |
1016 // Android's C library provides gettid(2). | 1016 // Android's C library provides gettid(2). |
1017 return gettid(); | 1017 return gettid(); |
1018 #else | 1018 #else |
1019 // Glibc doesn't provide a wrapper for gettid(2). | 1019 // Glibc doesn't provide a wrapper for gettid(2). |
1020 return syscall(SYS_gettid); | 1020 return syscall(SYS_gettid); |
1021 #endif | 1021 #endif |
1022 } | 1022 } |
1023 | 1023 |
1024 | 1024 |
1025 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { | |
1026 USE(info); | |
1027 if (signal != SIGPROF) return; | |
1028 Isolate* isolate = Isolate::UncheckedCurrent(); | |
1029 if (isolate == NULL || !isolate->IsInitialized() || !isolate->IsInUse()) { | |
1030 // We require a fully initialized and entered isolate. | |
1031 return; | |
1032 } | |
1033 if (v8::Locker::IsActive() && | |
1034 !isolate->thread_manager()->IsLockedByCurrentThread()) { | |
1035 return; | |
1036 } | |
1037 | |
1038 Sampler* sampler = isolate->logger()->sampler(); | |
1039 if (sampler == NULL || !sampler->IsActive()) return; | |
1040 | |
1041 TickSample sample_obj; | |
1042 TickSample* sample = CpuProfiler::TickSampleEvent(isolate); | |
1043 if (sample == NULL) sample = &sample_obj; | |
1044 | |
1045 // Extracting the sample from the context is extremely machine dependent. | |
1046 ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); | |
1047 mcontext_t& mcontext = ucontext->uc_mcontext; | |
1048 sample->state = isolate->current_vm_state(); | |
1049 #if V8_HOST_ARCH_IA32 | |
1050 sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_EIP]); | |
1051 sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_ESP]); | |
1052 sample->fp = reinterpret_cast<Address>(mcontext.gregs[REG_EBP]); | |
1053 #elif V8_HOST_ARCH_X64 | |
1054 sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_RIP]); | |
1055 sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_RSP]); | |
1056 sample->fp = reinterpret_cast<Address>(mcontext.gregs[REG_RBP]); | |
1057 #elif V8_HOST_ARCH_ARM | |
1058 #if defined(__GLIBC__) && !defined(__UCLIBC__) && \ | |
1059 (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3)) | |
1060 // Old GLibc ARM versions used a gregs[] array to access the register | |
1061 // values from mcontext_t. | |
1062 sample->pc = reinterpret_cast<Address>(mcontext.gregs[R15]); | |
1063 sample->sp = reinterpret_cast<Address>(mcontext.gregs[R13]); | |
1064 sample->fp = reinterpret_cast<Address>(mcontext.gregs[R11]); | |
1065 #else | |
1066 sample->pc = reinterpret_cast<Address>(mcontext.arm_pc); | |
1067 sample->sp = reinterpret_cast<Address>(mcontext.arm_sp); | |
1068 sample->fp = reinterpret_cast<Address>(mcontext.arm_fp); | |
1069 #endif // defined(__GLIBC__) && !defined(__UCLIBC__) && | |
1070 // (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3)) | |
1071 #elif V8_HOST_ARCH_MIPS | |
1072 sample->pc = reinterpret_cast<Address>(mcontext.pc); | |
1073 sample->sp = reinterpret_cast<Address>(mcontext.gregs[29]); | |
1074 sample->fp = reinterpret_cast<Address>(mcontext.gregs[30]); | |
1075 #endif // V8_HOST_ARCH_* | |
1076 sampler->SampleStack(sample); | |
1077 sampler->Tick(sample); | |
1078 } | |
1079 | |
1080 | |
1081 class Sampler::PlatformData : public Malloced { | 1025 class Sampler::PlatformData : public Malloced { |
1082 public: | 1026 public: |
1083 PlatformData() : vm_tid_(GetThreadID()) {} | 1027 PlatformData() : vm_tid_(GetThreadID()) {} |
1084 | 1028 |
1085 int vm_tid() const { return vm_tid_; } | 1029 int vm_tid() const { return vm_tid_; } |
1086 | 1030 |
1087 private: | 1031 private: |
1088 const int vm_tid_; | 1032 const int vm_tid_; |
1089 }; | 1033 }; |
1090 | 1034 |
1091 | 1035 |
1036 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context); | |
1037 | |
1038 | |
1092 class SignalSender : public Thread { | 1039 class SignalSender : public Thread { |
1093 public: | 1040 public: |
1094 enum SleepInterval { | 1041 enum SleepInterval { |
1095 HALF_INTERVAL, | 1042 HALF_INTERVAL, |
1096 FULL_INTERVAL | 1043 FULL_INTERVAL |
1097 }; | 1044 }; |
1098 | 1045 |
1099 static const int kSignalSenderStackSize = 64 * KB; | 1046 static const int kSignalSenderStackSize = 64 * KB; |
1100 | 1047 |
1101 explicit SignalSender(int interval) | 1048 explicit SignalSender(int interval) |
(...skipping 13 matching lines...) Expand all Loading... | |
1115 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); | 1062 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); |
1116 } | 1063 } |
1117 | 1064 |
1118 static void RestoreSignalHandler() { | 1065 static void RestoreSignalHandler() { |
1119 if (signal_handler_installed_) { | 1066 if (signal_handler_installed_) { |
1120 sigaction(SIGPROF, &old_signal_handler_, 0); | 1067 sigaction(SIGPROF, &old_signal_handler_, 0); |
1121 signal_handler_installed_ = false; | 1068 signal_handler_installed_ = false; |
1122 } | 1069 } |
1123 } | 1070 } |
1124 | 1071 |
1072 static void CallOldSignalHandler(int signal, siginfo_t* info, void* context) { | |
1073 if (signal_handler_installed_ && old_signal_handler_.sa_sigaction) | |
willchan no longer on Chromium
2012/12/12 22:28:37
old_signal_handler_.sa_sigaction is 0x1 in the cra
danno
2012/12/13 00:00:19
Go ahead and re-open this one, since I'd like to m
willchan no longer on Chromium
2012/12/13 00:15:58
Don't worry, that's exactly why I added Markus to
| |
1074 old_signal_handler_.sa_sigaction(signal, info, context); | |
Markus (顧孟勤)
2012/12/12 22:58:17
If you want to do this right, things get a lot mor
willchan no longer on Chromium
2012/12/13 00:15:58
Yeah, I'm going to skip almost all the corner case
| |
1075 } | |
1076 | |
1125 static void AddActiveSampler(Sampler* sampler) { | 1077 static void AddActiveSampler(Sampler* sampler) { |
1126 ScopedLock lock(mutex_); | 1078 ScopedLock lock(mutex_); |
1127 SamplerRegistry::AddActiveSampler(sampler); | 1079 SamplerRegistry::AddActiveSampler(sampler); |
1128 if (instance_ == NULL) { | 1080 if (instance_ == NULL) { |
1129 // Start a thread that will send SIGPROF signal to VM threads, | 1081 // Start a thread that will send SIGPROF signal to VM threads, |
1130 // when CPU profiling will be enabled. | 1082 // when CPU profiling will be enabled. |
1131 instance_ = new SignalSender(sampler->interval()); | 1083 instance_ = new SignalSender(sampler->interval()); |
1132 instance_->Start(); | 1084 instance_->Start(); |
1133 } else { | 1085 } else { |
1134 ASSERT(instance_->interval_ == sampler->interval()); | 1086 ASSERT(instance_->interval_ == sampler->interval()); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1248 DISALLOW_COPY_AND_ASSIGN(SignalSender); | 1200 DISALLOW_COPY_AND_ASSIGN(SignalSender); |
1249 }; | 1201 }; |
1250 | 1202 |
1251 | 1203 |
1252 Mutex* SignalSender::mutex_ = NULL; | 1204 Mutex* SignalSender::mutex_ = NULL; |
1253 SignalSender* SignalSender::instance_ = NULL; | 1205 SignalSender* SignalSender::instance_ = NULL; |
1254 struct sigaction SignalSender::old_signal_handler_; | 1206 struct sigaction SignalSender::old_signal_handler_; |
1255 bool SignalSender::signal_handler_installed_ = false; | 1207 bool SignalSender::signal_handler_installed_ = false; |
1256 | 1208 |
1257 | 1209 |
1210 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { | |
1211 USE(info); | |
1212 if (signal != SIGPROF) return; | |
Markus (顧孟勤)
2012/12/12 22:58:17
This seems somewhat bogus. That really should neve
| |
1213 SignalSender::CallOldSignalHandler(signal, info, context); | |
1214 Isolate* isolate = Isolate::UncheckedCurrent(); | |
1215 if (isolate == NULL || !isolate->IsInitialized() || !isolate->IsInUse()) { | |
1216 // We require a fully initialized and entered isolate. | |
1217 return; | |
1218 } | |
1219 if (v8::Locker::IsActive() && | |
1220 !isolate->thread_manager()->IsLockedByCurrentThread()) { | |
1221 return; | |
1222 } | |
1223 | |
1224 Sampler* sampler = isolate->logger()->sampler(); | |
1225 if (sampler == NULL || !sampler->IsActive()) return; | |
1226 | |
1227 TickSample sample_obj; | |
1228 TickSample* sample = CpuProfiler::TickSampleEvent(isolate); | |
1229 if (sample == NULL) sample = &sample_obj; | |
1230 | |
1231 // Extracting the sample from the context is extremely machine dependent. | |
1232 ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); | |
1233 mcontext_t& mcontext = ucontext->uc_mcontext; | |
1234 sample->state = isolate->current_vm_state(); | |
1235 #if V8_HOST_ARCH_IA32 | |
1236 sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_EIP]); | |
1237 sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_ESP]); | |
1238 sample->fp = reinterpret_cast<Address>(mcontext.gregs[REG_EBP]); | |
1239 #elif V8_HOST_ARCH_X64 | |
1240 sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_RIP]); | |
1241 sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_RSP]); | |
1242 sample->fp = reinterpret_cast<Address>(mcontext.gregs[REG_RBP]); | |
1243 #elif V8_HOST_ARCH_ARM | |
1244 #if defined(__GLIBC__) && !defined(__UCLIBC__) && \ | |
1245 (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3)) | |
1246 // Old GLibc ARM versions used a gregs[] array to access the register | |
1247 // values from mcontext_t. | |
1248 sample->pc = reinterpret_cast<Address>(mcontext.gregs[R15]); | |
1249 sample->sp = reinterpret_cast<Address>(mcontext.gregs[R13]); | |
1250 sample->fp = reinterpret_cast<Address>(mcontext.gregs[R11]); | |
1251 #else | |
1252 sample->pc = reinterpret_cast<Address>(mcontext.arm_pc); | |
1253 sample->sp = reinterpret_cast<Address>(mcontext.arm_sp); | |
1254 sample->fp = reinterpret_cast<Address>(mcontext.arm_fp); | |
1255 #endif // defined(__GLIBC__) && !defined(__UCLIBC__) && | |
1256 // (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3)) | |
1257 #elif V8_HOST_ARCH_MIPS | |
1258 sample->pc = reinterpret_cast<Address>(mcontext.pc); | |
1259 sample->sp = reinterpret_cast<Address>(mcontext.gregs[29]); | |
1260 sample->fp = reinterpret_cast<Address>(mcontext.gregs[30]); | |
1261 #endif // V8_HOST_ARCH_* | |
1262 sampler->SampleStack(sample); | |
1263 sampler->Tick(sample); | |
Markus (顧孟勤)
2012/12/12 22:58:17
I don't see any code here that preserves "errno".
| |
1264 } | |
1265 | |
1266 | |
1258 void OS::SetUp() { | 1267 void OS::SetUp() { |
1259 // Seed the random number generator. We preserve microsecond resolution. | 1268 // Seed the random number generator. We preserve microsecond resolution. |
1260 uint64_t seed = Ticks() ^ (getpid() << 16); | 1269 uint64_t seed = Ticks() ^ (getpid() << 16); |
1261 srandom(static_cast<unsigned int>(seed)); | 1270 srandom(static_cast<unsigned int>(seed)); |
1262 limit_mutex = CreateMutex(); | 1271 limit_mutex = CreateMutex(); |
1263 | 1272 |
1264 #ifdef __arm__ | 1273 #ifdef __arm__ |
1265 // When running on ARM hardware check that the EABI used by V8 and | 1274 // When running on ARM hardware check that the EABI used by V8 and |
1266 // by the C code is the same. | 1275 // by the C code is the same. |
1267 bool hard_float = OS::ArmUsingHardFloat(); | 1276 bool hard_float = OS::ArmUsingHardFloat(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1313 | 1322 |
1314 | 1323 |
1315 void Sampler::Stop() { | 1324 void Sampler::Stop() { |
1316 ASSERT(IsActive()); | 1325 ASSERT(IsActive()); |
1317 SignalSender::RemoveActiveSampler(this); | 1326 SignalSender::RemoveActiveSampler(this); |
1318 SetActive(false); | 1327 SetActive(false); |
1319 } | 1328 } |
1320 | 1329 |
1321 | 1330 |
1322 } } // namespace v8::internal | 1331 } } // namespace v8::internal |
OLD | NEW |