private int determineForkedJvmCount ( TestsCollection testCollection ) { int cores = Runtime . getRuntime ( ) . availableProcessors ( ) ; int jvmCount ; if ( this . parallelism . equals ( PARALLELISM_AUTO ) ) { if ( cores >= 8 ) { // Maximum parallel jvms is 4, conserve some memory and memory bandwidth. jvmCount = 4 ; } else if ( cores >= 4 ) { // Make some space for the aggregator. jvmCount = 3 ; } else if ( cores == 3 ) { // Yes, three-core chips are a thing. jvmCount = 2 ; } else { // even for dual cores it usually makes no sense to fork more than one // JVM. jvmCount = 1 ; } } else if ( this . parallelism . equals ( PARALLELISM_MAX ) ) { jvmCount = Runtime . getRuntime ( ) . availableProcessors ( ) ; } else { try { jvmCount = Math . max ( 1 , Integer . parseInt ( parallelism ) ) ; } catch ( NumberFormatException e ) { throw new BuildException ( "parallelism must be 'auto', 'max' or a valid integer: " + parallelism ) ; } } if ( ! testCollection . hasReplicatedSuites ( ) ) { jvmCount = Math . min ( testCollection . testClasses . size ( ) , jvmCount ) ; } return jvmCount ; }
Determine how many forked JVMs to use .