Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.9.1a is out! (05/10/19); Blog post: Raiding for Fun and Profit (11/27/19)

Author Topic: Java heap size mismatch  (Read 1350 times)

Serenitis

  • Admiral
  • *****
  • Posts: 809
    • View Profile
Java heap size mismatch
« on: June 15, 2017, 12:15:21 PM »

Not a bug, but somewhat technical.

While playing I got a little red text in the notification area about java minimum and maximum heap sizes not being the same repreated roughly once a minute.
I always thought the minimum (-xms) was the memory it got allocated when starting, and the maximum (-xmx) was what it was allowed to expand that to if it needed it.

I currently have vmparams set @ -Xms1536m -Xmx3584m.
Does SS need the maximum size to be declared as the starting amount now? (eg: Should I now use -Xms3584m -Xmx3584m?)
The game plays fine with my current settings, but the constant redtext is irritating.
Never seen it do this before, and I've used a small & large setting basically forever.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 15495
    • View Profile
Re: Java heap size mismatch
« Reply #1 on: June 15, 2017, 12:18:46 PM »

(The notification text is from a mod.)

Yes, you want the values to be the same. Otherwise, it may fail to allocate extra memory quickly enough when there's a sudden spike in demand (such as when saving), resulting in an OOM crash despite the memory needed being within the upper limit. Which entirely defeats the purpose of allocating more memory in the first place. I mean, it'll help because it won't crash like this *every* time - sometimes it'll allocate more quickly enough - but there's no real reason to chance it.
Logged

Serenitis

  • Admiral
  • *****
  • Posts: 809
    • View Profile
Re: Java heap size mismatch
« Reply #2 on: June 15, 2017, 12:21:47 PM »

Gotcha.
Changed the setting.
Thank you. :)
Logged

TJJ

  • Admiral
  • *****
  • Posts: 1829
    • View Profile
    • Email
Re: Java heap size mismatch
« Reply #3 on: June 16, 2017, 06:15:15 AM »

@Alex have you ever witnessed this actually happen?
'cos what you describe is contrary to the JVM specification; it simply doesn't work that way.
There aren't any race conditions, an OutOfMemoryError will only occur if an allocation won't fit in the heap.

Of course, the VM could encounter an error as a result of its attempt to expand the heap (if the OS isn't able to allocate more contiguous address space), though in a 64bit address space that becomes a non-issue.

Having a fixed heap size is still a good idea though, as it front loads any performance inconsistencies associated with heap expansion (and avoids the possibility of heap contraction).
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 15495
    • View Profile
Re: Java heap size mismatch
« Reply #4 on: June 16, 2017, 09:57:41 AM »

Pretty sure I've seen it a while ago, but not with Starsector. Entirely possible that I'm wrong, though - but as you say, even then it's still good to have the sizes match to avoid performance hiccups.
Logged