Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (562)
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 2086 times)
0 Members and 1 Guest are viewing this topic.
Offline NativeOne

Senior Newbie




Java games rock!


« Posted 2004-01-08 01: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 05: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 06: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
Offline princec

JGO Kernel


Medals: 379
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2004-01-08 08: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 18: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: 56
Projects: 11


Monkey for a head


« Reply #5 - Posted 2004-01-08 20: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 05: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
Offline princec

JGO Kernel


Medals: 379
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #7 - Posted 2004-01-09 06: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 07: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 01: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!
Legends of Yore - The Casual Retro Roguelike
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


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

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


good idea

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

BurntPizza (28 views)
2014-09-21 02:42:18

BurntPizza (18 views)
2014-09-21 01:30:30

moogie (19 views)
2014-09-21 00:26:15

UprightPath (27 views)
2014-09-20 20:14:06

BurntPizza (29 views)
2014-09-19 03:14:18

Dwinin (45 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (101 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56

mitcheeb (71 views)
2014-09-08 06:06:29
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!