| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 isolate_->stack_guard()->RequestInstallCode(); | 133 isolate_->stack_guard()->RequestInstallCode(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 | 136 |
| 137 static void DisposeRecompileJob(RecompileJob* job, | 137 static void DisposeRecompileJob(RecompileJob* job, |
| 138 bool restore_function_code) { | 138 bool restore_function_code) { |
| 139 // The recompile job is allocated in the CompilationInfo's zone. | 139 // The recompile job is allocated in the CompilationInfo's zone. |
| 140 CompilationInfo* info = job->info(); | 140 CompilationInfo* info = job->info(); |
| 141 if (restore_function_code) { | 141 if (restore_function_code) { |
| 142 if (info->is_osr()) { | 142 if (info->is_osr()) { |
| 143 if (!job->IsWaitingForInstall()) BackEdgeTable::RemoveStackCheck(info); | 143 if (!job->IsWaitingForInstall()) { |
| 144 // Remove stack check that guards OSR entry on original code. |
| 145 BackEdgeTable::RemoveStackCheck(info); |
| 146 } |
| 144 } else { | 147 } else { |
| 145 Handle<JSFunction> function = info->closure(); | 148 Handle<JSFunction> function = info->closure(); |
| 146 function->ReplaceCode(function->shared()->code()); | 149 function->ReplaceCode(function->shared()->code()); |
| 147 } | 150 } |
| 148 } | 151 } |
| 149 delete info; | 152 delete info; |
| 150 } | 153 } |
| 151 | 154 |
| 152 | 155 |
| 153 void OptimizingCompilerThread::FlushInputQueue(bool restore_function_code) { | 156 void OptimizingCompilerThread::FlushInputQueue(bool restore_function_code) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 } | 235 } |
| 233 | 236 |
| 234 | 237 |
| 235 void OptimizingCompilerThread::InstallOptimizedFunctions() { | 238 void OptimizingCompilerThread::InstallOptimizedFunctions() { |
| 236 ASSERT(!IsOptimizerThread()); | 239 ASSERT(!IsOptimizerThread()); |
| 237 HandleScope handle_scope(isolate_); | 240 HandleScope handle_scope(isolate_); |
| 238 | 241 |
| 239 RecompileJob* job; | 242 RecompileJob* job; |
| 240 while (output_queue_.Dequeue(&job)) { | 243 while (output_queue_.Dequeue(&job)) { |
| 241 CompilationInfo* info = job->info(); | 244 CompilationInfo* info = job->info(); |
| 245 Handle<JSFunction> function(*info->closure()); |
| 242 if (info->is_osr()) { | 246 if (info->is_osr()) { |
| 243 if (FLAG_trace_osr) { | 247 if (FLAG_trace_osr) { |
| 244 PrintF("[COSR - "); | 248 PrintF("[COSR - "); |
| 245 info->closure()->PrintName(); | 249 info->closure()->PrintName(); |
| 246 PrintF(" is ready for install and entry at AST id %d]\n", | 250 PrintF(" is ready for install and entry at AST id %d]\n", |
| 247 info->osr_ast_id().ToInt()); | 251 info->osr_ast_id().ToInt()); |
| 248 } | 252 } |
| 249 job->WaitForInstall(); | 253 job->WaitForInstall(); |
| 250 BackEdgeTable::RemoveStackCheck(info); | 254 BackEdgeTable::RemoveStackCheck(info); |
| 251 } else { | 255 } else { |
| 252 Compiler::InstallOptimizedCode(job); | 256 Handle<Code> code = Compiler::GetConcurrentlyOptimizedCode(job); |
| 257 function->ReplaceCode(*code); |
| 253 } | 258 } |
| 254 } | 259 } |
| 255 } | 260 } |
| 256 | 261 |
| 257 | 262 |
| 258 void OptimizingCompilerThread::QueueForOptimization(RecompileJob* job) { | 263 void OptimizingCompilerThread::QueueForOptimization(RecompileJob* job) { |
| 259 ASSERT(IsQueueAvailable()); | 264 ASSERT(IsQueueAvailable()); |
| 260 ASSERT(!IsOptimizerThread()); | 265 ASSERT(!IsOptimizerThread()); |
| 261 CompilationInfo* info = job->info(); | 266 CompilationInfo* info = job->info(); |
| 262 if (info->is_osr()) { | 267 if (info->is_osr()) { |
| 263 if (FLAG_trace_concurrent_recompilation) { | |
| 264 PrintF(" ** Queueing "); | |
| 265 info->closure()->PrintName(); | |
| 266 PrintF(" for concurrent on-stack replacement.\n"); | |
| 267 } | |
| 268 osr_attempts_++; | 268 osr_attempts_++; |
| 269 BackEdgeTable::AddStackCheck(info); | |
| 270 AddToOsrBuffer(job); | 269 AddToOsrBuffer(job); |
| 271 // Add job to the front of the input queue. | 270 // Add job to the front of the input queue. |
| 272 LockGuard<Mutex> access_input_queue(&input_queue_mutex_); | 271 LockGuard<Mutex> access_input_queue(&input_queue_mutex_); |
| 273 ASSERT_LT(input_queue_length_, input_queue_capacity_); | 272 ASSERT_LT(input_queue_length_, input_queue_capacity_); |
| 274 // Move shift_ back by one. | 273 // Move shift_ back by one. |
| 275 input_queue_shift_ = InputQueueIndex(input_queue_capacity_ - 1); | 274 input_queue_shift_ = InputQueueIndex(input_queue_capacity_ - 1); |
| 276 input_queue_[InputQueueIndex(0)] = job; | 275 input_queue_[InputQueueIndex(0)] = job; |
| 277 input_queue_length_++; | 276 input_queue_length_++; |
| 278 } else { | 277 } else { |
| 279 info->closure()->MarkInRecompileQueue(); | |
| 280 // Add job to the back of the input queue. | 278 // Add job to the back of the input queue. |
| 281 LockGuard<Mutex> access_input_queue(&input_queue_mutex_); | 279 LockGuard<Mutex> access_input_queue(&input_queue_mutex_); |
| 282 ASSERT_LT(input_queue_length_, input_queue_capacity_); | 280 ASSERT_LT(input_queue_length_, input_queue_capacity_); |
| 283 input_queue_[InputQueueIndex(input_queue_length_)] = job; | 281 input_queue_[InputQueueIndex(input_queue_length_)] = job; |
| 284 input_queue_length_++; | 282 input_queue_length_++; |
| 285 } | 283 } |
| 286 if (FLAG_block_concurrent_recompilation) { | 284 if (FLAG_block_concurrent_recompilation) { |
| 287 blocked_jobs_++; | 285 blocked_jobs_++; |
| 288 } else { | 286 } else { |
| 289 input_queue_semaphore_.Signal(); | 287 input_queue_semaphore_.Signal(); |
| 290 } | 288 } |
| 291 } | 289 } |
| 292 | 290 |
| 293 | 291 |
| 294 void OptimizingCompilerThread::Unblock() { | 292 void OptimizingCompilerThread::Unblock() { |
| 295 ASSERT(!IsOptimizerThread()); | 293 ASSERT(!IsOptimizerThread()); |
| 296 while (blocked_jobs_ > 0) { | 294 while (blocked_jobs_ > 0) { |
| 297 input_queue_semaphore_.Signal(); | 295 input_queue_semaphore_.Signal(); |
| 298 blocked_jobs_--; | 296 blocked_jobs_--; |
| 299 } | 297 } |
| 300 } | 298 } |
| 301 | 299 |
| 302 | 300 |
| 303 RecompileJob* OptimizingCompilerThread::FindReadyOSRCandidate( | 301 RecompileJob* OptimizingCompilerThread::FindReadyOSRCandidate( |
| 304 Handle<JSFunction> function, uint32_t osr_pc_offset) { | 302 Handle<JSFunction> function, BailoutId osr_ast_id) { |
| 305 ASSERT(!IsOptimizerThread()); | 303 ASSERT(!IsOptimizerThread()); |
| 306 for (int i = 0; i < osr_buffer_capacity_; i++) { | 304 for (int i = 0; i < osr_buffer_capacity_; i++) { |
| 307 RecompileJob* current = osr_buffer_[i]; | 305 RecompileJob* current = osr_buffer_[i]; |
| 308 if (current != NULL && | 306 if (current != NULL && |
| 309 current->IsWaitingForInstall() && | 307 current->IsWaitingForInstall() && |
| 310 current->info()->HasSameOsrEntry(function, osr_pc_offset)) { | 308 current->info()->HasSameOsrEntry(function, osr_ast_id)) { |
| 311 osr_hits_++; | 309 osr_hits_++; |
| 312 osr_buffer_[i] = NULL; | 310 osr_buffer_[i] = NULL; |
| 313 return current; | 311 return current; |
| 314 } | 312 } |
| 315 } | 313 } |
| 316 return NULL; | 314 return NULL; |
| 317 } | 315 } |
| 318 | 316 |
| 319 | 317 |
| 320 bool OptimizingCompilerThread::IsQueuedForOSR(Handle<JSFunction> function, | 318 bool OptimizingCompilerThread::IsQueuedForOSR(Handle<JSFunction> function, |
| 321 uint32_t osr_pc_offset) { | 319 BailoutId osr_ast_id) { |
| 322 ASSERT(!IsOptimizerThread()); | 320 ASSERT(!IsOptimizerThread()); |
| 323 for (int i = 0; i < osr_buffer_capacity_; i++) { | 321 for (int i = 0; i < osr_buffer_capacity_; i++) { |
| 324 RecompileJob* current = osr_buffer_[i]; | 322 RecompileJob* current = osr_buffer_[i]; |
| 325 if (current != NULL && | 323 if (current != NULL && |
| 326 current->info()->HasSameOsrEntry(function, osr_pc_offset)) { | 324 current->info()->HasSameOsrEntry(function, osr_ast_id)) { |
| 327 return !current->IsWaitingForInstall(); | 325 return !current->IsWaitingForInstall(); |
| 328 } | 326 } |
| 329 } | 327 } |
| 330 return false; | 328 return false; |
| 331 } | 329 } |
| 332 | 330 |
| 333 | 331 |
| 334 bool OptimizingCompilerThread::IsQueuedForOSR(JSFunction* function) { | 332 bool OptimizingCompilerThread::IsQueuedForOSR(JSFunction* function) { |
| 335 ASSERT(!IsOptimizerThread()); | 333 ASSERT(!IsOptimizerThread()); |
| 336 for (int i = 0; i < osr_buffer_capacity_; i++) { | 334 for (int i = 0; i < osr_buffer_capacity_; i++) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 | 375 |
| 378 | 376 |
| 379 bool OptimizingCompilerThread::IsOptimizerThread() { | 377 bool OptimizingCompilerThread::IsOptimizerThread() { |
| 380 LockGuard<Mutex> lock_guard(&thread_id_mutex_); | 378 LockGuard<Mutex> lock_guard(&thread_id_mutex_); |
| 381 return ThreadId::Current().ToInteger() == thread_id_; | 379 return ThreadId::Current().ToInteger() == thread_id_; |
| 382 } | 380 } |
| 383 #endif | 381 #endif |
| 384 | 382 |
| 385 | 383 |
| 386 } } // namespace v8::internal | 384 } } // namespace v8::internal |
| OLD | NEW |