Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (526)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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  
  Does HotSpot do dead code elimination?  (Read 3501 times)
0 Members and 1 Guest are viewing this topic.
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Posted 2004-08-03 11:49:51 »

On one hand I would expect so, OTOH I would expect javac to do this...
Is HotSpot able to do dead code elimination on the fly?

Offline princec

« JGO Spiffy Duke »


Medals: 423
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2004-08-03 14:16:50 »

AFAIK, server yes, client no.

Cas Smiley

Offline Azeem Jiva

Junior Devvie




Java VM Engineer, Sun Microsystems


« Reply #2 - Posted 2004-08-03 14:26:04 »

Both Client and Server do dead code elimination...

See:
http://java.sun.com/javaone/javaone2001/pdfs/2696.pdf
http://java.sun.com/products/hotspot/docs/whitepaper/Java_Hotspot_v1.4.1/Java_HSpot_WP_v1.4.1_1002_4.html
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #3 - Posted 2004-08-03 17:44:06 »

Thanks for that.

The PDF says at one point "Generated code can be problematic". Unfortunately, this is exactly the thing we (or rather, Toby) intend to do with dynamic recompilation of an emulated CPU. Are there any specific do's and (more importantly) don'ts here?

Offline Azeem Jiva

Junior Devvie




Java VM Engineer, Sun Microsystems


« Reply #4 - Posted 2004-08-03 20:07:27 »

Quote
Thanks for that.

The PDF says at one point "Generated code can be problematic". Unfortunately, this is exactly the thing we (or rather, Toby) intend to do with dynamic recompilation of an emulated CPU. Are there any specific do's and (more importantly) don'ts here?


I'm not sure, but the PDF is quite old (2001), and this may not be much of a problem anymore.  The only suggestions I can give, is to make sure your outputed code is as clean as possible Smiley
Offline princec

« JGO Spiffy Duke »


Medals: 423
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #5 - Posted 2004-08-04 07:50:03 »

I remember a while back that the client VM definitely didn't do dynamic dead code elimination in 1.4 as shown by some very simple tests... you're saying this is now sorted in 1.5?

As I recall, code like this
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
class Test {
final boolean flag;
Test(boolean flag) {
this.flag = flag;
}
void loop() {
if (flag) {
// blah
} else {
// bleh
}
}
}


under client kept the if() test; and under server it cleverly got removed.

Cas Smiley

Offline pepe

Junior Devvie




Nothing unreal exists


« Reply #6 - Posted 2004-08-04 09:25:31 »

Is there a tool to get or inspect the code generated by hotspot?

Home page: http://frederic.barachant.com
------------------------------------------------------
GoSub: java2D gamechmark http://frederic.barachant.com/GoSub/GoSub.jnlp
Offline rreyelts

Junior Devvie




There is nothing Nu under the sun


« Reply #7 - Posted 2004-08-04 13:10:30 »

Quote
Is there a tool to get or inspect the code generated by hotspot?

Exactly. How do you know what was or was not removed Cas? I'd love to be able to know the exact transformation HotSpot performs on my code at runtime.

God bless,
-Toby Reyelts

About me: http://jroller.com/page/rreyelts
Jace - Easier JNI: http://jace.reyelts.com/jace
Retroweaver - Compile on JDK1.5, and deploy on 1.4: http://retroweaver.sf.net.
Offline Azeem Jiva

Junior Devvie




Java VM Engineer, Sun Microsystems


« Reply #8 - Posted 2004-08-04 15:20:53 »

Quote

under client kept the if() test; and under server it cleverly got removed.

Cas Smiley


Client does dead code elimination, but only code that has a zero reference count and will not remove calls that return a null value.  
Something like an instanceOf, or in your case you if() statement are not dead code.  Client does not know that removing the if() might change the structure of the code. Server on the other hand does much more extensive evaluation of the code.  In this case Server realizes that the if() does nothing and removes it.  

