/** * Returns the initial buffer size based on the property set. * * @return Size in bytes. */ public long getInitialBufferSize() { long bufferSize = 0; long oldGenMax = getOldGenMax(); // If we did not get the value, throw exception if (oldGenMax == 0) { throw new RuntimeException("Could not calculate the old generation heap space. Please make sure CMR is running on the provided JVM."); } // Otherwise calculate now if (oldGenMax > maxOldSpaceOccupancyActiveFromOldGenSize) { bufferSize = (long) (oldGenMax * maxOldSpaceOccupancy); } else if (oldGenMax < minOldSpaceOccupancyActiveTillOldGenSize) { bufferSize = (long) (oldGenMax * minOldSpaceOccupancy); } else { // delta is the value that defines how much we can extend the minimum heap // occupancy // percentage by analyzing the max memory size // delta is actually representing additional percentage of heap we can take // it is always thru that: minHeapSizeOccupancy + delta < // maxHeapSizeOccupancy float delta = (maxOldSpaceOccupancy - minOldSpaceOccupancy) * ((float) (oldGenMax - minOldSpaceOccupancyActiveTillOldGenSize) / (maxOldSpaceOccupancyActiveFromOldGenSize - minOldSpaceOccupancyActiveTillOldGenSize)); bufferSize = (long) (oldGenMax * (minOldSpaceOccupancy + delta)); } return bufferSize; }
/** * Returns object security expansion rate based on the property set and given buffer size. * * @param bufferSize * Buffer's size that expansion rate has to be calculated for. * @return Expansion rate in percentages. */ public float getObjectSecurityExpansionRate(long bufferSize) { return (getObjectSecurityExpansionRateBufferSize(bufferSize) + getObjectSecurityExpansionRateBufferOccupancy(bufferSize, getOldGenMax())) / 2; }
/** * General Parameterized test to assure that no matter how big buffer size is, expansion rate * will be between min and max related. * * @param bufferSize * Buffer size. */ @Test(dataProvider = "Buffer-Size-Provider") public void parametrizedExpansionRateTest(long bufferSize) { float expansionRate = bufferProperties.getObjectSecurityExpansionRate(bufferSize); assertThat(expansionRate, is(lessThanOrEqualTo(bufferProperties.getMaxObjectExpansionRate()))); assertThat(expansionRate, is(greaterThanOrEqualTo(bufferProperties.getMinObjectExpansionRate()))); float relatedToSize = bufferProperties.getObjectSecurityExpansionRateBufferSize(bufferSize); float relatedToOccupancy = bufferProperties.getObjectSecurityExpansionRateBufferOccupancy(bufferSize, bufferProperties.getOldGenMax()); assertThat(expansionRate, is(equalTo((relatedToSize + relatedToOccupancy) / 2))); }
/** * Parameterized test to assure that no matter how big buffer size is, expansion rate will be * between min and max related to buffer occupancy. * * @param bufferSize * Buffer size. */ @Test(dataProvider = "Buffer-Size-Provider") public void parametrizedExpansionRateTestBufferOccupancy(long bufferSize) { float expansionRate = bufferProperties.getObjectSecurityExpansionRateBufferOccupancy(bufferSize, bufferProperties.getOldGenMax()); assertThat(expansionRate, is(lessThanOrEqualTo(bufferProperties.getMaxObjectExpansionRate()))); assertThat(expansionRate, is(greaterThanOrEqualTo(bufferProperties.getMinObjectExpansionRate()))); long maxOldGen = bufferProperties.getOldGenMax(); float occupancy = bufferSize / maxOldGen; if ((occupancy > bufferProperties.getMinObjectExpansionRateActiveTillOccupancy()) && (occupancy < bufferProperties.getMaxObjectExpansionRateActiveFromOccupancy())) { assertThat(expansionRate, is(lessThan(bufferProperties.getMaxObjectExpansionRate()))); assertThat(expansionRate, is(greaterThan(bufferProperties.getMinObjectExpansionRate()))); } }