3

Can i write bytecode inside a method of a class so that the compiler bypasses that part since it is already compiled. Something similar to writing assembly programs in C language using "asm"...

2
  • You should also look for bytecode manipulation libraries like ASM and javassist Commented Apr 3, 2015 at 16:52
  • Just curious, why would you want to do this? Your Java bytecode isn't ran on the target processor directly, it will either be interpreted or recompiled into native machine code. Commented Jul 13, 2015 at 2:27

1 Answer 1

4

I think you mean Java. If that's the case:

Short answer: no.

Long answer: There is nothing like asm { ... } in Java. But you could (not very clever in most situations) write a .class file (or have bytecode in textual representation and then assemble it in Java to a .class file) from Java and dynamically load and execute it.

Sign up to request clarification or add additional context in comments.

2 Comments

You said... "(or have bytecode in textual representation and then assemble it in Java to a .class file)"...can you give more inputs on this...
Sure, you store the textual bytecode representation (as javap -c SomeJavaClass outputs it) as a String in your Java source. While your program is running, you can assemble that code(e.g. with Jasmin (jasmin.sourceforge.net)) which gives you a .class file. That class can be loaded dynamically with the class loader. Finally, you can execute anything from that class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.