Skip to content

Nested GC callback #44046

Description

@theanarkh

Version

v19.0.0-pre

Platform

Darwin Kernel Version 20.3.0

Subsystem

perf_hooks

What steps will reproduce the bug?

The example code that triggers this bug has not been found. I found this bug in my project. I add some logs into node_perf.cc.

image

and found the log as follows.

image

This will make the value of gc duration inaccurate (node_perf.cc). The 4 and 16 is defined in GCType.

enum GCType {
  kGCTypeScavenge = 1 << 0,
  kGCTypeMinorMarkCompact = 1 << 1,
  kGCTypeMarkSweepCompact = 1 << 2,
  kGCTypeIncrementalMarking = 1 << 3,
  kGCTypeProcessWeakCallbacks = 1 << 4,
};

How often does it reproduce? Is there a required condition?

it is difficult to reproduce currently.

What is the expected behavior?

it should be 4 4 16 16.

What do you see instead?

4 16 16 4.

Additional information

cc @bnoordhuis

Activity

  1. bnoordhuis commented on Jul 30, 2022

    @bnoordhuis
    Member

    Weak phantom callbacks run during the prologue or epilogue of major GCs1 so the output you're seeing is not unexpected, just an artifact of how V8 implements them.

    1 The relevant method is Heap::CollectGarbage() in deps/v8/src/heap/heap.cc.

  2. theanarkh commented on Jul 30, 2022

    @theanarkh
    ContributorAuthor

    Thanks. So is it wrong to calculate the elapsed time for each GC type through prologue and epilogue callbacks ?

  3. bnoordhuis commented on Jul 30, 2022

    @bnoordhuis
    Member

    Yes. No. Depends on whether you count kGCTypeProcessWeakCallbacks as a separate type. :-)

  4. theanarkh commented on Jul 30, 2022

    @theanarkh
    ContributorAuthor

    Get it ! Thank you very much !

  5. added a commit that references this issue on Aug 16, 2022
  6. added a commit that references this issue on Aug 23, 2022
  7. added a commit that references this issue on Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions