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  *          during full GC are not aligned to SurvivorAlignmentInBytes value.
  29  * @requires vm.gc != "Z"
  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
  39  *                   -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent -XX:-ResizePLAB
  40  *                   -XX:+UnlockExperimentalVMOptions
  41  *                   -XX:SurvivorAlignmentInBytes=32
  42  *                   TestPromotionFromSurvivorToTenuredAfterFullGC 10m 9 TENURED
  43  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  44  *                   -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
  45  *                   -XX:OldSize=32m -XX:MaxHeapSize=160m -XX:-ResizePLAB
  46  *                   -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent
  47  *                   -XX:+UnlockExperimentalVMOptions
  48  *                   -XX:SurvivorAlignmentInBytes=32
  49  *                   TestPromotionFromSurvivorToTenuredAfterFullGC 20m 47
  50  *                   TENURED
  51  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  52  *                   -XX:+WhiteBoxAPI -XX:NewSize=200m -XX:MaxNewSize=200m
  53  *                   -XX:OldSize=32m -XX:MaxHeapSize=232m
  54  *                   -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent -XX:-ResizePLAB
  55  *                   -XX:+UnlockExperimentalVMOptions
  56  *                   -XX:SurvivorAlignmentInBytes=64
  57  *                   TestPromotionFromSurvivorToTenuredAfterFullGC 10m 9 TENURED
  58  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  59  *                   -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
  60  *                   -XX:OldSize=32m -XX:MaxHeapSize=160m
  61  *                   -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent -XX:-ResizePLAB
  62  *                   -XX:+UnlockExperimentalVMOptions
  63  *                   -XX:SurvivorAlignmentInBytes=64
  64  *                   TestPromotionFromSurvivorToTenuredAfterFullGC 20m 87
  65  *                   TENURED
  66  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  67  *                   -XX:+WhiteBoxAPI -XX:NewSize=256m -XX:MaxNewSize=256m
  68  *                   -XX:OldSize=32M -XX:MaxHeapSize=288m
  69  *                   -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent -XX:-ResizePLAB
  70  *                   -XX:+UnlockExperimentalVMOptions
  71  *                   -XX:SurvivorAlignmentInBytes=128
  72  *                    TestPromotionFromSurvivorToTenuredAfterFullGC 10m 9
  73  *                    TENURED
  74  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  75  *                   -XX:+WhiteBoxAPI -XX:NewSize=128m -XX:MaxNewSize=128m
  76  *                   -XX:OldSize=32m -XX:MaxHeapSize=160m
  77  *                   -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent -XX:-ResizePLAB
  78  *                   -XX:+UnlockExperimentalVMOptions
  79  *                   -XX:SurvivorAlignmentInBytes=128
  80  *                   TestPromotionFromSurvivorToTenuredAfterFullGC 20m 147
  81  *                   TENURED
  82  */
  83 public class TestPromotionFromSurvivorToTenuredAfterFullGC {
  84     public static void main(String args[]) {
  85         SurvivorAlignmentTestMain test
  86                 = SurvivorAlignmentTestMain.fromArgs(args);
  87         System.out.println(test);
  88 
  89         long expectedMemoryUsage = test.getExpectedMemoryUsage();
  90         test.baselineMemoryAllocation();
  91         System.gc();
  92         // increase expected usage by current old gen usage
  93         expectedMemoryUsage += SurvivorAlignmentTestMain.getAlignmentHelper(
  94                 SurvivorAlignmentTestMain.HeapSpace.TENURED)
  95                 .getActualMemoryUsage();
  96 
  97         test.allocate();
  98         SurvivorAlignmentTestMain.WHITE_BOX.youngGC();
  99         System.gc();
 100 
 101         test.verifyMemoryUsage(expectedMemoryUsage);
 102     }
 103 }