Skip to content

New Malloc Trace VM Options

Ralf Schmelter edited this page Apr 17, 2024 · 3 revisions

Whenever you seee <time-spec> in an option you have to use the 's' unit for seconds, 'm' for minutes, 'h' for hours and 'd' for days. Note that you can only use one unit. E.g. 20s or 2h.

  • -XX:+MallocTraceAtStartup: Enables the memory tracking at the start of the VM. Note that even with this flags some allocations will be done earlier and not be tracked.
  • -XX:-MallocTraceExitIfFail: When enabling the malloc trace at startup fails, the VM is stopped by default. With this flag that failure is silently ignored.
  • -XX:-MallocTraceTrackFree: By default when the memory trace is enabled via -XX:+MallocTraceAtStartup, the free() calls are tracked too. If this is not the intended behavior, use this flag.
  • -XX:MallocTraceEnableDelay=<time-spec>: This delays the startup of the memory tracking to be delayed by the given time. This can be useful to ignore all the memory allocation done during the initialization phase of the VM.
  • -XX:MallocTraceStackDepth=<stack-depth>: Sets the maxim depth of stored stacks to <stack-depth>.
  • -XX:MallocTraceOnlyNth=<nth>: If <nth> is not 1, then only about every <nth> allocation is tracked by the malloc trace. This saves memory and reduces the overhead of the trace.
  • -XX:-MallocTraceUseBacktrace: By default the trace tries to use the backtrace() call of the libc or librewind to get the stack traces. These methods generally get better stack traces, especially with optimized code on the stack (since it might have omitted the frame pointer). If this flag is given, be use the backup method. This method is faster, but might not be able to walk the whole stack.
  • -XX:MallocTraceUnwindLibName=<name>: The name of the libunwind library to use. The default should usually be OK, but if it is not found and you know where it could be found, this option allows you to specify the absolute path.
  • -XX:+MallocTraceDetailedStats: If given, we collect more detailed statistics for the malloc trace itself. This costs some performance.
  • -XX:+MallocTraceDumpOnError: If given and the VM detects and out of native memory error, we dump the result of the active malloc trace. Note that a lot of native OOMs are not detected by the VM, so you would not get a dump.
  • -XX:MallocTraceRainyDayFund=<size>: In order to have enough memory for the emergency dump of -XX:+MallocTraceDumpOnError, the VM reserves a rainy day fund at startup to be used during the dump. This option allows you to specify the size of that memory. The default is 1 MB.
    product(ccstr, MallocTraceDumpFilter, "",
    "If set, we only print stacks which contains functions which "
    "match the given string.")

    product(bool, MallocTraceDumpInternalStats, false,
    "If enabled we include internal statistics in the dump. ")

    product(uintx, MallocTraceDumpCount, 0,
    "The number of dumps to perform.")

    product(ccstr, MallocTraceDumpDelay, "1h",
    "The delay after the trace was enabled at which to start the "
    "regular dumps. The format supports seconds, minutes, hours "
    "and days, e.g. '1s 2m 3h 4d' or '20s'.")

    product(ccstr, MallocTraceDumpInterval, "1h",
    "The interval for the dump for the dumps. The format supports "
    "seconds, minutes, hours and days, e.g. '1s 2m 3h 4d' or '20s'.")

    product(bool, MallocTraceDumpSortByCount, false,
    "If given we sort the output by allocation count instead of "
    "allocation size.")

    product(uintx, MallocTraceDumpMaxEntries, 10,
    "If > 0 it limits the number of entries printed. If no sort "
    "is specified via -XX:MallocTraceDumpSort, we sort by "
    "size.")

    product(uintx, MallocTraceDumpPercentage, 0,
    "If > 0 we dump the given percentage of allocated bytes "
    "(or allocated objects if sorted by count). In that case the "
    "-XX:MallocTraceDumpMaxEntries option is ignored.")

    product(bool, MallocTraceDumpHideDumpAllocs, true,
    "If enabled we don't track the allocation done for the dump.")

    product(ccstr, MallocTraceDumpOutput, "stderr",
    "If set the dump is appended to the given file. 'stderr' and "
    "'stdout' can be used for dumping to stderr or stdout. "
    "Otherwise the dump is written to the given file name ( "
    "the first occurrance of '@pid' is replaced by the pid of the "
    "process).") \

Clone this wiki locally