Sometimes it might not function when the memory you specify is more than the available memory allocated to the VM by the environment in which it is running. Inspect the logs to find the specific error/exception being thrown.
Note that the available system memory might not all be available to the JVM regardless of the cap you specify. This depends on other applications that are running. The OS generally has the upper hand on memory allocation.
Also, this answer might help you.