Also if you want to know what the generated code from HotSpot looks like use:

-XX:+PrintOptoAssembly    // This dumps the generated assembly
-XX:+PrintCompilation        // This dumps the compiled methods

Both are unsupported, they might destroy your machine, crash your OS, standard disclaimer applies (saving myself here).  

Oh and -XX:+PrintOptoAssembly only works in debug mode, so you'll need to use the JDK and run java_g vs java.

Offline rreyelts

Junior Devvie




There is nothing Nu under the sun


« Reply #9 - Posted 2004-08-04 15:31:00 »

Quote

-XX:+PrintOptoAssembly    // This dumps the generated assembly
-XX:+PrintCompilation        // This dumps the compiled methods

Oh and -XX:+PrintOptoAssembly only works in debug mode, so you'll need to use the JDK and run java_g vs java.

First, thanks for the info.

Second, I'm running on x86 - where do I get debug mode java? I don't have a java_g, or any kind of jvm_g.dll or anything that I can spot.

God bless,
-Toby Reyelts

About me: http://jroller.com/page/rreyelts
Jace - Easier JNI: http://jace.reyelts.com/jace
Retroweaver - Compile on JDK1.5, and deploy on 1.4: http://retroweaver.sf.net.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Azeem Jiva

Junior Devvie




Java VM Engineer, Sun Microsystems


« Reply #10 - Posted 2004-08-04 15:32:29 »

Quote

First, thanks for the info.

Second, I'm running on x86 - where do I get debug mode java? I don't have a java_g, or any kind of jvm_g.dll or anything that I can spot.

God bless,
-Toby Reyelts


You should be able to get java_g with the JDK, or you use to be able to.  Maybe that's changed...
Offline rreyelts

Junior Devvie




There is nothing Nu under the sun


« Reply #11 - Posted 2004-08-04 15:42:49 »

Quote

You should be able to get java_g with the JDK, or you use to be able to.  Maybe that's changed...

I have both JDK 1.4.2_02 and and JDK 1.5.0-beta2, and neither have a java_g or anything similar (I should have been more specific - this is Windows x86 - not Solaris x86). I can point to several links off of Google that say that java_g was no longer distributed JDK1.2+.

Oh, and btw, I tried -XX:+PrintOptoAssembly and it wasn't recognized, but -XX:+PrintCompilation was.

God bless,
-Toby Reyelts

About me: http://jroller.com/page/rreyelts
Jace - Easier JNI: http://jace.reyelts.com/jace
Retroweaver - Compile on JDK1.5, and deploy on 1.4: http://retroweaver.sf.net.
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #12 - Posted 2004-08-05 11:34:46 »

You should be able to compile your own debug VM by getting the source through the Sun community license... I've never tried it myself, but I figured that would be how us mere mortals would get java_g.

There are a few flags that are marked as "debug only" in the docs for hotspot options that are on java.sun.com

Offline rreyelts

Junior Devvie




There is nothing Nu under the sun


« Reply #13 - Posted 2004-08-05 12:43:03 »

Quote
You should be able to compile your own debug VM by getting the source through the Sun community license...

There's got to be a better way than that. I don't think building the VM is a 1,2,3 step thing, and I don't have weeks to devote to it. On top of that, I would only get to see the output for the VM I built, as opposed to any VM I can run (i.e. JDK 1.5, etc...)

God bless,
-Toby Reyelts

About me: http://jroller.com/page/rreyelts
Jace - Easier JNI: http://jace.reyelts.com/jace
Retroweaver - Compile on JDK1.5, and deploy on 1.4: http://retroweaver.sf.net.
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #14 - Posted 2004-08-05 14:57:34 »

I never said that option didn't suck Smiley

I get the impression that the debug stuff is otherwise internal to Sun.

