Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
masesdevelopers opened this issue Feb 27, 2024 · 3 comments · Fixed by #375
Closed

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

masesdevelopers opened this issue Feb 27, 2024 · 3 comments · Fixed by #375
Assignees
Labels
enhancement New feature or request JNetReflector JNetReflector related issue

Comments

@masesdevelopers
Copy link
Contributor

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

@masesdevelopers masesdevelopers added enhancement New feature or request JNetReflector JNetReflector related issue labels Feb 27, 2024
@masesdevelopers masesdevelopers self-assigned this Feb 27, 2024
@masesdevelopers
Copy link
Contributor Author

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.

@masesdevelopers
Copy link
Contributor Author

masesdevelopers commented Feb 27, 2024

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.

@masesdevelopers
Copy link
Contributor Author

masesdevelopers commented Feb 28, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request JNetReflector JNetReflector related issue
Projects
None yet
1 participant