Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Compiler / GC stalls  (Read 5365 times)
0 Members and 1 Guest are viewing this topic.
Offline kaffiene
« Posted 2005-09-20 04:24:31 »

Hi All

I wrote some code doing a lot of sprite blitting.  Works really well - several hundred frames per second using dirty rectangles to avoid complete redraw.  Loverly stuff.

The only problem was that I keep getting "jittering" at the start of program execution (performance is stuttery for about first 5-10 seconds).  I've traced the GC and see that I get a single long GC then many tiny GC events which should be too swift to notice.  I presume that the stuttering in performance that I see is JIT - related.

Is there any way around this?  It really ruins the start of my game.  I've started coding this up in C++/SDL for comparison - unless I can find some way to avoid what I presume is compilation stalls, I'm going to just go with coding this up in C++.
Offline Niwak

Senior Member


Medals: 1
Projects: 1



« Reply #1 - Posted 2005-09-20 05:57:22 »

There are different ways to handle this ;
- either you disable JIT compilation with -Xint
- either you disable background JIT compilation with -Xbatch
- either you force JIT compilation at startup (before your program start) with -Xcompile flag (I'm not sure of the behavior of this flag)

             Vincent
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #2 - Posted 2005-09-20 06:17:14 »

Which version of the JDK are you using? Are you running the client or server compiler? Which garbage collector are you running? Could you post all of the command line arguments you're passing to the JVM?

Have you tried specifying -XX:-UseThreadPriorities? Does that have any effect?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kaffiene
« Reply #3 - Posted 2005-09-20 07:39:24 »

Which version of the JDK are you using? Are you running the client or server compiler? Which garbage collector are you running? Could you post all of the command line arguments you're passing to the JVM?

Have you tried specifying -XX:-UseThreadPriorities? Does that have any effect?


Hi Ken, thanks for tackling this...

- JDK version is 1.5.0_04
- Running both server and client JVMs (server by preference)
- I've tried standard GC and incgc

This is what I'm using at the mo, but I've played with the flags to no avail so far.
-ea -server -Xincgc -Xfuture

I haven't tried that Thread Priorities flag - I haven't seen it before.  I'll give it a go.
Offline kaffiene
« Reply #4 - Posted 2005-09-20 07:56:10 »

ok, tried the threads flag - doesn't make the problem go
Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #5 - Posted 2005-09-20 08:51:40 »

Try -XX:CompileThreshold=500

Cas Smiley

Offline Azeem Jiva

Junior Member




Java VM Engineer, Sun Microsystems


« Reply #6 - Posted 2005-09-20 14:42:58 »

Try -XX:CompileThreshold=500

Cas Smiley

I recommend against that, all that's doing is increasing the number of compiles and probably going to increase the stuttering.  You might try -Xbatch to disable background compilation.   
Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #7 - Posted 2005-09-20 18:12:42 »

What it'll do is reduce the stuttering to one big pause right at the beginning with any luck.

Something else that kaffiene hasn't mentioned is what tech. he's using to do drawing which can have a significant effect on stuttering...

Cas Smiley

Offline Raghar

Junior Member




Ue ni taete 'ru hitomi ni kono mi wa dou utsuru


« Reply #8 - Posted 2005-09-20 20:45:20 »

And what about precompile at background when showing a start menu? Playstations used this to make things less painful.
Offline kaffiene
« Reply #9 - Posted 2005-09-20 21:13:55 »

What it'll do is reduce the stuttering to one big pause right at the beginning with any luck.

Something else that kaffiene hasn't mentioned is what tech. he's using to do drawing which can have a significant effect on stuttering...

Cas Smiley
Good point - I'm using java 2d (drawimage, fillrect), rendering to a single VolatileImage then drawing that to screen.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kaffiene
« Reply #10 - Posted 2005-09-20 21:27:50 »

Try -XX:CompileThreshold=500

Cas Smiley

Well, that does seem to make it a bit better - at least on my work machine.  I'll need to wait till I get home and try it on my development machine to know if it works well enough on slower hardware, but it does look a bit better already (a twitch or two near the start - in the first 2 seconds or so) then apears to run well after that.

Offline kaffiene
« Reply #11 - Posted 2005-09-20 21:37:35 »

Cas - you're using a compiler for distributing your java games, aren't you?  Maybe I should look at static compilation for purposes of comparision (just in case some/all of the stuttering is due to my code rather than the JITter kicking in)
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #12 - Posted 2005-09-21 05:03:32 »

Have you tried setting a minimum heap size with -Xms to something realistic?

The best way to do this is to run your app with -Xverbose:gc and see what size
the heap gets to, and then set it as your min. heap size.

Thanks,
  Dmitri
Java2D Team
Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #13 - Posted 2005-09-21 08:39:22 »

Actually no, I do something mysterious and strange and use a plain old 1.4 client VM for my games (try the Webstart versions, which are virtually identical). I have a feeling your problem is Java2D related, not JIT related, because that's probably the only difference between your game and my games. Your source images might be in system RAM for a few frames and get punted over to VRAM after a short while or something.

Cas Smiley

Offline kaffiene
« Reply #14 - Posted 2005-09-21 21:11:41 »

Have you tried setting a minimum heap size with -Xms to something realistic?

The best way to do this is to run your app with -Xverbose:gc and see what size
the heap gets to, and then set it as your min. heap size.

No, I've left it at the defaults.  What's "something realistic"?
Offline kaffiene
« Reply #15 - Posted 2005-09-21 21:22:11 »

Actually no, I do something mysterious and strange and use a plain old 1.4 client VM for my games (try the Webstart versions, which are virtually identical). I have a feeling your problem is Java2D related, not JIT related, because that's probably the only difference between your game and my games. Your source images might be in system RAM for a few frames and get punted over to VRAM after a short while or something.

Ahh... that's possible - I'm not loading my sprites directly to volatile images, I'm just loading them and using them as plain old BufferedImages.  I'll check that out what affect changing that has.

BTW: I tried compiling the java with Jet and it did run very smoothly.

P.S.: Weren't you arguing against delivering non-compiled Java to people at one stage? 
Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #16 - Posted 2005-09-21 22:08:47 »

I never argued against it as such... the problem was a legal issue, which I've sidestepped by, er, compiling the game. Sort of.

Cas Smiley

Offline kaffiene
« Reply #17 - Posted 2005-09-22 01:41:17 »

I never argued against it as such... the problem was a legal issue, which I've sidestepped by, er, compiling the game. Sort of.

Cas Smiley

Sounds intriguing  Smiley  Care to elaborate?

At any rate - I switched to loading all the images as volitile images, which seems to have improved things a bit also.  I'll check it out on my development machine later tonight.
Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #18 - Posted 2005-09-22 10:11:27 »

Molebox is the solution to your legal woes. It's a compiler. Of sorts. What JVM? Ahem.

Cas Smiley

Offline Jeff

JGO Coder




Got any cats?


« Reply #19 - Posted 2005-09-22 16:27:37 »


BTW: I tried compiling the java with Jet and it did run very smoothly.


This begins to soudn an awful lot like start-up issues.

 Are you running on the server VM? You might try the client for grins.  Ist not quite as high peformacne but you may not need that little bit of extra eprformance and it stats up much more smoothly.

Otherwise see all the advcie allready given about forcing compile early and "warm up" your system if possible by runnign the render loop for  a few seconds without actually rendering.



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 trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #20 - Posted 2005-09-22 19:52:07 »

Quote
No, I've left it at the defaults.  What's "something realistic"?

Here's how to get the most realistic initial vm setting for your
game: run it with -verbose:gc and note the heap size when it stabilizes.

Then use that value as your initial heap - this will avoid many heap growing/full gc
cycles during startup.

Thanks,
   Dmitri
Java2D Team
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.

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

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

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

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

mitcheeb (56 views)
2014-09-08 06:06:29

BurntPizza (40 views)
2014-09-07 01:13:42

Longarmx (25 views)
2014-09-07 01:12:14

Longarmx (31 views)
2014-09-07 01:11:22

Longarmx (31 views)
2014-09-07 01:10:19

mitcheeb (39 views)
2014-09-04 23:08:59
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!