Diary of Mysaifu JVM

If you have any comment, please feel free to contact me.(Please include "Mysaifu" in the subject of your mail)
Please visit my blog if your browser can display Japanese characters.

Feb. 09, 2010
SSL/TLS support

GNU Classpath includes SSL/TLS library "Jessie". Jessie is a great library, but it does not work on Mysaifu JVM.
The reason is perfomance of Mysaifu JVM. Mysaifu JVM is a simple bytecode interpreter, which has no JIT (Just In Time) compiler. I tried to connect to SSL/TLS server, timeout occurred in "handshake" process.
So I started to rewrite SSL/TLS library with native code to solve this problem.

Feb. 08, 2010
Developing Mysaifu JVM Version 0.4.8

I'll add following two features to Mysaifu JVM Version 0.4.8
1. SSL/TLS support
 It works not only client mode, but also server mode.
2. Non blocking network channel support
 configureBlocking(false) will work in SocketChannel, ServerSocketChannel, and... Pipe.SinkChannel, .SourceChannel (I've never seen the program wich uses Pipe class).
I think I can release version 0.4.8 in March or April.

Jun. 06, 2008
Porting Java3D

I'm porting Java3D to Windows Mobile.

Apr. 03, 2007
I had forgotten to do ...

I had forgotten to maintain Mysaifu JVM, because I bought Nintendo Wii and I have been playing the Zelda every day.
Finally, I knocked down the last monster at the end of last month, so I restart work...

Sep. 08, 2006
How to build from source code

I released Mysaifu JVM 0.3.0, and How to build Mysaifu JVM from source code page.
I think it is easy to compile Mysaifu JVM, but if you have any problem, please feel free to contact me.

Aug. 22, 2006
Thank you for your bug report!

Many users send me a bug report. Thank you very much, and I am sorry for I cannot reply to all your mail.
But I read all your mail. I'll try to fix all problems.
Now I'm trying to support SWT.
Maybe it'll work in next version of Mysaifu JVM.

Mar. 26, 2006
Mysaifu JVM 0.2.4 released

Changes in this version:
Package java.awt

Package java.swing.filechooser JVM

Mar. 15, 2006
Mysaifu JVM 0.2.3 released

Changes in this version:

Mar. 14, 2006
Mysaifu JVM 0.2.3 will be available soon!

Mar. 03, 2006
Mysaifu JVM 0.2.2 released!

I released Version 0.2.2.
Now javax.sound.sampled supported. You can play and record sounds. Read and write sound file also.
Currently, supported sound format is linear-PCM (8bit/16bit).

Feb. 21, 2006
Support javax.sound.sampled package

I am implementing javax.sound.sampled package. I think that SourceDataLine and TargetDataLine will be available in next version.
The following programs could be run under Mysaifu JVM version 0.2.2 beta.

import javax.sound.sampled.*;

public class SoundTest {
	public static void main(String[] args) throws Exception {
		final float sampleRate = 8000f;
		final int sampleSizeInBits = 8;
		final int channels = 1;
		AudioFormat format
			= new AudioFormat(sampleRate,
		final int seconds = 10;
		System.out.println("Start recording " + seconds + " seconds");
		byte[] wavedata = record(format, seconds);
		System.out.println("Start playing");
		play(format, wavedata);

	static byte[] record(AudioFormat format, int seconds)
				throws LineUnavailableException {
		DataLine.Info info
		= new DataLine.Info(TargetDataLine.class,
		TargetDataLine line = (TargetDataLine) AudioSystem.getLine(info);
		int sampleRate = (int) format.getSampleRate();
		int channels = format.getChannels();
		int sampleSizeInBits = format.getSampleSizeInBits();
		final int bytesPerSec
			= (int) (sampleRate * channels * sampleSizeInBits / 8);
		byte[] buff = new byte[bytesPerSec * seconds];
		line.read(buff, 0, buff.length);
		return buff;

	static void play(AudioFormat format, byte[] wavedata)
			throws LineUnavailableException {
		DataLine.Info info
			= new DataLine.Info(SourceDataLine.class,
		SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
		line.write(wavedata, 0, wavedata.length);

Feb. 14, 2006
Mysaifu JVM Version 0.2.1 released

I released new version. Class library updated to GNU Classpath 0.20

Feb. 8, 2006
Mysaifu JVM Version 0.2.0 released

I released new version.
Class library version is GNU Classpath 0.19. I'm going to update library version, and I'll release Mysaifu JVM version 0.2.1 soon.

Jan. 9, 2006
SHBrowseForFolder() problem

I want to improve user interface of Mysaifu JVM.
To set CLASSPATH easier, I tried to add a "Select folder" dialog.
MSDN says that SHBrowseForFolder() is supported by Windows CE, and header file declares this function. So I wrote following code:

BROWSEINFO binfo = {0};
ITEMIDLIST* idlist = SHBrowseForFolder(&binfo);
SHGetPathFromIDList(idlist, path);
IMalloc* imalloc;
But link error occurred. (I linked ceshell.lib)
error LNK2019: unresolved external symbol __imp__SHBrowseForFolder referenced in function _WinMain
It seems that Pocket PC 2003 does not have this function.

Jan. 8, 2006
Limitations of shortcut file in Windows CE

Windows CE supports shortcut (*.lnk) file. You can create shortcut file by using SHCreateShortcut() API.
But target path and arguments limited to 256 bytes.

Dec. 23, 2005
JVM security

I want to improve the security of Mysaifu JVM in the next version. Then, the following functions will be added.
1. Loading constraints
2. Verifier
Loading constraints has been implemented. But about the verifier, because "byte code verifier" is difficult to me, I am taking pains to implement.

Dec. 8, 2005
Pocket PC user interface

Most Pocket PC applications do not have a window caption.
The window is always maximized, and user cannot change its size or change its position.
AWT implementation of Mysaifu JVM also follows these manners.

However, many java applications assumed that Frame and Dialog is movable and resizable.
This behaviour can be changed by setting the following system property.

Valid value is frame and dialog.
It is set as follows.

If you set this property, Frame and Dialog is movable/resizable like this.

Dec. 7, 2005
Version 0.1.9 will be released soon

I released version 0.1.8 few days ago, but I'll release next version soon.
Because it is clear that there are some fatal bugs in current version.
I am thankful to the person who reported the bugs.

Nov. 27, 2005
libiconv works!

Hooray! it works!

Nov. 25, 2005
Porting errno to Windows CE

Current version of Mysaifu JVM defines errno as following macro in errno.h.

#define errno GetLastError()
It works fine because GNU Classpath native libraries only read errno.
For example:
if (errno == EEXIST)
  // Error handling code
But it could not work in libiconv. libiconv set value to errno like this.
if (incount == RET_TOOFEW(0)) {
  errno = EINVAL;
This code cannnot be compiled.
xxx.c(76) : error C2106: '=' : left operand must be l-value
To compile libiconv, we need "real" errno. So I made tiny DLL called "errno.dll" to solve this problem.
New errno.h defines errno as following macro.
#define errno (*WCEGetErrnoAddress())
The WCEGetErrnoAddress() is a function which returns pointer of "real" errno.
int* WCEGetErrnoAddress();
According to the description of the man page, errno is a thread-local variable. Setting it in one thread does not affect its value in any other thread.
Fortunately, Windows CE supports thread local storage (TLS). So I could implement errno as thread-local variable.

Nov. 24, 2005
Encoding and decoding

GNU Classpath carries out encoding/decoding characters by libiconv.
I decided to port libiconv to Windows CE.
I have noticed errno being required for libiconv after a while.
However, there is no errno in Windows CE.
Then, I started to think how to implement errno on Windows CE.

Nov. 23, 2005
Memory mapped file in Windows CE

I challenged the memory mapped file of Windows CE in order to implement FileChannel.map() method.
In Win32 platform, we can map any file to memory.

HANDLE hFile    = CreateFile(...);
HANDLE hMapping = CreateFileMapping(hFile, ...);
LPVOID p        = MapViewOfFile(hMapping, ...);
MapViewOfFile() function returns the starting address of the mapped view.
But we cannot do this in Windows CE.
CreateFileMapping() always returns INVALID_HANDLE_VALUE, why?
Because Windows CE's CreateFileMapping() cannot map the file which opened by CreateFile() function, we must call CreateFileForMapping() instead of CreateFile().
The CreateFileForMapping() is a special version of CreateFile() function.
To use memory mapped file in Windows CE:
HANDLE hFile    = CreateFileForMapping(...);
HANDLE hMapping = CreateFileMapping(hFile, ...);
LPVOID p        = MapViewOfFile(hMapping, ...);
When map a file to memory by FileChannel.map(), the file is opened twice.
First, CreateFile() is called when FileChannel object created. Next, CreateFileForMapping() is called within FileChannel.map() method.
There is no problem if the file is opend by CreateFile() function with only GENERIC_READ flag,CreateFileForMapping() can open same file.
But if the file is opend with GENERIC_WRITE flag, CreateFileForMapping() will be failed.
It is because the CreateFileForMapping() allowes only FILE_SHARE_READ flag.
Therefore, the following code does not work.
_TCHAR* filename = _T("file.txt");
// Open the file
  = CreateFile(filename,
// Open the same file for mapping.
HANDLE hFileForMapping
  = CreateFileForMapping(filename,
                         GENERIC_WRITE | GENERIC_READ,
                         FILE_SHARE_READ, // FILE_SHARE_WRITE flag is ignored.

// hFileForMapping == INVALID_HANDLE_VALUE
I have not found the workaround of this problem yet.
Nov. 21, 2005
File locking in Windows CE

In Windows platform, you can lock any file by using LockFile function.
But Windows CE does not have this function, so I should achieve pseudo-file locking mechanism to implement FileChannel.lock() and tryLock() method.
I'm going to implement this mechanism with Win32 mutex objects.

Nov. 20, 2005
Improve performance of system class loader
When many files in the jar file, Mysaifu JVM takes long time to load a first class from the jar file.
I found the cause in the ZipFile class.
ZipFile class caches all ZipEntry of central directory in the jar file, it consumes time and heap memory.
I modified some methods of ZipFile class.
New methods are using native memory mapped files, and they do not cache instances of ZipEntry but cache the offset in the zip file.
New ZipFile class is not portable because it includes platform-dependent native codes, but performance is slightly improved and reduce memory usage.
Nov. 18, 2005
The plan for the next version
I am going to add the following functions to the next version. (Version 0.1.8)
1. Improvement performance of the system class loader.
2. Write FileChannel.lock() and tryLock() methods.
3. Write FileChannel.map() method.
4. Support character encoding/decoding.