• Stars
    star
    158
  • Rank 237,131 (Top 5 %)
  • Language
    Java
  • License
    Other
  • Created over 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Jasmin is an assembler for the Java Virtual Machine ⛺

Introduction

This document tries to answer some questions you might have about Jasmin. In particular, several people have asked me what Jasmin is, why they might use Jasmin, and why I wrote it in the first place. I've tried to give some answers to these questions below.

What is Jasmin?

Jasmin is a Java Assembler Interface. It takes ASCII descriptions for Java classes, written in a simple assembler-like syntax using the Java Virtual Machine instructions set. It converts them into binary Java class files suitable for loading into a Java interpreter.

To give you a flavor, here is the Jasmin assembly code for HelloWorld:

.class public HelloWorld
.super java/lang/Object

;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
    aload_0
    invokenonvirtual java/lang/Object/<init>()V
    return
.end method

;
; main() - prints out Hello World
;
.method public static main([Ljava/lang/String;)V
    .limit stack 2   ; up to two items can be pushed

    ; push System.out onto the stack
    getstatic java/lang/System/out Ljava/io/PrintStream;

    ; push a string onto the stack
    ldc "Hello World!"

    ; call the PrintStream.println() method.
    invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V

    ; done
    return
.end method

Jasmin was originally created as a companion to the book "Java Virtual Machine", written by Jon Meyer and Troy Downing and published by O'Reilly Associates. The book is now out of print. Jasmin survives as a SourceForge Open Source project.

Motivation for Jasmin

Jasmin was written because, at the time that we wrote the Java Virtual Machine book for O'Reilly, Sun had not published an assembler format for the Java virtual machine.

Generating a binary Java .class file is pretty fiddly. Its like creating an a.out (or .exe) file by hand. Even using a Java package like JAS (a Java API for creating class files, used internally by Jasmin and written by KB Sriram), you need to know a lot about the philosophy of the Java Virtual Machine before you can write something at the Virtual Machine level and generate a Java class.

We wanted something that made it very easy for a student or programmer to explore the Java Virtual Machine, or write a new language which targets the VM, without getting into the details of constant pool indices, attribute tables, and so on.

Creating a Java assembler seemed like a good solution.

Unfortunately, Sun has not seen the need to define a standard Java assembler format, and has not released tools perform Java assembly.

Sun does provide a javap program which can print the assembly code in a class file. However, the javap output is inappropriate for use as an assembler format. It is designed to be read by a person, not to be parsed by an assembler, so it has a number of omissions and drawbacks.

Internally, Sun has a Java assembler tool. In hindsight, the syntax used by their internal tool is nicer than the Jasmin syntax. However, to my knowledge, their tool is still not widely available, nor is it a formally supported part of the Sun JDK.

Update on Jasmin Today (2004)

Since Jasmin was written, it has become the de-facto standard assembly format for Java. It is used in dozens of compiler classes throughout the world, and has been ported and cloned multiple times. For better or worse, Jasmin remains the original Java assembler.

[As an interesting comparison, Microsoft .NET shipped out-of-box with an assembler, a disassembler, a standard IL assembly format, and built-in libraries for code-genning (generating classes on the fly). It would be great if Sun was as comprehensive in their support of the JVM].

What can I do with Jasmin?

To give you some ideas, below are some theoretical Jasmin users/uses.

Teachers

If you are teaching a compilers course, you could have students write a compiler which generates Jasmin assembly files, and then assembles those files into Java class files. Then you can integrate the advantages of the Virtual Machine (portability, the verifier, an object model...) into your courseware.

Hobbyists

Jasmin lets you poke around in Java at the VM level, so that you can gain a real understanding of how Java works and what the Virtual Machine is like.

System Implementors

If you are implementing a Java runtime system, Jasmin is an essential tool for generating test classes.

Advanced Programmers

You could use Jasmin to write a critical class or method by hand (e.g. if you think that Java isn't doing things as well as it could).

Alternatively, you could create a syntax extension to the Java language which uses Jasmin (or JAS).

Language Implementors

If you want to create an implementation of your favorite programming language which targets the Virtual Machine, Jasmin may be a simpler approach than writing a Java class file generator. This is especially true if your compiler is implemented in something other than Java, since you can create Java class files easily without having to get involved in the details of the binary file format.

Security Wizards

Sun's claim that the Java class verifier protects you from hostile programs is a pretty strong one. Jasmin lets you create 'hostile' class files and see if a Java implementation is really as secure as it should be.

Copyright (c) Jonathan Meyer, July 1996

http://jasmin.sf.net/about.html

More Repositories

1

lljvm

Low Level Java Virtual Machine
Java
441
star
2

pandiff

Prose diffs for any document format supported by Pandoc
TypeScript
274
star
3

tensor

Cross-platform Qt5/QML-based Matrix client
C++
156
star
4

subleq

CPU design and toolchain for a simple computer architecture
JavaScript
105
star
5

pixelstruct

a tool for visualising 3D scenes reconstructed from photographs
C++
45
star
6

TeX.js

TeXify: Typesetting for the Web
HTML
44
star
7

c-hashtable

Git mirror of the hash table data structure in C by Christopher Clark ⛺
C
44
star
8

eigenGPT

Minimal C++ implementation of GPT2
C++
39
star
9

scholarpedia

An outdated Scholarpedia mirror
37
star
10

ipfs-maps

OSM vector tiles on IPFS
CSS
29
star
11

dblp.yaml

DBLP in citeproc-yaml format
TeX
27
star
12

hs-ipfs-api

A Haskell client library for the IPFS API
Haskell
26
star
13

hubot-matrix

Matrix adapter for hubot
JavaScript
26
star
14

sdbm

Git mirror of sdbm source code ⛺
C
25
star
15

pyzui

PyZUI is an implementation of a Zooming User Interface (ZUI) for Python.
Python
19
star
16

stochaskell

Haskell
10
star
17

fpgatoy

Shadertoy for FPGAs
Verilog
9
star
18

gvwin

Shell
9
star
19

librtneat

A cleaned-up distribution of rtNEAT
C++
9
star
20

cspeak

C
8
star
21

mfc7400c

Implementation of the Brother MFC-7400C scanning protocol
C
7
star
22

aspi

Answer Set Programming, Interactively
Python
7
star
23

iccsh

Interactive C Compiler Shell
C
7
star
24

bib

Command-line bibliography manager
Python
6
star
25

polya

Hierarchical Bayesian Nonparametrics (Python/C++)
C++
6
star
26

latex-glassware

5
star
27

tp

SCSS
5
star
28

datum

Datum is a simple question answering system.
Java
4
star
29

texfonts

OpenType fonts included in TeX Live
CSS
4
star
30

librw-web

WebAssembly build of librw, with TypeScript bindings
TypeScript
4
star
31

dff2gltf

Converts DFF models to glTF, based on OpenRW
C++
3
star
32

deciban

3
star
33

latex-circuit

3
star
34

bootsh

Bootstrappable, self-hosting POSIX shell
C
3
star
35

blog

archive of my old blog
3
star
36

streetcar

C#
2
star
37

classfileanalyzer

Analyzer and Disassembler (Jasmin syntax 2) for Java class files
Java
2
star
38

davidar.github.com

My GitHub Page
HTML
2
star
39

cosmetic-filter

Basic cosmetic / element hiding filtering
JavaScript
2
star
40

toki-ante

CSS
2
star
41

3dglobe

PHP
2
star
42

jclassification

Java implementation of Support Vector Machine (SVM) and multi-layer neural-network, for supervised classification
Java
2
star
43

pytextcat

Python
2
star
44

rtneatbox

rtNEATbox is a simple neuro-evolution sandbox.
C++
2
star
45

fragx

GLSL Fragment Shader Executable Compiler
Python
2
star
46

pandoc-lang

Pandoc filter to detect the language of text
JavaScript
2
star
47

django-tabs

Git mirror of the django-tabs svn repository
Python
2
star
48

candc-docker

Docker image of C&C parser and Boxer
C
2
star
49

django-codehilite

Codehilite (source code syntax highlighting) template filter for Django
2
star
50

etc

Perl
1
star
51

glsl

https://www.shadertoy.com/user/davidar
GLSL
1
star
52

base-data

Python
1
star
53

fsimage

Shell
1
star
54

nodejs-sh

Call any program as if it were a Node.js function
TypeScript
1
star
55

bearssl

C
1
star
56

da.vidr.cc

Source code of da.vidr.cc
Java
1
star
57

blue-lacuna

Inform 7
1
star
58

obsidian-lacuna

Logseq graph of the island in Blue Lacuna https://blue-lacuna.textories.com/source.html
1
star
59

cutil

Various utility functions for C
C
1
star
60

django-helloworld

Django template tag that displays "Hello World!" in one of over 50 different languages
Python
1
star
61

docker-csx

Dockerised CiteSeerX
1
star
62

sdl-cube

C++
1
star
63

django-recurse

Git mirror of the recurse template tag by Lucas Murray
Python
1
star
64

django-quotes

Django template tag that displays a random quote
Python
1
star