test/gc/class_unloading/AllocateBeyondMetaspaceSize.java

Wed, 03 Sep 2014 09:25:44 +0200

author
tschatzl
date
Wed, 03 Sep 2014 09:25:44 +0200
changeset 7097
14b8221771dc
parent 6996
f3aeae1f9fc5
permissions
-rw-r--r--

Merge

stefank@6996 1 /*
stefank@6996 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
stefank@6996 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
stefank@6996 4 *
stefank@6996 5 * This code is free software; you can redistribute it and/or modify it
stefank@6996 6 * under the terms of the GNU General Public License version 2 only, as
stefank@6996 7 * published by the Free Software Foundation.
stefank@6996 8 *
stefank@6996 9 * This code is distributed in the hope that it will be useful, but WITHOUT
stefank@6996 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
stefank@6996 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
stefank@6996 12 * version 2 for more details (a copy is included in the LICENSE file that
stefank@6996 13 * accompanied this code).
stefank@6996 14 *
stefank@6996 15 * You should have received a copy of the GNU General Public License version
stefank@6996 16 * 2 along with this work; if not, write to the Free Software Foundation,
stefank@6996 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
stefank@6996 18 *
stefank@6996 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
stefank@6996 20 * or visit www.oracle.com if you need additional information or have any
stefank@6996 21 * questions.
stefank@6996 22 */
stefank@6996 23
stefank@6996 24 import sun.hotspot.WhiteBox;
stefank@6996 25
stefank@6996 26 class AllocateBeyondMetaspaceSize {
stefank@6996 27 public static Object dummy;
stefank@6996 28
stefank@6996 29 public static void main(String [] args) {
stefank@6996 30 if (args.length != 2) {
stefank@6996 31 throw new IllegalArgumentException("Usage: <MetaspaceSize> <YoungGenSize>");
stefank@6996 32 }
stefank@6996 33
stefank@6996 34 long metaspaceSize = Long.parseLong(args[0]);
stefank@6996 35 long youngGenSize = Long.parseLong(args[1]);
stefank@6996 36
stefank@6996 37 run(metaspaceSize, youngGenSize);
stefank@6996 38 }
stefank@6996 39
stefank@6996 40 private static void run(long metaspaceSize, long youngGenSize) {
stefank@6996 41 WhiteBox wb = WhiteBox.getWhiteBox();
stefank@6996 42
stefank@6996 43 long allocationBeyondMetaspaceSize = metaspaceSize * 2;
stefank@6996 44 long metaspace = wb.allocateMetaspace(null, allocationBeyondMetaspaceSize);
stefank@6996 45
stefank@6996 46 triggerYoungGC(youngGenSize);
stefank@6996 47
stefank@6996 48 wb.freeMetaspace(null, metaspace, metaspace);
stefank@6996 49 }
stefank@6996 50
stefank@6996 51 private static void triggerYoungGC(long youngGenSize) {
stefank@6996 52 long approxAllocSize = 32 * 1024;
stefank@6996 53 long numAllocations = 2 * youngGenSize / approxAllocSize;
stefank@6996 54
stefank@6996 55 for (long i = 0; i < numAllocations; i++) {
stefank@6996 56 dummy = new byte[(int)approxAllocSize];
stefank@6996 57 }
stefank@6996 58 }
stefank@6996 59 }

mercurial