hotspot/test/gc/survivorAlignment/AlignmentHelper.java
author lana
Thu, 12 May 2016 15:15:02 +0000
changeset 37915 be4ff50b6cb6
parent 27890 9c0e6a049e1f
permissions -rw-r--r--
Added tag jdk-9+118 for changeset cc643de7cb06
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27890
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
     1
/*
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
     4
 *
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
     8
 *
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    13
 * accompanied this code).
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    14
 *
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    18
 *
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    21
 * questions.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    22
 */
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    23
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    24
import java.lang.management.MemoryPoolMXBean;
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    25
import java.util.Optional;
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    26
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    27
import sun.hotspot.WhiteBox;
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    28
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    29
/**
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    30
 * Helper class aimed to provide information about alignment of objects in
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    31
 * particular heap space, expected memory usage after objects' allocation so on.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    32
 */
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    33
public class AlignmentHelper {
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    34
    private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    35
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    36
    private static final long OBJECT_ALIGNMENT_IN_BYTES_FOR_32_VM = 8L;
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    37
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    38
    /**
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    39
     * Max relative allowed actual memory usage deviation from expected memory
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    40
     * usage.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    41
     */
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    42
    private static final float MAX_RELATIVE_DEVIATION = 0.05f; // 5%
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    43
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    44
    public static final long OBJECT_ALIGNMENT_IN_BYTES = Optional.ofNullable(
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    45
            AlignmentHelper.WHITE_BOX.getIntxVMFlag("ObjectAlignmentInBytes"))
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    46
            .orElse(AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES_FOR_32_VM);
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    47
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    48
    public static final long SURVIVOR_ALIGNMENT_IN_BYTES = Optional.ofNullable(
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    49
            AlignmentHelper.WHITE_BOX.getIntxVMFlag("SurvivorAlignmentInBytes"))
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    50
            .orElseThrow(() ->new AssertionError(
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    51
                    "Unable to get SurvivorAlignmentInBytes value"));
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    52
    /**
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    53
     * Min amount of memory that will be occupied by an object.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    54
     */
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    55
    public static final long MIN_OBJECT_SIZE
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    56
            = AlignmentHelper.WHITE_BOX.getObjectSize(new Object());
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    57
    /**
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    58
     * Min amount of memory that will be occupied by an empty byte array.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    59
     */
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    60
    public static final long MIN_ARRAY_SIZE
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    61
            = AlignmentHelper.WHITE_BOX.getObjectSize(new byte[0]);
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    62
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    63
    /**
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    64
     * Precision at which actual memory usage in a heap space represented by
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    65
     * this sizing helper could be measured.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    66
     */
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    67
    private final long memoryUsageMeasurementPrecision;
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    68
    /**
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    69
     * Min amount of memory that will be occupied by an object allocated in a
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    70
     * heap space represented by this sizing helper.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    71
     */
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    72
    private final long minObjectSizeInThisSpace;
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    73
    /**
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    74
     * Object's alignment in a heap space represented by this sizing helper.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    75
     */
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    76
    private final long objectAlignmentInThisRegion;
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    77
    /**
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    78
     * MemoryPoolMXBean associated with a heap space represented by this sizing
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    79
     * helper.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    80
     */
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    81
    private final MemoryPoolMXBean poolMXBean;
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    82
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    83
    private static long alignUp(long value, long alignment) {
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    84
        return ((value - 1) / alignment + 1) * alignment;
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    85
    }
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    86
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    87
    protected AlignmentHelper(long memoryUsageMeasurementPrecision,
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    88
            long objectAlignmentInThisRegion, long minObjectSizeInThisSpace,
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    89
            MemoryPoolMXBean poolMXBean) {
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    90
        this.memoryUsageMeasurementPrecision = memoryUsageMeasurementPrecision;
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    91
        this.minObjectSizeInThisSpace = minObjectSizeInThisSpace;
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    92
        this.objectAlignmentInThisRegion = objectAlignmentInThisRegion;
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    93
        this.poolMXBean = poolMXBean;
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    94
    }
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    95
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    96
    /**
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    97
     * Returns how many objects have to be allocated to fill
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    98
     * {@code memoryToFill} bytes in this heap space using objects of size
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
    99
     * {@code objectSize}.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   100
     */
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   101
    public int getObjectsCount(long memoryToFill, long objectSize) {
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   102
        return (int) (memoryToFill / getObjectSizeInThisSpace(objectSize));
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   103
    }
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   104
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   105
    /**
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   106
     * Returns amount of memory that {@code objectsCount} of objects with size
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   107
     * {@code objectSize} will occupy this this space after allocation.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   108
     */
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   109
    public long getExpectedMemoryUsage(long objectSize, int objectsCount) {
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   110
        long correctedObjectSize = getObjectSizeInThisSpace(objectSize);
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   111
        return AlignmentHelper.alignUp(correctedObjectSize * objectsCount,
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   112
                memoryUsageMeasurementPrecision);
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   113
    }
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   114
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   115
    /**
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   116
     * Returns current memory usage in this heap space.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   117
     */
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   118
    public long getActualMemoryUsage() {
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   119
        return poolMXBean.getUsage().getUsed();
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   120
    }
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   121
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   122
    /**
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   123
     * Returns maximum memory usage deviation from {@code expectedMemoryUsage}
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   124
     * given the max allowed relative deviation equal to
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   125
     * {@code relativeDeviation}.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   126
     *
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   127
     * Note that value returned by this method is aligned according to
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   128
     * memory measurement precision for this heap space.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   129
     */
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   130
    public long getAllowedMemoryUsageDeviation(long expectedMemoryUsage) {
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   131
        long unalignedDeviation = (long) (expectedMemoryUsage *
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   132
                AlignmentHelper.MAX_RELATIVE_DEVIATION);
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   133
        return AlignmentHelper.alignUp(unalignedDeviation,
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   134
                memoryUsageMeasurementPrecision);
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   135
    }
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   136
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   137
    /**
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   138
     * Returns amount of memory that will be occupied by an object with size
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   139
     * {@code objectSize} in this heap space.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   140
     */
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   141
    public long getObjectSizeInThisSpace(long objectSize) {
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   142
        objectSize = Math.max(objectSize, minObjectSizeInThisSpace);
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   143
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   144
        long alignedObjectSize = AlignmentHelper.alignUp(objectSize,
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   145
                objectAlignmentInThisRegion);
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   146
        long sizeDiff = alignedObjectSize - objectSize;
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   147
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   148
        // If there is not enough space to fit padding object, then object will
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   149
        // be aligned to {@code 2 * objectAlignmentInThisRegion}.
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   150
        if (sizeDiff >= AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   151
                && sizeDiff < AlignmentHelper.MIN_OBJECT_SIZE) {
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   152
            alignedObjectSize += AlignmentHelper.MIN_OBJECT_SIZE;
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   153
            alignedObjectSize = AlignmentHelper.alignUp(alignedObjectSize,
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   154
                    objectAlignmentInThisRegion);
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   155
        }
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   156
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   157
        return alignedObjectSize;
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   158
    }
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   159
    @Override
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   160
    public String toString() {
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   161
        StringBuilder builder = new StringBuilder();
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   162
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   163
        builder.append(String.format("AlignmentHelper for memory pool '%s':%n",
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   164
                poolMXBean.getName()));
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   165
        builder.append(String.format("Memory usage measurement precision: %d%n",
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   166
                memoryUsageMeasurementPrecision));
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   167
        builder.append(String.format("Min object size in this space: %d%n",
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   168
                minObjectSizeInThisSpace));
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   169
        builder.append(String.format("Object alignment in this space: %d%n",
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   170
                objectAlignmentInThisRegion));
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   171
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   172
        return builder.toString();
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   173
    }
9c0e6a049e1f 8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff changeset
   174
}