Hi Vivek,
could be that it’s something with allocation memory.
https://forums.sifive.com/t/exception-in-thread-main-java-lang-outofmemoryerror-java-heap-space-failed-reallocation-of-scalar-replaced-objects/1854
try to increase maximum heap size
https://alvinalexander.com/blog/post/java/java-xmx-xms-memory-heap-size-control/
I hope this can help you.
Kind regards,
Domagoj