Provide api for accessing bytecode from java.lang.reflect.Method.

Remi Forax forax at univ-mlv.fr
Sat Sep 1 11:48:10 UTC 2018


----- Mail original -----
> De: "Сергей Чаулин" <cossack5 at mail.ru>
> À: "jdk-dev" <jdk-dev at openjdk.java.net>
> Envoyé: Vendredi 31 Août 2018 19:16:53
> Objet: Provide api for accessing bytecode from java.lang.reflect.Method.

> Hi,

Hi !

> 
> In .NET we can retrieve bytecode array from reflected class, e.g.:
> 
> MethodInfo mi =  typeof (Example).GetMethod( "MethodBodyExample" );
> MethodBody mb = mi.GetMethodBody();
> var bytes= mb.GetILAsByteArray();
> 
> How about having something like this in java ? Leveraging this, it would be
> possible to get bytecode of currently loaded classes (including lambdas),
> killing the need to load class as a resource.

I may be wrong but the main difference is that in .Net the bytecode array of a method contains references (metadata tokens) to one global datastructure (metadata tables) for whole the program while in Java, the bytecode array contains references to one data structure per class so in Java returning a byte array without the class is useless because you do not know how to interpret it.  

> 
> 
> 
> 
> С уважением,
> Сергей Чаулин

regards,
Rémi


More information about the jdk-dev mailing list