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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 defined(__arm__) && !defined(__BIONIC_HAVE_STRUCT_SIGCONTEXT) | 61 defined(__arm__) && !defined(__BIONIC_HAVE_STRUCT_SIGCONTEXT) |
62 #include <asm/sigcontext.h> | 62 #include <asm/sigcontext.h> |
63 #endif | 63 #endif |
64 | 64 |
65 #undef MAP_TYPE | 65 #undef MAP_TYPE |
66 | 66 |
67 #include "v8.h" | 67 #include "v8.h" |
68 | 68 |
69 #include "platform-posix.h" | 69 #include "platform-posix.h" |
70 #include "platform.h" | 70 #include "platform.h" |
| 71 #include "simulator.h" |
71 #include "v8threads.h" | 72 #include "v8threads.h" |
72 #include "vm-state-inl.h" | 73 #include "vm-state-inl.h" |
73 | 74 |
74 | 75 |
75 namespace v8 { | 76 namespace v8 { |
76 namespace internal { | 77 namespace internal { |
77 | 78 |
78 // 0 is never a valid thread id on Linux since tids and pids share a | 79 // 0 is never a valid thread id on Linux since tids and pids share a |
79 // name space and pid 0 is reserved (see man 2 kill). | 80 // name space and pid 0 is reserved (see man 2 kill). |
80 static const pthread_t kNoThread = (pthread_t) 0; | 81 static const pthread_t kNoThread = (pthread_t) 0; |
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 #if defined(__ANDROID__) | 1070 #if defined(__ANDROID__) |
1070 // Android's C library provides gettid(2). | 1071 // Android's C library provides gettid(2). |
1071 return gettid(); | 1072 return gettid(); |
1072 #else | 1073 #else |
1073 // Glibc doesn't provide a wrapper for gettid(2). | 1074 // Glibc doesn't provide a wrapper for gettid(2). |
1074 return syscall(SYS_gettid); | 1075 return syscall(SYS_gettid); |
1075 #endif | 1076 #endif |
1076 } | 1077 } |
1077 | 1078 |
1078 | 1079 |
| 1080 class Sampler::PlatformData : public Malloced { |
| 1081 public: |
| 1082 PlatformData() |
| 1083 : vm_tid_(GetThreadID()), |
| 1084 profiled_thread_id_(ThreadId::Current()) {} |
| 1085 |
| 1086 pthread_t vm_tid() const { return vm_tid_; } |
| 1087 ThreadId profiled_thread_id() { return profiled_thread_id_; } |
| 1088 |
| 1089 private: |
| 1090 pthread_t vm_tid_; |
| 1091 ThreadId profiled_thread_id_; |
| 1092 }; |
| 1093 |
| 1094 |
1079 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { | 1095 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { |
1080 #if defined(__native_client__) | 1096 #if defined(__native_client__) |
1081 // As Native Client does not support signal handling, profiling | 1097 // As Native Client does not support signal handling, profiling |
1082 // is disabled. | 1098 // is disabled. |
1083 return; | 1099 return; |
1084 #else | 1100 #else |
1085 USE(info); | 1101 USE(info); |
1086 if (signal != SIGPROF) return; | 1102 if (signal != SIGPROF) return; |
1087 Isolate* isolate = Isolate::UncheckedCurrent(); | 1103 Isolate* isolate = Isolate::UncheckedCurrent(); |
1088 if (isolate == NULL || !isolate->IsInitialized() || !isolate->IsInUse()) { | 1104 if (isolate == NULL || !isolate->IsInitialized() || !isolate->IsInUse()) { |
1089 // We require a fully initialized and entered isolate. | 1105 // We require a fully initialized and entered isolate. |
1090 return; | 1106 return; |
1091 } | 1107 } |
1092 if (v8::Locker::IsActive() && | 1108 if (v8::Locker::IsActive() && |
1093 !isolate->thread_manager()->IsLockedByCurrentThread()) { | 1109 !isolate->thread_manager()->IsLockedByCurrentThread()) { |
1094 return; | 1110 return; |
1095 } | 1111 } |
1096 | 1112 |
1097 Sampler* sampler = isolate->logger()->sampler(); | 1113 Sampler* sampler = isolate->logger()->sampler(); |
1098 if (sampler == NULL || !sampler->IsActive()) return; | 1114 if (sampler == NULL || !sampler->IsActive()) return; |
1099 | 1115 |
| 1116 #if defined(USE_SIMULATOR) |
| 1117 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS |
| 1118 ThreadId thread_id = sampler->platform_data()->profiled_thread_id(); |
| 1119 Isolate::PerIsolateThreadData* per_thread_data = isolate-> |
| 1120 FindPerThreadDataForThread(thread_id); |
| 1121 if (!per_thread_data) return; |
| 1122 Simulator* sim = per_thread_data->simulator(); |
| 1123 // Check if there is active simulator before allocating TickSample. |
| 1124 if (!sim) return; |
| 1125 #endif |
| 1126 #endif // USE_SIMULATOR |
| 1127 |
1100 TickSample sample_obj; | 1128 TickSample sample_obj; |
1101 TickSample* sample = isolate->cpu_profiler()->TickSampleEvent(); | 1129 TickSample* sample = isolate->cpu_profiler()->TickSampleEvent(); |
1102 if (sample == NULL) sample = &sample_obj; | 1130 if (sample == NULL) sample = &sample_obj; |
1103 | 1131 |
| 1132 #if defined(USE_SIMULATOR) |
| 1133 #if V8_TARGET_ARCH_ARM |
| 1134 sample->pc = reinterpret_cast<Address>(sim->get_register(Simulator::pc)); |
| 1135 sample->sp = reinterpret_cast<Address>(sim->get_register(Simulator::sp)); |
| 1136 sample->fp = reinterpret_cast<Address>(sim->get_register(Simulator::r11)); |
| 1137 #elif V8_TARGET_ARCH_MIPS |
| 1138 sample->pc = reinterpret_cast<Address>(sim->get_register(Simulator::pc)); |
| 1139 sample->sp = reinterpret_cast<Address>(sim->get_register(Simulator::sp)); |
| 1140 sample->fp = reinterpret_cast<Address>(sim->get_register(Simulator::fp)); |
| 1141 #endif |
| 1142 #else |
1104 // Extracting the sample from the context is extremely machine dependent. | 1143 // Extracting the sample from the context is extremely machine dependent. |
1105 ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); | 1144 ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); |
1106 mcontext_t& mcontext = ucontext->uc_mcontext; | 1145 mcontext_t& mcontext = ucontext->uc_mcontext; |
1107 sample->state = isolate->current_vm_state(); | 1146 sample->state = isolate->current_vm_state(); |
1108 #if V8_HOST_ARCH_IA32 | 1147 #if V8_HOST_ARCH_IA32 |
1109 sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_EIP]); | 1148 sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_EIP]); |
1110 sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_ESP]); | 1149 sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_ESP]); |
1111 sample->fp = reinterpret_cast<Address>(mcontext.gregs[REG_EBP]); | 1150 sample->fp = reinterpret_cast<Address>(mcontext.gregs[REG_EBP]); |
1112 #elif V8_HOST_ARCH_X64 | 1151 #elif V8_HOST_ARCH_X64 |
1113 sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_RIP]); | 1152 sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_RIP]); |
(...skipping 11 matching lines...) Expand all Loading... |
1125 sample->pc = reinterpret_cast<Address>(mcontext.arm_pc); | 1164 sample->pc = reinterpret_cast<Address>(mcontext.arm_pc); |
1126 sample->sp = reinterpret_cast<Address>(mcontext.arm_sp); | 1165 sample->sp = reinterpret_cast<Address>(mcontext.arm_sp); |
1127 sample->fp = reinterpret_cast<Address>(mcontext.arm_fp); | 1166 sample->fp = reinterpret_cast<Address>(mcontext.arm_fp); |
1128 #endif // defined(__GLIBC__) && !defined(__UCLIBC__) && | 1167 #endif // defined(__GLIBC__) && !defined(__UCLIBC__) && |
1129 // (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3)) | 1168 // (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3)) |
1130 #elif V8_HOST_ARCH_MIPS | 1169 #elif V8_HOST_ARCH_MIPS |
1131 sample->pc = reinterpret_cast<Address>(mcontext.pc); | 1170 sample->pc = reinterpret_cast<Address>(mcontext.pc); |
1132 sample->sp = reinterpret_cast<Address>(mcontext.gregs[29]); | 1171 sample->sp = reinterpret_cast<Address>(mcontext.gregs[29]); |
1133 sample->fp = reinterpret_cast<Address>(mcontext.gregs[30]); | 1172 sample->fp = reinterpret_cast<Address>(mcontext.gregs[30]); |
1134 #endif // V8_HOST_ARCH_* | 1173 #endif // V8_HOST_ARCH_* |
| 1174 #endif // USE_SIMULATOR |
1135 sampler->SampleStack(sample); | 1175 sampler->SampleStack(sample); |
1136 sampler->Tick(sample); | 1176 sampler->Tick(sample); |
1137 #endif // __native_client__ | 1177 #endif // __native_client__ |
1138 } | 1178 } |
1139 | 1179 |
1140 | 1180 |
1141 class Sampler::PlatformData : public Malloced { | |
1142 public: | |
1143 PlatformData() : vm_tid_(GetThreadID()) {} | |
1144 | |
1145 int vm_tid() const { return vm_tid_; } | |
1146 | |
1147 private: | |
1148 const int vm_tid_; | |
1149 }; | |
1150 | |
1151 | |
1152 class SignalSender : public Thread { | 1181 class SignalSender : public Thread { |
1153 public: | 1182 public: |
1154 static const int kSignalSenderStackSize = 64 * KB; | 1183 static const int kSignalSenderStackSize = 64 * KB; |
1155 | 1184 |
1156 explicit SignalSender(int interval) | 1185 explicit SignalSender(int interval) |
1157 : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)), | 1186 : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)), |
1158 vm_tgid_(getpid()), | 1187 vm_tgid_(getpid()), |
1159 interval_(interval) {} | 1188 interval_(interval) {} |
1160 | 1189 |
1161 static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } | 1190 static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1335 | 1364 |
1336 | 1365 |
1337 void Sampler::Stop() { | 1366 void Sampler::Stop() { |
1338 ASSERT(IsActive()); | 1367 ASSERT(IsActive()); |
1339 SignalSender::RemoveActiveSampler(this); | 1368 SignalSender::RemoveActiveSampler(this); |
1340 SetActive(false); | 1369 SetActive(false); |
1341 } | 1370 } |
1342 | 1371 |
1343 | 1372 |
1344 } } // namespace v8::internal | 1373 } } // namespace v8::internal |
OLD | NEW |