Skip to content

Provides some methods that are possible in JNI, but not possible in Java.

License

Notifications You must be signed in to change notification settings

BlueberryMC/NativeUtil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NativeUtil

Provides some methods that are possible in JNI, but not possible in Java (without using Unsafe etc.)

Note

  • callTypeMethod and invokeType methods are 30x+ slower than reflection (68.447 ± 30.569 ns/op)
  • Method with java.lang.Void parameter type is not supported and will crash the JVM when trying to invoke them
  • You need to use BoxedValue class to pass the value of boxed primitive type to method, for example:
    Method method2 = YouCannotCreateInstanceOfThisClass.class.getDeclaredMethod("calculate", Integer.class, Integer.class);
    long method2id = NativeUtil.getMethodId(method2);
    int i2 = NativeUtil.callInt(method2id, null, new BoxedValue(100000), new BoxedValue(15115));
    assert i2 == 115115 : i2;

Repository

Maven

<repositories>
    ...
    <repository>
        <id>blueberrymc-repo</id>
        <url>https://repo.blueberrymc.net/repository/maven-public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>net.blueberrymc</groupId>
        <artifactId>native-util</artifactId>
        <version>[version]</version>
    </dependency>
</dependencies>

Gradle

repositories {
    maven {
        url "https://repo.blueberrymc.net/repository/maven-public/"
    }
}

dependencies {
    implementation 'net.blueberrymc:native-util:[version]'
}

Gradle (Kotlin)

repositories {
    maven { url = uri("https://repo.blueberrymc.net/repository/maven-public/") }
}

dependencies {
    implementation("net.blueberrymc:native-util:[version]")
}

About

Provides some methods that are possible in JNI, but not possible in Java.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published