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.