Path: blob/master/test/hotspot/jtreg/runtime/6626217/Loader2.java
40942 views
/*1* Copyright (c) 2010, 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*22*/2324import java.io.ByteArrayInputStream;25import java.io.FileInputStream;26public class Loader2 extends ClassLoader {27int _recur;28public void print( String msg ) {29for( int i=0; i<_recur; i++ )30System.out.print(" ");31System.out.println(">>Loader2>> "+msg);32}3334protected Class findClass2(String name) throws ClassNotFoundException {35print("Fetching the implementation of "+name);36int old = _recur;37try {38FileInputStream fi = new FileInputStream(name+".class");39byte result[] = new byte[fi.available()];40fi.read(result);4142print("DefineClass1 on "+name);43_recur++;44Class clazz = defineClass(name, result, 0, result.length);45_recur = old;46print("Returning newly loaded class.");47return clazz;48} catch (Exception e) {49_recur = old;50print("Not found on disk.");51// If we caught an exception, either the class was not found or52// it was unreadable by our process.53return null;54//throw new ClassNotFoundException(e.toString());55}56}5758protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException {59// Attempt a disk load first60Class c = findClass2(name);61if( c == null ) {62// check if the class has already been loaded63print("Checking for prior loaded class "+name);64c = findLoadedClass(name);65print("Letting super-loader load "+name);66int old = _recur;67_recur++;68c = super.loadClass(name, false);69_recur=old;70}71if (resolve) { print("Resolving class "+name); resolveClass(c); }72print("Returning clazz "+c.getClassLoader()+":"+name);73return c;74}75}767778