Running Java programs in gem5(or any language which is not C)

陌路散爱 提交于 2020-03-04 06:06:28

问题


This may be a silly question, but i'm learning about gem5 recently and i'm being able to simulate my C programs using this software, in syscall emulation and in full system simulation. However, whenever I try to simulate any Java program into it, I get this error(syscall emulation):

gem5 Simulator System.  http://gem5.org
gem5 is copyrighted software; use the --copyright option for details.

gem5 compiled Aug 26 2019 12:58:15
gem5 started Sep  5 2019 14:56:02
gem5 executing on (...), pid 6115
command line: build/X86/gem5.opt configs/learning_gem5/part1/test.py

Global frequency set at 1000000000000 ticks per second
warn: DRAM device capacity (8192 Mbytes) does not match the address range assigned (512 Mbytes)
fatal: fatal condition !obj_file occurred: Cannot load object file /home/taoliveira/Downloads/Gem5/gem5/configs/learning_gem5/part1/../../../my-progs/MergeSort/bin/x86/linux/MergeSort.
Memory Usage: 661468 KBytes

In this case, I tried a simple mergesort Java program. It is compiling and executing normally outside the gem5 simulator. In the .py file where I have my machine(it's the simple.py of gem5 tutorials), the binary is a path which leads to the .jar file. I've heard that .jar would not work properly in gem5 but I don't know what to use instead. So, what I have to do to run non-C programs in gem5 simulator? In this case, what I have to do to run a java program?

I looked everywhere for an answer but wasn't able to find it. Can anyone help me, please? Thanks in advance.

I'm using Ubuntu 18.04 and Java 1.8.0_201.

Edit : I've tried to convert my Java code to native machine code(x86) and did it with GraalVM, and i'm passing it to the runscript, in the same way I did with C programs. However, it shows me a new error when loading the script:

loading script...
Fatal error: Failed to create a new Isolate. (code 6)

Never seen it before and didn't find anything about it when googling.


回答1:


You execute Java programs exactly the same way you execute C programs:

  • Gem5 doesn't understand C, so if you want to execute a C program, you first need to compile it to a language Gem5 understands, or you need to interpret it in an interpreter that is written in a language Gem5 understands.
  • Gem5 doesn't understand Java, so if you want to execute a Java program, you first need to compile it to a language Gem5 understands, or you need to interpret it in an interpreter that is written in a language Gem5 understands.

Here are a couple of possibilities I can think of:

  • use a native code compiler to compile Java to Alpha, ARM, Sparc, or x86 native machine code,
  • use a Java interpreter written in (or compiled to) Alpha, ARM, Sparc, or x86 native machine code to interpret that Java code,
  • use a JVM compiler to compile Java to JVM bytecode, then use a JVM written in (or compiled to) Alpha, ARM, Sparc, or x86 native machine code to interpret that JVM bytecode, or
  • use a JVM compiler to compile Java to JVM bytecode, then use a native code compiler to compile the JVM bytecode to Alpha, ARM, Sparc, or x86 native machine code.

It is, of course, possible to chain and/or mix any number of the above.




回答2:


Similar post: Is it possible to run java -jar on gem5 simulator with ISA x86?

A full system Ubuntu image will almost certainly work (pre-install Java with QEMU user mode before running gem5).

X86 syscall emulation could in theory just work, the command line would be something like:

build/X86/gem5.opt \
  configs/example/se.py \
  --cmd /usr/bin/java \
  --options HelloWorld \
  --param 'system.cpu[0].workload[:].release = "5.2.1"' \

where /usr/bin/java is the Java interpreter ELF executable just like your C program, and HelloWorld.class is the compiled Java class passed as an argument to java.

However, I tried this on Ubuntu 18.04 and gem5 61005bb9ef455b2ac851f8a992f2cec5686e520f and it failed with:

/usr/bin/java: error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory

I'm not sure why that was the case, it would require further investigation.

SE ARM userland does not currently support dynamic loaded executables, so you would need to compile JVM statically, which might be a pain / impossible.



来源:https://stackoverflow.com/questions/58399259/running-java-programs-in-gem5or-any-language-which-is-not-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!