Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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  
  Bounded GC  (Read 1449 times)
0 Members and 1 Guest are viewing this topic.
Offline swpalmer

JGO Coder

Where's the Kaboom?

« Posted 2003-07-08 15:24:44 »

There was talk some time ago about implementing something along the lines of:

System.gc( int n );

which would tell (ask) the garbage collector to run for at most n milliseconds.  This would replace or be used in combination with the Thread.sleep( int n ) call that might appear in gaming loops.  

Alternatively there could be a way to ask the GC to run while a buffer strategy is waiting for the video sync to flip buffers.  Thus allowing the GC to optimally use the 'dead' time in a typical game or animation loop.

Has anymore thought gone into that?  Now that we have Ken here, who I read previously worked on the HotSpot team, perhaps he could comment on the feasibility or nudge the appropriate people to make this part of Java 1.5?

I think Jeff indicated that the first case of limiting the GC to N ms was quite doable according to the guys he talked to.

Offline Spiff

Senior Newbie

Java games rock!

« Reply #1 - Posted 2003-07-08 16:30:34 »

I see a problem with this. Right now there's the rule "no allocating in the main loop". Adding bounded GC would give us the rule "you can allocate some, but not enough to overwhelm what the GC can collect in about 10ms". And of course, this rule would change depending on the deployment scenario. I imagine it might be pretty hard to determine just how many new's you're allowed and of what size each new should be.

It seems to me that this would make programming harder than just using the no-allocation rule. Unless, of course, the GC can collect gobs more in a few ms than you would ever likely allocate.
Offline swpalmer

JGO Coder

Where's the Kaboom?

« Reply #2 - Posted 2003-07-08 16:56:09 »

The "no allocation" rule is more of a guideline.  As I recall Cas mentioned that Alien Flux does some small allocations in the main loop.  Combined with other options to minimize GC delays (e.g. concurrent GC) and adjusting the heap size appropriately you should be able to allocate in the main loop if you are careful not to get carried away.

I think not allocating anything in the main loop is a very large restriction.  That alone might undo much of the productivity gains that Java otherwise would give you, as it can effect the design significantly.

And remember that if the GC is invoked for a few ms EVERY FRAME that it adds up to a significant amount.  Also, I don't see that this would do any harm.. if there will be GC interrupting the main loop it is best to have something like this to help minimize the disruption.

Turn on verbose GC (I use -Xloggc:<file>) in your game to see how frequently GC takes place and how long it runs... that will give some better idea of how effective this might be.  I would like to hear the results from anyone that would like to try that experiment actually.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel

Medals: 343
Projects: 3
Exp: 16 years

Eh? Who? What? ... Me?

« Reply #3 - Posted 2003-07-08 17:28:36 »

The problem is very simply, to avoid allocating so much that the processing time required to collect the garbage exceeds what time you've got left over from drawing. I can safely allocate aliens and particle emitters in my rendering loop without any trouble at all, and numerous other sundries.

I perform a full GC at opportune moments (level end), and with Jet, I already have a bounded collector.

Rather than specify the bounds using System.gc(int) it might be prudent to supply the value as a -X switch. It is, after all, only a suggestion to the garbage collector about how long it needs; if it needs more time, it'll have to use more time. In other words, I think it's a platform tuning question rather than a programmatic one. At this stage.

Cas Smiley

Offline swpalmer

JGO Coder

Where's the Kaboom?

« Reply #4 - Posted 2003-07-08 21:52:17 »

Rather than specify the bounds using System.gc(int) it might be prudent to supply the value as a -X switch. It is, after all, only a suggestion to the garbage collector about how long it needs; if it needs more time, it'll have to use more time.

The way I was thinking the only time it would really take (significantly) more time was when it was triggered by an allocation that would otherwise fail.  Even in that case it would not trigger a full GC, but only enough to satisfy the allocation... a true full GC would only ever happen when System.gc() is called (with no bounds).

But I don't know enough about it, so maybe you just can't work it that way.

Offline Abuse

JGO Coder

Medals: 11

falling into the abyss of reality

« Reply #5 - Posted 2003-07-08 23:50:51 »

We all know the GC was never tailored for Games.

Spose the key question is; should Sun (now they have a *fairly* official games division) now *re*tailor the GC so it supports the needs of Games.

I say Yeah!
We all prolly say Yeah!
All it takes is for 1 high up n00by(aka Manager :p) @Sun to say Nay, and we're all scuppered Sad

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.


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

The first screenshot will be displayed as a thumbnail.

CogWheelz (11 views)
2014-07-30 21:08:39

Riven (21 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (29 views)
2014-07-23 21:07:15

Riven (30 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22 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‑
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!