test/hotspot/jtreg/runtime/LoadClass/TriggerResize.java
author shade
Thu, 30 Nov 2017 17:13:33 +0100
branchepsilon-gc-branch
changeset 55934 912c55e702d6
parent 47774 69c081ca110a
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47774
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
     1
/*
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
     4
 *
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
     7
 * published by the Free Software Foundation.
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
     8
 *
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    13
 * accompanied this code).
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    14
 *
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    18
 *
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    21
 * questions.
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    22
 */
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    23
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    24
import java.lang.ClassLoader;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    25
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    26
public class TriggerResize extends ClassLoader
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    27
{
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    28
  static private int[] DATA = // bytes for "class TestCase00000 {}"
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    29
  {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    30
    -54,    -2,   -70,   -66,     0,     0,     0,    52,    0,     13, //   0
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    31
     10,     0,     3,     0,    10,     7,     0,    11,    7,      0, //  10
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    32
     12,     1,     0,     6,    60,   105,   110,   105,  116,     62, //  20
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    33
      1,     0,     3,    40,    41,    86,     1,     0,     4,    67, //  30
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    34
    111,   100,   101,     1,     0,    15,    76,   105,   110,   101, //  40
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    35
     78,   117,   109,    98,   101,   114,    84,    97,    98,   108, //  50
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    36
    101,     1,     0,    10,    83,   111,   117,   114,    99,   101, //  60
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    37
     70,   105,   108,   101,     1,     0,    18,    84,   101,   115, //  70
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    38
    116,    67,    97,   115,   101,    48,    48,    48,    48,    48, //  80
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    39
     46,   106,    97,   118,    97,    12,     0,     4,     0,     5, //  90
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    40
      1,     0,    13,    84,   101,   115,   116,    67,    97,   115, // 100
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    41
    101,    48,    48,    48,    48,    48,     1,     0,    16,   106, // 110
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    42
     97,   118,    97,    47,   108,    97,   110,   103,    47,    79, // 120
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    43
     98,   106,   101,    99,   116,     0,    32,     0,     2,     0, // 130
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    44
      3,     0,     0,     0,     0,     0,     1,     0,     0,     0, // 140
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    45
      4,     0,     5,     0,     1,     0,     6,     0,     0,     0, // 150
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    46
     29,     0,     1,     0,     1,     0,     0,     0,     5,    42, // 160
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    47
    -73,     0,     1,   -79,     0,     0,     0,     1,     0,     7, // 170
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    48
      0,     0,     0,     6,     0,     1,     0,     0,     0,     1, // 180
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    49
      0,     1,     0,     8,     0,     0,     0,     2,     0,     9  // 190
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    50
  };
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    51
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    52
  static private int INDEX1 = 85;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    53
  static private int INDEX2 = 111;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    54
  static private int BASE = 48;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    55
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    56
  public TriggerResize()
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    57
  {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    58
    super();
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    59
  }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    60
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    61
  public void load(int index)
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    62
  {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    63
    byte[] bytes = new byte[TriggerResize.DATA.length];
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    64
    for (int i=0; i<bytes.length; i++)
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    65
    {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    66
      bytes[i] = (byte)TriggerResize.DATA[i];
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    67
    }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    68
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    69
    // replace id "00000" in TestCase00000 to generate new class on the fly
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    70
    {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    71
      int byte1 = index % 10;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    72
      int byte2 = index / 10 % 10;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    73
      int byte3 = index / 100 % 10;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    74
      int byte4 = index / 1000 % 10;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    75
      int byte5 = index / 10000 % 10;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    76
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    77
      bytes[INDEX1+0] = bytes[INDEX2+0] = (byte)(BASE+byte5);
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    78
      bytes[INDEX1+1] = bytes[INDEX2+1] = (byte)(BASE+byte4);
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    79
      bytes[INDEX1+2] = bytes[INDEX2+2] = (byte)(BASE+byte3);
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    80
      bytes[INDEX1+3] = bytes[INDEX2+3] = (byte)(BASE+byte2);
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    81
      bytes[INDEX1+4] = bytes[INDEX2+4] = (byte)(BASE+byte1);
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    82
    }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    83
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    84
    Class generatedClass = defineClass(bytes, 0, bytes.length);
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    85
    resolveClass(generatedClass);
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    86
  }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    87
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    88
  public static void main(String args[]) throws Exception
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    89
  {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    90
    int count = 0;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    91
    if (args.length >= 1) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    92
      Integer i = new Integer(args[0]);
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    93
      count = i.intValue();
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    94
    }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    95
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    96
    TriggerResize test = new TriggerResize();
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    97
    for (int i = 0; i <= count; i++)
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    98
    {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
    99
      test.load(i);
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
   100
    }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
   101
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
   102
    // trigger safepoint to resize the SystemDictionary if needed
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
   103
    System.gc();
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
   104
  }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents:
diff changeset
   105
}