@@ -29,6 +29,7 @@ import (
2929const (
3030 executableName = "java-buildpack-memory-calculator"
3131 totalFlag = "totMemory"
32+ threadsFlag = "stackThreads"
3233 weightsFlag = "memoryWeights"
3334 sizesFlag = "memorySizes"
3435 initialsFlag = "memoryInitials"
4748 totMemory = flag .String (totalFlag , "" ,
4849 "total memory available to allocate, expressed as an integral " +
4950 "number of bytes, kilobytes, megabytes or gigabytes" )
51+ stackThreads = flag .Int (threadsFlag , 0 ,
52+ "number of threads to use in stack allocation calculations, e.g. '50'; " +
53+ "the default value of 0 causes an estimate to be used" )
5054 memoryWeights = flag .String (weightsFlag , "" ,
5155 "the weights given to each memory type, e.g. 'heap:15,permgen:5,stack:1,native:2'" )
5256 memorySizes = flag .String (sizesFlag , "" ,
5862)
5963
6064// Validate flags passed on command line; exit(1) if invalid; exit(2) if help printed
61- func ValidateFlags () (memSize memory.MemSize , weights map [string ]float64 , sizes map [string ]memory.Range , initials map [string ]float64 ) {
65+ func ValidateFlags () (memSize memory.MemSize , numThreads int , weights map [string ]float64 , sizes map [string ]memory.Range , initials map [string ]float64 ) {
6266
6367 flag .Parse () // exit on error
6468
@@ -69,11 +73,12 @@ func ValidateFlags() (memSize memory.MemSize, weights map[string]float64, sizes
6973
7074 // validation routines will not return on error
7175 memSize = validateTotMemory (* totMemory )
76+ numThreads = validateNumThreads (* stackThreads )
7277 weights = validateWeights (* memoryWeights )
7378 sizes = validateSizes (* memorySizes )
7479 initials = validateInitials (* memoryInitials )
7580
76- return memSize , weights , sizes , initials
81+ return memSize , numThreads , weights , sizes , initials
7782}
7883
7984func validateTotMemory (mem string ) memory.MemSize {
@@ -178,6 +183,14 @@ func validateInitials(initials string) map[string]float64 {
178183 return is
179184}
180185
186+ func validateNumThreads (stackThreads int ) int {
187+ if stackThreads < 0 {
188+ fmt .Fprintf (os .Stderr , "Error in -%s flag; value must be positive" , threadsFlag )
189+ os .Exit (1 )
190+ }
191+ return stackThreads
192+ }
193+
181194func noArgs (args []string ) bool {
182195 return len (args ) == 0
183196}
0 commit comments