-2

What am I doing wrong?

Image of it
Image of it

Andreas
  • 154,647
  • 11
  • 152
  • 247
Relliks
  • 5
  • 3

1 Answers1

2

Let me guess: 32-bit OS, or a 32-bit JVM (java -version and uname -a will get you some ways in figuring this out).

32-bit addressing gives you a grand total of just 4GB of accessible memory (Because 2 ^ 32 is 4gb), and of that 4 gb of address space, usually about 1gb is marked off by the OS as 'sorry, nope, I wont let you use any of those 1 billion numbers for addressing, because I reserved those for DMA to the graphics card, or pipes arranged by the kernel or who knows what. I'm the kernel, I say you can't have those, tough luck'. That means the area around which a 32-bit will fail a malloc call regardless of how much RAM you shoved into that box is just around exactly 3GB.

Lower it to 2.5GB or so (it's not just heap that java needs, there's some extras, so leave some room), or ensure both your OS and your VM are 64-bit, then none of this is an issue.

NB: I assume you already know this, but generally if you start java with just an -Xmx and no -Xms option, java will immediately (try to) allocate that maximum. Some of the other answers so far seem to misunderstand your problem, but note that something like java -Xms1g -Xmx3g would result in java starting normally, but it will then crash later on when it gets near that 3GB mark. For servers, specifying both -Xms and -Xmx, whilst somewhat common advice, is generally a dumb idea - you don't want your server to bounce around its memory requirements like that, better for processes to fail immediately, instead of failing at some nebulous later time juuust when all the customers are connecting. Leave the notion of having the VM shrink and grow the memory it claims from the OS to desktop deployments.

rzwitserloot
  • 85,357
  • 5
  • 51
  • 72