1 /*
   2  * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 8031323
  27  * @summary Verify that objects promoted from survivor space to tenured space
  28  *          when their age exceeded tenuring threshold are not aligned to
  29  *          SurvivorAlignmentInBytes value.
  30  * @library /test/lib
  31  * @modules java.base/jdk.internal.misc
  32  *          java.management
  33  * @build sun.hotspot.WhiteBox
  34  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  35  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  36  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  37  *                   -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
  38  *                   -XX:OldSize=32M -XX:MaxHeapSize=160m -XX:SurvivorRatio=1 -XX:-ResizePLAB
  39  *                   -XX:-ExplicitGCInvokesConcurrent
  40  *                   -XX:+UnlockExperimentalVMOptions
  41  *                   -XX:SurvivorAlignmentInBytes=32
  42  *                   TestPromotionFromSurvivorToTenuredAfterMinorGC 10m 9
  43  *                   TENURED
  44  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  45  *                   -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
  46  *                   -XX:OldSize=32M -XX:MaxHeapSize=160m -XX:SurvivorRatio=1 -XX:-ResizePLAB
  47  *                   -XX:-ExplicitGCInvokesConcurrent
  48  *                   -XX:+UnlockExperimentalVMOptions
  49  *                   -XX:SurvivorAlignmentInBytes=32
  50  *                   TestPromotionFromSurvivorToTenuredAfterMinorGC 20m 47
  51  *                   TENURED
  52  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  53  *                   -XX:+WhiteBoxAPI -XX:NewSize=200m -XX:MaxNewSize=200m
  54  *                   -XX:OldSize=32M -XX:MaxHeapSize=232m -XX:SurvivorRatio=1 -XX:-ResizePLAB
  55  *                   -XX:-ExplicitGCInvokesConcurrent
  56  *                   -XX:+UnlockExperimentalVMOptions
  57  *                   -XX:SurvivorAlignmentInBytes=64
  58  *                   TestPromotionFromSurvivorToTenuredAfterMinorGC 10m 9
  59  *                   TENURED
  60  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  61  *                   -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
  62  *                   -XX:OldSize=32M -XX:MaxHeapSize=160m -XX:SurvivorRatio=1 -XX:-ResizePLAB
  63  *                   -XX:-ExplicitGCInvokesConcurrent
  64  *                   -XX:+UnlockExperimentalVMOptions
  65  *                   -XX:SurvivorAlignmentInBytes=64
  66  *                   TestPromotionFromSurvivorToTenuredAfterMinorGC 20m 87
  67  *                   TENURED
  68  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  69  *                   -XX:+WhiteBoxAPI -XX:NewSize=256m -XX:MaxNewSize=256m
  70  *                   -XX:OldSize=32M -XX:MaxHeapSize=288m -XX:SurvivorRatio=1 -XX:-ResizePLAB
  71  *                   -XX:-ExplicitGCInvokesConcurrent
  72  *                   -XX:+UnlockExperimentalVMOptions
  73  *                   -XX:SurvivorAlignmentInBytes=128
  74  *                    TestPromotionFromSurvivorToTenuredAfterMinorGC 10m 9
  75  *                    TENURED
  76  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  77  *                   -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
  78  *                   -XX:OldSize=32M -XX:MaxHeapSize=160m -XX:SurvivorRatio=1 -XX:-ResizePLAB
  79  *                   -XX:-ExplicitGCInvokesConcurrent
  80  *                   -XX:+UnlockExperimentalVMOptions
  81  *                   -XX:SurvivorAlignmentInBytes=128
  82  *                   TestPromotionFromSurvivorToTenuredAfterMinorGC 20m 147
  83  *                   TENURED
  84  */
  85 public class TestPromotionFromSurvivorToTenuredAfterMinorGC {
  86     public static void main(String args[]) throws Exception {
  87         SurvivorAlignmentTestMain test
  88                 = SurvivorAlignmentTestMain.fromArgs(args);
  89         System.out.println(test);
  90 
  91         long expectedMemoryUsage = test.getExpectedMemoryUsage();
  92         test.baselineMemoryAllocation();
  93         SurvivorAlignmentTestMain.WHITE_BOX.fullGC();
  94         // increase expected usage by current old gen usage
  95         expectedMemoryUsage += SurvivorAlignmentTestMain.getAlignmentHelper(
  96                 SurvivorAlignmentTestMain.HeapSpace.TENURED)
  97                 .getActualMemoryUsage();
  98 
  99         test.allocate();
 100         for (int i = 0; i <= SurvivorAlignmentTestMain.MAX_TENURING_THRESHOLD; i++) {
 101             SurvivorAlignmentTestMain.WHITE_BOX.youngGC();
 102         }
 103 
 104         // Sometimes we see that data unrelated to the test has been allocated during
 105         // the loop. This data is included in the expectedMemoryUsage since we look
 106         // through all threads to see what they allocated. If this data is still in
 107         // the survivor area however, it should not be included in expectedMemoryUsage
 108         // since the verification below only look at what's in tenured space.
 109         expectedMemoryUsage -= SurvivorAlignmentTestMain.getAlignmentHelper(
 110                                    SurvivorAlignmentTestMain.HeapSpace.SURVIVOR)
 111                                    .getActualMemoryUsage();
 112         test.verifyMemoryUsage(expectedMemoryUsage);
 113     }
 114 }