VMKit Runtime Link Error

Hi!

I build VMKit and run some programs successfully. But when using java.util.concurrent.locks.ReentrantLock and java.util.concurrent.locks.Condition, I catch a Throwable :

java.lang.UnsatisfiedLinkError: sun.misc.Unsafe.unpark(Ljava/lang/Object;)V

after using the function :

void java.util.concurrent.locks.Condition.await()

My test program is as follows:

import java.lang.*;

import java.util.Map;

import java.io.*;

import java.util.concurrent.locks.*;

class BoundedBuffer {

Lock lock;

Condition notFull;

Condition notEmpty;

final Object[] items = new Object[100];

int putptr, takeptr, count;

public BoundedBuffer(int init_count)

{

lock = new ReentrantLock();

notFull = lock.newCondition();

notEmpty = lock.newCondition();

count = init_count;

putptr = takeptr = 0;

}

public void put(Object x) throws InterruptedException {

lock.lock();

try {

while (count == items.length)

notFull.await();

items[putptr] = x;

if (++putptr == items.length)

putptr = 0;

++count;

notEmpty.signal();

} finally {

lock.unlock();

}

}

public Object take() throws InterruptedException {

Object x = null;

lock.lock();

try {

while (count == 0)

notEmpty.await();

x = items[takeptr];

if (++takeptr == items.length)

takeptr = 0;

–count;

notFull.signal();

} catch (Throwable t){

System.out.println("BoundedBuffer.catch " + t.toString());

} finally {

lock.unlock();

}

return x;

}

public static void main(String[] args) throws InterruptedException

{

BoundedBuffer buffer = new BoundedBuffer(0);

buffer.take();

return ;

}

}

Can anyone please tell me why the error?

Thanks!

Li Li

Hi Lilissun,

VMKit does not implement all sun.misc.Unsafe methods. Looking at your example, it looks like GNU Classpath (the library that provides java.* classes) rely on sun.misc.Unsafe.unpark, and that the method must be implemented by the VM. Implementing them is not trivial and requires a good understanding of the threading library in VMKit, but I will be happy to help if you want to take a look at it.

Cheers,
Nicolas