Wed, 26 Nov 2014 14:17:06 +0400
8037968: Add tests on alignment of objects copied to survivor space
Reviewed-by: jmasa, dfazunen
1.1 --- a/test/TEST.groups Thu Dec 18 21:59:05 2014 -0800 1.2 +++ b/test/TEST.groups Wed Nov 26 14:17:06 2014 +0400 1.3 @@ -171,6 +171,7 @@ 1.4 gc/g1/TestShrinkAuxiliaryData20.java \ 1.5 gc/g1/TestShrinkAuxiliaryData25.java \ 1.6 gc/g1/TestShrinkAuxiliaryData30.java \ 1.7 + gc/survivorAlignment \ 1.8 runtime/InternalApi/ThreadCpuTimesDeadlock.java \ 1.9 serviceability/threads/TestFalseDeadLock.java \ 1.10 serviceability/jvmti/GetObjectSizeOverflow.java \
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/gc/arguments/TestSurvivorAlignmentInBytesOption.java Wed Nov 26 14:17:06 2014 +0400 2.3 @@ -0,0 +1,120 @@ 2.4 +/* 2.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +import com.oracle.java.testlibrary.ExitCode; 2.28 +import com.oracle.java.testlibrary.Utils; 2.29 +import com.oracle.java.testlibrary.cli.CommandLineOptionTest; 2.30 + 2.31 +import java.util.Collections; 2.32 +import java.util.LinkedList; 2.33 +import java.util.List; 2.34 + 2.35 +/** 2.36 + * @test 2.37 + * @bug 8031323 2.38 + * @summary Verify SurvivorAlignmentInBytes option processing. 2.39 + * @library /testlibrary 2.40 + * @run main TestSurvivorAlignmentInBytesOption 2.41 + */ 2.42 +public class TestSurvivorAlignmentInBytesOption { 2.43 + private static final String[] FILTERED_VM_OPTIONS 2.44 + = Utils.getFilteredTestJavaOpts( 2.45 + "UnlockExperimentalVMOptions", 2.46 + "SurvivorAlignmentInBytes", 2.47 + "ObjectAlignmentInBytes"); 2.48 + 2.49 + public static void main(String args[]) throws Throwable { 2.50 + String optionName = "SurvivorAlignmentInBytes"; 2.51 + String optionIsExperimental 2.52 + = CommandLineOptionTest.getExperimentalOptionErrorMessage( 2.53 + optionName); 2.54 + String valueIsTooSmall= ".*SurvivorAlignmentInBytes=.*must be greater" 2.55 + + " than ObjectAlignmentInBytes.*"; 2.56 + String mustBePowerOf2 = ".*SurvivorAlignmentInBytes=.*must be " 2.57 + + "power of 2.*"; 2.58 + 2.59 + // Verify that without -XX:+UnlockExperimentalVMOptions usage of 2.60 + // SurvivorAlignmentInBytes option will cause JVM startup failure 2.61 + // with the warning message saying that that option is experimental. 2.62 + CommandLineOptionTest.verifyJVMStartup( 2.63 + new String[]{optionIsExperimental}, null, ExitCode.FAIL, false, 2.64 + TestSurvivorAlignmentInBytesOption.prepareOptions( 2.65 + "-XX:-UnlockExperimentalVMOptions", 2.66 + CommandLineOptionTest.prepareNumericFlag( 2.67 + optionName, 64))); 2.68 + 2.69 + // Verify that with -XX:+UnlockExperimentalVMOptions passed to JVM 2.70 + // usage of SurvivorAlignmentInBytes option won't cause JVM startup 2.71 + // failure. 2.72 + CommandLineOptionTest.verifyJVMStartup( 2.73 + null, new String[]{optionIsExperimental}, ExitCode.OK, false, 2.74 + TestSurvivorAlignmentInBytesOption.prepareOptions( 2.75 + CommandLineOptionTest.prepareNumericFlag( 2.76 + optionName, 64))); 2.77 + 2.78 + // Verify that if specified SurvivorAlignmentInBytes is lower then 2.79 + // ObjectAlignmentInBytes, then the JVM startup will fail with 2.80 + // appropriate error message. 2.81 + CommandLineOptionTest.verifyJVMStartup( 2.82 + new String[]{valueIsTooSmall}, null, ExitCode.FAIL, false, 2.83 + TestSurvivorAlignmentInBytesOption.prepareOptions( 2.84 + CommandLineOptionTest.prepareNumericFlag( 2.85 + optionName, 2))); 2.86 + 2.87 + // Verify that if specified SurvivorAlignmentInBytes value is not 2.88 + // a power of 2 then the JVM startup will fail with appropriate error 2.89 + // message. 2.90 + CommandLineOptionTest.verifyJVMStartup( 2.91 + new String[]{mustBePowerOf2}, null, ExitCode.FAIL, false, 2.92 + TestSurvivorAlignmentInBytesOption.prepareOptions( 2.93 + CommandLineOptionTest.prepareNumericFlag( 2.94 + optionName, 127))); 2.95 + 2.96 + // Verify that if SurvivorAlignmentInBytes has correct value, then 2.97 + // the JVM will be started without errors. 2.98 + CommandLineOptionTest.verifyJVMStartup( 2.99 + null, new String[]{".*SurvivorAlignmentInBytes.*"}, 2.100 + ExitCode.OK, false, 2.101 + TestSurvivorAlignmentInBytesOption.prepareOptions( 2.102 + CommandLineOptionTest.prepareNumericFlag( 2.103 + optionName, 128))); 2.104 + 2.105 + // Verify that we can setup different SurvivorAlignmentInBytes values. 2.106 + for (int alignment = 32; alignment <= 128; alignment *= 2) { 2.107 + CommandLineOptionTest.verifyOptionValue(optionName, 2.108 + Integer.toString(alignment), false, 2.109 + TestSurvivorAlignmentInBytesOption.prepareOptions( 2.110 + CommandLineOptionTest.prepareNumericFlag( 2.111 + optionName, alignment))); 2.112 + } 2.113 + } 2.114 + 2.115 + private static String[] prepareOptions(String... options) { 2.116 + List<String> finalOptions = new LinkedList<>(); 2.117 + Collections.addAll(finalOptions, 2.118 + TestSurvivorAlignmentInBytesOption.FILTERED_VM_OPTIONS); 2.119 + finalOptions.add(CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS); 2.120 + Collections.addAll(finalOptions, options); 2.121 + return finalOptions.toArray(new String[finalOptions.size()]); 2.122 + } 2.123 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/gc/survivorAlignment/AlignmentHelper.java Wed Nov 26 14:17:06 2014 +0400 3.3 @@ -0,0 +1,174 @@ 3.4 +/* 3.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +import java.lang.management.MemoryPoolMXBean; 3.28 +import java.util.Optional; 3.29 + 3.30 +import sun.hotspot.WhiteBox; 3.31 + 3.32 +/** 3.33 + * Helper class aimed to provide information about alignment of objects in 3.34 + * particular heap space, expected memory usage after objects' allocation so on. 3.35 + */ 3.36 +public class AlignmentHelper { 3.37 + private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); 3.38 + 3.39 + private static final long OBJECT_ALIGNMENT_IN_BYTES_FOR_32_VM = 8L; 3.40 + 3.41 + /** 3.42 + * Max relative allowed actual memory usage deviation from expected memory 3.43 + * usage. 3.44 + */ 3.45 + private static final float MAX_RELATIVE_DEVIATION = 0.05f; // 5% 3.46 + 3.47 + public static final long OBJECT_ALIGNMENT_IN_BYTES = Optional.ofNullable( 3.48 + AlignmentHelper.WHITE_BOX.getIntxVMFlag("ObjectAlignmentInBytes")) 3.49 + .orElse(AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES_FOR_32_VM); 3.50 + 3.51 + public static final long SURVIVOR_ALIGNMENT_IN_BYTES = Optional.ofNullable( 3.52 + AlignmentHelper.WHITE_BOX.getIntxVMFlag("SurvivorAlignmentInBytes")) 3.53 + .orElseThrow(() ->new AssertionError( 3.54 + "Unable to get SurvivorAlignmentInBytes value")); 3.55 + /** 3.56 + * Min amount of memory that will be occupied by an object. 3.57 + */ 3.58 + public static final long MIN_OBJECT_SIZE 3.59 + = AlignmentHelper.WHITE_BOX.getObjectSize(new Object()); 3.60 + /** 3.61 + * Min amount of memory that will be occupied by an empty byte array. 3.62 + */ 3.63 + public static final long MIN_ARRAY_SIZE 3.64 + = AlignmentHelper.WHITE_BOX.getObjectSize(new byte[0]); 3.65 + 3.66 + /** 3.67 + * Precision at which actual memory usage in a heap space represented by 3.68 + * this sizing helper could be measured. 3.69 + */ 3.70 + private final long memoryUsageMeasurementPrecision; 3.71 + /** 3.72 + * Min amount of memory that will be occupied by an object allocated in a 3.73 + * heap space represented by this sizing helper. 3.74 + */ 3.75 + private final long minObjectSizeInThisSpace; 3.76 + /** 3.77 + * Object's alignment in a heap space represented by this sizing helper. 3.78 + */ 3.79 + private final long objectAlignmentInThisRegion; 3.80 + /** 3.81 + * MemoryPoolMXBean associated with a heap space represented by this sizing 3.82 + * helper. 3.83 + */ 3.84 + private final MemoryPoolMXBean poolMXBean; 3.85 + 3.86 + private static long alignUp(long value, long alignment) { 3.87 + return ((value - 1) / alignment + 1) * alignment; 3.88 + } 3.89 + 3.90 + protected AlignmentHelper(long memoryUsageMeasurementPrecision, 3.91 + long objectAlignmentInThisRegion, long minObjectSizeInThisSpace, 3.92 + MemoryPoolMXBean poolMXBean) { 3.93 + this.memoryUsageMeasurementPrecision = memoryUsageMeasurementPrecision; 3.94 + this.minObjectSizeInThisSpace = minObjectSizeInThisSpace; 3.95 + this.objectAlignmentInThisRegion = objectAlignmentInThisRegion; 3.96 + this.poolMXBean = poolMXBean; 3.97 + } 3.98 + 3.99 + /** 3.100 + * Returns how many objects have to be allocated to fill 3.101 + * {@code memoryToFill} bytes in this heap space using objects of size 3.102 + * {@code objectSize}. 3.103 + */ 3.104 + public int getObjectsCount(long memoryToFill, long objectSize) { 3.105 + return (int) (memoryToFill / getObjectSizeInThisSpace(objectSize)); 3.106 + } 3.107 + 3.108 + /** 3.109 + * Returns amount of memory that {@code objectsCount} of objects with size 3.110 + * {@code objectSize} will occupy this this space after allocation. 3.111 + */ 3.112 + public long getExpectedMemoryUsage(long objectSize, int objectsCount) { 3.113 + long correctedObjectSize = getObjectSizeInThisSpace(objectSize); 3.114 + return AlignmentHelper.alignUp(correctedObjectSize * objectsCount, 3.115 + memoryUsageMeasurementPrecision); 3.116 + } 3.117 + 3.118 + /** 3.119 + * Returns current memory usage in this heap space. 3.120 + */ 3.121 + public long getActualMemoryUsage() { 3.122 + return poolMXBean.getUsage().getUsed(); 3.123 + } 3.124 + 3.125 + /** 3.126 + * Returns maximum memory usage deviation from {@code expectedMemoryUsage} 3.127 + * given the max allowed relative deviation equal to 3.128 + * {@code relativeDeviation}. 3.129 + * 3.130 + * Note that value returned by this method is aligned according to 3.131 + * memory measurement precision for this heap space. 3.132 + */ 3.133 + public long getAllowedMemoryUsageDeviation(long expectedMemoryUsage) { 3.134 + long unalignedDeviation = (long) (expectedMemoryUsage * 3.135 + AlignmentHelper.MAX_RELATIVE_DEVIATION); 3.136 + return AlignmentHelper.alignUp(unalignedDeviation, 3.137 + memoryUsageMeasurementPrecision); 3.138 + } 3.139 + 3.140 + /** 3.141 + * Returns amount of memory that will be occupied by an object with size 3.142 + * {@code objectSize} in this heap space. 3.143 + */ 3.144 + public long getObjectSizeInThisSpace(long objectSize) { 3.145 + objectSize = Math.max(objectSize, minObjectSizeInThisSpace); 3.146 + 3.147 + long alignedObjectSize = AlignmentHelper.alignUp(objectSize, 3.148 + objectAlignmentInThisRegion); 3.149 + long sizeDiff = alignedObjectSize - objectSize; 3.150 + 3.151 + // If there is not enough space to fit padding object, then object will 3.152 + // be aligned to {@code 2 * objectAlignmentInThisRegion}. 3.153 + if (sizeDiff >= AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES 3.154 + && sizeDiff < AlignmentHelper.MIN_OBJECT_SIZE) { 3.155 + alignedObjectSize += AlignmentHelper.MIN_OBJECT_SIZE; 3.156 + alignedObjectSize = AlignmentHelper.alignUp(alignedObjectSize, 3.157 + objectAlignmentInThisRegion); 3.158 + } 3.159 + 3.160 + return alignedObjectSize; 3.161 + } 3.162 + @Override 3.163 + public String toString() { 3.164 + StringBuilder builder = new StringBuilder(); 3.165 + 3.166 + builder.append(String.format("AlignmentHelper for memory pool '%s':%n", 3.167 + poolMXBean.getName())); 3.168 + builder.append(String.format("Memory usage measurement precision: %d%n", 3.169 + memoryUsageMeasurementPrecision)); 3.170 + builder.append(String.format("Min object size in this space: %d%n", 3.171 + minObjectSizeInThisSpace)); 3.172 + builder.append(String.format("Object alignment in this space: %d%n", 3.173 + objectAlignmentInThisRegion)); 3.174 + 3.175 + return builder.toString(); 3.176 + } 3.177 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/gc/survivorAlignment/SurvivorAlignmentTestMain.java Wed Nov 26 14:17:06 2014 +0400 4.3 @@ -0,0 +1,416 @@ 4.4 +/* 4.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 + * or visit www.oracle.com if you need additional information or have any 4.24 + * questions. 4.25 + */ 4.26 + 4.27 +import java.lang.management.ManagementFactory; 4.28 +import java.lang.management.MemoryPoolMXBean; 4.29 +import java.util.Objects; 4.30 +import java.util.Optional; 4.31 +import java.util.regex.Matcher; 4.32 +import java.util.regex.Pattern; 4.33 + 4.34 +import com.oracle.java.testlibrary.Asserts; 4.35 +import com.sun.management.ThreadMXBean; 4.36 +import sun.hotspot.WhiteBox; 4.37 +import sun.misc.Unsafe; 4.38 + 4.39 +/** 4.40 + * Main class for tests on {@code SurvivorAlignmentInBytes} option. 4.41 + * 4.42 + * Typical usage is to obtain instance using fromArgs method, allocate objects 4.43 + * and verify that actual memory usage in tested heap space is close to 4.44 + * expected. 4.45 + */ 4.46 +public class SurvivorAlignmentTestMain { 4.47 + enum HeapSpace { 4.48 + EDEN, 4.49 + SURVIVOR, 4.50 + TENURED 4.51 + } 4.52 + 4.53 + public static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); 4.54 + 4.55 + public static final long MAX_TENURING_THRESHOLD = Optional.ofNullable( 4.56 + SurvivorAlignmentTestMain.WHITE_BOX.getIntxVMFlag( 4.57 + "MaxTenuringThreshold")).orElse(15L); 4.58 + 4.59 + /** 4.60 + * Regexp used to parse memory size params, like 2G, 34m or 15k. 4.61 + */ 4.62 + private static final Pattern SIZE_REGEX 4.63 + = Pattern.compile("(?<size>[0-9]+)(?<multiplier>[GMKgmk])?"); 4.64 + 4.65 + // Names of different heap spaces. 4.66 + private static final String DEF_NEW_EDEN = "Eden Space"; 4.67 + private static final String DEF_NEW_SURVIVOR = "Survivor Space"; 4.68 + private static final String PAR_NEW_EDEN = "Par Eden Space"; 4.69 + private static final String PAR_NEW_SURVIVOR = "Par Survivor Space"; 4.70 + private static final String PS_EDEN = "PS Eden Space"; 4.71 + private static final String PS_SURVIVOR = "PS Survivor Space"; 4.72 + private static final String G1_EDEN = "G1 Eden Space"; 4.73 + private static final String G1_SURVIVOR = "G1 Survivor Space"; 4.74 + private static final String SERIAL_TENURED = "Tenured Gen"; 4.75 + private static final String CMS_TENURED = "CMS Old Gen"; 4.76 + private static final String PS_TENURED = "PS Old Gen"; 4.77 + private static final String G1_TENURED = "G1 Old Gen"; 4.78 + 4.79 + private static final long G1_HEAP_REGION_SIZE = Optional.ofNullable( 4.80 + SurvivorAlignmentTestMain.WHITE_BOX.getUintxVMFlag( 4.81 + "G1HeapRegionSize")).orElse(-1L); 4.82 + 4.83 + /** 4.84 + * Min size of free chunk in CMS generation. 4.85 + * An object allocated in CMS generation will at least occupy this amount 4.86 + * of bytes. 4.87 + */ 4.88 + private static final long CMS_MIN_FREE_CHUNK_SIZE 4.89 + = 3L * Unsafe.ADDRESS_SIZE; 4.90 + 4.91 + private static final AlignmentHelper EDEN_SPACE_HELPER; 4.92 + private static final AlignmentHelper SURVIVOR_SPACE_HELPER; 4.93 + private static final AlignmentHelper TENURED_SPACE_HELPER; 4.94 + /** 4.95 + * Amount of memory that should be filled during a test run. 4.96 + */ 4.97 + private final long memoryToFill; 4.98 + /** 4.99 + * The size of an objects that will be allocated during a test run. 4.100 + */ 4.101 + private final long objectSize; 4.102 + /** 4.103 + * Amount of memory that will be actually occupied by an object in eden 4.104 + * space. 4.105 + */ 4.106 + private final long actualObjectSize; 4.107 + /** 4.108 + * Storage for allocated objects. 4.109 + */ 4.110 + private final Object[] garbage; 4.111 + /** 4.112 + * Heap space whose memory usage is a subject of assertions during the test 4.113 + * run. 4.114 + */ 4.115 + private final HeapSpace testedSpace; 4.116 + 4.117 + private long[] baselinedThreadMemoryUsage = null; 4.118 + private long[] threadIds = null; 4.119 + 4.120 + /** 4.121 + * Initialize {@code EDEN_SPACE_HELPER}, {@code SURVIVOR_SPACE_HELPER} and 4.122 + * {@code TENURED_SPACE_HELPER} to represent heap spaces in use. 4.123 + * 4.124 + * Note that regardless to GC object's alignment in survivor space is 4.125 + * expected to be equal to {@code SurvivorAlignmentInBytes} value and 4.126 + * alignment in other spaces is expected to be equal to 4.127 + * {@code ObjectAlignmentInBytes} value. 4.128 + * 4.129 + * In CMS generation we can't allocate less then {@code MinFreeChunk} value, 4.130 + * for other CGs we expect that object of size {@code MIN_OBJECT_SIZE} 4.131 + * could be allocated as it is (of course, its size could be aligned 4.132 + * according to alignment value used in a particular space). 4.133 + * 4.134 + * For G1 GC MXBeans could report memory usage only with region size 4.135 + * precision (if an object allocated in some G1 heap region, then all region 4.136 + * will claimed as used), so for G1's spaces precision is equal to 4.137 + * {@code G1HeapRegionSize} value. 4.138 + */ 4.139 + static { 4.140 + AlignmentHelper edenHelper = null; 4.141 + AlignmentHelper survivorHelper = null; 4.142 + AlignmentHelper tenuredHelper = null; 4.143 + for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) { 4.144 + switch (pool.getName()) { 4.145 + case SurvivorAlignmentTestMain.DEF_NEW_EDEN: 4.146 + case SurvivorAlignmentTestMain.PAR_NEW_EDEN: 4.147 + case SurvivorAlignmentTestMain.PS_EDEN: 4.148 + Asserts.assertNull(edenHelper, 4.149 + "Only one bean for eden space is expected."); 4.150 + edenHelper = new AlignmentHelper( 4.151 + AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES, 4.152 + AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES, 4.153 + AlignmentHelper.MIN_OBJECT_SIZE, pool); 4.154 + break; 4.155 + case SurvivorAlignmentTestMain.G1_EDEN: 4.156 + Asserts.assertNull(edenHelper, 4.157 + "Only one bean for eden space is expected."); 4.158 + edenHelper = new AlignmentHelper( 4.159 + SurvivorAlignmentTestMain.G1_HEAP_REGION_SIZE, 4.160 + AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES, 4.161 + AlignmentHelper.MIN_OBJECT_SIZE, pool); 4.162 + break; 4.163 + case SurvivorAlignmentTestMain.DEF_NEW_SURVIVOR: 4.164 + case SurvivorAlignmentTestMain.PAR_NEW_SURVIVOR: 4.165 + case SurvivorAlignmentTestMain.PS_SURVIVOR: 4.166 + Asserts.assertNull(survivorHelper, 4.167 + "Only one bean for survivor space is expected."); 4.168 + survivorHelper = new AlignmentHelper( 4.169 + AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES, 4.170 + AlignmentHelper.SURVIVOR_ALIGNMENT_IN_BYTES, 4.171 + AlignmentHelper.MIN_OBJECT_SIZE, pool); 4.172 + break; 4.173 + case SurvivorAlignmentTestMain.G1_SURVIVOR: 4.174 + Asserts.assertNull(survivorHelper, 4.175 + "Only one bean for survivor space is expected."); 4.176 + survivorHelper = new AlignmentHelper( 4.177 + SurvivorAlignmentTestMain.G1_HEAP_REGION_SIZE, 4.178 + AlignmentHelper.SURVIVOR_ALIGNMENT_IN_BYTES, 4.179 + AlignmentHelper.MIN_OBJECT_SIZE, pool); 4.180 + break; 4.181 + case SurvivorAlignmentTestMain.SERIAL_TENURED: 4.182 + case SurvivorAlignmentTestMain.PS_TENURED: 4.183 + case SurvivorAlignmentTestMain.G1_TENURED: 4.184 + Asserts.assertNull(tenuredHelper, 4.185 + "Only one bean for tenured space is expected."); 4.186 + tenuredHelper = new AlignmentHelper( 4.187 + AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES, 4.188 + AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES, 4.189 + AlignmentHelper.MIN_OBJECT_SIZE, pool); 4.190 + break; 4.191 + case SurvivorAlignmentTestMain.CMS_TENURED: 4.192 + Asserts.assertNull(tenuredHelper, 4.193 + "Only one bean for tenured space is expected."); 4.194 + tenuredHelper = new AlignmentHelper( 4.195 + AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES, 4.196 + AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES, 4.197 + SurvivorAlignmentTestMain.CMS_MIN_FREE_CHUNK_SIZE, 4.198 + pool); 4.199 + break; 4.200 + } 4.201 + } 4.202 + EDEN_SPACE_HELPER = Objects.requireNonNull(edenHelper, 4.203 + "AlignmentHelper for eden space should be initialized."); 4.204 + SURVIVOR_SPACE_HELPER = Objects.requireNonNull(survivorHelper, 4.205 + "AlignmentHelper for survivor space should be initialized."); 4.206 + TENURED_SPACE_HELPER = Objects.requireNonNull(tenuredHelper, 4.207 + "AlignmentHelper for tenured space should be initialized."); 4.208 + } 4.209 + /** 4.210 + * Returns an SurvivorAlignmentTestMain instance constructed using CLI 4.211 + * options. 4.212 + * 4.213 + * Following options are expected: 4.214 + * <ul> 4.215 + * <li>memoryToFill</li> 4.216 + * <li>objectSize</li> 4.217 + * </ul> 4.218 + * 4.219 + * Both argument may contain multiplier suffix k, m or g. 4.220 + */ 4.221 + public static SurvivorAlignmentTestMain fromArgs(String[] args) { 4.222 + Asserts.assertEQ(args.length, 3, "Expected three arguments: " 4.223 + + "memory size, object size and tested heap space name."); 4.224 + 4.225 + long memoryToFill = parseSize(args[0]); 4.226 + long objectSize = Math.max(parseSize(args[1]), 4.227 + AlignmentHelper.MIN_ARRAY_SIZE); 4.228 + HeapSpace testedSpace = HeapSpace.valueOf(args[2]); 4.229 + 4.230 + return new SurvivorAlignmentTestMain(memoryToFill, objectSize, 4.231 + testedSpace); 4.232 + } 4.233 + 4.234 + /** 4.235 + * Returns a value parsed from a string with format 4.236 + * <integer><multiplier>. 4.237 + */ 4.238 + private static long parseSize(String sizeString) { 4.239 + Matcher matcher = SIZE_REGEX.matcher(sizeString); 4.240 + Asserts.assertTrue(matcher.matches(), 4.241 + "sizeString should have following format \"[0-9]+([MBK])?\""); 4.242 + long size = Long.valueOf(matcher.group("size")); 4.243 + 4.244 + if (matcher.group("multiplier") != null) { 4.245 + long K = 1024L; 4.246 + // fall through multipliers 4.247 + switch (matcher.group("multiplier").toLowerCase()) { 4.248 + case "g": 4.249 + size *= K; 4.250 + case "m": 4.251 + size *= K; 4.252 + case "k": 4.253 + size *= K; 4.254 + } 4.255 + } 4.256 + return size; 4.257 + } 4.258 + 4.259 + private SurvivorAlignmentTestMain(long memoryToFill, long objectSize, 4.260 + HeapSpace testedSpace) { 4.261 + this.objectSize = objectSize; 4.262 + this.memoryToFill = memoryToFill; 4.263 + this.testedSpace = testedSpace; 4.264 + 4.265 + AlignmentHelper helper = SurvivorAlignmentTestMain.EDEN_SPACE_HELPER; 4.266 + 4.267 + this.actualObjectSize = helper.getObjectSizeInThisSpace( 4.268 + this.objectSize); 4.269 + int arrayLength = helper.getObjectsCount(memoryToFill, this.objectSize); 4.270 + garbage = new Object[arrayLength]; 4.271 + } 4.272 + 4.273 + /** 4.274 + * Allocate byte arrays to fill {@code memoryToFill} memory. 4.275 + */ 4.276 + public void allocate() { 4.277 + int byteArrayLength = Math.max((int) (objectSize 4.278 + - Unsafe.ARRAY_BYTE_BASE_OFFSET), 0); 4.279 + 4.280 + for (int i = 0; i < garbage.length; i++) { 4.281 + garbage[i] = new byte[byteArrayLength]; 4.282 + } 4.283 + } 4.284 + 4.285 + /** 4.286 + * Release memory occupied after {@code allocate} call. 4.287 + */ 4.288 + public void release() { 4.289 + for (int i = 0; i < garbage.length; i++) { 4.290 + garbage[i] = null; 4.291 + } 4.292 + } 4.293 + 4.294 + /** 4.295 + * Returns expected amount of memory occupied in a {@code heapSpace} by 4.296 + * objects referenced from {@code garbage} array. 4.297 + */ 4.298 + public long getExpectedMemoryUsage() { 4.299 + AlignmentHelper alignmentHelper = getAlignmentHelper(testedSpace); 4.300 + return alignmentHelper.getExpectedMemoryUsage(objectSize, 4.301 + garbage.length); 4.302 + } 4.303 + 4.304 + /** 4.305 + * Verifies that memory usage in a {@code heapSpace} deviates from 4.306 + * {@code expectedUsage} for no more than {@code MAX_RELATIVE_DEVIATION}. 4.307 + */ 4.308 + public void verifyMemoryUsage(long expectedUsage) { 4.309 + AlignmentHelper alignmentHelper = getAlignmentHelper(testedSpace); 4.310 + 4.311 + long actualMemoryUsage = alignmentHelper.getActualMemoryUsage(); 4.312 + boolean otherThreadsAllocatedMemory = areOtherThreadsAllocatedMemory(); 4.313 + 4.314 + long memoryUsageDiff = Math.abs(actualMemoryUsage - expectedUsage); 4.315 + long maxAllowedUsageDiff 4.316 + = alignmentHelper.getAllowedMemoryUsageDeviation(expectedUsage); 4.317 + 4.318 + System.out.println("Verifying memory usage in space: " + testedSpace); 4.319 + System.out.println("Allocated objects count: " + garbage.length); 4.320 + System.out.println("Desired object size: " + objectSize); 4.321 + System.out.println("Actual object size: " + actualObjectSize); 4.322 + System.out.println("Expected object size in space: " 4.323 + + alignmentHelper.getObjectSizeInThisSpace(objectSize)); 4.324 + System.out.println("Expected memory usage: " + expectedUsage); 4.325 + System.out.println("Actual memory usage: " + actualMemoryUsage); 4.326 + System.out.println("Memory usage diff: " + memoryUsageDiff); 4.327 + System.out.println("Max allowed usage diff: " + maxAllowedUsageDiff); 4.328 + 4.329 + if (memoryUsageDiff > maxAllowedUsageDiff 4.330 + && otherThreadsAllocatedMemory) { 4.331 + System.out.println("Memory usage diff is incorrect, but it seems " 4.332 + + "like someone else allocated objects"); 4.333 + return; 4.334 + } 4.335 + 4.336 + Asserts.assertLTE(memoryUsageDiff, maxAllowedUsageDiff, 4.337 + "Actual memory usage should not deviate from expected for " + 4.338 + "more then " + maxAllowedUsageDiff); 4.339 + } 4.340 + 4.341 + /** 4.342 + * Baselines amount of memory allocated by each thread. 4.343 + */ 4.344 + public void baselineMemoryAllocation() { 4.345 + ThreadMXBean bean = (ThreadMXBean) ManagementFactory.getThreadMXBean(); 4.346 + threadIds = bean.getAllThreadIds(); 4.347 + baselinedThreadMemoryUsage = bean.getThreadAllocatedBytes(threadIds); 4.348 + } 4.349 + 4.350 + /** 4.351 + * Checks if threads other then the current thread were allocating objects 4.352 + * after baselinedThreadMemoryUsage call. 4.353 + * 4.354 + * If baselinedThreadMemoryUsage was not called, then this method will return 4.355 + * {@code false}. 4.356 + */ 4.357 + public boolean areOtherThreadsAllocatedMemory() { 4.358 + if (baselinedThreadMemoryUsage == null) { 4.359 + return false; 4.360 + } 4.361 + 4.362 + ThreadMXBean bean = (ThreadMXBean) ManagementFactory.getThreadMXBean(); 4.363 + long currentMemoryAllocation[] 4.364 + = bean.getThreadAllocatedBytes(threadIds); 4.365 + boolean otherThreadsAllocatedMemory = false; 4.366 + 4.367 + System.out.println("Verifying amount of memory allocated by threads:"); 4.368 + for (int i = 0; i < threadIds.length; i++) { 4.369 + System.out.format("Thread %d%nbaseline allocation: %d" 4.370 + + "%ncurrent allocation:%d%n", threadIds[i], 4.371 + baselinedThreadMemoryUsage[i], currentMemoryAllocation[i]); 4.372 + System.out.println(bean.getThreadInfo(threadIds[i])); 4.373 + 4.374 + long bytesAllocated = Math.abs(currentMemoryAllocation[i] 4.375 + - baselinedThreadMemoryUsage[i]); 4.376 + if (bytesAllocated > 0 4.377 + && threadIds[i] != Thread.currentThread().getId()) { 4.378 + otherThreadsAllocatedMemory = true; 4.379 + } 4.380 + } 4.381 + 4.382 + return otherThreadsAllocatedMemory; 4.383 + } 4.384 + 4.385 + @Override 4.386 + public String toString() { 4.387 + StringBuilder builder = new StringBuilder(); 4.388 + 4.389 + builder.append(String.format("SurvivorAlignmentTestMain info:%n")); 4.390 + builder.append(String.format("Desired object size: %d%n", objectSize)); 4.391 + builder.append(String.format("Memory to fill: %d%n", memoryToFill)); 4.392 + builder.append(String.format("Objects to be allocated: %d%n", 4.393 + garbage.length)); 4.394 + 4.395 + builder.append(String.format("Alignment helpers to be used: %n")); 4.396 + for (HeapSpace heapSpace: HeapSpace.values()) { 4.397 + builder.append(String.format("For space %s:%n%s%n", heapSpace, 4.398 + getAlignmentHelper(heapSpace))); 4.399 + } 4.400 + 4.401 + return builder.toString(); 4.402 + } 4.403 + 4.404 + /** 4.405 + * Returns {@code AlignmentHelper} for a space {@code heapSpace}. 4.406 + */ 4.407 + public static AlignmentHelper getAlignmentHelper(HeapSpace heapSpace) { 4.408 + switch (heapSpace) { 4.409 + case EDEN: 4.410 + return SurvivorAlignmentTestMain.EDEN_SPACE_HELPER; 4.411 + case SURVIVOR: 4.412 + return SurvivorAlignmentTestMain.SURVIVOR_SPACE_HELPER; 4.413 + case TENURED: 4.414 + return SurvivorAlignmentTestMain.TENURED_SPACE_HELPER; 4.415 + default: 4.416 + throw new Error("Unexpected heap space: " + heapSpace); 4.417 + } 4.418 + } 4.419 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/gc/survivorAlignment/TestAllocationInEden.java Wed Nov 26 14:17:06 2014 +0400 5.3 @@ -0,0 +1,84 @@ 5.4 +/* 5.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. 5.11 + * 5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 + * version 2 for more details (a copy is included in the LICENSE file that 5.16 + * accompanied this code). 5.17 + * 5.18 + * You should have received a copy of the GNU General Public License version 5.19 + * 2 along with this work; if not, write to the Free Software Foundation, 5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 + * 5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.23 + * or visit www.oracle.com if you need additional information or have any 5.24 + * questions. 5.25 + */ 5.26 + 5.27 +/** 5.28 + * @test 5.29 + * @bug 8031323 5.30 + * @summary Verify that object's alignment in eden space is not affected by 5.31 + * SurvivorAlignmentInBytes option. 5.32 + * @library /testlibrary /testlibrary/whitebox 5.33 + * @build TestAllocationInEden SurvivorAlignmentTestMain AlignmentHelper 5.34 + * @run main ClassFileInstaller sun.hotspot.WhiteBox 5.35 + * sun.hotspot.WhiteBox$WhiteBoxPermission 5.36 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 5.37 + * -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m 5.38 + * -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions 5.39 + * -XX:SurvivorAlignmentInBytes=32 -XX:-UseTLAB 5.40 + * -XX:OldSize=128m -XX:-ExplicitGCInvokesConcurrent 5.41 + * TestAllocationInEden 10m 9 EDEN 5.42 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 5.43 + * -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m 5.44 + * -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions 5.45 + * -XX:SurvivorAlignmentInBytes=32 -XX:-UseTLAB 5.46 + * -XX:OldSize=128m -XX:-ExplicitGCInvokesConcurrent 5.47 + * TestAllocationInEden 10m 47 EDEN 5.48 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 5.49 + * -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m 5.50 + * -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions 5.51 + * -XX:SurvivorAlignmentInBytes=64 -XX:-UseTLAB 5.52 + * -XX:OldSize=128m -XX:-ExplicitGCInvokesConcurrent 5.53 + * TestAllocationInEden 10m 9 EDEN 5.54 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 5.55 + * -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m 5.56 + * -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions 5.57 + * -XX:SurvivorAlignmentInBytes=64 -XX:-UseTLAB 5.58 + * -XX:OldSize=128m -XX:-ExplicitGCInvokesConcurrent 5.59 + * TestAllocationInEden 10m 87 EDEN 5.60 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 5.61 + * -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m 5.62 + * -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions 5.63 + * -XX:SurvivorAlignmentInBytes=128 -XX:-UseTLAB 5.64 + * -XX:OldSize=128m -XX:-ExplicitGCInvokesConcurrent 5.65 + * TestAllocationInEden 10m 9 EDEN 5.66 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 5.67 + * -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m 5.68 + * -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions 5.69 + * -XX:SurvivorAlignmentInBytes=128 -XX:-UseTLAB 5.70 + * -XX:OldSize=128m -XX:-ExplicitGCInvokesConcurrent 5.71 + * TestAllocationInEden 10m 147 EDEN 5.72 + */ 5.73 +public class TestAllocationInEden { 5.74 + public static void main(String args[]) { 5.75 + SurvivorAlignmentTestMain test 5.76 + = SurvivorAlignmentTestMain.fromArgs(args); 5.77 + System.out.println(test); 5.78 + 5.79 + long expectedMemoryUsage = test.getExpectedMemoryUsage(); 5.80 + test.baselineMemoryAllocation(); 5.81 + System.gc(); 5.82 + 5.83 + test.allocate(); 5.84 + 5.85 + test.verifyMemoryUsage(expectedMemoryUsage); 5.86 + } 5.87 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/gc/survivorAlignment/TestPromotionFromEdenToTenured.java Wed Nov 26 14:17:06 2014 +0400 6.3 @@ -0,0 +1,96 @@ 6.4 +/* 6.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 + * 6.8 + * This code is free software; you can redistribute it and/or modify it 6.9 + * under the terms of the GNU General Public License version 2 only, as 6.10 + * published by the Free Software Foundation. 6.11 + * 6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.15 + * version 2 for more details (a copy is included in the LICENSE file that 6.16 + * accompanied this code). 6.17 + * 6.18 + * You should have received a copy of the GNU General Public License version 6.19 + * 2 along with this work; if not, write to the Free Software Foundation, 6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.21 + * 6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.23 + * or visit www.oracle.com if you need additional information or have any 6.24 + * questions. 6.25 + */ 6.26 + 6.27 +/** 6.28 + * @test 6.29 + * @bug 8031323 6.30 + * @summary Verify that objects promoted from eden space to tenured space during 6.31 + * full GC are not aligned to SurvivorAlignmentInBytes value. 6.32 + * @library /testlibrary /testlibrary/whitebox 6.33 + * @build TestPromotionFromEdenToTenured SurvivorAlignmentTestMain 6.34 + * AlignmentHelper 6.35 + * @run main ClassFileInstaller sun.hotspot.WhiteBox 6.36 + * sun.hotspot.WhiteBox$WhiteBoxPermission 6.37 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 6.38 + * -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m 6.39 + * -XX:OldSize=32m -XX:SurvivorRatio=1 6.40 + * -XX:-ExplicitGCInvokesConcurrent 6.41 + * -XX:+UnlockExperimentalVMOptions 6.42 + * -XX:SurvivorAlignmentInBytes=32 6.43 + * TestPromotionFromEdenToTenured 10m 9 TENURED 6.44 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 6.45 + * -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m 6.46 + * -XX:OldSize=32m -XX:SurvivorRatio=1 6.47 + * -XX:-ExplicitGCInvokesConcurrent 6.48 + * -XX:+UnlockExperimentalVMOptions 6.49 + * -XX:SurvivorAlignmentInBytes=32 6.50 + * TestPromotionFromEdenToTenured 10m 47 TENURED 6.51 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 6.52 + * -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m 6.53 + * -XX:OldSize=32m -XX:SurvivorRatio=1 6.54 + * -XX:-ExplicitGCInvokesConcurrent 6.55 + * -XX:+UnlockExperimentalVMOptions 6.56 + * -XX:SurvivorAlignmentInBytes=64 6.57 + * TestPromotionFromEdenToTenured 10m 9 TENURED 6.58 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 6.59 + * -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m 6.60 + * -XX:OldSize=32m -XX:SurvivorRatio=1 6.61 + * -XX:-ExplicitGCInvokesConcurrent 6.62 + * -XX:+UnlockExperimentalVMOptions 6.63 + * -XX:SurvivorAlignmentInBytes=64 6.64 + * TestPromotionFromEdenToTenured 10m 87 TENURED 6.65 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 6.66 + * -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m 6.67 + * -XX:OldSize=32M -XX:SurvivorRatio=1 6.68 + * -XX:-ExplicitGCInvokesConcurrent 6.69 + * -XX:+UnlockExperimentalVMOptions 6.70 + * -XX:SurvivorAlignmentInBytes=128 6.71 + * TestPromotionFromEdenToTenured 10m 9 TENURED 6.72 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 6.73 + * -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m 6.74 + * -XX:OldSize=32m -XX:SurvivorRatio=1 6.75 + * -XX:-ExplicitGCInvokesConcurrent 6.76 + * -XX:+UnlockExperimentalVMOptions 6.77 + * -XX:SurvivorAlignmentInBytes=128 6.78 + * TestPromotionFromEdenToTenured 10m 147 TENURED 6.79 + */ 6.80 +public class TestPromotionFromEdenToTenured { 6.81 + public static void main(String args[]) { 6.82 + SurvivorAlignmentTestMain test 6.83 + = SurvivorAlignmentTestMain.fromArgs(args); 6.84 + System.out.println(test); 6.85 + 6.86 + long expectedMemoryUsage = test.getExpectedMemoryUsage(); 6.87 + test.baselineMemoryAllocation(); 6.88 + System.gc(); 6.89 + // increase expected usage by current old gen usage 6.90 + expectedMemoryUsage += SurvivorAlignmentTestMain.getAlignmentHelper( 6.91 + SurvivorAlignmentTestMain.HeapSpace.TENURED) 6.92 + .getActualMemoryUsage(); 6.93 + 6.94 + test.allocate(); 6.95 + System.gc(); 6.96 + 6.97 + test.verifyMemoryUsage(expectedMemoryUsage); 6.98 + } 6.99 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/gc/survivorAlignment/TestPromotionFromSurvivorToTenuredAfterFullGC.java Wed Nov 26 14:17:06 2014 +0400 7.3 @@ -0,0 +1,101 @@ 7.4 +/* 7.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.7 + * 7.8 + * This code is free software; you can redistribute it and/or modify it 7.9 + * under the terms of the GNU General Public License version 2 only, as 7.10 + * published by the Free Software Foundation. 7.11 + * 7.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 7.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.15 + * version 2 for more details (a copy is included in the LICENSE file that 7.16 + * accompanied this code). 7.17 + * 7.18 + * You should have received a copy of the GNU General Public License version 7.19 + * 2 along with this work; if not, write to the Free Software Foundation, 7.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.21 + * 7.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 7.23 + * or visit www.oracle.com if you need additional information or have any 7.24 + * questions. 7.25 + */ 7.26 + 7.27 +/** 7.28 + * @test 7.29 + * @bug 8031323 7.30 + * @summary Verify that objects promoted from survivor space to tenured space 7.31 + * during full GC are not aligned to SurvivorAlignmentInBytes value. 7.32 + * @library /testlibrary /testlibrary/whitebox 7.33 + * @build TestPromotionFromSurvivorToTenuredAfterFullGC 7.34 + * SurvivorAlignmentTestMain AlignmentHelper 7.35 + * @run main ClassFileInstaller sun.hotspot.WhiteBox 7.36 + * sun.hotspot.WhiteBox$WhiteBoxPermission 7.37 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 7.38 + * -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m 7.39 + * -XX:OldSize=32m -XX:SurvivorRatio=1 7.40 + * -XX:-ExplicitGCInvokesConcurrent 7.41 + * -XX:+UnlockExperimentalVMOptions 7.42 + * -XX:SurvivorAlignmentInBytes=32 7.43 + * TestPromotionFromSurvivorToTenuredAfterFullGC 10m 9 TENURED 7.44 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 7.45 + * -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m 7.46 + * -XX:OldSize=32m -XX:SurvivorRatio=1 7.47 + * -XX:-ExplicitGCInvokesConcurrent 7.48 + * -XX:+UnlockExperimentalVMOptions 7.49 + * -XX:SurvivorAlignmentInBytes=32 7.50 + * TestPromotionFromSurvivorToTenuredAfterFullGC 20m 47 7.51 + * TENURED 7.52 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 7.53 + * -XX:+WhiteBoxAPI -XX:NewSize=200m -XX:MaxNewSize=200m 7.54 + * -XX:OldSize=32m -XX:InitialHeapSize=232m 7.55 + * -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent 7.56 + * -XX:+UnlockExperimentalVMOptions 7.57 + * -XX:SurvivorAlignmentInBytes=64 7.58 + * TestPromotionFromSurvivorToTenuredAfterFullGC 10m 9 TENURED 7.59 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 7.60 + * -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m 7.61 + * -XX:OldSize=32m -XX:SurvivorRatio=1 7.62 + * -XX:-ExplicitGCInvokesConcurrent 7.63 + * -XX:+UnlockExperimentalVMOptions 7.64 + * -XX:SurvivorAlignmentInBytes=64 7.65 + * TestPromotionFromSurvivorToTenuredAfterFullGC 20m 87 7.66 + * TENURED 7.67 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 7.68 + * -XX:+WhiteBoxAPI -XX:NewSize=256m -XX:MaxNewSize=256m 7.69 + * -XX:OldSize=32M -XX:InitialHeapSize=288m 7.70 + * -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent 7.71 + * -XX:+UnlockExperimentalVMOptions 7.72 + * -XX:SurvivorAlignmentInBytes=128 7.73 + * TestPromotionFromSurvivorToTenuredAfterFullGC 10m 9 7.74 + * TENURED 7.75 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 7.76 + * -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m 7.77 + * -XX:OldSize=32m -XX:SurvivorRatio=1 7.78 + * -XX:-ExplicitGCInvokesConcurrent 7.79 + * -XX:+UnlockExperimentalVMOptions 7.80 + * -XX:SurvivorAlignmentInBytes=128 7.81 + * TestPromotionFromSurvivorToTenuredAfterFullGC 20m 147 7.82 + * TENURED 7.83 + */ 7.84 +public class TestPromotionFromSurvivorToTenuredAfterFullGC { 7.85 + public static void main(String args[]) { 7.86 + SurvivorAlignmentTestMain test 7.87 + = SurvivorAlignmentTestMain.fromArgs(args); 7.88 + System.out.println(test); 7.89 + 7.90 + long expectedMemoryUsage = test.getExpectedMemoryUsage(); 7.91 + test.baselineMemoryAllocation(); 7.92 + System.gc(); 7.93 + // increase expected usage by current old gen usage 7.94 + expectedMemoryUsage += SurvivorAlignmentTestMain.getAlignmentHelper( 7.95 + SurvivorAlignmentTestMain.HeapSpace.TENURED) 7.96 + .getActualMemoryUsage(); 7.97 + 7.98 + test.allocate(); 7.99 + SurvivorAlignmentTestMain.WHITE_BOX.youngGC(); 7.100 + System.gc(); 7.101 + 7.102 + test.verifyMemoryUsage(expectedMemoryUsage); 7.103 + } 7.104 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/test/gc/survivorAlignment/TestPromotionFromSurvivorToTenuredAfterMinorGC.java Wed Nov 26 14:17:06 2014 +0400 8.3 @@ -0,0 +1,106 @@ 8.4 +/* 8.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.7 + * 8.8 + * This code is free software; you can redistribute it and/or modify it 8.9 + * under the terms of the GNU General Public License version 2 only, as 8.10 + * published by the Free Software Foundation. 8.11 + * 8.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 8.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.15 + * version 2 for more details (a copy is included in the LICENSE file that 8.16 + * accompanied this code). 8.17 + * 8.18 + * You should have received a copy of the GNU General Public License version 8.19 + * 2 along with this work; if not, write to the Free Software Foundation, 8.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.21 + * 8.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 8.23 + * or visit www.oracle.com if you need additional information or have any 8.24 + * questions. 8.25 + */ 8.26 + 8.27 +/** 8.28 + * @test 8.29 + * @bug 8031323 8.30 + * @summary Verify that objects promoted from survivor space to tenured space 8.31 + * when their age exceeded tenuring threshold are not aligned to 8.32 + * SurvivorAlignmentInBytes value. 8.33 + * @library /testlibrary /testlibrary/whitebox 8.34 + * @build TestPromotionFromSurvivorToTenuredAfterMinorGC 8.35 + * SurvivorAlignmentTestMain AlignmentHelper 8.36 + * @run main ClassFileInstaller sun.hotspot.WhiteBox 8.37 + * sun.hotspot.WhiteBox$WhiteBoxPermission 8.38 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 8.39 + * -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m 8.40 + * -XX:OldSize=32M -XX:SurvivorRatio=1 8.41 + * -XX:-ExplicitGCInvokesConcurrent 8.42 + * -XX:+UnlockExperimentalVMOptions 8.43 + * -XX:SurvivorAlignmentInBytes=32 8.44 + * TestPromotionFromSurvivorToTenuredAfterMinorGC 10m 9 8.45 + * TENURED 8.46 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 8.47 + * -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m 8.48 + * -XX:OldSize=32M -XX:SurvivorRatio=1 8.49 + * -XX:-ExplicitGCInvokesConcurrent 8.50 + * -XX:+UnlockExperimentalVMOptions 8.51 + * -XX:SurvivorAlignmentInBytes=32 8.52 + * TestPromotionFromSurvivorToTenuredAfterMinorGC 20m 47 8.53 + * TENURED 8.54 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 8.55 + * -XX:+WhiteBoxAPI -XX:NewSize=200m -XX:MaxNewSize=200m 8.56 + * -XX:OldSize=32M -XX:InitialHeapSize=232m 8.57 + * -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent 8.58 + * -XX:+UnlockExperimentalVMOptions 8.59 + * -XX:SurvivorAlignmentInBytes=64 8.60 + * TestPromotionFromSurvivorToTenuredAfterMinorGC 10m 9 8.61 + * TENURED 8.62 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 8.63 + * -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m 8.64 + * -XX:OldSize=32M -XX:SurvivorRatio=1 8.65 + * -XX:-ExplicitGCInvokesConcurrent 8.66 + * -XX:+UnlockExperimentalVMOptions 8.67 + * -XX:SurvivorAlignmentInBytes=64 8.68 + * TestPromotionFromSurvivorToTenuredAfterMinorGC 20m 87 8.69 + * TENURED 8.70 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 8.71 + * -XX:+WhiteBoxAPI -XX:NewSize=256m -XX:MaxNewSize=256m 8.72 + * -XX:OldSize=32M -XX:InitialHeapSize=288m 8.73 + * -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent 8.74 + * -XX:+UnlockExperimentalVMOptions 8.75 + * -XX:SurvivorAlignmentInBytes=128 8.76 + * TestPromotionFromSurvivorToTenuredAfterMinorGC 10m 9 8.77 + * TENURED 8.78 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 8.79 + * -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m 8.80 + * -XX:OldSize=32M -XX:SurvivorRatio=1 8.81 + * -XX:-ExplicitGCInvokesConcurrent 8.82 + * -XX:+UnlockExperimentalVMOptions 8.83 + * -XX:SurvivorAlignmentInBytes=128 8.84 + * TestPromotionFromSurvivorToTenuredAfterMinorGC 20m 147 8.85 + * TENURED 8.86 + */ 8.87 +public class TestPromotionFromSurvivorToTenuredAfterMinorGC { 8.88 + public static void main(String args[]) throws Exception { 8.89 + SurvivorAlignmentTestMain test 8.90 + = SurvivorAlignmentTestMain.fromArgs(args); 8.91 + System.out.println(test); 8.92 + 8.93 + long expectedMemoryUsage = test.getExpectedMemoryUsage(); 8.94 + test.baselineMemoryAllocation(); 8.95 + SurvivorAlignmentTestMain.WHITE_BOX.fullGC(); 8.96 + // increase expected usage by current old gen usage 8.97 + expectedMemoryUsage += SurvivorAlignmentTestMain.getAlignmentHelper( 8.98 + SurvivorAlignmentTestMain.HeapSpace.TENURED) 8.99 + .getActualMemoryUsage(); 8.100 + 8.101 + test.allocate(); 8.102 + for (int i = 0; i <= SurvivorAlignmentTestMain.MAX_TENURING_THRESHOLD; 8.103 + i++) { 8.104 + SurvivorAlignmentTestMain.WHITE_BOX.youngGC(); 8.105 + } 8.106 + 8.107 + test.verifyMemoryUsage(expectedMemoryUsage); 8.108 + } 8.109 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/test/gc/survivorAlignment/TestPromotionToSurvivor.java Wed Nov 26 14:17:06 2014 +0400 9.3 @@ -0,0 +1,85 @@ 9.4 +/* 9.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9.7 + * 9.8 + * This code is free software; you can redistribute it and/or modify it 9.9 + * under the terms of the GNU General Public License version 2 only, as 9.10 + * published by the Free Software Foundation. 9.11 + * 9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 9.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 9.15 + * version 2 for more details (a copy is included in the LICENSE file that 9.16 + * accompanied this code). 9.17 + * 9.18 + * You should have received a copy of the GNU General Public License version 9.19 + * 2 along with this work; if not, write to the Free Software Foundation, 9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 9.21 + * 9.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 9.23 + * or visit www.oracle.com if you need additional information or have any 9.24 + * questions. 9.25 + */ 9.26 + 9.27 +/** 9.28 + * @test 9.29 + * @bug 8031323 9.30 + * @summary Verify that objects promoted from eden space to survivor space after 9.31 + * minor GC are aligned to SurvivorAlignmentInBytes. 9.32 + * @library /testlibrary /testlibrary/whitebox 9.33 + * @build TestPromotionToSurvivor 9.34 + * SurvivorAlignmentTestMain AlignmentHelper 9.35 + * @run main ClassFileInstaller sun.hotspot.WhiteBox 9.36 + * sun.hotspot.WhiteBox$WhiteBoxPermission 9.37 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 9.38 + * -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m 9.39 + * -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions 9.40 + * -XX:SurvivorAlignmentInBytes=32 -XX:OldSize=128m 9.41 + * -XX:-ExplicitGCInvokesConcurrent 9.42 + * TestPromotionToSurvivor 10m 9 SURVIVOR 9.43 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 9.44 + * -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m 9.45 + * -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions 9.46 + * -XX:SurvivorAlignmentInBytes=32 -XX:OldSize=128m 9.47 + * TestPromotionToSurvivor 20m 47 SURVIVOR 9.48 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 9.49 + * -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m 9.50 + * -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions 9.51 + * -XX:SurvivorAlignmentInBytes=64 -XX:OldSize=128m 9.52 + * -XX:-ExplicitGCInvokesConcurrent 9.53 + * TestPromotionToSurvivor 8m 9 SURVIVOR 9.54 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 9.55 + * -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m 9.56 + * -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions 9.57 + * -XX:SurvivorAlignmentInBytes=64 -XX:OldSize=128m 9.58 + * -XX:-ExplicitGCInvokesConcurrent 9.59 + * TestPromotionToSurvivor 20m 87 SURVIVOR 9.60 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 9.61 + * -XX:+WhiteBoxAPI -XX:NewSize=256m -XX:MaxNewSize=256m 9.62 + * -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions 9.63 + * -XX:SurvivorAlignmentInBytes=128 -XX:OldSize=32m 9.64 + * -XX:InitialHeapSize=288m -XX:-ExplicitGCInvokesConcurrent 9.65 + * TestPromotionToSurvivor 10m 9 SURVIVOR 9.66 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 9.67 + * -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m 9.68 + * -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions 9.69 + * -XX:SurvivorAlignmentInBytes=128 -XX:OldSize=128m 9.70 + * -XX:-ExplicitGCInvokesConcurrent 9.71 + * TestPromotionToSurvivor 20m 147 SURVIVOR 9.72 + */ 9.73 +public class TestPromotionToSurvivor { 9.74 + public static void main(String args[]) { 9.75 + SurvivorAlignmentTestMain test 9.76 + = SurvivorAlignmentTestMain.fromArgs(args); 9.77 + System.out.println(test); 9.78 + 9.79 + long expectedUsage = test.getExpectedMemoryUsage(); 9.80 + test.baselineMemoryAllocation(); 9.81 + SurvivorAlignmentTestMain.WHITE_BOX.fullGC(); 9.82 + 9.83 + test.allocate(); 9.84 + SurvivorAlignmentTestMain.WHITE_BOX.youngGC(); 9.85 + 9.86 + test.verifyMemoryUsage(expectedUsage); 9.87 + } 9.88 +}