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