After a couple of weeks, the Java SWI-Prolog interface will immediately work in JNI_CreateJavaVM. Well, on most machines. It works fine on one of my machines, which runs the same version of Ubuntu and openjdk ... I split this into this small program:
#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
static JavaVM *jvm;
int
main(int argc, char **argv)
{ JavaVMInitArgs vm_args = {0};
JNIEnv *env;
JavaVMOption opt[8] = {0};
int optn = 0;
int r;
opt[optn++].optionString = "-Djava.class.path=" "jpl.jar:.";
opt[optn++].optionString = "-Xrs";
vm_args.version = JNI_VERSION_1_2;
vm_args.nOptions = optn;
vm_args.options = opt;
r = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
fprintf(stderr, "Got %d\n", r);
exit(0);
}
This is compiled with
JVM=/usr/lib/jvm/java-8-oracle
gcc -I$JVM/include \
-I$JVM/include/linux \
-L$JVM/jre/lib/amd64/server \
-L$JVM/jre/lib/amd64 \
-g -Wall -o t t.c -ljsig -ljava -lverify -ljvm
Gdb does not give an unused stack trace, as it claims to have stack corruption somewhere in the JVM. I'm pretty lost, as it crashes when using Oracle and OpenJDK java, assuming this is my fault. On the other hand, this has worked for years, and this is what you will find in all the examples.
Ubuntu platform 16.04, amd64, gcc 5.4.0
valgrindtalks about it. Funny, he says the same thing on a machine where he works without a glitch.
==9642== Memcheck, a memory error detector
==9642== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==9642== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==9642== Command: ./t
==9642==
==9642== Warning: set address range perms: large range [0x5cb200000, 0x7c0000000) (noaccess)
==9642== Warning: set address range perms: large range [0x5cb200000, 0x5e0100000) (defined)
==9642== Warning: set address range perms: large range [0x7c0000000, 0x800000000) (noaccess)
==9642== Invalid write of size 4
==9642== at 0x84C0BE7: ???
==9642== by 0x84AE4E6: ???
==9642== by 0x549C11A: ??? (in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so)
==9642== by 0x545ABA6: ??? (in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so)
==9642== by 0x545AFA1: ??? (in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so)
==9642== by 0x545B3FF: ??? (in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so)
==9642== by 0x545B1B1: ??? (in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so)
==9642== by 0x545B3FF: ??? (in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so)
==9642== by 0x584A9BB: ??? (in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so)
==9642== by 0x54C31E1: JNI_CreateJavaVM (in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so)
==9642== by 0x4007C7: main (t.c:22)
==9642== Address 0xffeffea00 is on thread 1 stack
==9642== 4096 bytes below stack pointer