We profiling our application with Java Flight Recorder and found massive locks on java.lang.ref.Reference$Lock object.
I investigate some places in stacktraces and findout that in all cases - there is array allocation
example of code ( position 3 on image):
public static char[] copyOfRange(char[] original, int from, int to) {
int newLength = to - from;
if (newLength < 0)
throw new IllegalArgumentException(from + " > " + to);
// stacktrace points on next line
char[] copy = new char[newLength];
System.arraycopy(original, from, copy, 0,
Math.min(original.length - from, newLength));
return copy;
}
I'm suspect that such locking has something with GC, but can't found any relevant information. Where I can read more on this topic?
End goal of activity: understand what is pappenning in such case, witch factors afect this and how we can decrease lock time of such operations.
Some details from comments:
- Java 8
- Heap 512Mb
- GC - G1
- With experiments I find out, that locktime is decreasing with heap size increase.

