These 3 commits aren't strictly dependent on each other but they are closely related. I must admit that I was surprised how bad the handling for this was. Perhaps this stuff was put together during the 32-bit era when heap requirements were much lower.
I've only tried this as part of an IcedTea build but it works well there. Note that -XshowSettings:vm will still show the requested -Xmx amount, even if an overflow caused that amount to be rejected. Runtime.getRuntime().maxMemory() subsequently returns the corrected amount.