[GR-45625] polyglot+LLVM "hello world" throws UnsupportedOperationException
Describe GraalVM and your environment :
- GraalVM version: 22.3.1
- CE
- JDK version: [e.g.: JDK8]
- OS and OS Version: Windows 10
- Architecture: Intel 64
- The output of
java -Xinternalversion:
OpenJDK 64-Bit Server VM (19.0.2+7-jvmci-22.3-b12) for windows-amd64 JRE (19.0.2+7-jvmci-22.3-b12), built on 2022-12-28T13:55:33Z by "" with MS VC++ 17.1 (VS2022)
Have you verified this issue still happens when using the latest snapshot? Yes (GraalVM CE 23.0.0-dev-20230331_1201)
Describe the issue
In Java, I'm trying to embed LLVM bitcode generated from simplest C++ code. The eval() function throws exception as below.
Steps to reproduce the issue
hello1.cpp
int main() {
return 0;
}
HelloPolyglot.java
import org.graalvm.polyglot.*;
import org.graalvm.polyglot.proxy.*;
import org.graalvm.polyglot.io.ByteSequence;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.File;
import java.io.IOException;
public class HelloPolyglot {
public static void main(String[] args) throws IOException {
String bcFilePath = "hello1.bc";
File file = new File(".", bcFilePath);
String language = Source.findLanguage(file);
System.out.println("Language detected:\t" + language);
byte[] llvmBitcode = Files.readAllBytes(Paths.get(bcFilePath));
System.out.println("LLVM bytecode length:\t" + llvmBitcode.length);
Source source = Source.newBuilder("llvm",
ByteSequence.create(llvmBitcode),
"<literal>").buildLiteral();
Context context = Context.newBuilder().allowAllAccess(true).build(); // allowNativeAccess
context.eval(source);
context.close();
}
}
The command I use to generate LLVM from C++ (results in creation of hello1.bc file):
/c/PROGRAMY/graalvm-ce-java19-22.3.1/lib/llvm/bin/clang++ -c -emit-llvm hello1.cpp
Then I compile and run the Java code: javac HelloPolyglot.java java HelloPolyglot
The Java output:
LLVM bytecode length: 2264
Exception in thread "main" org.graalvm.polyglot.PolyglotException: java.lang.UnsupportedOperationException: null not supported as key!
at org.graalvm.sdk/org.graalvm.collections.EconomicMapImpl.checkKeyNonNull(EconomicMapImpl.java:640)
at org.graalvm.sdk/org.graalvm.collections.EconomicMapImpl.get(EconomicMapImpl.java:242)
at com.oracle.truffle.llvm.runtime.LLVMLanguage.getCachedLibrary(LLVMLanguage.java:762)
at com.oracle.truffle.llvm.runtime.LLVMLanguage.parse(LLVMLanguage.java:726)
at org.graalvm.truffle/com.oracle.truffle.api.TruffleLanguage$ParsingRequest.parse(TruffleLanguage.java:1000)
at org.graalvm.truffle/com.oracle.truffle.api.TruffleLanguage.parse(TruffleLanguage.java:1357)
at org.graalvm.truffle/com.oracle.truffle.api.LanguageAccessor$LanguageImpl.parse(LanguageAccessor.java:298)
at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotSourceCache.parseImpl(PolyglotSourceCache.java:94)
at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotSourceCache$WeakCache.lookup(PolyglotSourceCache.java:222)
at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotSourceCache.parseCached(PolyglotSourceCache.java:80)
at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotLanguageContext.parseCached(PolyglotLanguageContext.java:372)
at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextImpl.eval(PolyglotContextImpl.java:1480)
at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextDispatch.eval(PolyglotContextDispatch.java:63)
at org.graalvm.sdk/org.graalvm.polyglot.Context.eval(Context.java:402)
at HelloPolyglot.main(HelloPolyglot.java:32)
Suppressed: Attached Guest Language Frames (0)
Internal GraalVM error, please report at https://github.com/oracle/graal/issues/.
Expected behavior I expected the C++ code to be executed within Java application, without throwing the exception.
Hi, Thank you for reporting this, we'll take a look into it shortly
Tracked internally on GR 45625
No news on this after 16 months? The polyglot+LLVM setup seems not working at all, while it is still described as possible on the www...
While it's not our highest priority at the moment for new feature development, the LLVM runtime should work fine and it is used internally, e.g. by the Ruby implementation.
Note that using -emit-llvm and .bc files was never really supported. That's what we used in the very early versions of the LLVM runtime. You should be using our toolchain wrappers to compile to executables or libraries with embedded bitcode. See https://www.graalvm.org/latest/reference-manual/llvm/#llvm-toolchain
This was introduced in 19.2.0 and declared stable in 19.3.0, almost 5 years ago.