1 /*
   2  * Copyright (c) 2014, 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  * @requires vm.gc != "Shenandoah"
  31  * @library /testlibrary /testlibrary/whitebox
  32  * @build TestPromotionFromSurvivorToTenuredAfterMinorGC
  33  *        SurvivorAlignmentTestMain AlignmentHelper
  34  * @run main 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
  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
  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
  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
  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
  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
  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;
 101              i++) {
 102             SurvivorAlignmentTestMain.WHITE_BOX.youngGC();
 103         }
 104 
 105         test.verifyMemoryUsage(expectedMemoryUsage);
 106     }
 107 }