Path: blob/master/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/GeneratedClassProducer.java
41159 views
/*1* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22package utils;2324import jdk.test.lib.classloader.GeneratingClassLoader;2526/**27* Garbage producer that creates classes loaded with GeneratingClassLoader.28*29* Note: this class is not thread-safe.30*/31class GeneratedClassProducer {3233private int number;34private String className;35private StringBuilder sb = new StringBuilder();36private int minPerClassLoader = 50;37private int maxPerClassLoader = 150;38private int count;39private GeneratingClassLoader loader = new GeneratingClassLoader();4041GeneratedClassProducer() {42this(GeneratingClassLoader.DEFAULT_CLASSNAME);43}4445GeneratedClassProducer(String className) {46this.className = className;47}4849String getNewName() {50sb.delete(0, sb.length());51sb.append("Class");52sb.append(number);53int n = loader.getNameLength() - sb.length();54for (int i = 0; i < n; ++i) {55sb.append('_');56}57return sb.toString();58}5960Class create(long memory) {61try {62if (number++ > maxPerClassLoader || loader == null) {63loader = new GeneratingClassLoader(className);64count = 50;65number = 0;66}67return loader.loadClass(getNewName());68} catch (ClassNotFoundException e) {69throw new RuntimeException(e);70}71}72}737475