< prev index next >

test/lib/jdk/test/lib/classloader/GeneratingClassLoader.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 18,41 **** * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! package utils; import java.io.*; import java.util.*; /** * Classloader that generates classes on the fly. * * This classloader can load classes with name starting with 'Class'. It will * use TemplateClass as template and will replace class name in the bytecode of * template class. It can be used for example to detect memory leaks in class ! * loading or to quickly fill PermGen. */ ! class GeneratingClassLoader extends ClassLoader { public synchronized Class loadClass(String name) throws ClassNotFoundException { return loadClass(name, false); } --- 18,44 ---- * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! package jdk.test.lib.classloader; import java.io.*; import java.util.*; /** * Classloader that generates classes on the fly. * * This classloader can load classes with name starting with 'Class'. It will * use TemplateClass as template and will replace class name in the bytecode of * template class. It can be used for example to detect memory leaks in class ! * loading or to quickly fill Metaspace. */ ! class TemplateClass { ! } ! ! public class GeneratingClassLoader extends ClassLoader { public synchronized Class loadClass(String name) throws ClassNotFoundException { return loadClass(name, false); }
*** 61,71 **** /** * Create generating class loader that will use class file for given class * from classpath as template. */ ! GeneratingClassLoader(String templateClassName) { this.templateClassName = templateClassName; classPath = System.getProperty("java.class.path").split(File.pathSeparator); try { templateClassNameBytes = templateClassName.getBytes(encoding); } catch (UnsupportedEncodingException e) { --- 64,74 ---- /** * Create generating class loader that will use class file for given class * from classpath as template. */ ! public GeneratingClassLoader(String templateClassName) { this.templateClassName = templateClassName; classPath = System.getProperty("java.class.path").split(File.pathSeparator); try { templateClassNameBytes = templateClassName.getBytes(encoding); } catch (UnsupportedEncodingException e) {
*** 75,97 **** /** * Create generating class loader that will use class file for * nsk.share.classload.TemplateClass as template. */ ! GeneratingClassLoader() { this(TemplateClass.class.getName()); } ! int getNameLength() { return templateClassName.length(); } String getPrefix() { return PREFIX; } ! String getClassName(int number) { StringBuffer sb = new StringBuffer(); sb.append(PREFIX); sb.append(number); int n = templateClassName.length() - sb.length(); for (int i = 0; i < n; ++i) { --- 78,100 ---- /** * Create generating class loader that will use class file for * nsk.share.classload.TemplateClass as template. */ ! public GeneratingClassLoader() { this(TemplateClass.class.getName()); } ! public int getNameLength() { return templateClassName.length(); } String getPrefix() { return PREFIX; } ! public String getClassName(int number) { StringBuffer sb = new StringBuffer(); sb.append(PREFIX); sb.append(number); int n = templateClassName.length() - sb.length(); for (int i = 0; i < n; ++i) {
*** 181,191 **** this.offsets[i] = offsets.get(i).intValue(); } } } ! static final String DEFAULT_CLASSNAME = TemplateClass.class.getName(); static final String PREFIX = "Class"; private final String[] classPath; private byte[] bytecode; private int[] offsets; --- 184,194 ---- this.offsets[i] = offsets.get(i).intValue(); } } } ! public static final String DEFAULT_CLASSNAME = TemplateClass.class.getName(); static final String PREFIX = "Class"; private final String[] classPath; private byte[] bytecode; private int[] offsets;
< prev index next >