OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 { | 417 { |
418 TRACE_EVENT_END0("v8", "minorGC"); | 418 TRACE_EVENT_END0("v8", "minorGC"); |
419 if (isMainThread()) { | 419 if (isMainThread()) { |
420 TRACE_EVENT_SET_NONCONST_SAMPLING_STATE(V8PerIsolateData::from(isolate)-
>previousSamplingState()); | 420 TRACE_EVENT_SET_NONCONST_SAMPLING_STATE(V8PerIsolateData::from(isolate)-
>previousSamplingState()); |
421 ScriptForbiddenScope::exit(); | 421 ScriptForbiddenScope::exit(); |
422 } | 422 } |
423 } | 423 } |
424 | 424 |
425 void V8GCController::majorGCEpilogue(v8::Isolate* isolate) | 425 void V8GCController::majorGCEpilogue(v8::Isolate* isolate) |
426 { | 426 { |
427 v8::HandleScope scope(isolate); | |
428 | |
429 TRACE_EVENT_END0("v8", "majorGC"); | 427 TRACE_EVENT_END0("v8", "majorGC"); |
430 if (isMainThread()) { | 428 if (isMainThread()) { |
431 TRACE_EVENT_SET_NONCONST_SAMPLING_STATE(V8PerIsolateData::from(isolate)-
>previousSamplingState()); | 429 TRACE_EVENT_SET_NONCONST_SAMPLING_STATE(V8PerIsolateData::from(isolate)-
>previousSamplingState()); |
432 ScriptForbiddenScope::exit(); | 430 ScriptForbiddenScope::exit(); |
| 431 |
| 432 // Schedule a precise GC to avoid the following scenario: |
| 433 // (1) A DOM object X holds a v8::Persistent to a V8 object. |
| 434 // Assume that X is small but the V8 object is huge. |
| 435 // The v8::Persistent is released when X is destructed. |
| 436 // (2) X's DOM wrapper is created. |
| 437 // (3) The DOM wrapper becomes unreachable. |
| 438 // (4) V8 triggers a GC. The V8's GC collects the DOM wrapper. |
| 439 // However, X is not collected until a next Oilpan's GC is |
| 440 // triggered. |
| 441 // (5) If a lot of such DOM objects are created, we end up with |
| 442 // a situation where V8's GC collects the DOM wrappers but |
| 443 // the DOM objects are not collected forever. (Note that |
| 444 // Oilpan's GC is not triggered unless Oilpan's heap gets full.) |
| 445 // (6) V8 hits OOM. |
| 446 ThreadState::current()->setGCRequested(); |
433 } | 447 } |
434 } | 448 } |
435 | 449 |
436 void V8GCController::collectGarbage(v8::Isolate* isolate) | 450 void V8GCController::collectGarbage(v8::Isolate* isolate) |
437 { | 451 { |
438 v8::HandleScope handleScope(isolate); | 452 v8::HandleScope handleScope(isolate); |
439 RefPtr<ScriptState> scriptState = ScriptState::create(v8::Context::New(isola
te), DOMWrapperWorld::create()); | 453 RefPtr<ScriptState> scriptState = ScriptState::create(v8::Context::New(isola
te), DOMWrapperWorld::create()); |
440 ScriptState::Scope scope(scriptState.get()); | 454 ScriptState::Scope scope(scriptState.get()); |
441 V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, "if (gc) gc();
"), isolate); | 455 V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, "if (gc) gc();
"), isolate); |
442 scriptState->disposePerContextData(); | 456 scriptState->disposePerContextData(); |
443 } | 457 } |
444 | 458 |
445 void V8GCController::reportDOMMemoryUsageToV8(v8::Isolate* isolate) | 459 void V8GCController::reportDOMMemoryUsageToV8(v8::Isolate* isolate) |
446 { | 460 { |
447 if (!isMainThread()) | 461 if (!isMainThread()) |
448 return; | 462 return; |
449 | 463 |
450 static size_t lastUsageReportedToV8 = 0; | 464 static size_t lastUsageReportedToV8 = 0; |
451 | 465 |
452 size_t currentUsage = Partitions::currentDOMMemoryUsage(); | 466 size_t currentUsage = Partitions::currentDOMMemoryUsage(); |
453 int64_t diff = static_cast<int64_t>(currentUsage) - static_cast<int64_t>(las
tUsageReportedToV8); | 467 int64_t diff = static_cast<int64_t>(currentUsage) - static_cast<int64_t>(las
tUsageReportedToV8); |
454 isolate->AdjustAmountOfExternalAllocatedMemory(diff); | 468 isolate->AdjustAmountOfExternalAllocatedMemory(diff); |
455 | 469 |
456 lastUsageReportedToV8 = currentUsage; | 470 lastUsageReportedToV8 = currentUsage; |
457 } | 471 } |
458 | 472 |
459 } // namespace blink | 473 } // namespace blink |
OLD | NEW |