Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/classloaders/DoItYourselfClassLoader.java
41161 views
/*1* Copyright (c) 2014, 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 gc.g1.unloading.classloaders;2324import java.net.MalformedURLException;25import java.net.URL;26import java.security.CodeSigner;27import java.security.CodeSource;2829/**30*31* This is just a classloader that doesn't follow delegation pattern.32*33*/34public class DoItYourselfClassLoader extends FinalizableClassloader {3536private static long counter = 0;3738/**39* We force different classes to have different protection domains40*/41public Class<?> defineClass(String name, byte[] bytes) {42URL url;43try {44url = new URL("http://random.url.com/" + (counter++));45} catch (MalformedURLException e) {46throw new RuntimeException("This is impossible, but there is mistake in simple call to URL constructor", e);47}48return defineClass(name, bytes, 0, bytes.length, new CodeSource(url, new CodeSigner[] {}));49}5051}525354