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

Improve/Fix direct mapping support #919

Merged

Conversation

matthiasblaesing
Copy link
Member

This changeset intends to to improve the stability of the direct mapping support.
For the implementation itself only the first two commits are relevant, as they cover
the changes, the other changes are follow-up work (rebuilding binaries) and
cleanups.

To summarize, there are two main issues:

  • the direct mapping causes errors in the code flow if primitive wrappers are used as parameters. From my analyses the problem is, that the JVM passes the values directly to the native code. That means the native side can get primitives and wrapper classes. For the interface bound code paths via the normal dispatch, all parameters are passed as objects and unwrapped as necessary, this is not possible in the direct path. Instead of trying to add the unwrapping information, I removed the wrapper mappings from the defaults and added a sample to the unittests where TypeMapped types are used to emulated Wrapper classes.
    Given that direct mapping is used to gain performance I think this is acceptable. (first commit)

  • if a NULL value is passed to a mapping that expects an IntegerType, this leads to JVM crash - this is fixed by replacing the value with a primitive 0 (second commit)

@twall could you have a look please?

}
}
}
final Map<Class,PrimitiveConverter> convertes = new HashMap<Class,PrimitiveConverter>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in convertes => converters

Copy link
Contributor

@twall twall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

For direct mapped methods the java value is directly passed to the C
side. For wrappers this means, that the object pointer is passed and
not the primitive values.

This changeset removes the mappings for the Wrapper classes and makes
it possible to use a type converter to make the call possible, at the
cost of higher calling costs.

Closes: java-native-access#918
…M crash

When a IntergetType based type is defined in a direct mapping and a
NullPointer is passed to that call, a method call is tried on that
NullPointer via JNI, resulting in a JVM crash.

This changeset replaces the value with "0" if a NULL pointer is passed
and adds unittests for the possible calling conventions.

Closes: java-native-access#905
@matthiasblaesing matthiasblaesing merged commit 2856d95 into java-native-access:master Feb 5, 2018
@matthiasblaesing matthiasblaesing deleted the directmapping branch March 19, 2018 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants