Search code examples
javaassemblyjavap

Can java disassembled code run without OS?


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?


Solution

  • 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. Also https://en.wikipedia.org/wiki/Jazelle but that apparently requires a "software JVM" to handle complicated things, and ... it has been "de-emphasized" in ARMv7.