提交 0e0e8c17 编写于 作者: A asaha

Merge

...@@ -584,6 +584,8 @@ bc5a90a4db47f1c497d7894434c42325f595cd02 hs25.40-b22 ...@@ -584,6 +584,8 @@ bc5a90a4db47f1c497d7894434c42325f595cd02 hs25.40-b22
f8fc5cbe082ce0fb0c6c1dcd39493a16ed916353 hs25.40-b23 f8fc5cbe082ce0fb0c6c1dcd39493a16ed916353 hs25.40-b23
d9349fa8822336e0244da0a8448f3e6b2d62741d jdk8u40-b19 d9349fa8822336e0244da0a8448f3e6b2d62741d jdk8u40-b19
c3933f52eeb33f70ee562464edddfe9f01d944fd jdk8u40-b20 c3933f52eeb33f70ee562464edddfe9f01d944fd jdk8u40-b20
d2e9a6bec4f2eec8506eed16f7324992a85d8480 hs25.40-b24
25ec4a67433744bbe3406e5069e7fd1876ebbf2f jdk8u40-b21
b95f13f05f553309cd74d6ccf8fcedb259c6716c jdk8u45-b00 b95f13f05f553309cd74d6ccf8fcedb259c6716c jdk8u45-b00
41c3c456e326185053f0654be838f4b0bfb38078 jdk8u45-b01 41c3c456e326185053f0654be838f4b0bfb38078 jdk8u45-b01
626fd8c2eec63e2a2dff3839bfe12c0431bf00a4 jdk8u45-b02 626fd8c2eec63e2a2dff3839bfe12c0431bf00a4 jdk8u45-b02
......
...@@ -171,6 +171,7 @@ needs_compact3 = \ ...@@ -171,6 +171,7 @@ needs_compact3 = \
gc/g1/TestShrinkAuxiliaryData20.java \ gc/g1/TestShrinkAuxiliaryData20.java \
gc/g1/TestShrinkAuxiliaryData25.java \ gc/g1/TestShrinkAuxiliaryData25.java \
gc/g1/TestShrinkAuxiliaryData30.java \ gc/g1/TestShrinkAuxiliaryData30.java \
gc/survivorAlignment \
runtime/InternalApi/ThreadCpuTimesDeadlock.java \ runtime/InternalApi/ThreadCpuTimesDeadlock.java \
serviceability/threads/TestFalseDeadLock.java \ serviceability/threads/TestFalseDeadLock.java \
serviceability/jvmti/GetObjectSizeOverflow.java \ serviceability/jvmti/GetObjectSizeOverflow.java \
......
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.oracle.java.testlibrary.ExitCode;
import com.oracle.java.testlibrary.cli.CommandLineOptionTest;
/**
* @test
* @bug 8031323
* @summary Verify SurvivorAlignmentInBytes option processing.
* @library /testlibrary
* @requires vm.opt.SurvivorAlignmentInBytes == null
* & vm.opt.ObjectAlignmentInBytes == null
* & vm.opt.UnlockExperimentalVMOptions == null
* & (vm.opt.IgnoreUnrecognizedVMOptions == null
* | vm.opt.IgnoreUnrecognizedVMOptions == "false")
* @run main TestSurvivorAlignmentInBytesOption
*/
public class TestSurvivorAlignmentInBytesOption {
public static void main(String args[]) throws Throwable {
String optionName = "SurvivorAlignmentInBytes";
String unlockExperimentalVMOpts = "UnlockExperimentalVMOptions";
String optionIsExperimental
= CommandLineOptionTest.getExperimentalOptionErrorMessage(
optionName);
String valueIsTooSmall= ".*SurvivorAlignmentInBytes=.*must be greater"
+ " than ObjectAlignmentInBytes.*";
String mustBePowerOf2 = ".*SurvivorAlignmentInBytes=.*must be "
+ "power of 2.*";
// Verify that without -XX:+UnlockExperimentalVMOptions usage of
// SurvivorAlignmentInBytes option will cause JVM startup failure
// with the warning message saying that that option is experimental.
CommandLineOptionTest.verifyJVMStartup(
new String[]{optionIsExperimental}, null, ExitCode.FAIL, false,
"-XX:-UnlockExperimentalVMOptions",
CommandLineOptionTest.prepareBooleanFlag(
unlockExperimentalVMOpts, false),
CommandLineOptionTest.prepareNumericFlag(optionName, 64));
// Verify that with -XX:+UnlockExperimentalVMOptions passed to JVM
// usage of SurvivorAlignmentInBytes option won't cause JVM startup
// failure.
CommandLineOptionTest.verifyJVMStartup(
null, new String[]{optionIsExperimental}, ExitCode.OK, false,
CommandLineOptionTest.prepareBooleanFlag(
unlockExperimentalVMOpts, true),
CommandLineOptionTest.prepareNumericFlag(optionName, 64));
// Verify that if specified SurvivorAlignmentInBytes is lower then
// ObjectAlignmentInBytes, then the JVM startup will fail with
// appropriate error message.
CommandLineOptionTest.verifyJVMStartup(
new String[]{valueIsTooSmall}, null, ExitCode.FAIL, false,
CommandLineOptionTest.prepareBooleanFlag(
unlockExperimentalVMOpts, true),
CommandLineOptionTest.prepareNumericFlag(optionName, 2));
// Verify that if specified SurvivorAlignmentInBytes value is not
// a power of 2 then the JVM startup will fail with appropriate error
// message.
CommandLineOptionTest.verifyJVMStartup(
new String[]{mustBePowerOf2}, null, ExitCode.FAIL, false,
CommandLineOptionTest.prepareBooleanFlag(
unlockExperimentalVMOpts, true),
CommandLineOptionTest.prepareNumericFlag(optionName, 127));
// Verify that if SurvivorAlignmentInBytes has correct value, then
// the JVM will be started without errors.
CommandLineOptionTest.verifyJVMStartup(
null, new String[]{".*SurvivorAlignmentInBytes.*"},
ExitCode.OK, false,
CommandLineOptionTest.prepareBooleanFlag(
unlockExperimentalVMOpts, true),
CommandLineOptionTest.prepareNumericFlag(optionName, 128));
// Verify that we can setup different SurvivorAlignmentInBytes values.
for (int alignment = 32; alignment <= 128; alignment *= 2) {
CommandLineOptionTest.verifyOptionValue(optionName,
Integer.toString(alignment),
CommandLineOptionTest.prepareBooleanFlag(
unlockExperimentalVMOpts, true),
CommandLineOptionTest.prepareNumericFlag(
optionName, alignment));
}
}
}
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.lang.management.MemoryPoolMXBean;
import java.util.Optional;
import sun.hotspot.WhiteBox;
/**
* Helper class aimed to provide information about alignment of objects in
* particular heap space, expected memory usage after objects' allocation so on.
*/
public class AlignmentHelper {
private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
private static final long OBJECT_ALIGNMENT_IN_BYTES_FOR_32_VM = 8L;
/**
* Max relative allowed actual memory usage deviation from expected memory
* usage.
*/
private static final float MAX_RELATIVE_DEVIATION = 0.05f; // 5%
public static final long OBJECT_ALIGNMENT_IN_BYTES = Optional.ofNullable(
AlignmentHelper.WHITE_BOX.getIntxVMFlag("ObjectAlignmentInBytes"))
.orElse(AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES_FOR_32_VM);
public static final long SURVIVOR_ALIGNMENT_IN_BYTES = Optional.ofNullable(
AlignmentHelper.WHITE_BOX.getIntxVMFlag("SurvivorAlignmentInBytes"))
.orElseThrow(() ->new AssertionError(
"Unable to get SurvivorAlignmentInBytes value"));
/**
* Min amount of memory that will be occupied by an object.
*/
public static final long MIN_OBJECT_SIZE
= AlignmentHelper.WHITE_BOX.getObjectSize(new Object());
/**
* Min amount of memory that will be occupied by an empty byte array.
*/
public static final long MIN_ARRAY_SIZE
= AlignmentHelper.WHITE_BOX.getObjectSize(new byte[0]);
/**
* Precision at which actual memory usage in a heap space represented by
* this sizing helper could be measured.
*/
private final long memoryUsageMeasurementPrecision;
/**
* Min amount of memory that will be occupied by an object allocated in a
* heap space represented by this sizing helper.
*/
private final long minObjectSizeInThisSpace;
/**
* Object's alignment in a heap space represented by this sizing helper.
*/
private final long objectAlignmentInThisRegion;
/**
* MemoryPoolMXBean associated with a heap space represented by this sizing
* helper.
*/
private final MemoryPoolMXBean poolMXBean;
private static long alignUp(long value, long alignment) {
return ((value - 1) / alignment + 1) * alignment;
}
protected AlignmentHelper(long memoryUsageMeasurementPrecision,
long objectAlignmentInThisRegion, long minObjectSizeInThisSpace,
MemoryPoolMXBean poolMXBean) {
this.memoryUsageMeasurementPrecision = memoryUsageMeasurementPrecision;
this.minObjectSizeInThisSpace = minObjectSizeInThisSpace;
this.objectAlignmentInThisRegion = objectAlignmentInThisRegion;
this.poolMXBean = poolMXBean;
}
/**
* Returns how many objects have to be allocated to fill
* {@code memoryToFill} bytes in this heap space using objects of size
* {@code objectSize}.
*/
public int getObjectsCount(long memoryToFill, long objectSize) {
return (int) (memoryToFill / getObjectSizeInThisSpace(objectSize));
}
/**
* Returns amount of memory that {@code objectsCount} of objects with size
* {@code objectSize} will occupy this this space after allocation.
*/
public long getExpectedMemoryUsage(long objectSize, int objectsCount) {
long correctedObjectSize = getObjectSizeInThisSpace(objectSize);
return AlignmentHelper.alignUp(correctedObjectSize * objectsCount,
memoryUsageMeasurementPrecision);
}
/**
* Returns current memory usage in this heap space.
*/
public long getActualMemoryUsage() {
return poolMXBean.getUsage().getUsed();
}
/**
* Returns maximum memory usage deviation from {@code expectedMemoryUsage}
* given the max allowed relative deviation equal to
* {@code relativeDeviation}.
*
* Note that value returned by this method is aligned according to
* memory measurement precision for this heap space.
*/
public long getAllowedMemoryUsageDeviation(long expectedMemoryUsage) {
long unalignedDeviation = (long) (expectedMemoryUsage *
AlignmentHelper.MAX_RELATIVE_DEVIATION);
return AlignmentHelper.alignUp(unalignedDeviation,
memoryUsageMeasurementPrecision);
}
/**
* Returns amount of memory that will be occupied by an object with size
* {@code objectSize} in this heap space.
*/
public long getObjectSizeInThisSpace(long objectSize) {
objectSize = Math.max(objectSize, minObjectSizeInThisSpace);
long alignedObjectSize = AlignmentHelper.alignUp(objectSize,
objectAlignmentInThisRegion);
long sizeDiff = alignedObjectSize - objectSize;
// If there is not enough space to fit padding object, then object will
// be aligned to {@code 2 * objectAlignmentInThisRegion}.
if (sizeDiff >= AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES
&& sizeDiff < AlignmentHelper.MIN_OBJECT_SIZE) {
alignedObjectSize += AlignmentHelper.MIN_OBJECT_SIZE;
alignedObjectSize = AlignmentHelper.alignUp(alignedObjectSize,
objectAlignmentInThisRegion);
}
return alignedObjectSize;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(String.format("AlignmentHelper for memory pool '%s':%n",
poolMXBean.getName()));
builder.append(String.format("Memory usage measurement precision: %d%n",
memoryUsageMeasurementPrecision));
builder.append(String.format("Min object size in this space: %d%n",
minObjectSizeInThisSpace));
builder.append(String.format("Object alignment in this space: %d%n",
objectAlignmentInThisRegion));
return builder.toString();
}
}
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.oracle.java.testlibrary.Asserts;
import com.sun.management.ThreadMXBean;
import sun.hotspot.WhiteBox;
import sun.misc.Unsafe;
/**
* Main class for tests on {@code SurvivorAlignmentInBytes} option.
*
* Typical usage is to obtain instance using fromArgs method, allocate objects
* and verify that actual memory usage in tested heap space is close to
* expected.
*/
public class SurvivorAlignmentTestMain {
enum HeapSpace {
EDEN,
SURVIVOR,
TENURED
}
public static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
public static final long MAX_TENURING_THRESHOLD = Optional.ofNullable(
SurvivorAlignmentTestMain.WHITE_BOX.getIntxVMFlag(
"MaxTenuringThreshold")).orElse(15L);
/**
* Regexp used to parse memory size params, like 2G, 34m or 15k.
*/
private static final Pattern SIZE_REGEX
= Pattern.compile("(?<size>[0-9]+)(?<multiplier>[GMKgmk])?");
// Names of different heap spaces.
private static final String DEF_NEW_EDEN = "Eden Space";
private static final String DEF_NEW_SURVIVOR = "Survivor Space";
private static final String PAR_NEW_EDEN = "Par Eden Space";
private static final String PAR_NEW_SURVIVOR = "Par Survivor Space";
private static final String PS_EDEN = "PS Eden Space";
private static final String PS_SURVIVOR = "PS Survivor Space";
private static final String G1_EDEN = "G1 Eden Space";
private static final String G1_SURVIVOR = "G1 Survivor Space";
private static final String SERIAL_TENURED = "Tenured Gen";
private static final String CMS_TENURED = "CMS Old Gen";
private static final String PS_TENURED = "PS Old Gen";
private static final String G1_TENURED = "G1 Old Gen";
private static final long G1_HEAP_REGION_SIZE = Optional.ofNullable(
SurvivorAlignmentTestMain.WHITE_BOX.getUintxVMFlag(
"G1HeapRegionSize")).orElse(-1L);
/**
* Min size of free chunk in CMS generation.
* An object allocated in CMS generation will at least occupy this amount
* of bytes.
*/
private static final long CMS_MIN_FREE_CHUNK_SIZE
= 3L * Unsafe.ADDRESS_SIZE;
private static final AlignmentHelper EDEN_SPACE_HELPER;
private static final AlignmentHelper SURVIVOR_SPACE_HELPER;
private static final AlignmentHelper TENURED_SPACE_HELPER;
/**
* Amount of memory that should be filled during a test run.
*/
private final long memoryToFill;
/**
* The size of an objects that will be allocated during a test run.
*/
private final long objectSize;
/**
* Amount of memory that will be actually occupied by an object in eden
* space.
*/
private final long actualObjectSize;
/**
* Storage for allocated objects.
*/
private final Object[] garbage;
/**
* Heap space whose memory usage is a subject of assertions during the test
* run.
*/
private final HeapSpace testedSpace;
private long[] baselinedThreadMemoryUsage = null;
private long[] threadIds = null;
/**
* Initialize {@code EDEN_SPACE_HELPER}, {@code SURVIVOR_SPACE_HELPER} and
* {@code TENURED_SPACE_HELPER} to represent heap spaces in use.
*
* Note that regardless to GC object's alignment in survivor space is
* expected to be equal to {@code SurvivorAlignmentInBytes} value and
* alignment in other spaces is expected to be equal to
* {@code ObjectAlignmentInBytes} value.
*
* In CMS generation we can't allocate less then {@code MinFreeChunk} value,
* for other CGs we expect that object of size {@code MIN_OBJECT_SIZE}
* could be allocated as it is (of course, its size could be aligned
* according to alignment value used in a particular space).
*
* For G1 GC MXBeans could report memory usage only with region size
* precision (if an object allocated in some G1 heap region, then all region
* will claimed as used), so for G1's spaces precision is equal to
* {@code G1HeapRegionSize} value.
*/
static {
AlignmentHelper edenHelper = null;
AlignmentHelper survivorHelper = null;
AlignmentHelper tenuredHelper = null;
for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
switch (pool.getName()) {
case SurvivorAlignmentTestMain.DEF_NEW_EDEN:
case SurvivorAlignmentTestMain.PAR_NEW_EDEN:
case SurvivorAlignmentTestMain.PS_EDEN:
Asserts.assertNull(edenHelper,
"Only one bean for eden space is expected.");
edenHelper = new AlignmentHelper(
AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES,
AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES,
AlignmentHelper.MIN_OBJECT_SIZE, pool);
break;
case SurvivorAlignmentTestMain.G1_EDEN:
Asserts.assertNull(edenHelper,
"Only one bean for eden space is expected.");
edenHelper = new AlignmentHelper(
SurvivorAlignmentTestMain.G1_HEAP_REGION_SIZE,
AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES,
AlignmentHelper.MIN_OBJECT_SIZE, pool);
break;
case SurvivorAlignmentTestMain.DEF_NEW_SURVIVOR:
case SurvivorAlignmentTestMain.PAR_NEW_SURVIVOR:
case SurvivorAlignmentTestMain.PS_SURVIVOR:
Asserts.assertNull(survivorHelper,
"Only one bean for survivor space is expected.");
survivorHelper = new AlignmentHelper(
AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES,
AlignmentHelper.SURVIVOR_ALIGNMENT_IN_BYTES,
AlignmentHelper.MIN_OBJECT_SIZE, pool);
break;
case SurvivorAlignmentTestMain.G1_SURVIVOR:
Asserts.assertNull(survivorHelper,
"Only one bean for survivor space is expected.");
survivorHelper = new AlignmentHelper(
SurvivorAlignmentTestMain.G1_HEAP_REGION_SIZE,
AlignmentHelper.SURVIVOR_ALIGNMENT_IN_BYTES,
AlignmentHelper.MIN_OBJECT_SIZE, pool);
break;
case SurvivorAlignmentTestMain.SERIAL_TENURED:
case SurvivorAlignmentTestMain.PS_TENURED:
case SurvivorAlignmentTestMain.G1_TENURED:
Asserts.assertNull(tenuredHelper,
"Only one bean for tenured space is expected.");
tenuredHelper = new AlignmentHelper(
AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES,
AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES,
AlignmentHelper.MIN_OBJECT_SIZE, pool);
break;
case SurvivorAlignmentTestMain.CMS_TENURED:
Asserts.assertNull(tenuredHelper,
"Only one bean for tenured space is expected.");
tenuredHelper = new AlignmentHelper(
AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES,
AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES,
SurvivorAlignmentTestMain.CMS_MIN_FREE_CHUNK_SIZE,
pool);
break;
}
}
EDEN_SPACE_HELPER = Objects.requireNonNull(edenHelper,
"AlignmentHelper for eden space should be initialized.");
SURVIVOR_SPACE_HELPER = Objects.requireNonNull(survivorHelper,
"AlignmentHelper for survivor space should be initialized.");
TENURED_SPACE_HELPER = Objects.requireNonNull(tenuredHelper,
"AlignmentHelper for tenured space should be initialized.");
}
/**
* Returns an SurvivorAlignmentTestMain instance constructed using CLI
* options.
*
* Following options are expected:
* <ul>
* <li>memoryToFill</li>
* <li>objectSize</li>
* </ul>
*
* Both argument may contain multiplier suffix k, m or g.
*/
public static SurvivorAlignmentTestMain fromArgs(String[] args) {
Asserts.assertEQ(args.length, 3, "Expected three arguments: "
+ "memory size, object size and tested heap space name.");
long memoryToFill = parseSize(args[0]);
long objectSize = Math.max(parseSize(args[1]),
AlignmentHelper.MIN_ARRAY_SIZE);
HeapSpace testedSpace = HeapSpace.valueOf(args[2]);
return new SurvivorAlignmentTestMain(memoryToFill, objectSize,
testedSpace);
}
/**
* Returns a value parsed from a string with format
* &lt;integer&gt;&lt;multiplier&gt;.
*/
private static long parseSize(String sizeString) {
Matcher matcher = SIZE_REGEX.matcher(sizeString);
Asserts.assertTrue(matcher.matches(),
"sizeString should have following format \"[0-9]+([MBK])?\"");
long size = Long.valueOf(matcher.group("size"));
if (matcher.group("multiplier") != null) {
long K = 1024L;
// fall through multipliers
switch (matcher.group("multiplier").toLowerCase()) {
case "g":
size *= K;
case "m":
size *= K;
case "k":
size *= K;
}
}
return size;
}
private SurvivorAlignmentTestMain(long memoryToFill, long objectSize,
HeapSpace testedSpace) {
this.objectSize = objectSize;
this.memoryToFill = memoryToFill;
this.testedSpace = testedSpace;
AlignmentHelper helper = SurvivorAlignmentTestMain.EDEN_SPACE_HELPER;
this.actualObjectSize = helper.getObjectSizeInThisSpace(
this.objectSize);
int arrayLength = helper.getObjectsCount(memoryToFill, this.objectSize);
garbage = new Object[arrayLength];
}
/**
* Allocate byte arrays to fill {@code memoryToFill} memory.
*/
public void allocate() {
int byteArrayLength = Math.max((int) (objectSize
- Unsafe.ARRAY_BYTE_BASE_OFFSET), 0);
for (int i = 0; i < garbage.length; i++) {
garbage[i] = new byte[byteArrayLength];
}
}
/**
* Release memory occupied after {@code allocate} call.
*/
public void release() {
for (int i = 0; i < garbage.length; i++) {
garbage[i] = null;
}
}
/**
* Returns expected amount of memory occupied in a {@code heapSpace} by
* objects referenced from {@code garbage} array.
*/
public long getExpectedMemoryUsage() {
AlignmentHelper alignmentHelper = getAlignmentHelper(testedSpace);
return alignmentHelper.getExpectedMemoryUsage(objectSize,
garbage.length);
}
/**
* Verifies that memory usage in a {@code heapSpace} deviates from
* {@code expectedUsage} for no more than {@code MAX_RELATIVE_DEVIATION}.
*/
public void verifyMemoryUsage(long expectedUsage) {
AlignmentHelper alignmentHelper = getAlignmentHelper(testedSpace);
long actualMemoryUsage = alignmentHelper.getActualMemoryUsage();
boolean otherThreadsAllocatedMemory = areOtherThreadsAllocatedMemory();
long memoryUsageDiff = Math.abs(actualMemoryUsage - expectedUsage);
long maxAllowedUsageDiff
= alignmentHelper.getAllowedMemoryUsageDeviation(expectedUsage);
System.out.println("Verifying memory usage in space: " + testedSpace);
System.out.println("Allocated objects count: " + garbage.length);
System.out.println("Desired object size: " + objectSize);
System.out.println("Actual object size: " + actualObjectSize);
System.out.println("Expected object size in space: "
+ alignmentHelper.getObjectSizeInThisSpace(objectSize));
System.out.println("Expected memory usage: " + expectedUsage);
System.out.println("Actual memory usage: " + actualMemoryUsage);
System.out.println("Memory usage diff: " + memoryUsageDiff);
System.out.println("Max allowed usage diff: " + maxAllowedUsageDiff);
if (memoryUsageDiff > maxAllowedUsageDiff
&& otherThreadsAllocatedMemory) {
System.out.println("Memory usage diff is incorrect, but it seems "
+ "like someone else allocated objects");
return;
}
Asserts.assertLTE(memoryUsageDiff, maxAllowedUsageDiff,
"Actual memory usage should not deviate from expected for " +
"more then " + maxAllowedUsageDiff);
}
/**
* Baselines amount of memory allocated by each thread.
*/
public void baselineMemoryAllocation() {
ThreadMXBean bean = (ThreadMXBean) ManagementFactory.getThreadMXBean();
threadIds = bean.getAllThreadIds();
baselinedThreadMemoryUsage = bean.getThreadAllocatedBytes(threadIds);
}
/**
* Checks if threads other then the current thread were allocating objects
* after baselinedThreadMemoryUsage call.
*
* If baselinedThreadMemoryUsage was not called, then this method will return
* {@code false}.
*/
public boolean areOtherThreadsAllocatedMemory() {
if (baselinedThreadMemoryUsage == null) {
return false;
}
ThreadMXBean bean = (ThreadMXBean) ManagementFactory.getThreadMXBean();
long currentMemoryAllocation[]
= bean.getThreadAllocatedBytes(threadIds);
boolean otherThreadsAllocatedMemory = false;
System.out.println("Verifying amount of memory allocated by threads:");
for (int i = 0; i < threadIds.length; i++) {
System.out.format("Thread %d%nbaseline allocation: %d"
+ "%ncurrent allocation:%d%n", threadIds[i],
baselinedThreadMemoryUsage[i], currentMemoryAllocation[i]);
System.out.println(bean.getThreadInfo(threadIds[i]));
long bytesAllocated = Math.abs(currentMemoryAllocation[i]
- baselinedThreadMemoryUsage[i]);
if (bytesAllocated > 0
&& threadIds[i] != Thread.currentThread().getId()) {
otherThreadsAllocatedMemory = true;
}
}
return otherThreadsAllocatedMemory;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(String.format("SurvivorAlignmentTestMain info:%n"));
builder.append(String.format("Desired object size: %d%n", objectSize));
builder.append(String.format("Memory to fill: %d%n", memoryToFill));
builder.append(String.format("Objects to be allocated: %d%n",
garbage.length));
builder.append(String.format("Alignment helpers to be used: %n"));
for (HeapSpace heapSpace: HeapSpace.values()) {
builder.append(String.format("For space %s:%n%s%n", heapSpace,
getAlignmentHelper(heapSpace)));
}
return builder.toString();
}
/**
* Returns {@code AlignmentHelper} for a space {@code heapSpace}.
*/
public static AlignmentHelper getAlignmentHelper(HeapSpace heapSpace) {
switch (heapSpace) {
case EDEN:
return SurvivorAlignmentTestMain.EDEN_SPACE_HELPER;
case SURVIVOR:
return SurvivorAlignmentTestMain.SURVIVOR_SPACE_HELPER;
case TENURED:
return SurvivorAlignmentTestMain.TENURED_SPACE_HELPER;
default:
throw new Error("Unexpected heap space: " + heapSpace);
}
}
}
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 8031323
* @summary Verify that object's alignment in eden space is not affected by
* SurvivorAlignmentInBytes option.
* @library /testlibrary /testlibrary/whitebox
* @build TestAllocationInEden SurvivorAlignmentTestMain AlignmentHelper
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m
* -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=32 -XX:-UseTLAB
* -XX:OldSize=128m -XX:MaxHeapSize=192m
* -XX:-ExplicitGCInvokesConcurrent
* TestAllocationInEden 10m 9 EDEN
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m
* -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=32 -XX:-UseTLAB
* -XX:OldSize=128m -XX:MaxHeapSize=192m
* -XX:-ExplicitGCInvokesConcurrent
* TestAllocationInEden 10m 47 EDEN
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m
* -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=64 -XX:-UseTLAB
* -XX:OldSize=128m -XX:MaxHeapSize=192m
* -XX:-ExplicitGCInvokesConcurrent
* TestAllocationInEden 10m 9 EDEN
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m
* -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=64 -XX:-UseTLAB
* -XX:OldSize=128m -XX:MaxHeapSize=192m
* -XX:-ExplicitGCInvokesConcurrent
* TestAllocationInEden 10m 87 EDEN
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m
* -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=128 -XX:-UseTLAB
* -XX:OldSize=128m -XX:MaxHeapSize=192m
* -XX:-ExplicitGCInvokesConcurrent
* TestAllocationInEden 10m 9 EDEN
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m
* -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=128 -XX:-UseTLAB
* -XX:OldSize=128m -XX:MaxHeapSize=192m
* -XX:-ExplicitGCInvokesConcurrent
* TestAllocationInEden 10m 147 EDEN
*/
public class TestAllocationInEden {
public static void main(String args[]) {
SurvivorAlignmentTestMain test
= SurvivorAlignmentTestMain.fromArgs(args);
System.out.println(test);
long expectedMemoryUsage = test.getExpectedMemoryUsage();
test.baselineMemoryAllocation();
System.gc();
test.allocate();
test.verifyMemoryUsage(expectedMemoryUsage);
}
}
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 8031323
* @summary Verify that objects promoted from eden space to tenured space during
* full GC are not aligned to SurvivorAlignmentInBytes value.
* @library /testlibrary /testlibrary/whitebox
* @build TestPromotionFromEdenToTenured SurvivorAlignmentTestMain
* AlignmentHelper
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m
* -XX:OldSize=32m -XX:MaxHeapSize=96m -XX:SurvivorRatio=1
* -XX:-ExplicitGCInvokesConcurrent
* -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=32
* TestPromotionFromEdenToTenured 10m 9 TENURED
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m
* -XX:OldSize=32m -XX:MaxHeapSize=96m -XX:SurvivorRatio=1
* -XX:-ExplicitGCInvokesConcurrent
* -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=32
* TestPromotionFromEdenToTenured 10m 47 TENURED
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m
* -XX:OldSize=32m -XX:MaxHeapSize=96m
* -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent
* -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=64
* TestPromotionFromEdenToTenured 10m 9 TENURED
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m
* -XX:OldSize=32m -XX:MaxHeapSize=128m
* -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent
* -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=64
* TestPromotionFromEdenToTenured 10m 87 TENURED
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m
* -XX:OldSize=32M -XX:MaxHeapSize=96m -XX:SurvivorRatio=1
* -XX:-ExplicitGCInvokesConcurrent
* -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=128
* TestPromotionFromEdenToTenured 10m 9 TENURED
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m
* -XX:OldSize=32m -XX:MaxHeapSize=96m -XX:SurvivorRatio=1
* -XX:-ExplicitGCInvokesConcurrent
* -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=128
* TestPromotionFromEdenToTenured 10m 147 TENURED
*/
public class TestPromotionFromEdenToTenured {
public static void main(String args[]) {
SurvivorAlignmentTestMain test
= SurvivorAlignmentTestMain.fromArgs(args);
System.out.println(test);
long expectedMemoryUsage = test.getExpectedMemoryUsage();
test.baselineMemoryAllocation();
System.gc();
// increase expected usage by current old gen usage
expectedMemoryUsage += SurvivorAlignmentTestMain.getAlignmentHelper(
SurvivorAlignmentTestMain.HeapSpace.TENURED)
.getActualMemoryUsage();
test.allocate();
System.gc();
test.verifyMemoryUsage(expectedMemoryUsage);
}
}
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 8031323
* @summary Verify that objects promoted from survivor space to tenured space
* during full GC are not aligned to SurvivorAlignmentInBytes value.
* @library /testlibrary /testlibrary/whitebox
* @build TestPromotionFromSurvivorToTenuredAfterFullGC
* SurvivorAlignmentTestMain AlignmentHelper
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
* -XX:OldSize=32m -XX:MaxHeapSize=160m
* -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent
* -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=32
* TestPromotionFromSurvivorToTenuredAfterFullGC 10m 9 TENURED
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
* -XX:OldSize=32m -XX:MaxHeapSize=160m
* -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent
* -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=32
* TestPromotionFromSurvivorToTenuredAfterFullGC 20m 47
* TENURED
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=200m -XX:MaxNewSize=200m
* -XX:OldSize=32m -XX:MaxHeapSize=232m
* -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent
* -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=64
* TestPromotionFromSurvivorToTenuredAfterFullGC 10m 9 TENURED
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
* -XX:OldSize=32m -XX:MaxHeapSize=160m
* -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent
* -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=64
* TestPromotionFromSurvivorToTenuredAfterFullGC 20m 87
* TENURED
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=256m -XX:MaxNewSize=256m
* -XX:OldSize=32M -XX:MaxHeapSize=288m
* -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent
* -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=128
* TestPromotionFromSurvivorToTenuredAfterFullGC 10m 9
* TENURED
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
* -XX:OldSize=32m -XX:MaxHeapSize=160m
* -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent
* -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=128
* TestPromotionFromSurvivorToTenuredAfterFullGC 20m 147
* TENURED
*/
public class TestPromotionFromSurvivorToTenuredAfterFullGC {
public static void main(String args[]) {
SurvivorAlignmentTestMain test
= SurvivorAlignmentTestMain.fromArgs(args);
System.out.println(test);
long expectedMemoryUsage = test.getExpectedMemoryUsage();
test.baselineMemoryAllocation();
System.gc();
// increase expected usage by current old gen usage
expectedMemoryUsage += SurvivorAlignmentTestMain.getAlignmentHelper(
SurvivorAlignmentTestMain.HeapSpace.TENURED)
.getActualMemoryUsage();
test.allocate();
SurvivorAlignmentTestMain.WHITE_BOX.youngGC();
System.gc();
test.verifyMemoryUsage(expectedMemoryUsage);
}
}
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 8031323
* @summary Verify that objects promoted from survivor space to tenured space
* when their age exceeded tenuring threshold are not aligned to
* SurvivorAlignmentInBytes value.
* @library /testlibrary /testlibrary/whitebox
* @build TestPromotionFromSurvivorToTenuredAfterMinorGC
* SurvivorAlignmentTestMain AlignmentHelper
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
* -XX:OldSize=32M -XX:MaxHeapSize=160m -XX:SurvivorRatio=1
* -XX:-ExplicitGCInvokesConcurrent
* -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=32
* TestPromotionFromSurvivorToTenuredAfterMinorGC 10m 9
* TENURED
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
* -XX:OldSize=32M -XX:MaxHeapSize=160m -XX:SurvivorRatio=1
* -XX:-ExplicitGCInvokesConcurrent
* -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=32
* TestPromotionFromSurvivorToTenuredAfterMinorGC 20m 47
* TENURED
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=200m -XX:MaxNewSize=200m
* -XX:OldSize=32M -XX:MaxHeapSize=232m -XX:SurvivorRatio=1
* -XX:-ExplicitGCInvokesConcurrent
* -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=64
* TestPromotionFromSurvivorToTenuredAfterMinorGC 10m 9
* TENURED
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
* -XX:OldSize=32M -XX:MaxHeapSize=160m -XX:SurvivorRatio=1
* -XX:-ExplicitGCInvokesConcurrent
* -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=64
* TestPromotionFromSurvivorToTenuredAfterMinorGC 20m 87
* TENURED
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=256m -XX:MaxNewSize=256m
* -XX:OldSize=32M -XX:MaxHeapSize=288m -XX:SurvivorRatio=1
* -XX:-ExplicitGCInvokesConcurrent
* -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=128
* TestPromotionFromSurvivorToTenuredAfterMinorGC 10m 9
* TENURED
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
* -XX:OldSize=32M -XX:MaxHeapSize=160m -XX:SurvivorRatio=1
* -XX:-ExplicitGCInvokesConcurrent
* -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=128
* TestPromotionFromSurvivorToTenuredAfterMinorGC 20m 147
* TENURED
*/
public class TestPromotionFromSurvivorToTenuredAfterMinorGC {
public static void main(String args[]) throws Exception {
SurvivorAlignmentTestMain test
= SurvivorAlignmentTestMain.fromArgs(args);
System.out.println(test);
long expectedMemoryUsage = test.getExpectedMemoryUsage();
test.baselineMemoryAllocation();
SurvivorAlignmentTestMain.WHITE_BOX.fullGC();
// increase expected usage by current old gen usage
expectedMemoryUsage += SurvivorAlignmentTestMain.getAlignmentHelper(
SurvivorAlignmentTestMain.HeapSpace.TENURED)
.getActualMemoryUsage();
test.allocate();
for (int i = 0; i <= SurvivorAlignmentTestMain.MAX_TENURING_THRESHOLD;
i++) {
SurvivorAlignmentTestMain.WHITE_BOX.youngGC();
}
test.verifyMemoryUsage(expectedMemoryUsage);
}
}
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 8031323
* @summary Verify that objects promoted from eden space to survivor space after
* minor GC are aligned to SurvivorAlignmentInBytes.
* @library /testlibrary /testlibrary/whitebox
* @build TestPromotionToSurvivor
* SurvivorAlignmentTestMain AlignmentHelper
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
* -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=32 -XX:OldSize=128m
* -XX:MaxHeapSize=256m -XX:-ExplicitGCInvokesConcurrent
* TestPromotionToSurvivor 10m 9 SURVIVOR
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
* -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=32 -XX:OldSize=128m
* -XX:MaxHeapSize=256m -XX:-ExplicitGCInvokesConcurrent
* TestPromotionToSurvivor 20m 47 SURVIVOR
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
* -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=64 -XX:OldSize=128m
* -XX:MaxHeapSize=256m -XX:-ExplicitGCInvokesConcurrent
* TestPromotionToSurvivor 8m 9 SURVIVOR
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
* -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=64 -XX:OldSize=128m
* -XX:MaxHeapSize=256m -XX:-ExplicitGCInvokesConcurrent
* TestPromotionToSurvivor 20m 87 SURVIVOR
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=256m -XX:MaxNewSize=256m
* -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=128 -XX:OldSize=128m
* -XX:MaxHeapSize=384m -XX:-ExplicitGCInvokesConcurrent
* TestPromotionToSurvivor 10m 9 SURVIVOR
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
* -XX:SurvivorRatio=1 -XX:+UnlockExperimentalVMOptions
* -XX:SurvivorAlignmentInBytes=128 -XX:OldSize=128m
* -XX:MaxHeapSize=256m -XX:-ExplicitGCInvokesConcurrent
* TestPromotionToSurvivor 20m 147 SURVIVOR
*/
public class TestPromotionToSurvivor {
public static void main(String args[]) {
SurvivorAlignmentTestMain test
= SurvivorAlignmentTestMain.fromArgs(args);
System.out.println(test);
long expectedUsage = test.getExpectedMemoryUsage();
test.baselineMemoryAllocation();
SurvivorAlignmentTestMain.WHITE_BOX.fullGC();
test.allocate();
SurvivorAlignmentTestMain.WHITE_BOX.youngGC();
test.verifyMemoryUsage(expectedUsage);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册