Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Unreachable code removal  (Read 1727 times)
0 Members and 1 Guest are viewing this topic.
Offline NativeOne

Senior Newbie




Java games rock!


« Posted 2004-01-08 02:59:36 »

When a block of code is unreachable at compile time, will the compiler remove it? Example:

final boolean DO_THAT = false;

if (DO_THAT) {
 // code...
}

In my application I'm specially interested in the removal of the condition check, since the condition will always be true or false at compile time.
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #1 - Posted 2004-01-08 06:30:46 »

dunno, but this can easily be checked out with a decompiler or by just examining the size of the class file.

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline Golthar

Junior Member




;)


« Reply #2 - Posted 2004-01-08 07:47:52 »

I thought the compiler spec said something like that.
In any case, we have an static class called debug in one of our projects and it has a static final boolean.
Seems to work for us

come visit us: http://www.otf1337.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online princec
« League of Dukes »

JGO Kernel


Medals: 196
Projects: 3


Eh? Who? What? ... Me?


« Reply #3 - Posted 2004-01-08 09:17:41 »

Unreachable code is removed by the Java compiler but I think only if you specify -O with javac ("optimizing"). I think Eclipse and other IDEs always optimize.

Dynamically unreachable code is removed by the server Hotspot JVM too (ie. assertions and the like).


Cas Smiley

Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #4 - Posted 2004-01-08 19:26:46 »

Quote
When a block of code is unreachable at compile time, will the compiler remove it? Example:

final boolean DO_THAT = false;

if (DO_THAT) {
 // code...
}


IIRC from the earlier thread about this, there are two scenarios:
1 - the final flag is in the same class. In this case, by definition, the compiler removes the relevant code.
2 - the final flag is in a different class; nothing happens (because the "other class" could be recoded and recompiled at any time, invalidating the assumption).

Basically, "final" has no meaning outside of the class file it's defined in?

malloc will be first against the wall when the revolution comes...
Offline Orangy Tang

JGO Kernel


Medals: 48
Projects: 11


Monkey for a head


« Reply #5 - Posted 2004-01-08 21:31:09 »

Quote

2 - the final flag is in a different class; nothing happens (because the "other class" could be recoded and recompiled at any time, invalidating the assumption).

That was what I had thought, but apparently thats not the case. See here: http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=Tuning;action=display;num=1067092857;start=15

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Jeff

JGO Coder




Got any cats?


« Reply #6 - Posted 2004-01-09 06:48:10 »

final static boolean foo = false;

if (foo) {
 // this is removed
}

Thats been true by definition in Java since the very beginning, one of the reasons we don't miss having a precompiler so much Smiley

I forget why the static, if you really want me to I could dig into the manuals and figure it out.



Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Online princec
« League of Dukes »

JGO Kernel


Medals: 196
Projects: 3


Eh? Who? What? ... Me?


« Reply #7 - Posted 2004-01-09 07:27:35 »

It is indeed true about static finals - even when in other classes they will affect the compilation and throw out dead code. Good thing too or my Sys.DEBUG flag would be bugger all use!

Cas Smiley

Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #8 - Posted 2004-01-09 08:36:55 »

Quote
It is indeed true about static finals - even when in other classes they will affect the compilation and throw out dead code. Good thing too or my Sys.DEBUG flag would be bugger all use!

Cas Smiley


...but what about non-static finals; is my question above correct, that an ordinary final doesn't have relevance outside the class?

malloc will be first against the wall when the revolution comes...
Offline Jeff

JGO Coder




Got any cats?


« Reply #9 - Posted 2004-01-11 02:12:43 »

I'll ask one of the compiler geeks...

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline Abuse

JGO Coder


Medals: 2


falling into the abyss of reality


« Reply #10 - Posted 2004-01-13 02:28:26 »

Quote
I'll ask one of the compiler experts...


good idea

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (77 views)
2013-05-17 21:29:12

alaslipknot (89 views)
2013-05-16 21:24:48

gouessej (119 views)
2013-05-16 00:53:38

gouessej (113 views)
2013-05-16 00:17:58

theagentd (125 views)
2013-05-15 15:01:13

theagentd (113 views)
2013-05-15 15:00:54

StreetDoggy (156 views)
2013-05-14 15:56:26

kutucuk (178 views)
2013-05-12 17:10:36

kutucuk (178 views)
2013-05-12 15:36:09

UnluckyDevil (186 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.1 seconds with 20 queries.