| 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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 260 |
| 261 void objectGroupingForMajorGC(v8::Isolate* isolate, bool constructRetainedObject
Infos) | 261 void objectGroupingForMajorGC(v8::Isolate* isolate, bool constructRetainedObject
Infos) |
| 262 { | 262 { |
| 263 MajorGCWrapperVisitor visitor(isolate, constructRetainedObjectInfos); | 263 MajorGCWrapperVisitor visitor(isolate, constructRetainedObjectInfos); |
| 264 isolate->VisitHandlesWithClassIds(&visitor); | 264 isolate->VisitHandlesWithClassIds(&visitor); |
| 265 visitor.notifyFinished(); | 265 visitor.notifyFinished(); |
| 266 } | 266 } |
| 267 | 267 |
| 268 void gcPrologueForMajorGC(v8::Isolate* isolate, bool constructRetainedObjectInfo
s) | 268 void gcPrologueForMajorGC(v8::Isolate* isolate, bool constructRetainedObjectInfo
s) |
| 269 { | 269 { |
| 270 if (isMainThread()) { | 270 objectGroupingForMajorGC(isolate, constructRetainedObjectInfos); |
| 271 { | |
| 272 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "DOMMajorGC"); | |
| 273 objectGroupingForMajorGC(isolate, constructRetainedObjectInfos); | |
| 274 } | |
| 275 V8PerIsolateData::from(isolate)->setPreviousSamplingState(TRACE_EVENT_GE
T_SAMPLING_STATE()); | |
| 276 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8MajorGC"); | |
| 277 } else { | |
| 278 objectGroupingForMajorGC(isolate, constructRetainedObjectInfos); | |
| 279 } | |
| 280 } | 271 } |
| 281 | 272 |
| 282 } // namespace | 273 } // namespace |
| 283 | 274 |
| 284 void V8GCController::gcPrologue(v8::Isolate* isolate, v8::GCType type, v8::GCCal
lbackFlags flags) | 275 void V8GCController::gcPrologue(v8::Isolate* isolate, v8::GCType type, v8::GCCal
lbackFlags flags) |
| 285 { | 276 { |
| 286 if (isMainThread()) | 277 if (isMainThread()) |
| 287 ScriptForbiddenScope::enter(); | 278 ScriptForbiddenScope::enter(); |
| 288 | 279 |
| 289 // TODO(haraken): A GC callback is not allowed to re-enter V8. This means | 280 // TODO(haraken): A GC callback is not allowed to re-enter V8. This means |
| 290 // that it's unsafe to run Oilpan's GC in the GC callback because it may | 281 // that it's unsafe to run Oilpan's GC in the GC callback because it may |
| 291 // run finalizers that call into V8. To avoid the risk, we should post | 282 // run finalizers that call into V8. To avoid the risk, we should post |
| 292 // a task to schedule the Oilpan's GC. | 283 // a task to schedule the Oilpan's GC. |
| 293 // (In practice, there is no finalizer that calls into V8 and thus is safe.) | 284 // (In practice, there is no finalizer that calls into V8 and thus is safe.) |
| 294 | 285 |
| 295 v8::HandleScope scope(isolate); | 286 v8::HandleScope scope(isolate); |
| 296 switch (type) { | 287 switch (type) { |
| 297 case v8::kGCTypeScavenge: | 288 case v8::kGCTypeScavenge: |
| 298 if (ThreadState::current()) | 289 if (ThreadState::current()) |
| 299 ThreadState::current()->willStartV8GC(BlinkGC::V8MinorGC); | 290 ThreadState::current()->willStartV8GC(BlinkGC::V8MinorGC); |
| 300 | 291 |
| 301 TRACE_EVENT_BEGIN1("devtools.timeline,v8", "MinorGC", "usedHeapSizeBefor
e", usedHeapSize(isolate)); | 292 TRACE_EVENT_BEGIN1("devtools.timeline,v8", "MinorGC", "usedHeapSizeBefor
e", usedHeapSize(isolate)); |
| 302 if (isMainThread()) { | |
| 303 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "DOMMinorGC"); | |
| 304 } | |
| 305 visitWeakHandlesForMinorGC(isolate); | 293 visitWeakHandlesForMinorGC(isolate); |
| 306 if (isMainThread()) { | |
| 307 V8PerIsolateData::from(isolate)->setPreviousSamplingState(TRACE_EVEN
T_GET_SAMPLING_STATE()); | |
| 308 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8MinorGC"); | |
| 309 } | |
| 310 break; | 294 break; |
| 311 case v8::kGCTypeMarkSweepCompact: | 295 case v8::kGCTypeMarkSweepCompact: |
| 312 if (ThreadState::current()) | 296 if (ThreadState::current()) |
| 313 ThreadState::current()->willStartV8GC(BlinkGC::V8MajorGC); | 297 ThreadState::current()->willStartV8GC(BlinkGC::V8MajorGC); |
| 314 | 298 |
| 315 TRACE_EVENT_BEGIN2("devtools.timeline,v8", "MajorGC", "usedHeapSizeBefor
e", usedHeapSize(isolate), "type", "atomic pause"); | 299 TRACE_EVENT_BEGIN2("devtools.timeline,v8", "MajorGC", "usedHeapSizeBefor
e", usedHeapSize(isolate), "type", "atomic pause"); |
| 316 gcPrologueForMajorGC(isolate, flags & v8::kGCCallbackFlagConstructRetain
edObjectInfos); | 300 gcPrologueForMajorGC(isolate, flags & v8::kGCCallbackFlagConstructRetain
edObjectInfos); |
| 317 break; | 301 break; |
| 318 case v8::kGCTypeIncrementalMarking: | 302 case v8::kGCTypeIncrementalMarking: |
| 319 if (ThreadState::current()) | 303 if (ThreadState::current()) |
| 320 ThreadState::current()->willStartV8GC(BlinkGC::V8MajorGC); | 304 ThreadState::current()->willStartV8GC(BlinkGC::V8MajorGC); |
| 321 | 305 |
| 322 TRACE_EVENT_BEGIN2("devtools.timeline,v8", "MajorGC", "usedHeapSizeBefor
e", usedHeapSize(isolate), "type", "incremental marking"); | 306 TRACE_EVENT_BEGIN2("devtools.timeline,v8", "MajorGC", "usedHeapSizeBefor
e", usedHeapSize(isolate), "type", "incremental marking"); |
| 323 gcPrologueForMajorGC(isolate, flags & v8::kGCCallbackFlagConstructRetain
edObjectInfos); | 307 gcPrologueForMajorGC(isolate, flags & v8::kGCCallbackFlagConstructRetain
edObjectInfos); |
| 324 break; | 308 break; |
| 325 case v8::kGCTypeProcessWeakCallbacks: | 309 case v8::kGCTypeProcessWeakCallbacks: |
| 326 TRACE_EVENT_BEGIN2("devtools.timeline,v8", "MajorGC", "usedHeapSizeBefor
e", usedHeapSize(isolate), "type", "weak processing"); | 310 TRACE_EVENT_BEGIN2("devtools.timeline,v8", "MajorGC", "usedHeapSizeBefor
e", usedHeapSize(isolate), "type", "weak processing"); |
| 327 if (isMainThread()) { | |
| 328 V8PerIsolateData::from(isolate)->setPreviousSamplingState(TRACE_EVEN
T_GET_SAMPLING_STATE()); | |
| 329 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMajorGC"); | |
| 330 } | |
| 331 break; | 311 break; |
| 332 default: | 312 default: |
| 333 ASSERT_NOT_REACHED(); | 313 ASSERT_NOT_REACHED(); |
| 334 } | 314 } |
| 335 } | 315 } |
| 336 | 316 |
| 337 void V8GCController::gcEpilogue(v8::Isolate* isolate, v8::GCType type, v8::GCCal
lbackFlags flags) | 317 void V8GCController::gcEpilogue(v8::Isolate* isolate, v8::GCType type, v8::GCCal
lbackFlags flags) |
| 338 { | 318 { |
| 339 switch (type) { | 319 switch (type) { |
| 340 case v8::kGCTypeScavenge: | 320 case v8::kGCTypeScavenge: |
| 341 TRACE_EVENT_END1("devtools.timeline,v8", "MinorGC", "usedHeapSizeAfter",
usedHeapSize(isolate)); | 321 TRACE_EVENT_END1("devtools.timeline,v8", "MinorGC", "usedHeapSizeAfter",
usedHeapSize(isolate)); |
| 342 if (isMainThread()) { | |
| 343 TRACE_EVENT_SET_NONCONST_SAMPLING_STATE(V8PerIsolateData::from(isola
te)->previousSamplingState()); | |
| 344 } | |
| 345 // TODO(haraken): Remove this. See the comment in gcPrologue. | 322 // TODO(haraken): Remove this. See the comment in gcPrologue. |
| 346 if (ThreadState::current()) | 323 if (ThreadState::current()) |
| 347 ThreadState::current()->scheduleV8FollowupGCIfNeeded(BlinkGC::V8Mino
rGC); | 324 ThreadState::current()->scheduleV8FollowupGCIfNeeded(BlinkGC::V8Mino
rGC); |
| 348 break; | 325 break; |
| 349 case v8::kGCTypeMarkSweepCompact: | 326 case v8::kGCTypeMarkSweepCompact: |
| 350 TRACE_EVENT_END1("devtools.timeline,v8", "MajorGC", "usedHeapSizeAfter",
usedHeapSize(isolate)); | 327 TRACE_EVENT_END1("devtools.timeline,v8", "MajorGC", "usedHeapSizeAfter",
usedHeapSize(isolate)); |
| 351 if (isMainThread()) { | |
| 352 TRACE_EVENT_SET_NONCONST_SAMPLING_STATE(V8PerIsolateData::from(isola
te)->previousSamplingState()); | |
| 353 } | |
| 354 if (ThreadState::current()) | 328 if (ThreadState::current()) |
| 355 ThreadState::current()->scheduleV8FollowupGCIfNeeded(BlinkGC::V8Majo
rGC); | 329 ThreadState::current()->scheduleV8FollowupGCIfNeeded(BlinkGC::V8Majo
rGC); |
| 356 break; | 330 break; |
| 357 case v8::kGCTypeIncrementalMarking: | 331 case v8::kGCTypeIncrementalMarking: |
| 358 TRACE_EVENT_END1("devtools.timeline,v8", "MajorGC", "usedHeapSizeAfter",
usedHeapSize(isolate)); | 332 TRACE_EVENT_END1("devtools.timeline,v8", "MajorGC", "usedHeapSizeAfter",
usedHeapSize(isolate)); |
| 359 if (isMainThread()) { | |
| 360 TRACE_EVENT_SET_NONCONST_SAMPLING_STATE(V8PerIsolateData::from(isola
te)->previousSamplingState()); | |
| 361 } | |
| 362 break; | 333 break; |
| 363 case v8::kGCTypeProcessWeakCallbacks: | 334 case v8::kGCTypeProcessWeakCallbacks: |
| 364 TRACE_EVENT_END1("devtools.timeline,v8", "MajorGC", "usedHeapSizeAfter",
usedHeapSize(isolate)); | 335 TRACE_EVENT_END1("devtools.timeline,v8", "MajorGC", "usedHeapSizeAfter",
usedHeapSize(isolate)); |
| 365 if (isMainThread()) { | |
| 366 TRACE_EVENT_SET_NONCONST_SAMPLING_STATE(V8PerIsolateData::from(isola
te)->previousSamplingState()); | |
| 367 } | |
| 368 break; | 336 break; |
| 369 default: | 337 default: |
| 370 ASSERT_NOT_REACHED(); | 338 ASSERT_NOT_REACHED(); |
| 371 } | 339 } |
| 372 | 340 |
| 373 if (isMainThread()) | 341 if (isMainThread()) |
| 374 ScriptForbiddenScope::exit(); | 342 ScriptForbiddenScope::exit(); |
| 375 | 343 |
| 376 // v8::kGCCallbackFlagForced forces a Blink heap garbage collection | 344 // v8::kGCCallbackFlagForced forces a Blink heap garbage collection |
| 377 // when a garbage collection was forced from V8. This is either used | 345 // when a garbage collection was forced from V8. This is either used |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 Visitor* m_visitor; | 424 Visitor* m_visitor; |
| 457 }; | 425 }; |
| 458 | 426 |
| 459 void V8GCController::traceDOMWrappers(v8::Isolate* isolate, Visitor* visitor) | 427 void V8GCController::traceDOMWrappers(v8::Isolate* isolate, Visitor* visitor) |
| 460 { | 428 { |
| 461 DOMWrapperTracer tracer(visitor); | 429 DOMWrapperTracer tracer(visitor); |
| 462 isolate->VisitHandlesWithClassIds(&tracer); | 430 isolate->VisitHandlesWithClassIds(&tracer); |
| 463 } | 431 } |
| 464 | 432 |
| 465 } // namespace blink | 433 } // namespace blink |
| OLD | NEW |