OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 PrintF(scope.file(), | 350 PrintF(scope.file(), |
351 " / %" V8PRIxPTR "]\n", reinterpret_cast<intptr_t>(function)); | 351 " / %" V8PRIxPTR "]\n", reinterpret_cast<intptr_t>(function)); |
352 } | 352 } |
353 } | 353 } |
354 }; | 354 }; |
355 | 355 |
356 // Unlink all functions that refer to marked code. | 356 // Unlink all functions that refer to marked code. |
357 SelectedCodeUnlinker unlinker; | 357 SelectedCodeUnlinker unlinker; |
358 VisitAllOptimizedFunctionsForContext(context, &unlinker); | 358 VisitAllOptimizedFunctionsForContext(context, &unlinker); |
359 | 359 |
| 360 Isolate* isolate = context->GetHeap()->isolate(); |
| 361 #ifdef DEBUG |
| 362 Code* topmost_optimized_code = NULL; |
| 363 bool safe_to_deopt_topmost_optimized_code = false; |
| 364 // Make sure all activations of optimized code can deopt at their current PC. |
| 365 // The topmost optimized code has special handling because it cannot be |
| 366 // deoptimized due to weak object dependency. |
| 367 for (StackFrameIterator it(isolate, isolate->thread_local_top()); |
| 368 !it.done(); it.Advance()) { |
| 369 StackFrame::Type type = it.frame()->type(); |
| 370 if (type == StackFrame::OPTIMIZED) { |
| 371 Code* code = it.frame()->LookupCode(); |
| 372 if (FLAG_trace_deopt) { |
| 373 JSFunction* function = |
| 374 static_cast<OptimizedFrame*>(it.frame())->function(); |
| 375 CodeTracer::Scope scope(isolate->GetCodeTracer()); |
| 376 PrintF(scope.file(), "[deoptimizer found activation of function: "); |
| 377 function->PrintName(scope.file()); |
| 378 PrintF(scope.file(), |
| 379 " / %" V8PRIxPTR "]\n", reinterpret_cast<intptr_t>(function)); |
| 380 } |
| 381 SafepointEntry safepoint = code->GetSafepointEntry(it.frame()->pc()); |
| 382 int deopt_index = safepoint.deoptimization_index(); |
| 383 bool safe_to_deopt = deopt_index != Safepoint::kNoDeoptimizationIndex; |
| 384 CHECK(topmost_optimized_code == NULL || safe_to_deopt); |
| 385 if (topmost_optimized_code == NULL) { |
| 386 topmost_optimized_code = code; |
| 387 safe_to_deopt_topmost_optimized_code = safe_to_deopt; |
| 388 } |
| 389 } |
| 390 } |
| 391 #endif |
| 392 |
360 // Move marked code from the optimized code list to the deoptimized | 393 // Move marked code from the optimized code list to the deoptimized |
361 // code list, collecting them into a ZoneList. | 394 // code list, collecting them into a ZoneList. |
362 Isolate* isolate = context->GetHeap()->isolate(); | |
363 Zone zone(isolate); | 395 Zone zone(isolate); |
364 ZoneList<Code*> codes(10, &zone); | 396 ZoneList<Code*> codes(10, &zone); |
365 | 397 |
366 // Walk over all optimized code objects in this native context. | 398 // Walk over all optimized code objects in this native context. |
367 Code* prev = NULL; | 399 Code* prev = NULL; |
368 Object* element = context->OptimizedCodeListHead(); | 400 Object* element = context->OptimizedCodeListHead(); |
369 while (!element->IsUndefined()) { | 401 while (!element->IsUndefined()) { |
370 Code* code = Code::cast(element); | 402 Code* code = Code::cast(element); |
371 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); | 403 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); |
372 Object* next = code->next_code_link(); | 404 Object* next = code->next_code_link(); |
(...skipping 12 matching lines...) Expand all Loading... |
385 // Move the code to the _deoptimized_ code list. | 417 // Move the code to the _deoptimized_ code list. |
386 code->set_next_code_link(context->DeoptimizedCodeListHead()); | 418 code->set_next_code_link(context->DeoptimizedCodeListHead()); |
387 context->SetDeoptimizedCodeListHead(code); | 419 context->SetDeoptimizedCodeListHead(code); |
388 } else { | 420 } else { |
389 // Not marked; preserve this element. | 421 // Not marked; preserve this element. |
390 prev = code; | 422 prev = code; |
391 } | 423 } |
392 element = next; | 424 element = next; |
393 } | 425 } |
394 | 426 |
395 #ifdef DEBUG | |
396 // Make sure all activations of optimized code can deopt at their current PC. | |
397 for (StackFrameIterator it(isolate, isolate->thread_local_top()); | |
398 !it.done(); it.Advance()) { | |
399 StackFrame::Type type = it.frame()->type(); | |
400 if (type == StackFrame::OPTIMIZED) { | |
401 Code* code = it.frame()->LookupCode(); | |
402 if (FLAG_trace_deopt) { | |
403 JSFunction* function = | |
404 static_cast<OptimizedFrame*>(it.frame())->function(); | |
405 CodeTracer::Scope scope(isolate->GetCodeTracer()); | |
406 PrintF(scope.file(), "[deoptimizer patches for lazy deopt: "); | |
407 function->PrintName(scope.file()); | |
408 PrintF(scope.file(), | |
409 " / %" V8PRIxPTR "]\n", reinterpret_cast<intptr_t>(function)); | |
410 } | |
411 SafepointEntry safepoint = code->GetSafepointEntry(it.frame()->pc()); | |
412 int deopt_index = safepoint.deoptimization_index(); | |
413 CHECK(deopt_index != Safepoint::kNoDeoptimizationIndex); | |
414 } | |
415 } | |
416 #endif | |
417 | |
418 // TODO(titzer): we need a handle scope only because of the macro assembler, | 427 // TODO(titzer): we need a handle scope only because of the macro assembler, |
419 // which is only used in EnsureCodeForDeoptimizationEntry. | 428 // which is only used in EnsureCodeForDeoptimizationEntry. |
420 HandleScope scope(isolate); | 429 HandleScope scope(isolate); |
421 | 430 |
422 // Now patch all the codes for deoptimization. | 431 // Now patch all the codes for deoptimization. |
423 for (int i = 0; i < codes.length(); i++) { | 432 for (int i = 0; i < codes.length(); i++) { |
| 433 #ifdef DEBUG |
| 434 if (codes[i] == topmost_optimized_code) { |
| 435 ASSERT(safe_to_deopt_topmost_optimized_code); |
| 436 } |
| 437 #endif |
424 // It is finally time to die, code object. | 438 // It is finally time to die, code object. |
425 // Do platform-specific patching to force any activations to lazy deopt. | 439 // Do platform-specific patching to force any activations to lazy deopt. |
426 PatchCodeForDeoptimization(isolate, codes[i]); | 440 PatchCodeForDeoptimization(isolate, codes[i]); |
427 | 441 |
428 // We might be in the middle of incremental marking with compaction. | 442 // We might be in the middle of incremental marking with compaction. |
429 // Tell collector to treat this code object in a special way and | 443 // Tell collector to treat this code object in a special way and |
430 // ignore all slots that might have been recorded on it. | 444 // ignore all slots that might have been recorded on it. |
431 isolate->heap()->mark_compact_collector()->InvalidateCode(codes[i]); | 445 isolate->heap()->mark_compact_collector()->InvalidateCode(codes[i]); |
432 } | 446 } |
433 } | 447 } |
(...skipping 3098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3532 | 3546 |
3533 void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) { | 3547 void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) { |
3534 v->VisitPointer(BitCast<Object**>(&function_)); | 3548 v->VisitPointer(BitCast<Object**>(&function_)); |
3535 v->VisitPointers(parameters_, parameters_ + parameters_count_); | 3549 v->VisitPointers(parameters_, parameters_ + parameters_count_); |
3536 v->VisitPointers(expression_stack_, expression_stack_ + expression_count_); | 3550 v->VisitPointers(expression_stack_, expression_stack_ + expression_count_); |
3537 } | 3551 } |
3538 | 3552 |
3539 #endif // ENABLE_DEBUGGER_SUPPORT | 3553 #endif // ENABLE_DEBUGGER_SUPPORT |
3540 | 3554 |
3541 } } // namespace v8::internal | 3555 } } // namespace v8::internal |
OLD | NEW |