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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 osr_attempts_++; | 227 osr_attempts_++; |
228 } | 228 } |
229 input_queue_.Enqueue(optimizing_compiler); | 229 input_queue_.Enqueue(optimizing_compiler); |
230 input_queue_semaphore_.Signal(); | 230 input_queue_semaphore_.Signal(); |
231 } | 231 } |
232 | 232 |
233 | 233 |
234 OptimizingCompiler* OptimizingCompilerThread::FindReadyOSRCandidate( | 234 OptimizingCompiler* OptimizingCompilerThread::FindReadyOSRCandidate( |
235 Handle<JSFunction> function, uint32_t osr_pc_offset) { | 235 Handle<JSFunction> function, uint32_t osr_pc_offset) { |
236 ASSERT(!IsOptimizerThread()); | 236 ASSERT(!IsOptimizerThread()); |
237 LockGuard<Mutex> access_osr_lists(&osr_list_mutex_); | 237 OptimizingCompiler* result = NULL; |
238 for (int i = 0; i < ready_for_osr_.length(); i++) { | 238 { LockGuard<Mutex> access_osr_lists(&osr_list_mutex_); |
239 if (ready_for_osr_[i]->info()->HasSameOsrEntry(function, osr_pc_offset)) { | 239 for (int i = 0; i < ready_for_osr_.length(); i++) { |
240 osr_hits_++; | 240 if (ready_for_osr_[i]->info()->HasSameOsrEntry(function, osr_pc_offset)) { |
241 return ready_for_osr_.Remove(i); | 241 osr_hits_++; |
| 242 result = ready_for_osr_.Remove(i); |
| 243 break; |
| 244 } |
242 } | 245 } |
243 } | 246 } |
244 return NULL; | 247 RemoveStaleOSRCandidates(); |
| 248 return result; |
245 } | 249 } |
246 | 250 |
247 | 251 |
248 bool OptimizingCompilerThread::IsQueuedForOSR(Handle<JSFunction> function, | 252 bool OptimizingCompilerThread::IsQueuedForOSR(Handle<JSFunction> function, |
249 uint32_t osr_pc_offset) { | 253 uint32_t osr_pc_offset) { |
250 ASSERT(!IsOptimizerThread()); | 254 ASSERT(!IsOptimizerThread()); |
251 LockGuard<Mutex> access_osr_lists(&osr_list_mutex_); | 255 LockGuard<Mutex> access_osr_lists(&osr_list_mutex_); |
252 for (int i = 0; i < osr_candidates_.length(); i++) { | 256 for (int i = 0; i < osr_candidates_.length(); i++) { |
253 if (osr_candidates_[i]->info()->HasSameOsrEntry(function, osr_pc_offset)) { | 257 if (osr_candidates_[i]->info()->HasSameOsrEntry(function, osr_pc_offset)) { |
254 return true; | 258 return true; |
255 } | 259 } |
256 } | 260 } |
257 return false; | 261 return false; |
258 } | 262 } |
259 | 263 |
260 | 264 |
| 265 bool OptimizingCompilerThread::IsQueuedForOSR(JSFunction* function) { |
| 266 ASSERT(!IsOptimizerThread()); |
| 267 LockGuard<Mutex> access_osr_lists(&osr_list_mutex_); |
| 268 for (int i = 0; i < osr_candidates_.length(); i++) { |
| 269 if (*osr_candidates_[i]->info()->closure() == function) { |
| 270 return true; |
| 271 } |
| 272 } |
| 273 return false; |
| 274 } |
| 275 |
| 276 |
261 void OptimizingCompilerThread::RemoveStaleOSRCandidates(int limit) { | 277 void OptimizingCompilerThread::RemoveStaleOSRCandidates(int limit) { |
262 ASSERT(!IsOptimizerThread()); | 278 ASSERT(!IsOptimizerThread()); |
263 LockGuard<Mutex> access_osr_lists(&osr_list_mutex_); | 279 LockGuard<Mutex> access_osr_lists(&osr_list_mutex_); |
264 while (ready_for_osr_.length() > limit) { | 280 while (ready_for_osr_.length() > limit) { |
265 OptimizingCompiler* compiler = ready_for_osr_.Remove(0); | 281 OptimizingCompiler* compiler = ready_for_osr_.Remove(0); |
266 CompilationInfo* throw_away = compiler->info(); | 282 CompilationInfo* throw_away = compiler->info(); |
267 if (FLAG_trace_osr) { | 283 if (FLAG_trace_osr) { |
268 PrintF("[COSR - Discarded "); | 284 PrintF("[COSR - Discarded "); |
269 throw_away->closure()->PrintName(); | 285 throw_away->closure()->PrintName(); |
270 PrintF(", AST id %d]\n", | 286 PrintF(", AST id %d]\n", |
271 throw_away->osr_ast_id().ToInt()); | 287 throw_away->osr_ast_id().ToInt()); |
272 } | 288 } |
273 delete throw_away; | 289 delete throw_away; |
274 } | 290 } |
275 } | 291 } |
276 | 292 |
277 | 293 |
278 #ifdef DEBUG | 294 #ifdef DEBUG |
279 bool OptimizingCompilerThread::IsOptimizerThread() { | 295 bool OptimizingCompilerThread::IsOptimizerThread() { |
280 if (!FLAG_concurrent_recompilation) return false; | 296 if (!FLAG_concurrent_recompilation) return false; |
281 LockGuard<Mutex> lock_guard(&thread_id_mutex_); | 297 LockGuard<Mutex> lock_guard(&thread_id_mutex_); |
282 return ThreadId::Current().ToInteger() == thread_id_; | 298 return ThreadId::Current().ToInteger() == thread_id_; |
283 } | 299 } |
284 #endif | 300 #endif |
285 | 301 |
286 | 302 |
287 } } // namespace v8::internal | 303 } } // namespace v8::internal |
OLD | NEW |