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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 | 73 |
74 double ceiling(double x) { | 74 double ceiling(double x) { |
75 return ceil(x); | 75 return ceil(x); |
76 } | 76 } |
77 | 77 |
78 | 78 |
79 static Mutex* limit_mutex = NULL; | 79 static Mutex* limit_mutex = NULL; |
80 | 80 |
81 | 81 |
82 void OS::SetUp() { | 82 void OS::PostSetUp() { |
83 // Seed the random number generator. We preserve microsecond resolution. | 83 POSIXPostSetUp(); |
84 uint64_t seed = Ticks() ^ (getpid() << 16); | |
85 srandom(static_cast<unsigned int>(seed)); | |
86 limit_mutex = CreateMutex(); | |
87 | |
88 #ifdef __arm__ | |
89 // When running on ARM hardware check that the EABI used by V8 and | |
90 // by the C code is the same. | |
91 bool hard_float = OS::ArmUsingHardFloat(); | |
92 if (hard_float) { | |
93 #if !USE_EABI_HARDFLOAT | |
94 PrintF("ERROR: Binary compiled with -mfloat-abi=hard but without " | |
95 "-DUSE_EABI_HARDFLOAT\n"); | |
96 exit(1); | |
97 #endif | |
98 } else { | |
99 #if USE_EABI_HARDFLOAT | |
100 PrintF("ERROR: Binary not compiled with -mfloat-abi=hard but with " | |
101 "-DUSE_EABI_HARDFLOAT\n"); | |
102 exit(1); | |
103 #endif | |
104 } | |
105 #endif | |
106 } | 84 } |
107 | 85 |
108 | 86 |
109 void OS::PostSetUp() { | |
110 // Math functions depend on CPU features therefore they are initialized after | |
111 // CPU. | |
112 MathSetup(); | |
113 } | |
114 | |
115 | |
116 uint64_t OS::CpuFeaturesImpliedByPlatform() { | 87 uint64_t OS::CpuFeaturesImpliedByPlatform() { |
117 return 0; // Linux runs on anything. | 88 return 0; // Linux runs on anything. |
118 } | 89 } |
119 | 90 |
120 | 91 |
121 #ifdef __arm__ | 92 #ifdef __arm__ |
122 static bool CPUInfoContainsString(const char * search_string) { | 93 static bool CPUInfoContainsString(const char * search_string) { |
123 const char* file_name = "/proc/cpuinfo"; | 94 const char* file_name = "/proc/cpuinfo"; |
124 // This is written as a straight shot one pass parser | 95 // This is written as a straight shot one pass parser |
125 // and not using STL string and ifstream because, | 96 // and not using STL string and ifstream because, |
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 FULL_INTERVAL | 1048 FULL_INTERVAL |
1078 }; | 1049 }; |
1079 | 1050 |
1080 static const int kSignalSenderStackSize = 64 * KB; | 1051 static const int kSignalSenderStackSize = 64 * KB; |
1081 | 1052 |
1082 explicit SignalSender(int interval) | 1053 explicit SignalSender(int interval) |
1083 : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)), | 1054 : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)), |
1084 vm_tgid_(getpid()), | 1055 vm_tgid_(getpid()), |
1085 interval_(interval) {} | 1056 interval_(interval) {} |
1086 | 1057 |
| 1058 static void SetUp() { |
| 1059 if (!mutex_) { |
| 1060 mutex_ = OS::CreateMutex(); |
| 1061 } |
| 1062 } |
| 1063 |
1087 static void InstallSignalHandler() { | 1064 static void InstallSignalHandler() { |
1088 struct sigaction sa; | 1065 struct sigaction sa; |
1089 sa.sa_sigaction = ProfilerSignalHandler; | 1066 sa.sa_sigaction = ProfilerSignalHandler; |
1090 sigemptyset(&sa.sa_mask); | 1067 sigemptyset(&sa.sa_mask); |
1091 sa.sa_flags = SA_RESTART | SA_SIGINFO; | 1068 sa.sa_flags = SA_RESTART | SA_SIGINFO; |
1092 signal_handler_installed_ = | 1069 signal_handler_installed_ = |
1093 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); | 1070 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); |
1094 } | 1071 } |
1095 | 1072 |
1096 static void RestoreSignalHandler() { | 1073 static void RestoreSignalHandler() { |
1097 if (signal_handler_installed_) { | 1074 if (signal_handler_installed_) { |
1098 sigaction(SIGPROF, &old_signal_handler_, 0); | 1075 sigaction(SIGPROF, &old_signal_handler_, 0); |
1099 signal_handler_installed_ = false; | 1076 signal_handler_installed_ = false; |
1100 } | 1077 } |
1101 } | 1078 } |
1102 | 1079 |
1103 static void AddActiveSampler(Sampler* sampler) { | 1080 static void AddActiveSampler(Sampler* sampler) { |
1104 ScopedLock lock(mutex_.Pointer()); | 1081 ScopedLock lock(mutex_); |
1105 SamplerRegistry::AddActiveSampler(sampler); | 1082 SamplerRegistry::AddActiveSampler(sampler); |
1106 if (instance_ == NULL) { | 1083 if (instance_ == NULL) { |
1107 // Start a thread that will send SIGPROF signal to VM threads, | 1084 // Start a thread that will send SIGPROF signal to VM threads, |
1108 // when CPU profiling will be enabled. | 1085 // when CPU profiling will be enabled. |
1109 instance_ = new SignalSender(sampler->interval()); | 1086 instance_ = new SignalSender(sampler->interval()); |
1110 instance_->Start(); | 1087 instance_->Start(); |
1111 } else { | 1088 } else { |
1112 ASSERT(instance_->interval_ == sampler->interval()); | 1089 ASSERT(instance_->interval_ == sampler->interval()); |
1113 } | 1090 } |
1114 } | 1091 } |
1115 | 1092 |
1116 static void RemoveActiveSampler(Sampler* sampler) { | 1093 static void RemoveActiveSampler(Sampler* sampler) { |
1117 ScopedLock lock(mutex_.Pointer()); | 1094 ScopedLock lock(mutex_); |
1118 SamplerRegistry::RemoveActiveSampler(sampler); | 1095 SamplerRegistry::RemoveActiveSampler(sampler); |
1119 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { | 1096 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { |
1120 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); | 1097 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); |
1121 delete instance_; | 1098 delete instance_; |
1122 instance_ = NULL; | 1099 instance_ = NULL; |
1123 RestoreSignalHandler(); | 1100 RestoreSignalHandler(); |
1124 } | 1101 } |
1125 } | 1102 } |
1126 | 1103 |
1127 // Implement Thread::Run(). | 1104 // Implement Thread::Run(). |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1210 #endif // DEBUG | 1187 #endif // DEBUG |
1211 USE(result); | 1188 USE(result); |
1212 #endif // ANDROID | 1189 #endif // ANDROID |
1213 } | 1190 } |
1214 | 1191 |
1215 const int vm_tgid_; | 1192 const int vm_tgid_; |
1216 const int interval_; | 1193 const int interval_; |
1217 RuntimeProfilerRateLimiter rate_limiter_; | 1194 RuntimeProfilerRateLimiter rate_limiter_; |
1218 | 1195 |
1219 // Protects the process wide state below. | 1196 // Protects the process wide state below. |
1220 static LazyMutex mutex_; | 1197 static Mutex* mutex_; |
1221 static SignalSender* instance_; | 1198 static SignalSender* instance_; |
1222 static bool signal_handler_installed_; | 1199 static bool signal_handler_installed_; |
1223 static struct sigaction old_signal_handler_; | 1200 static struct sigaction old_signal_handler_; |
1224 | 1201 |
1225 private: | 1202 private: |
1226 DISALLOW_COPY_AND_ASSIGN(SignalSender); | 1203 DISALLOW_COPY_AND_ASSIGN(SignalSender); |
1227 }; | 1204 }; |
1228 | 1205 |
1229 | 1206 |
1230 LazyMutex SignalSender::mutex_ = LAZY_MUTEX_INITIALIZER; | 1207 Mutex* SignalSender::mutex_ = NULL; |
1231 SignalSender* SignalSender::instance_ = NULL; | 1208 SignalSender* SignalSender::instance_ = NULL; |
1232 struct sigaction SignalSender::old_signal_handler_; | 1209 struct sigaction SignalSender::old_signal_handler_; |
1233 bool SignalSender::signal_handler_installed_ = false; | 1210 bool SignalSender::signal_handler_installed_ = false; |
1234 | 1211 |
1235 | 1212 |
| 1213 void OS::SetUp() { |
| 1214 // Seed the random number generator. We preserve microsecond resolution. |
| 1215 uint64_t seed = Ticks() ^ (getpid() << 16); |
| 1216 srandom(static_cast<unsigned int>(seed)); |
| 1217 limit_mutex = CreateMutex(); |
| 1218 |
| 1219 #ifdef __arm__ |
| 1220 // When running on ARM hardware check that the EABI used by V8 and |
| 1221 // by the C code is the same. |
| 1222 bool hard_float = OS::ArmUsingHardFloat(); |
| 1223 if (hard_float) { |
| 1224 #if !USE_EABI_HARDFLOAT |
| 1225 PrintF("ERROR: Binary compiled with -mfloat-abi=hard but without " |
| 1226 "-DUSE_EABI_HARDFLOAT\n"); |
| 1227 exit(1); |
| 1228 #endif |
| 1229 } else { |
| 1230 #if USE_EABI_HARDFLOAT |
| 1231 PrintF("ERROR: Binary not compiled with -mfloat-abi=hard but with " |
| 1232 "-DUSE_EABI_HARDFLOAT\n"); |
| 1233 exit(1); |
| 1234 #endif |
| 1235 } |
| 1236 #endif |
| 1237 SignalSender::SetUp(); |
| 1238 } |
| 1239 |
| 1240 |
1236 Sampler::Sampler(Isolate* isolate, int interval) | 1241 Sampler::Sampler(Isolate* isolate, int interval) |
1237 : isolate_(isolate), | 1242 : isolate_(isolate), |
1238 interval_(interval), | 1243 interval_(interval), |
1239 profiling_(false), | 1244 profiling_(false), |
1240 active_(false), | 1245 active_(false), |
1241 samples_taken_(0) { | 1246 samples_taken_(0) { |
1242 data_ = new PlatformData; | 1247 data_ = new PlatformData; |
1243 } | 1248 } |
1244 | 1249 |
1245 | 1250 |
(...skipping 11 matching lines...) Expand all Loading... |
1257 | 1262 |
1258 | 1263 |
1259 void Sampler::Stop() { | 1264 void Sampler::Stop() { |
1260 ASSERT(IsActive()); | 1265 ASSERT(IsActive()); |
1261 SignalSender::RemoveActiveSampler(this); | 1266 SignalSender::RemoveActiveSampler(this); |
1262 SetActive(false); | 1267 SetActive(false); |
1263 } | 1268 } |
1264 | 1269 |
1265 | 1270 |
1266 } } // namespace v8::internal | 1271 } } // namespace v8::internal |
OLD | NEW |