I am trying to use Google's OR-Tools from a Java application on macOS. Therefore, I have copied the lib folder from the official binary to my working directory. Trying to execute the following program fails with an Illegal instruction: 4 error message and an exit code of 132, however:
import com.google.ortools.linearsolver.MPSolver;
import com.google.ortools.linearsolver.MPVariable;
public class MWE {
static {
System.loadLibrary("jniortools");
}
public static void main(String[] args) {
MPSolver solver = new MPSolver("Solver",
MPSolver.OptimizationProblemType.CBC_MIXED_INTEGER_PROGRAMMING);
MPVariable x = solver.makeBoolVar("x");
System.out.println("Calling solver.solve()...");
final MPSolver.ResultStatus resultStatus = solver.solve();
System.out.println("Done!");
}
}
The output that I get from this is the following:
$ javac -cp lib/com.google.ortools.jar:lib/protobuf.jar:. MWE.java
$ java -Djava.library.path=lib -cp lib/com.google.ortools.jar:lib/protobuf.jar:. MWE
Calling solver.solve()...
Illegal instruction: 4
Adding -Xss2048k to the java call solves the problem:
$ java -Xss2048k -Djava.library.path=lib -cp lib/com.google.ortools.jar:lib/protobuf.jar:. MWE
Calling solver.solve()...
Done!
If the library needs an increased stack size, this seems understandable to me. However, it is very inconvenient that the application just crashed and does not give me the opportunity to react to this issue (by throwing an Exception, for instance).
- Is this the intended behavior of JNI library calls if they run into issues or a bug?
- In any case: Is there a workaround or a fix that would allow me to react to this issue?
For the sake of completeness, these are the versions of the involved pieces of software:
- macOS 10.13.6
- OpenJDK 1.8.0_242
- OR-Tools 7.5.7466
- Xcode 10.1