Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Avoid creating a stacktrace prior to JDK 1.7

Reply
Thread Tools

Avoid creating a stacktrace prior to JDK 1.7

 
 
Jan Burse
Guest
Posts: n/a
 
      10-02-2011

Lew schrieb:
> There's a difference between "no information" and "information that
> there is no information". The latter tells you something, at least.


My original question was: How can I force an exception to not
record some stack frame list at all.

One proposed solution so far was pre-allocating exceptions
from a call site with a few stack frames. Eventually also
calling the following method on the pre-allocated exception:

setStackTrace(new StackTraceElement[0]);

So as to even free the stack trace that was allocate from the
call site with only a few stack frames. The above method is
available since JDK 1.4.

What about calling setStackTrace() just after the new and before
the throw. This would only give a space advantage but not a
time advantage.

Any other suggestions?

Bye

 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      10-02-2011
On 10/2/2011 2:26 PM, Jan Burse wrote:
>
> Lew schrieb:
>> There's a difference between "no information" and "information that
> > there is no information". The latter tells you something, at least.

>
> My original question was: How can I force an exception to not
> record some stack frame list at all.
>
> One proposed solution so far was pre-allocating exceptions
> from a call site with a few stack frames. Eventually also
> calling the following method on the pre-allocated exception:
>
> setStackTrace(new StackTraceElement[0]);
>
> So as to even free the stack trace that was allocate from the
> call site with only a few stack frames. The above method is
> available since JDK 1.4.
>
> What about calling setStackTrace() just after the new and before
> the throw. This would only give a space advantage but not a
> time advantage.


I've become confused about what you're looking for. The thread
began with your desire to avoid filling a stack trace entirely:

> Will it every time I call it for a
> non-existing class build the whole stack
> trace for the exception x and then
> immediately forget about it? [...]
> If I were to write my own forName()
> method I would set the writableStackTrace
> to false if the exception is only needed
> to immediately notify the callee about
> something.


From this perspective, how does it improve matters if you replace
a filled-in trace with a new one of your own devising, however short?
What is your goal?

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)d
 
Reply With Quote
 
 
 
 
Jan Burse
Guest
Posts: n/a
 
      10-02-2011
Eric Sosman schrieb:
> From this perspective, how does it improve matters if you replace
> a filled-in trace with a new one of your own devising, however short?
> What is your goal?


In the pre-allocated case less memory usage. In the dynamic
case, earlier GC of the stack trace. This is known as
"agressive" pointer zeroing.

An effect to GC would only be seen if the exception it self
is not immediately reclaimed. For example when the try-catch
rippling process is slow or when it is somewhere retained on
the top level.

For example I have seen the following programming pattern:

try {
validateFormFields();
} catch (ValidationError x) {
informEndUser(x);
}

You usually don't show a stack trace to the en-user. You
generate some user friendly message. But the above example
does not fully work as an example, since the high frequency
use of the exception is missing.

But any, the bets are open. Any further suggestions to
have exceptions without the stack trace created in the
first place?

Bye
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JDK 1.5 or JDK 1.6 Pep Java 19 07-15-2007 12:06 AM
regarding JDk 141 and JDK 122 for linux 64 bit Platform Jaggu Java 3 01-08-2007 10:47 AM
What is the difference between J2EE, JDK, JDK-SDK, JRE and J2SE packages ? Ulf Meinhardt Java 0 08-10-2006 07:12 PM
jEdit: compiles JDK 1.5.0 ok, but runs JDK 1.4.1 (why?) Thomas G. Marshall Java 5 08-06-2004 04:12 AM
Help with converting IDS from JDK 1.1 to JDK 1.4 Babar Java 1 05-20-2004 09:11 PM



Advertisments