1 /*
   2  * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2020 SAP SE. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 /*
  27  * @test id=debug
  28  * @bug 8251158
  29  * @library /test/lib
  30  * @modules java.base/jdk.internal.misc
  31  *          java.management
  32  * @build sun.hotspot.WhiteBox
  33  * @requires (vm.debug == true)
  34  *
  35  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  36  *
  37  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI  -XX:VerifyMetaspaceInterval=10                                        TestMetaspaceAllocation
  38  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI  -XX:VerifyMetaspaceInterval=10  -XX:MetaspaceReclaimPolicy=none       TestMetaspaceAllocation
  39  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI  -XX:VerifyMetaspaceInterval=10  -XX:MetaspaceReclaimPolicy=aggressive TestMetaspaceAllocation
  40  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI  -XX:VerifyMetaspaceInterval=10  -XX:+MetaspaceGuardAllocations        TestMetaspaceAllocation
  41  *
  42  */
  43 
  44 /*
  45  * @test id=ndebug
  46  * @bug 8251158
  47  * @library /test/lib
  48  * @modules java.base/jdk.internal.misc
  49  *          java.management
  50  * @build sun.hotspot.WhiteBox
  51  * @requires (vm.debug == false)
  52  *
  53  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  54  *
  55  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI                                        TestMetaspaceAllocation
  56  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI  -XX:MetaspaceReclaimPolicy=none       TestMetaspaceAllocation
  57  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI  -XX:MetaspaceReclaimPolicy=aggressive TestMetaspaceAllocation
  58  */
  59 
  60 public class TestMetaspaceAllocation {
  61 
  62     public static void main(String[] args) {
  63 
  64         MetaspaceTestContext context = new MetaspaceTestContext();
  65         MetaspaceTestArena arena1 = context.createArena(false, 1024 * 1024 * 4);
  66         MetaspaceTestArena arena2 = context.createArena(true,1024 * 1024 * 4);
  67 
  68         Allocation a1 = arena1.allocate(100);
  69         Allocation a2 = arena2.allocate(100);
  70 
  71         long used = context.usedWords();
  72         long committed = context.committedWords();
  73 
  74         System.out.println("used " + used + " committed " + committed);
  75 
  76         arena1.deallocate(a1);
  77 
  78         context.destroyArena(arena2);
  79         context.destroyArena(arena1);
  80 
  81         context.purge();
  82 
  83         context.destroy();
  84 
  85     }
  86 }