Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

grunt "minall" step fails with Error: Could not create virtual machine. (Solution found, unsure about PR) #4595

Closed
benlesh opened this issue Oct 23, 2013 · 8 comments

Comments

@benlesh
Copy link
Contributor

benlesh commented Oct 23, 2013

All steps outlined for building the Angular project would work right up until I ran grunt package. At that point it would run until it made it to the "minall" task and it would fail.

Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Problem discovered

Upon further investigation I went into lib/utils.js and had grunt.log print out the shell command it was executing to run closure.jar against each file.

The command that was being run was:

java -Xmx2g -cp bower_components/closure-compiler/compiler.jar;bower_components/ng-closure-runner/ngcompiler.jar org.angularjs.closurerunner.NgClosureRunner --compilation_level SIMPLE_OPTIMIZATIONS --language_in ECMASCRIPT5_STRICT --minerr_pass --minerr_errors build/angular-sanitize-errors.json --minerr_url http://errors.angularjs.org/undefined/ --source_map_format=V3 --create_source_map build/angular-sanitize.min.js.map --js build/angular-sanitize.js1--js_output_file build/angular-sanitize.min.js

At that point I was given the message(s):

Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Apparently my 32-bit JVM on Windows 7 does not like allocating 2gb of space. I'm not sure why, because AFAIK, 2gb is the maximum heap size value.

Workaround

When I changed -Xmx2g to -Xmx512m everything worked fine and I was able to build.

Question(s)

  • Given the nature of how this JVM is being used, is 2GB max heap really necessary, or can it be reduced to 512MB?
  • Should this be handled in the java32flags() function in utils? In other words, if it's a 32 bit JVM should the max heap flag be reduced, whereas 64-bit JVM could state the same?

... either way I'm glad I finally got past this issue at least locally.

@mamboer
Copy link

mamboer commented Oct 29, 2013

+1
same issue met!

@tathamoddie
Copy link
Contributor

+1
Same issue here.

tathamoddie added a commit to tathamoddie/angular.js that referenced this issue Nov 8, 2013
The current grunt scripts require at least 2GB of heap space to be
allocated by the JVM, even though this is not needed to actually complete
the build. Adding 64-bit to the mix, this means grunt package fails on
machines without a whole 4GB of RAM free.

Closes angular#4595
@caitp
Copy link
Contributor

caitp commented Dec 10, 2013

This bug was run into on one of my separate repositories which uses the closure compiler as well, and we were able to solve it by the mechanism suggested here:

When I changed -Xmx2g to -Xmx512m everything worked fine and I was able to build.

I thought there was already a patch implementing this, but maybe I'm mistaken

edit I guess #4831 wasn't merged yet... hmm

I guess they aren't sure about merging it because they aren't positive 512mb would be enough for the closure compiler to work on the library. It's hard to say --- but since people with 32bit JVMs seem to be able to build Angular with that setting, and not with the higher setting, it's probably okay, is it not?

@benlesh
Copy link
Contributor Author

benlesh commented Dec 10, 2013

Well, something needs to be done, I inadvertently committed that change to utils.js in a PR. It was caught, fortunately, but still. It seems like maybe an automated check or something could be done? I'm not sure.

@benlesh
Copy link
Contributor Author

benlesh commented Dec 11, 2013

Fix: Install 64-bit JVM

  1. Install the 64-bit version of Java 7 SE
  2. Close whatever consoles you have open (PowerShell, CMD, etc)
  3. Update your PATH variables: Remove C:\Program Files (x86)\Java\jre7\bin (the 32-bit version) and add: C:\Program Files\Java\jre7\bin (the 64-bit version)
  4. Reopen your console app and try grunt package again

Don't worry about installing 32-bit and 64-bit Java side-by-side

They work together just fine. In fact, you can even have multiple version of Java (6 and 7 for example) installed side-by-side. No worries.

@ghost
Copy link

ghost commented Apr 21, 2014

Ben Lesh
blesh , Thanks!

@olostan
Copy link
Contributor

olostan commented Jul 15, 2014

Tried that solution, after switching to 64-bit Java (Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)) I have

Running "minall" task                                                                                    
Error occurred during initialization of VM                                                               
Could not reserve enough space for object heap                                                           
Error occurred during initialization of VM                                                               
Could not reserve enough space for object heap                                                           
Error occurred during initialization of VM                                                               
Could not reserve enough space for object heap                                                           
Error occurred during initialization of VM                                                               
Could not reserve enough space for object heap                                                           
Error occurred during initialization of VM                                                               
Could not reserve enough space for object heap                                                           
Error occurred during initialization of VM                                                               
Could not reserve enough space for object heap                                                           
Error occurred during initialization of VM                                                               
Could not reserve enough space for object heap                                                           
Error occurred during initialization of VM                                                               
Unable to allocate 68160KB bitmaps for parallel garbage collection for the requested 2181120KB heap.     
Error occurred during initialization of VM                                                               
Unable to allocate 68160KB bitmaps for parallel garbage collection for the requested 2181120KB heap.     
Error: Could not create the Java Virtual Machine.                                                        
Error: A fatal exception has occurred. Program will exit.                                                
Error: Could not create the Java Virtual Machine.                                                        
Error: A fatal exception has occurred. Program will exit.                                                
Warning: Error minifying build/angular-animate.js Use --force to continue.                               

I have Win7 x64, 8GB RAM.

As I understand, the only workaround is to apply this change: MJRichardson@51e3290 ?

@qcgm1978
Copy link

@Blesh yes, it also solved my problem on mac by installing java 64bit for mac.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants