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  * @library /test/lib
  29  * @modules java.base/jdk.internal.misc
  30  *          java.management
  31  * @build sun.hotspot.WhiteBox
  32  * @requires (vm.debug == true)
  33  *
  34  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  35  *
  36  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI  -XX:VerifyMetaspaceInterval=10                                        TestMetaspaceAllocation
  37  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI  -XX:VerifyMetaspaceInterval=10  -XX:MetaspaceReclaimPolicy=none       TestMetaspaceAllocation
  38  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI  -XX:VerifyMetaspaceInterval=10  -XX:MetaspaceReclaimPolicy=aggressive TestMetaspaceAllocation
  39  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI  -XX:VerifyMetaspaceInterval=10  -XX:+MetaspaceGuardAllocations        TestMetaspaceAllocation
  40  *
  41  */
  42 
  43 /*
  44  * @test id=ndebug
  45  * @library /test/lib
  46  * @modules java.base/jdk.internal.misc
  47  *          java.management
  48  * @build sun.hotspot.WhiteBox
  49  * @requires (vm.debug == false)
  50  *
  51  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  52  *
  53  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI                                        TestMetaspaceAllocation
  54  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI  -XX:MetaspaceReclaimPolicy=none       TestMetaspaceAllocation
  55  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI  -XX:MetaspaceReclaimPolicy=aggressive TestMetaspaceAllocation
  56  */
  57 
  58 public class TestMetaspaceAllocation {
  59 
  60     public static void main(String[] args) {
  61 
  62         MetaspaceTestContext context = new MetaspaceTestContext();
  63         MetaspaceTestArena arena1 = context.createArena(false, 1024 * 1024 * 4);
  64         MetaspaceTestArena arena2 = context.createArena(true,1024 * 1024 * 4);
  65 
  66         Allocation a1 = arena1.allocate(100);
  67         Allocation a2 = arena2.allocate(100);
  68 
  69         long used = context.usedWords();
  70         long committed = context.committedWords();
  71 
  72         System.out.println("used " + used + " committed " + committed);
  73 
  74         arena1.deallocate(a1);
  75 
  76         context.destroyArena(arena2);
  77         context.destroyArena(arena1);
  78 
  79         context.purge();
  80 
  81         context.destroy();
  82 
  83     }
  84 }