🔒 Locked
[java] Random JVM Lag
Advertisement
Original Post
Okay another disappointment from Java... This might have been my fault since I haven't been steadily testing my Asteroids game on Windows machines, always on Linux tho. I decided its been a few modifications since I tested it and to my surprise it is acting VERY messed up... On Linux it works fine. On Windows... The game runs from WAY to smooth to SUPER laggy just completely randomly... Every object is moving via a time differential (timeDelta), to force the game into its speed at a constant time I decided to pass in just 30.0 to test this lag problem more. WindowsXP goes crazy... The game `ll be working fine one minute, then SUPER speedy the next, then SUPER laggy, I'm talkin lag like 1fps. Again, on Linux it works fine in all case's... Using the timeDelta with Linux the game looks great... I tested in Linux and WinXp on the same machine (dual boot) I tested it on a WinXP only box I tested it on a WinME only box. Only worked in Linux like I want it to... Any advice?
I am using System.nanoTime()
I think I found the root of the problem...
The GARBAGE COLLECTOR
See, I was testing a routine I wrote for the game and as I wrote it I threw in a 'new Point2D.Double()' every frame, 6 times a frame, per Asteroid.... So thats roughly 24-42 new's a frame... ooops... these which where immediatly discarded...
The game stopped going into SUPER speed and SUPER lag on Windows, just a few tiny lags now.
However, it is odd that Linux was able to garbage collect just fine where WindowsXP on the same machine freaked out.
I think I found the root of the problem...
The GARBAGE COLLECTOR
See, I was testing a routine I wrote for the game and as I wrote it I threw in a 'new Point2D.Double()' every frame, 6 times a frame, per Asteroid.... So thats roughly 24-42 new's a frame... ooops... these which where immediatly discarded...
The game stopped going into SUPER speed and SUPER lag on Windows, just a few tiny lags now.
However, it is odd that Linux was able to garbage collect just fine where WindowsXP on the same machine freaked out.
I'm curious: are you running your game with the -server option on the Windows box...figure you are but I'm just curious.
L-
L-
Hmmm
No I am not running my game with the server option in Windows.
On both Linux and Windows I've always just done
'java class_with_main'
What does this '-server' option allow?
I have Jdk1.5 installed, or whicever is the most recent one from Sun.
The problem isn't confirmed gone yet, it stills jumps around on windows, just a lot less since I stopped leaving so much for the garbage collector. 7*6*2 = 84 calls to new a frame at most, each reference being lost immediatly... I don't think thats a good idea for anything... With that eliminated to 0 calls it smoothed out a ton... but not fully.
However... Linux in all aspects should have been complaining along side windows... But I get absolutely NO lag in Linux...
No I am not running my game with the server option in Windows.
On both Linux and Windows I've always just done
'java class_with_main'
What does this '-server' option allow?
I have Jdk1.5 installed, or whicever is the most recent one from Sun.
The problem isn't confirmed gone yet, it stills jumps around on windows, just a lot less since I stopped leaving so much for the garbage collector. 7*6*2 = 84 calls to new a frame at most, each reference being lost immediatly... I don't think thats a good idea for anything... With that eliminated to 0 calls it smoothed out a ton... but not fully.
However... Linux in all aspects should have been complaining along side windows... But I get absolutely NO lag in Linux...
Quote:
Original post by Halsafar
7*6*2 = 84 calls to new a frame at most, each reference being lost immediatly... I don't think thats a good idea for anything...
Thats a *tiny* amount of new'ing for a single frame. You can quite happily new much more than that and the gc won't even register (as your linux test shows). It does sound like you're hitting some other odd snag of some sort.
84 calls to new on class Point2D.double()
which in my best guess has a double x,y instance and whatever other vars Object inheritance tacks on. But from what I can know is there, only 16 bytes a piece (double = 8byte in Java right?)...
84 * 16 = 1344bytes == 1.344kb
Thats nothing indeed...
The snag is odd... However I seem to have eliminated it completly now. I re-wrote how my game handled frame-to-frame time, took our all calls to new during the gameLoop with ease and now it runs fine even on a P2 233mhz 32mb ram (WinMe) comp... Well it should, its only Asteroids :)
which in my best guess has a double x,y instance and whatever other vars Object inheritance tacks on. But from what I can know is there, only 16 bytes a piece (double = 8byte in Java right?)...
84 * 16 = 1344bytes == 1.344kb
Thats nothing indeed...
The snag is odd... However I seem to have eliminated it completly now. I re-wrote how my game handled frame-to-frame time, took our all calls to new during the gameLoop with ease and now it runs fine even on a P2 233mhz 32mb ram (WinMe) comp... Well it should, its only Asteroids :)
Here is a link that describes the -server option:
Sun Doc
To quote from it:
"Java HotSpot Server VM:
The Java HotSpot Server VM is designed for maximum program execution speed for applications running in a server environment. The Java HotSpot Server VM is invoked by using the -server command-line option when launching an application, as in:
java -server MyApp
Rapid memory allocation and garbage collection - Java HotSpot technology provides for rapid memory allocation for objects, and it has a fast, efficient, state-of-the-art garbage collector."
L-
Sun Doc
To quote from it:
"Java HotSpot Server VM:
The Java HotSpot Server VM is designed for maximum program execution speed for applications running in a server environment. The Java HotSpot Server VM is invoked by using the -server command-line option when launching an application, as in:
java -server MyApp
Rapid memory allocation and garbage collection - Java HotSpot technology provides for rapid memory allocation for objects, and it has a fast, efficient, state-of-the-art garbage collector."
L-
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement