Reputation: 178
.j file converts to .class file and .java file converts to .class file. So
Why will I choose Jasmin over javac? Is there any performance cost? Or any other reason for preferring Jasmin.
Upvotes: 1
Views: 1101
Reputation: 44042
From the webpage of the Jasmin project:
Jasmin was originally created as a companion to the book "Java Virtual Machine"
Jasmin was not written with the intent to create production Java applications, Jasmin is mostly used for educational purposes. From a general perspective, you are right that you can express any Java application as Java source code which is then compiled to Java byte code. Furthermore, no JVM language such as Scala or Groovy is able to create different byte code. But they are sometimes able to express the same byte code in a different, more human-readable, manner.
Jasmin is build with the same idea. If you want to learn how the Java virtual machine works, you need to play around a little. Thus, it makes sense to express a Java class in a more raw manner such that you can understand the concepts of how a compiled Java class is structured. However, the Jasmin format is still more high-level than the byte code format. For instance, you do not need to manage the constant pool. You can write:
ldc "Hello World"
instead of loading the value from an index after adding the Hello World
string to the class's constant pool. The latter is rather boring book-keeping and Jasmin will manage this for you. Thus, use Jasmin for learning. Not for writing actual code. You will not be able to gain performance with using Jasmin. Byte code is an interim format and a Java application's speed is gained by a JVM's just in time compiler which will interpret the byte code and speed it up. By writing your own Jasmin instructions, you might even loose performance because the just in time compiler will not recognize your patterns. But again, Jasmin is not meant for this. Jasmin is for learning.
Upvotes: 0
Reputation: 25777
Jasmin's format is more low-level. For example, when you compile a .java file, you can't get some sequences of byte codes that you can get with a .j file.
So, by generating a .j file you have more freedom
Upvotes: 2