Improved memory limit detection for java