Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why does java.lang.Throwable delay the StackTrace array construction?

0
10 Posted

Why does java.lang.Throwable delay the StackTrace array construction?

0
10

Well consider what happens in a VM. VMThrowable.fillInStackTrace() is very fast — it’s just a chain of addresses. VMThrowable.getStackTrace() is very slow, because it has to convert all those addresses into StackTraceElements. I suspect that you can get the trace for the whole stack in less time than it takes to create a single StackTraceElement. For this reason, the vmState is stored and lazily converted to a StackTraceElement[]. (Andrew Haley) A particular problem is posed by OutOfMemoryException: throwing it shouldn’t require any memory (there’s none anyway). Some propose that the VM should preallocate it at bootstrap, but this doesn’t solve the problem. In Chris Gray’s words “if several threads throw OOME at the same time, the stack traces can get mixed up […snip…] This situation is less improbable than you might think, since if one thread encounters an OOM situation, all other threads should encounter one too. With some forms of co-operative multi-threading you may get away w

0

Well consider what happens in a VM. VMThrowable.fillInStackTrace() is very fast — it’s just a chain of addresses. VMThrowable.getStackTrace() is very slow, because it has to convert all those addresses into StackTraceElements. I suspect that you can get the trace for the whole stack in less time than it takes to create a single StackTraceElement. For this reason, the vmState is stored and lazily converted to a StackTraceElement[]. (Andrew Haley) A particular problem is posed by OutOfMemoryException: throwing it shouldn’t require any memory (there’s none anyway). Some propose that the VM should preallocate it at bootstrap, but this doesn’t solve the problem. In Chris Gray’s words “if several threads throw OOME at the same time, the stack traces can get mixed up […snip…] This situation is less improbable than you might think, since if one thread encounters an OOM situation, all other threads should encounter one too.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123