Can java disassembled code run without OS?

85 views Asked by At

I disassembled a java class file to Assembly using javap. Then Can I run the assembly code generated by the javap command without Os? Or is there something like il2cpu.net for java?

2

There are 2 answers

8
Stephen C On BEST ANSWER

No you can't.

  1. The javap command outputs disassembled bytecodes, not machine instructions.

  2. You can't run disassembled code. Disassembled code is just text .. that needs to be assembled to ... something ... before it can be executed ... by something.

  3. Bytecodes cannot be executed by regular hardware1. On regular hardware (e.g. Intel, M1, SPARC, etc) they need to be interpreted / JIT compiled by a regular JVM, or compiled to native code using an AOT compiler.

  4. All mainstream JVMs run on top of an operating system. Even outliers like JNode (which did boot and run on bare x86 hardware) have much of the functionality of an operating system embedded in them.

  5. If you compiled the bytecodes to native code executable, you would still need an operating system to run the executable on. Just like you would any other native code executable.


1 - It is possible in theory to implement hardware that executes bytecodes as its native instruction set, but no such hardware is commercially available. There was a Sun project to build a native Java platform, but it was canned a long time ago. There are others too, but nothing has gained traction. See https://en.wikipedia.org/wiki/Java_processor for some leads.

4
Rob Audenaerde On

No :)

  • javap does not generate code. It can print bytecode and the fields+methods, but it is not a decompiler.
  • You can run bytecode in a JVM *) (which runs on a OS), but for that you don't need javap
  • You also tranform a class/jar to native-image and run without JVM, but you will still need an OS. See here

*) strictly speaking, there is also hardware capable of running bytecode directly: https://en.wikipedia.org/wiki/Java_processor