Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Who firstly creates Class<?> object during class-loading process?

In the documentation I found:

Class objects are constructed automatically by the Java Virtual Machine as classes are loaded and by calls to the defineClass method in the class loader.

I checked the source code, but didn't find the place defineClass to be called e.g. from loadClass method. Could you show me, please, who and when call defineClass method according to this scheme:

scheme

Picture source

like image 376
Rudziankoŭ Avatar asked Dec 03 '15 16:12

Rudziankoŭ


1 Answers

The defineClass() method is called during the invocation of ClassLoader#loadClass(). However, this is not directly done within the java.lang.ClassLoader class but in one of its subclasses, e.g. in URLClassLoader#findClass().

The call to ClassLoader#defineClass() ends up in a call to one of the native methods defineClass1() or defineClass2(). The C implementations of these methods can be found in OpenJDK in src/share/native/java/lang/ClassLoader.c.

like image 71
Stefan Ferstl Avatar answered Oct 12 '22 17:10

Stefan Ferstl