{'fraction_non_alphanumeric': 0.02891566265060241, 'fraction_numerical': 0.00034423407917383823, 'mean_word_length': 5.415011037527594, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
JNI-C++ integration made easy

The Java Native Interface (JNI) [1] provides interoperation between Java code running on a Java Virtual Machine and code written in other programming languages (e.g., C++ or assembly). The JNI is useful when existing libraries need to be integrated into Java code, or when portions of the code are implemented in other languages for improved performance. The Java Native Interface is extremely flexible, allowing Java methods to invoke native methods and vice versa, as well as allowing native functions to manipulate Java objects. However, this flexibility comes at the expense of extra effort for the native language programmer, who has to explicitly specify how to connect to various Java objects (and later to disconnect from them, to avoid resource leak). We suggest a template-based framework that relieves the C++ programmer from most of this burden. In particular, the proposed technique provides automatic selection of the right functions to access Java objects based on their types, automatic release of previously acquired resources when they are no longer necessary, and overall simpler interface through grouping of auxiliary functions. Introduction The Java Native Interface is a powerful framework for seamless integration between Java and other programming languages (called “native languages” in the JNI terminology). A common case of using the JNI is when a system architect wants to benefit from both worlds, implementing communication protocols in Java and computationally expensive algorithmic parts in C++ (the latter are usually compiled into a dynamic library, which is then invoked from the Java code). The JNI renders native applications with much of the functionality of Java, allowing them to call Java methods, access and modify Java variables, manipulate Java exceptions, ensure thread-safety through Java thread synchronization mechanisms, and ultimately to directly invoke the Java Virtual Machine. This functional wealth is provided through a rather complex interface between the native code and the Java programming environment. For example, accessing an integer Java member variable from the native code is a multi-step process, which involves first querying the class type whose variable is to be retrieved (using the JNI function GetObjectClass), obtaining the field identifier (using GetFieldID), and finally retrieving the field per se (using GetIntField). The latter function is a representative of a set of functions (Get Field), each corresponding to a different variable type; thus, accessing a variable requires explicit specification of the appropriate function. To streamline these steps, we suggest using a template (parameterized with a variable type), which encapsulates all these low-level operations, giving the programmer easy-to-use assignment/modification functionality similar to that of native C++ variables. As far as