From Java8 and above, you may use below command:
jcmd JAVA_PROCESS_ID
GC.heap_info
You may refer to sum of, total and used memory from the output.
Sample Command And Output: jcmd 9758 GC.heap_info
PSYoungGen total 1579520K, used 487543K [0x0000000751d80000, 0x00000007c0000000, 0x00000007c0000000)
eden space 1354240K, 36% used [0x0000000751d80000,0x000000076f99dc40,0x00000007a4800000)
from space 225280K, 0% used [0x00000007b2400000,0x00000007b2400000,0x00000007c0000000)
to space 225280K, 0% used [0x00000007a4800000,0x00000007a4800000,0x00000007b2400000)
ParOldGen total 3610112K, used 0K [0x0000000675800000, 0x0000000751d80000, 0x0000000751d80000)
object space 3610112K, 0% used [0x0000000675800000,0x0000000675800000,0x0000000751d80000)
Metaspace used 16292K, capacity 16582K, committed 16896K, reserved 1064960K
class space used 1823K, capacity 1936K, committed 2048K, reserved 1048576K
For more details on jcmd command, visit link here