HelloWorld
First, you'll need to compile, check and install
JanosVM somewhere. Then, copy the doc/janosvm/tutorial directory to a
scratch directory and compile HelloWorld.java:
buffy@ucsd tutorial> jikes -classpath <install dir>/share/kaffe/JanosVM.jar HelloWorld.java
Note that you have to use the JanosVM.jar JAR file since it contains the
JanosVM specific classes, as well as the basic Java classes. Next, run the
class file with the following command:
buffy@ucsd tutorial> janosvm -config tutorial.config HelloWorld
[Ignore any warnings for now]
Hello World!
The janosvm command executes Kaffe with JanosVM.jar so the
JanosVM extensions detect their classes and become active, however, you can
still run the java command to emulate the standard version of Kaffe
(handy for running the regression tests). Once the JanosVM extensions become
active they will configure themselves using the file specified by
-config and create the "kernel" team. The kernel class file, HelloWorld
in this case, is then executed and the VM exits since there weren't any
non-daemon threads created. This way of starting things up isn't especially
useful so let's look at some extra options:
-jsitcpport
- Specify the TCP port used to send and receive JanosVM
Scripting Interface (JSI) messages.
-noexit
- Causes the VM to stay alive even though there are only daemon
threads running.
-name
- Specify the name to use for this instance of the VM. This is
used to store information in a simple registry in ~/.janosvm/registry/
.
With these options we can now run an instance of the VM that won't exit
immediately and doesn't need a kernel class file:
buffy@ucsd tutorial> janosvm -config tutorial.config -name janosvm \
-jsitcpport 14000 -noexit &
buffy@ucsd tutorial> jsihey janosvm execute run of team 1 with class \
HelloWorld then nothing
Hello World!
Here, we used the jsihey command to send a JSI message to the VM we just
started. This particular message tells team 1, the kernel, to execute the
HelloWorld class with no arguments. If you wanted to pass arguments to the
class you'll need to add some data to the message by adding with and a
number of identifier/value pairs to the command line. In the case of the
run message, it can contain the arg and args identifiers
which specify a single argument and separate arguments grouped together within
quotes, respectively. For example:
buffy@ucsd tutorial> jsihey janosvm execute run of team 1 with class \
HelloWorld args "xander anya" arg "Willow Rosenberg" then nothing
Hello xander
Hello anya
Hello Willow Rosenberg
Since we're done with the VM for this section we send it a shutdown message
so that it quits.
buffy@ucsd tutorial> jsihey janosvm shutdown
The jsihey tool can send a number of other messages also; check out its
man page for more details. There is also a simple python binding for JSI in
the janosvm/libraries/unsupported/jsi/pylib directory if you don't like
shell scripts. Anyway, let's move on to the next
section...
Copyright (c) 2000, 2001 The University of Utah and the Flux Group.
All rights reserved.
Permission to use, copy, modify, distribute, and sell this
documentation for any purpose is hereby granted without fee,
provided that the above copyright notice(s) appear in all copies.