diff --git a/calculator/calculator.go b/calculator/calculator.go index 9a448e2..c5895f8 100644 --- a/calculator/calculator.go +++ b/calculator/calculator.go @@ -42,9 +42,7 @@ func (c Calculator) Calculate() ([]fmt.Stringer, error) { headRoom := c.headRoom() directMemory := j.MaxDirectMemory - if directMemory == nil { - d := memory.DefaultMaxDirectMemory - directMemory = &d + if directMemory != nil { options = append(options, *directMemory) } @@ -69,12 +67,12 @@ func (c Calculator) Calculate() ([]fmt.Stringer, error) { options = append(options, *stack) } - overhead := c.overhead(headRoom, directMemory, metaspace, reservedCodeCache, stack) + overhead := c.overhead(headRoom, metaspace, reservedCodeCache, stack) available := memory.Size(*c.TotalMemory) if overhead > available { - return nil, fmt.Errorf("required memory %s is greater than %s available for allocation: %s, %s, %s, %s x %d threads", - overhead, available, directMemory, metaspace, reservedCodeCache, stack, *c.ThreadCount) + return nil, fmt.Errorf("required memory %s is greater than %s available for allocation: %s, %s, %s x %d threads", + overhead, available, metaspace, reservedCodeCache, stack, *c.ThreadCount) } heap := j.MaxHeap @@ -85,8 +83,8 @@ func (c Calculator) Calculate() ([]fmt.Stringer, error) { } if overhead+memory.Size(*heap) > available { - return nil, fmt.Errorf("required memory %s is greater than %s available for allocation: %s, %s, %s, %s, %s x %d threads", - overhead+memory.Size(*heap), available, directMemory, heap, metaspace, reservedCodeCache, stack, *c.ThreadCount) + return nil, fmt.Errorf("required memory %s is greater than %s available for allocation: %s, %s, %s, %s x %d threads", + overhead+memory.Size(*heap), available, heap, metaspace, reservedCodeCache, stack, *c.ThreadCount) } return options, nil @@ -104,9 +102,8 @@ func (c Calculator) metaspace() memory.MaxMetaspace { return memory.MaxMetaspace((*c.LoadedClassCount * 5800) + 14000000) } -func (c Calculator) overhead(headRoom memory.Size, directMemory *memory.MaxDirectMemory, metaspace *memory.MaxMetaspace, reservedCodeCache *memory.ReservedCodeCache, stack *memory.Stack) memory.Size { +func (c Calculator) overhead(headRoom memory.Size, metaspace *memory.MaxMetaspace, reservedCodeCache *memory.ReservedCodeCache, stack *memory.Stack) memory.Size { return headRoom + - memory.Size(*directMemory) + memory.Size(*metaspace) + memory.Size(*reservedCodeCache) + memory.Size(int64(*stack)*int64(*c.ThreadCount)) diff --git a/calculator/calculator_test.go b/calculator/calculator_test.go index 2fee186..330f57b 100644 --- a/calculator/calculator_test.go +++ b/calculator/calculator_test.go @@ -45,11 +45,10 @@ func TestCalculator(t *testing.T) { it("uses default and calculated values", func() { g.Expect(c.Calculate()).To(ConsistOf( - memory.DefaultMaxDirectMemory, memory.MaxMetaspace(19800000), memory.DefaultReservedCodeCache, memory.DefaultStack, - memory.MaxHeap(231858240), + memory.MaxHeap(242344000), )) }) @@ -58,10 +57,11 @@ func TestCalculator(t *testing.T) { c.JvmOptions.MaxDirectMemory = &d g.Expect(c.Calculate()).To(ConsistOf( + memory.MaxDirectMemory(1048576), memory.MaxMetaspace(19800000), memory.DefaultReservedCodeCache, memory.DefaultStack, - memory.MaxHeap(241295424), + memory.MaxHeap(242344000), )) }) @@ -70,10 +70,9 @@ func TestCalculator(t *testing.T) { c.JvmOptions.MaxMetaspace = &m g.Expect(c.Calculate()).To(ConsistOf( - memory.DefaultMaxDirectMemory, memory.DefaultReservedCodeCache, memory.DefaultStack, - memory.MaxHeap(250609664), + memory.MaxHeap(261095424), )) }) @@ -82,10 +81,9 @@ func TestCalculator(t *testing.T) { c.JvmOptions.ReservedCodeCache = &r g.Expect(c.Calculate()).To(ConsistOf( - memory.DefaultMaxDirectMemory, memory.MaxMetaspace(19800000), memory.DefaultStack, - memory.MaxHeap(482467904), + memory.MaxHeap(492953664), )) }) @@ -94,10 +92,9 @@ func TestCalculator(t *testing.T) { c.JvmOptions.Stack = &s g.Expect(c.Calculate()).To(ConsistOf( - memory.DefaultMaxDirectMemory, memory.MaxMetaspace(19800000), memory.DefaultReservedCodeCache, - memory.MaxHeap(231858240), + memory.MaxHeap(242344000), )) }) @@ -106,7 +103,6 @@ func TestCalculator(t *testing.T) { c.JvmOptions.MaxHeap = &h g.Expect(c.Calculate()).To(ConsistOf( - memory.DefaultMaxDirectMemory, memory.MaxMetaspace(19800000), memory.DefaultReservedCodeCache, memory.DefaultStack, diff --git a/memory/max_direct_memory.go b/memory/max_direct_memory.go index 3e9b03a..9186db8 100644 --- a/memory/max_direct_memory.go +++ b/memory/max_direct_memory.go @@ -22,8 +22,6 @@ import ( "strings" ) -const DefaultMaxDirectMemory = MaxDirectMemory(10 * Mibi) - var maxDirectMemoryRE = regexp.MustCompile(fmt.Sprintf("^-XX:MaxDirectMemorySize=(%s)$", sizePattern)) type MaxDirectMemory Size