• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

assertion code overhead when disabled

 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider this statement from the assertion spec.

Programmers developing applications for resource-constrained devices may wish to strip assertions out of class files entirely. While this makes it impossible to enable assertions in the field, it also reduces class file size, possibly leading to improved class loading performance. In the absence of a high quality JIT, it could lead to decreased footprint and improved runtime performance.


Assertions disabled, compared to the absence of assertion code, could degrade performance. Is that right?
Does your favorite exam prep book say assertions disabled do not cause any overhead?
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to the Sun documentation I have seen, running with assertions disabled should cause no performance degradation.
I ran a test with 1,000,000 iterations and the difference between no assertions and assertions turned off was 1 millisecond. YMMV.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marlene, I'm moving this discussion to the Performance forum as the SCJP exam does not deal with performance issues.
You can continue this discussion there. Thank you
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alas, this question does not belong in the performance forum.
I was trying to show people studying for the SCJP that the spec says one thing and the certification books say another.
I am worried I will get the answer wrong on the exam if I answer according to the spec.
[ June 16, 2003: Message edited by: Marlene Miller ]
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The assert statement is syntatic sugar for this:

So that is how assertions when disabled could affect performance, depending on the compiler.
Oh well, since I am here... I am curious to know what a footprint is.
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One of the key phrases in that statement is: "In the absence of a high quality JIT."
There is no unnecessary footprint with a half-decent JIT compiler when assertions are disabled. Since assertions cannot be turned on or off in a class that's already been loaded, the JIT can either omit or include them at class loading time and never think about it again. In fact, the optimization is so simple that even a half-decent interpretter could do it.
I supposed a JVM could translate "assert Expression1 : Expression2" so that it's fundamentally equivalent to
if ($assertionEnabled && !Expression1)
throw new java.lang.AssertionError(Expression2);
but there's no reason to do so unless that JVM offers the ability to change $assertionEnabled's value for an already loaded class at runtime, which would be very non-standard.
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marlene Miller:
Alas, this question does not belong in the performance forum.
I was trying to show people studying for the SCJP that the spec says one thing and the certification books say another.
I am worried I will get the answer wrong on the exam if I answer according to the spec.


As was previously stated, performance questions such as these are not on the exam since performance is highly dependent on JVM implementation.
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you David. Very helpful. It did not occur to me the JIT would actually strip out the assert statements.
Thank you Thomas. I blew it again. I'll try not to post out-of-scope questions. But if I do, you can reply Out of Scope, if you would like.
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marlene,
I was trying to show people studying for the SCJP that the spec says one thing and the certification books say another.
I am worried I will get the answer wrong on the exam if I answer according to the spec.

Always trust the spec as it is the ultimate authoritative document
I'm sorry if you think that I should not have moved your post. No hard feelings
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Valentin. I need some more practice writing crystal clear posts. I also need a better filter for out-of-scope questions.
 
reply
    Bookmark Topic Watch Topic
  • New Topic