Skip to content

Avoid excessive memory copies for read only JNI memory #637

@jasonkatonica

Description

@jasonkatonica

A common pattern through JNI code that is present in this project is to perform the following two APIs within a JNI method:

value = (*env)->GetPrimitiveArrayCritical(env, methodvariable, &isCopy);
...
if (value != NULL) {
    (*env)->ReleasePrimitiveArrayCritical(env, methodvariable, value, 0);
}

In these cases where the value being referenced is only used as input during processing we should instead be using JNI_ABORT instead of the value 0 in the call to ReleasePrimitiveArrayCritical.

The value 0 indicates that a copy of the value is to be made back to the java object. In many cases what we intend here, for read only values, is the JNI method to use the value JNI_ABORT. This may improve performance since excessive copies could be avoided in these cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions