masesgroup/JNet

Identify the method signature and use it to invoke the JVM counter-part

masesdevelopers opened this issue · 3 comments

Is your feature request related to a problem? Please describe.
Current behavior is based on parameters deduction from .NET side. JNetReflector identify the parameters types and the behavior is constrained, however, under the hood, the exact match cannot happens if one parameter is null because JCOBridge is not able to infer the right JVM type the first time the method is searched.

Describe the solution you'd like
On each Method identified from JNetReflector, it shall extract, or build, the signature and use it to invoke the right method.

Describe alternatives you've considered
N/A

Additional context
N/A

The accessibility flag shall be changed in JVM because from JNI it is possible only from JDK 19 due to https://bugs.openjdk.org/browse/JDK-8280831. A convenient way it to update JNetReflectorHelper class to return signature directly from JVM.

The signature field cannot be used since it is filled only when generic information are available. So #374 (comment) is usefulness.

JDK comes with a tool, named javap, able to extract signature from a class name in its parameter:

javap -public -s java.lang.Object

reports in output:

Compiled from "Object.java"
public class java.lang.Object {
  public java.lang.Object();
    descriptor: ()V

  public final native java.lang.Class<?> getClass();
    descriptor: ()Ljava/lang/Class;

  public native int hashCode();
    descriptor: ()I

  public boolean equals(java.lang.Object);
    descriptor: (Ljava/lang/Object;)Z

  public java.lang.String toString();
    descriptor: ()Ljava/lang/String;

  public final native void notify();
    descriptor: ()V

  public final native void notifyAll();
    descriptor: ()V

  public final void wait() throws java.lang.InterruptedException;
    descriptor: ()V

  public final native void wait(long) throws java.lang.InterruptedException;
    descriptor: (J)V

  public final void wait(long, int) throws java.lang.InterruptedException;
    descriptor: (JI)V
}

what shall be done is to parse this output matching method with the string after descriptor:, the tool shall be executed on each class will be analyzed from JNetReflector.

Avoid to import, or use, the source classes javap is based on for two reasons:

  • the license terms
  • JNetReflector shall use the corresponding javap of the JDK running JNetReflector.

The signature field cannot be used since it is filled only when generic information are available. So #374 (comment) is usefulness.

JDK comes with a tool, named javap, able to extract signature from a class name in its parameter:

javap -public -s java.lang.Object

reports in output:

Compiled from "Object.java"
public class java.lang.Object {
  public java.lang.Object();
    descriptor: ()V

  public final native java.lang.Class<?> getClass();
    descriptor: ()Ljava/lang/Class;

  public native int hashCode();
    descriptor: ()I

  public boolean equals(java.lang.Object);
    descriptor: (Ljava/lang/Object;)Z

  public java.lang.String toString();
    descriptor: ()Ljava/lang/String;

  public final native void notify();
    descriptor: ()V

  public final native void notifyAll();
    descriptor: ()V

  public final void wait() throws java.lang.InterruptedException;
    descriptor: ()V

  public final native void wait(long) throws java.lang.InterruptedException;
    descriptor: (J)V

  public final void wait(long, int) throws java.lang.InterruptedException;
    descriptor: (JI)V
}

what shall be done is to parse this output matching method with the string after descriptor:, the tool shall be executed on each class will be analyzed from JNetReflector.

First test done, however the execution of JNetReflector slows done considerately: till now an external javap process is launched for each class under analysis. The parser shall be updated to reduce the number of executions considering that javap is able to parse multiple set on command-line, the limit can be imposed from the OS limit when a process is requested to be launched.

Important

Currently there is no way to use the signature because JCOBridge does not have any API supporting it.