[MAT-403] port in files that manage memory and jni interface