1 /*
   2  * Copyright (c) 2014, 2019, 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 package gc.survivorAlignment;
  25 
  26 /**
  27  * @test
  28  * @bug 8031323
  29  * @summary Verify that objects promoted from eden space to tenured space during
  30  *          full GC are not aligned to SurvivorAlignmentInBytes value.
  31  * @requires vm.gc != "Z" & vm.gc != "Shenandoah"
  32  * @library /test/lib
  33  * @library /
  34  * @modules java.base/jdk.internal.misc
  35  *          java.management
  36  * @build sun.hotspot.WhiteBox
  37  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  38  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  39  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  40  *                   -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m
  41  *                   -XX:OldSize=32m -XX:MaxHeapSize=96m -XX:SurvivorRatio=1
  42  *                   -XX:-ExplicitGCInvokesConcurrent -XX:-ResizePLAB
  43  *                   -XX:+UnlockExperimentalVMOptions
  44  *                   -XX:SurvivorAlignmentInBytes=32
  45  *                   gc.survivorAlignment.TestPromotionFromEdenToTenured 10m 9 TENURED
  46  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  47  *                   -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m
  48  *                   -XX:OldSize=32m -XX:MaxHeapSize=96m -XX:SurvivorRatio=1
  49  *                   -XX:-ExplicitGCInvokesConcurrent -XX:-ResizePLAB
  50  *                   -XX:+UnlockExperimentalVMOptions
  51  *                   -XX:SurvivorAlignmentInBytes=32
  52  *                   gc.survivorAlignment.TestPromotionFromEdenToTenured 10m 47 TENURED
  53  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  54  *                   -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m
  55  *                   -XX:OldSize=32m  -XX:MaxHeapSize=96m
  56  *                   -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent -XX:-ResizePLAB
  57  *                   -XX:+UnlockExperimentalVMOptions
  58  *                   -XX:SurvivorAlignmentInBytes=64
  59  *                   gc.survivorAlignment.TestPromotionFromEdenToTenured 10m 9 TENURED
  60  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  61  *                   -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m
  62  *                   -XX:OldSize=32m -XX:MaxHeapSize=128m
  63  *                   -XX:SurvivorRatio=1 -XX:-ExplicitGCInvokesConcurrent -XX:-ResizePLAB
  64  *                   -XX:+UnlockExperimentalVMOptions
  65  *                   -XX:SurvivorAlignmentInBytes=64
  66  *                   gc.survivorAlignment.TestPromotionFromEdenToTenured 10m 87 TENURED
  67  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  68  *                   -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m
  69  *                   -XX:OldSize=32M -XX:MaxHeapSize=96m -XX:SurvivorRatio=1
  70  *                   -XX:-ExplicitGCInvokesConcurrent -XX:-ResizePLAB
  71  *                   -XX:+UnlockExperimentalVMOptions
  72  *                   -XX:SurvivorAlignmentInBytes=128
  73  *                   gc.survivorAlignment.TestPromotionFromEdenToTenured 10m 9 TENURED
  74  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  75  *                   -XX:+WhiteBoxAPI -XX:NewSize=64m -XX:MaxNewSize=64m
  76  *                   -XX:OldSize=32m -XX:MaxHeapSize=96m -XX:SurvivorRatio=1
  77  *                   -XX:-ExplicitGCInvokesConcurrent -XX:-ResizePLAB
  78  *                   -XX:+UnlockExperimentalVMOptions
  79  *                   -XX:SurvivorAlignmentInBytes=128
  80  *                   gc.survivorAlignment.TestPromotionFromEdenToTenured 10m 147 TENURED
  81  */
  82 public class TestPromotionFromEdenToTenured {
  83     public static void main(String args[]) {
  84         SurvivorAlignmentTestMain test
  85                 = SurvivorAlignmentTestMain.fromArgs(args);
  86         System.out.println(test);
  87 
  88         long expectedMemoryUsage = test.getExpectedMemoryUsage();
  89         test.baselineMemoryAllocation();
  90         System.gc();
  91         // increase expected usage by current old gen usage
  92         expectedMemoryUsage += SurvivorAlignmentTestMain.getAlignmentHelper(
  93                 SurvivorAlignmentTestMain.HeapSpace.TENURED)
  94                 .getActualMemoryUsage();
  95 
  96         test.allocate();
  97         System.gc();
  98 
  99         test.verifyMemoryUsage(expectedMemoryUsage);
 100     }
 101 }