Index: vm/vmcore/include/classloader.h =================================================================== --- vm/vmcore/include/classloader.h (revision 598974) +++ vm/vmcore/include/classloader.h (working copy) @@ -180,6 +180,7 @@ } } bool InsertClass(Class* clss); + void InsertInitiatedClass(Class* clss); Class* AllocateAndReportInstance(const Global_Env* env, Class* klass); Class* NewClass(const Global_Env* env, const String* name); Package* ProvidePackage(Global_Env* env, const String *class_name, const char *jar); Index: vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp =================================================================== --- vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp (revision 598974) +++ vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp (working copy) @@ -117,6 +117,14 @@ return clss ? jni_class_from_handle(jenv, clss) : NULL; } +JNIEXPORT void JNICALL +Java_java_lang_ClassLoader_registerInitiatedClass(JNIEnv* env, jobject loader, jclass clazz) { + ClassLoader* cl = class_loader_lookup(loader); + Class* clss = jclass_to_struct_Class(clazz); + cl->InsertInitiatedClass(clss); +} + + /* * Class: java_lang_VMClassRegistry * Method: getClass Index: vm/vmcore/src/kernel_classes/native/java_lang_ClassLoader.h =================================================================== --- vm/vmcore/src/kernel_classes/native/java_lang_ClassLoader.h (revision 598974) +++ vm/vmcore/src/kernel_classes/native/java_lang_ClassLoader.h (working copy) @@ -37,62 +37,14 @@ Java_java_lang_ClassLoader_findLoadedClass(JNIEnv *, jobject, jstring); -/* - * Method: java.lang.ClassLoader.defineClass0(Ljava/lang/String;[BII)Ljava/lang/Class; - * Throws: java.lang.ClassFormatError - */ -JNIEXPORT jclass JNICALL -Java_java_lang_ClassLoader_defineClass0(JNIEnv *, jobject, - jstring, jbyteArray, jint, jint); - - -#ifdef __cplusplus -} -#endif - -#endif /* _JAVA_LANG_CLASSLOADER_H */ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - - -/* Header for class java.lang.ClassLoader */ - -#ifndef _JAVA_LANG_CLASSLOADER_H -#define _JAVA_LANG_CLASSLOADER_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Native methods */ - -/* * Method: java.lang.ClassLoader.findLoadedClass(Ljava/lang/String;)Ljava/lang/Class; */ -JNIEXPORT jclass JNICALL -Java_java_lang_ClassLoader_findLoadedClass(JNIEnv *, jobject, - jstring); +JNIEXPORT void JNICALL +Java_java_lang_ClassLoader_registerInitiatedClass(JNIEnv *, jobject, jclass); -/* - * Method: java.lang.ClassLoader.defineClass(Ljava/lang/String;[BII)Ljava/lang/Class; +/* + * Method: java.lang.ClassLoader.defineClass0(Ljava/lang/String;[BII)Ljava/lang/Class; * Throws: java.lang.ClassFormatError */ JNIEXPORT jclass JNICALL @@ -105,4 +57,3 @@ #endif #endif /* _JAVA_LANG_CLASSLOADER_H */ - Index: vm/vmcore/src/kernel_classes/javasrc/java/lang/Class.java =================================================================== --- vm/vmcore/src/kernel_classes/javasrc/java/lang/Class.java (revision 598974) +++ vm/vmcore/src/kernel_classes/javasrc/java/lang/Class.java (working copy) @@ -146,6 +146,12 @@ clazz = classLoader.loadClass(name); } } + if(classLoader != null && classLoader.findLoadedClass(name) == null) { + // classloader overloads loadClass method though it is not + // generally recommended + // have to register initiating loader for clazz from here + classLoader.registerInitiatedClass(clazz); + } if(clazz == null) { throw new ClassNotFoundException(name); } Index: vm/vmcore/src/kernel_classes/javasrc/java/lang/ClassLoader.java =================================================================== --- vm/vmcore/src/kernel_classes/javasrc/java/lang/ClassLoader.java (revision 598974) +++ vm/vmcore/src/kernel_classes/javasrc/java/lang/ClassLoader.java (working copy) @@ -549,6 +549,12 @@ } /** + * Registers this class loader as initiating for a class + * Declared as package private to use it from java.lang.Class.forName + */ + native void registerInitiatedClass(Class clazz); + + /** * @com.intel.drl.spec_ref */ protected synchronized Class loadClass(String name, boolean resolve) @@ -568,6 +574,15 @@ } else { try { clazz = parentClassLoader.loadClass(name); + try { + VMStack.getCallerClass(0) + .asSubclass(ClassLoader.class); + } catch(ClassCastException ex) { + // caller class is not a subclass of java/lang/ClassLoader + // so, register as initiating loader as we are called from + // outside of ClassLoader delegation chain + registerInitiatedClass(clazz); + } } catch (ClassNotFoundException e) { } } Index: vm/vmcore/src/class_support/classloader.cpp =================================================================== --- vm/vmcore/src/class_support/classloader.cpp (revision 598974) +++ vm/vmcore/src/class_support/classloader.cpp (working copy) @@ -1737,6 +1737,13 @@ return true; } + +void ClassLoader::InsertInitiatedClass(Class* clss) +{ + LMAutoUnlock aulock(&m_lock); + m_initiatedClasses->Insert(clss->get_name(), clss); +} + void BootstrapClassLoader::ReportAndExit(const char* exnclass, std::stringstream& exnmsg) { std::stringstream ss;