How is it possible that StringBuilder.setLength(0) invokes Arrays.fill? How is it possible that StringBuilder.setLength(0) invokes Arrays.fill? arrays arrays

How is it possible that StringBuilder.setLength(0) invokes Arrays.fill?


There is an issue with JFR. It collects stack traces asynchronously, i.e. not only at safepoints like many other profilers do. On one hand, this makes sampling more realistic, since there is no safepoint bias. On the other hand, HotSpot JVM is not able to walk the stack correctly at any random moment of time.

HotSpot private API AsyncGetCallTrace tries to do best to recover current stack trace from any arbitrary point where a timer signal has interrupted the application. However, some places in the code are not safe for stack walking. If AsyncGetCallTrace is called at one of those places, it may return invalid stack trace or no stack trace at all.

This is a known issue of AsyncGetCallTrace. JDK-8022893 has the examples and the analysis of the problem. It is a rather often situation that AsyncGetCallTrace (and all profilers based on it) returns inaccurate trace where some frames are mistakenly replaced by neighbour methods.