1

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.

Yaksa
  • 176
  • 1
  • 12

2 Answers2

0

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.

Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
  • Sorry for my ignorance, but how can I compile the java program to x86 native machine code? I kinda had this idea before this topic, but I wasn't able to find any ways to do it. I've read that gcj could do this, but since it's obsolete I can't install it. Do you know CodeBlocks? Whenever I compile my C programs into it, it generates a binary that just works. Is there another tool like this to java programs? – Yaksa Oct 16 '19 at 14:27
0

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.

Analogous for Python: Is it possible to run Python code in Gem5 syscall emulation mode?

Ciro Santilli
  • 3,693
  • 1
  • 18
  • 44
  • I'm not familiarized with QEMU, but in my case I need to simulate programs using only gem5 and nothing else. Also, how can I get an ELF executable to java programs? In my C programs it was just automatically generated by CodeBlocks. – Yaksa Oct 16 '19 at 14:32
  • @Thiago QEMU is just to modify a full system disk image easily. Please Google how to compile and run C and Java programs from the command line. Learning how to do everything on the CLI is fundamental in addition to IDE method :-) – Ciro Santilli Oct 16 '19 at 14:37
  • Hi Ciro. I've edited the post with something I tried today. Can you give it a look please? Do you know what it can be? – Yaksa Oct 30 '19 at 16:19
  • @Thiago hi there. You have to determine if the error message comes from gem5 or in your program, and dig in a bit more, e.g. at least a stack trace. That said, the performance characteristics are likely going to be very different using GraalVM than the actual system's Java implementation. Does it work on your host? – Ciro Santilli Oct 30 '19 at 16:29
  • I've tested the java's executable after converting it using native-image. It works fine. The error shown comes from the output of the ongoing simulation in m5out directory of gem5, the file system.pc.com_1.device. I have no idea of what it is and I don't know how to dig in into something like this. – Yaksa Oct 30 '19 at 18:25