Skip to content

Latest commit

 

History

History
57 lines (45 loc) · 1.53 KB

README.md

File metadata and controls

57 lines (45 loc) · 1.53 KB

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]")
}