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?
-
What do you mean, exactly, by "without OS"? – Seva Alekseyev Apr 06 '22 at 14:28
-
Like running the generated code directly in a processor – Arsh Coder Apr 06 '22 at 14:28
-
Can the generated code run directly on a processor? – Arsh Coder Apr 06 '22 at 14:33
-
1I guess by "without OS" the OP really means "without a virtual machine". Well, the answer is **no**. – Seva Alekseyev Apr 06 '22 at 14:39
-
1You're confused, @JFan - bytecode and machinecode are not the same thing at all. java isn't compiled to 'assembly', it's compiled to bytecode which no chip can run. a JVM can run this (there used to be a chip something like 20 years ago, but it wasn't as simple as 'it will just run bytecode', and isn't around anymore). – rzwitserloot Apr 06 '22 at 14:43
-
So is there something like [il2cpu.net](https://www.il2cpu.net/) for java – Arsh Coder Apr 10 '22 at 06:46
2 Answers
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 needjavap
- 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

- 19,195
- 10
- 76
- 121
-
2*but it is not a decompiler.* - Also doesn't produce native *machine code* or a CPU assembly language representation of it (like x86 `add eax, [rdi]`). From a `.class` file, you need a (JIT or AoT) compiler to get machine code. CPUs don't run source-code or Java bytecode, they run machine instructions (format depends on the ISA, that's why we have JVMs). Ah, I see StephenC's answer already covers this. – Peter Cordes Apr 06 '22 at 22:32
-
Technically, decompling is the process of reversing a compile step. Compiling does not necessarily have to compile to machine-code, but can also produce intermediate-level-byte-code (java byte-code, but also for example LLVM IR) that needs further processing to be able to be run on a CPU. – Rob Audenaerde Apr 08 '22 at 15:16
-
Well sure, but if it was a decompiler, you'd have Java source code, back to square 1, since you can't run that a bare CPU either (especially not directly; it needs to be in some kind of binary format for it to even be plausible). – Peter Cordes Apr 08 '22 at 15:21
-
So is there something like [il2cpu.net](https://www.il2cpu.net/) for java – Arsh Coder Apr 10 '22 at 06:46
No you can't.
The
javap
command outputs disassembled bytecodes, not machine instructions.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.
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.
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.
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.

- 698,415
- 94
- 811
- 1,216
-
-
The Java virtual machine, in all likelihood, compiles your Java to native code that runs directly on the CPU (e. g. is not interpreted). This is call JIT (just-in-time) compilation, most JVMs support that. – Seva Alekseyev Apr 06 '22 at 14:42
-
@JFan - No. There is no practical way to do that. (Apart from JNode ... which is a dead project now, and never really worked well enough to be viable. You *really* need an OS underneath to deal with stuff like memory management, etc. JNode on a micro-kernel OS might have been viable, but they had other ideas.) – Stephen C Apr 06 '22 at 14:43
-
@Stephen C: read up re:Jazelle. ARM is in the middle of phasing it out, though. – Seva Alekseyev Apr 06 '22 at 14:44
-
I hadn't heard of that one before. But in a sense it does prove my point. It requires special hardware. And even then, the Java on Jazelle runtime will rely on the platform OS for all of the things that an OS normally does. – Stephen C Apr 06 '22 at 14:55
-
Re: Java Processor: there were also some ARM extensions like Jazelle (https://en.wikipedia.org/wiki/Jazelle), but I think that still needed a software JVM. (Direct Bytecode eXecution does have to trap back to the JVM for complicated things; not sure what the cutoff is, but probably memory allocation.) But that's kind of a footnote to a footnote, not something that could fully run a bytecode program without other software. – Peter Cordes Apr 06 '22 at 22:41
-
So is there something like [il2cpu.net](https://www.il2cpu.net/) for java – Arsh Coder Apr 10 '22 at 06:45
-
Well yea: [Graalvm](https://stackoverflow.com/questions/51489954/). But that is a completely different question to what you asked in the first place. – Stephen C Apr 10 '22 at 06:49