more wip work on hooked functions and jnienv

This stuff is needed for upcoming module.
Sending now to avoid huge pull req later.