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