Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible that write a program with Java bytecode instructions directly?

Tags:

java

In .NET platform it is possible to write a program with Common Intermediate Language directly and compile the sources with IL Assembler (ILASM).

For example below code is "Hello World" program.

.assembly Hello {}
.assembly extern mscorlib {}
.method static void Main()
{
    .entrypoint
    .maxstack 1
    ldstr "Hello, world!"
    call void [mscorlib]System.Console::WriteLine(string)
    ret
}

Is it possible that write a program with Java bytecode instructions directly like .NET?

like image 412
Amir Saniyan Avatar asked Dec 30 '12 16:12

Amir Saniyan


People also ask

Can bytecode be directly executed?

A bytecode program may be executed by parsing and directly executing the instructions, one at a time. This kind of bytecode interpreter is very portable. Some systems, called dynamic translators, or just-in-time (JIT) compilers, translate bytecode into machine code as necessary at runtime.

Is Java bytecode directly executable?

This bytecode file can be used on any platform (that has installed Java). However, bytecode is not an executable file. To execute a bytecode file, you actually need to invoke a Java interpreter (called java).

What are bytecode instructions explain their use in Java?

Java bytecode is the instruction set for the Java Virtual Machine. It acts similar to an assembler which is an alias representation of a C++ code. As soon as a java program is compiled, java bytecode is generated. In more apt terms, java bytecode is the machine code in the form of a .

How is Java bytecode executed?

They can be executed by intepretation, just-in-time compiling, or any other technique that was chosen by the designer of a particular JVM. A method's bytecode stream is a sequence of instructions for the Java virtual machine. Each instruction consists of a one-byte opcode followed by zero or more operands.


1 Answers

You can check out Jasmin. From Wikipedia,

Some projects provide Java assemblers to enable writing Java bytecode by hand. Assembly code may be also generated by machine, for example by compiler targeting Java virtual machine. Notable Java assemblers include:

Jasmin, takes textual descriptions for Java classes, written in a simple assembly-like syntax using Java Virtual Machine instruction set and generates a Java class file.

Jamaica, a macro assembly language for the Java virtual machine. Java syntax is used for class or interface definition. Method bodies are specified using bytecode instructions.

Note: I've not used any of these tools personally.

like image 74
Swapnil Avatar answered Nov 09 '22 18:11

Swapnil