Recently I am reading the JDK 19(the JDK 8,11,12 the reflection code seems did not change, so any version is ok) source code about reflection. The key to get class like this in reflection.cpp
C++ class Reflection::invoke_method
method:
oop mirror = java_lang_reflect_Method::clazz(method_mirror);
get the class instance like this:
InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(mirror));
I found the native code invoke the java class by using JNI to get the class. why using native code to implement the reflection? what is the advantage of native code to implement reflection? I am googled and found no one talk about this.
PS: I have also read the reflection could implement by Java with bytecode.