polyglot-compiler / JLang

JLang: Ahead-of-time compilation of Java programs to LLVM
http://polyglot-compiler.github.io/JLang/
Other
287 stars 30 forks source link

Throw Exceptions in JNI/JVM API #24

Open dz333 opened 6 years ago

dz333 commented 6 years ago

Many of the JNI APIs can throw exceptions; however we have not implemented this behavior in most cases yet.

There is an example for how to do this in: jvm.cpp: JVM_FindClassFromCaller & exception.cpp

This relies on JLang-compiled code for creating and throwing Java Exceptions. The downside of this is that a separate function needs to be compiled for each type of exception that the runtime might throw. This is actually probably reasonable since the runtime only throws a handful of exception types (probably fewer than a dozen).

However, we could use our runtime class loading and object creation (see class.cpp: LoadJavaClassFromLib and factory.cpp:CreateJavaObject) to create the exceptions and merely use a JLang-compiled method to throw them. This does require knowing how to call appropriate constructors however, which is a bit of runtime reflection that, as of yet, is unimplemented.