Shame, 'cause it would be quite cool to see what sort of code was produced.  But I suspect then that Sun would get bombarded with complaints that the code produced wasn't the best possible code for the task, by people that don't understand that it can take time for a complier to produce really really optimized code and when you are compiling on-the-fly you don't have all the time (or memory, etc.) in the world to optimize.

Offline rreyelts

Junior Devvie




There is nothing Nu under the sun


« Reply #15 - Posted 2004-08-05 16:29:45 »

Quote
I never said that option didn't suck Smiley

Lol.

Quote
I get the impression that the debug stuff is otherwise internal to Sun.

Well, they used to ship java_g in the early days. I'm more under the impression no one used it, so they just stopped shipping it.

Quote
But I suspect then that Sun would get bombarded with complaints that the code produced wasn't the best possible code for the task

Perhaps, but that's not the goal. The goal is to understand what the compiler is/is not optimizing, so you know if you need to hand optimize something yourself.

God bless,
-Toby Reyelts

About me: http://jroller.com/page/rreyelts
Jace - Easier JNI: http://jace.reyelts.com/jace
Retroweaver - Compile on JDK1.5, and deploy on 1.4: http://retroweaver.sf.net.
Offline Azeem Jiva

Junior Devvie




Java VM Engineer, Sun Microsystems


« Reply #16 - Posted 2004-08-05 18:38:18 »

Quote


Perhaps, but that's not the goal. The goal is to understand what the compiler is/is not optimizing, so you know if you need to hand optimize something yourself.


If  that's your goal then you need a good profiler.  Seeing what the compiler outputs is meaningless unless you understand assembly.  Even then a good profiler (there are a bunch) will tell you much more than any stream of assembly.  
Offline rreyelts

Junior Devvie




There is nothing Nu under the sun


« Reply #17 - Posted 2004-08-05 18:48:34 »

Quote
If  that's your goal then you need a good profiler.

I don't see how that is the case. The profiler isn't going to tell me whether or not HotSpot performed a particular optimization for me - which is what I need to know.

God bless,
-Toby Reyelts

About me: http://jroller.com/page/rreyelts
Jace - Easier JNI: http://jace.reyelts.com/jace
Retroweaver - Compile on JDK1.5, and deploy on 1.4: http://retroweaver.sf.net.
Offline Azeem Jiva

Junior Devvie




Java VM Engineer, Sun Microsystems


« Reply #18 - Posted 2004-08-05 19:33:44 »

Maybe I misunderstood you, but I'm guessing the reason you want to see what optimizations are being applied is because you are trying to improve performance.  Am I right?   If you really want to see what optimizations are being applied, then you'll need to start reading the HotSpot source code (I'm sure its on java.sun.com) and build a debug version and go from there.  If you want to improve performance, than you need to profile your code and see which methods are taking up the majority of CPU cycles, etc and go from there.  

Either way to see the assembly output, you'll need the debug bits (and I guess we don't give them out anymore).  Building HotSpot isn't difficult under any of the unixes (make fastdebug), but Windows requires a bit more work
Offline rreyelts

Junior Devvie




There is nothing Nu under the sun


« Reply #19 - Posted 2004-08-05 19:43:05 »

Quote
Maybe I misunderstood you, but I'm guessing the reason you want to see what optimizations are being applied is because you are trying to improve performance.

You're working under the assumption that I don't know what will speed up the program. It's well known in emulation circles that the dead code removal that dynamic recompilation brings is a huge win. The question is whether or not HotSpot will provide that dead code removal, or if I need to implement it myself.

If I can't easily determine whether or not HotSpot performs that optimization, it will be a darn shame, because it means that I will have no choice but to implement the optimization myself. And as far as reading assembly goes, I think you'll find that a fair share of the people on this board know how to do just that.

God bless,
-Toby Reyelts

About me: http://jroller.com/page/rreyelts
Jace - Easier JNI: http://jace.reyelts.com/jace
Retroweaver - Compile on JDK1.5, and deploy on 1.4: http://retroweaver.sf.net.
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #20 - Posted 2004-08-05 22:14:21 »

Quote
Building HotSpot isn't difficult under any of the unixes (make fastdebug), but Windows requires a bit more work


I bet Mac OS X isn't included in "any unixes" Sad

Are you saying there is no Developer Studio project to just load and click "build" Smiley ?

I'd love to know if for your own release builds you use something like Intel's compiler and you didn't cheap out on something known to produce inferior intel code like gcc.

Offline Azeem Jiva

Junior Devvie




Java VM Engineer, Sun Microsystems


« Reply #21 - Posted 2004-08-06 13:26:49 »

Quote


I bet Mac OS X isn't included in "any unixes" Sad

Are you saying there is no Developer Studio project to just load and click "build" Smiley ?

I'd love to know if for your own release builds you use something like Intel's compiler and you didn't cheap out on something known to produce inferior intel code like gcc.


Well Apple does the porting for OSX, so you'll have to ask one of them.

Well for our platforms, we use the Sun Compilers for Solaris (SPARC and X86), we use GCC for the Linux platforms and MSVC++ for Windows.  A long time ago I tried using Intel's compilers and at least back then the resulting binaries were horrible broken, and I didn't try very hard to figure out why.   Although other people have done similar tests (when we changed Solaris compilers for example), and we've found that the C++ compilers didn't make much of a difference in performance for Java.  Mostly because Java spends most of its time in generated code.
Offline trembovetski

Senior Devvie




If only I knew what I'm talking about!


« Reply #22 - Posted 2004-08-14 21:05:39 »

Quote

.   Although other people have done similar tests (when we changed Solaris compilers for example), and we've found that the C++ compilers didn't make much of a difference in performance for Java...


This depends on the library used by the java app. Java2D, for example, has a lot of native code (most of the rendering loops are native), and recent experiments with VC7 free MS toolkit showed some promising results - generated code was smaller and faster (at least, on 2D benchmarks).


Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #23 - Posted 2004-08-16 03:12:04 »

Quote
This depends on the library used by the java app. Java2D, for example, has a lot of native code (most of the rendering loops are native), and recent experiments with VC7 free MS toolkit showed some promising results - generated code was smaller and faster (at least, on 2D benchmarks).


If you went with hand optimized SIMD instructions for things like blitting loops you would get a HUGE performance boost.  If you are going to change this area don't go half way.  SIMD instructions would be perfect for the sort of multiply-accumulate operations needed to blit with transparency or translucent areas.  Not to mention the filtering used for smooth scaling of image. (But I guess you leave that to the JAI APIs?)

Have you experimented with SIMD for blitting loops?

Offline princec

« JGO Spiffy Duke »


Medals: 423
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #24 - Posted 2004-08-16 08:03:26 »

Hell, just hire a game programmer contractor to write your blit routines and be amazed at the 4x speed increase. It'll come out of a different budget too so it'll be easy to get approval for it. And there won't be any need to wait for 1.6 either, it could go into 1.5.0_01 Smiley

Cas Smiley

Offline abies

Senior Devvie





« Reply #25 - Posted 2004-09-01 16:50:10 »

On a bit side note, has anybody managed to use java with AMD CodeAnalyst ? So far, I was able to use it only with statically compiled binaries, which is a shame - seems to be a really powerful tool for profiling.

Artur Biesiadowski
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.

toopeicgaming1999 (72 views)
2014-11-26 15:22:04

toopeicgaming1999 (61 views)
2014-11-26 15:20:36

toopeicgaming1999 (15 views)
2014-11-26 15:20:08

SHC (28 views)
2014-11-25 12:00:59

SHC (27 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (27 views)
2014-11-24 19:59:16

trollwarrior1 (40 views)
2014-11-22 12:13:56

xFryIx (78 views)
2014-11-13 12:34:49

digdugdiggy (56 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!