Say hi to VMKit: JVM/LLVM, CLI/LLVM

Hi everyone,

I've just checked in a JVM and a CLI for LLVM (called JnJVM and N3). Both are placed in the vmkit svn directory.
You can find the source code here:

svn co http://llvm.org/svn/llvm-project/vmkit/trunk vmkit

Its licensed under the U of I Open Source License, so now that's in svn, you can change whatever you want, as long as HelloWorld.java and HelloWorld.cs work :wink:

I haven't tested the build process on many machines, mostly on gentoo linux/x86 and linux/ppc. There are probably some dev libs that VMKit requires and the configure script does not check. A good thing would be to make the build process cleaner.

The README file on root explains the few steps to run the virtual machines.

I should probably say here that you currently need to patch llvm to get things working :frowning: Let's hope this won't be true too long.

Happy hacking!

Nicolas

PS: I won't be able to check my emails until Wednesday, so really, happy hacking! :wink:

Here's a patch that gets Mvm compiling on Darwin.

--Owen

mvm.patch.gz (669 Bytes)

Nicolas Geoffray wrote:

Hi everyone,

I've just checked in a JVM and a CLI for LLVM (called JnJVM and N3).
Both are placed in the vmkit svn directory.
You can find the source code here:
  
Very nice!
svn co http://llvm.org/svn/llvm-project/vmkit/trunk vmkit

Its licensed under the U of I Open Source License, so now that's in svn,
you can change whatever you want, as long as HelloWorld.java and
HelloWorld.cs work :wink:

I haven't tested the build process on many machines, mostly on gentoo
linux/x86 and linux/ppc. There are probably some dev libs that VMKit
requires and the configure script does not check. A good thing would be
to make the build process cleaner.

The code is not 64-bit clean, attached is a patch to get it compile on
x86-64 Linux.
I also fixed some g++-4.2 warnings (const issues, symbol visibility).

The libJnJVM directory builds, but it won't run, I get endless messages
like this:
; ****************************************************** ;
; SIGSEGV occured during a collection ;
; I'm trying to let the allocator in a coherent stat ;
; but the collector is DEAD and will never collect again ;
; ****************************************************** ;

Probably there are more 64-bit issues to solve. Unfortunately I don't
have time to look into this deeper now.

Best regards,
--Edwin

build64.patch (30.2 KB)

Hello, Edwin

Probably there are more 64-bit issues to solve. Unfortunately I don't
have time to look into this deeper now.

At least these "4" looks pretty suspicious:

- (void *)gcset((gc **)((unsigned int)this + nbb + 4 - sizeof(void
*)),
+ (void *)gcset((gc **)((size_t)this + nbb + 4 - sizeof(void *)),
                             (Object*)m);

Thanks, I am going to download now.

Instead of "size_t" and "ssize_t", it be better to use "uintptr_t" and "intptr_t" in all cases, since they were made for these situations.

-bw

Anton Korobeynikov wrote:

Hello, Edwin
  

Hi Anton,

Probably there are more 64-bit issues to solve. Unfortunately I don't
have time to look into this deeper now.
    

At least these "4" looks pretty suspicious:

- (void *)gcset((gc **)((unsigned int)this + nbb + 4 - sizeof(void
*)),
+ (void *)gcset((gc **)((size_t)this + nbb + 4 - sizeof(void *)),
                             (Object*)m);
  
Good point.

I think it would be best to review the code Class by Class to locate
64-bit problems.
Having unit-tests for this code would make this a lot easier ....

Maybe somebody participating at GSoC could take care of this :wink:

Best regards,
--Edwin

Owen Anderson wrote:

Here's a patch that gets Mvm compiling on Darwin.

Applied! Thanks Owen.

I've also modified configure.ac so that libopcodes is not used on darwin.

Nicolas

Very nice Torok! I applied most of the patch. A few comments:

1) What is your jni.h file? I can't compile the Jni.cpp file with your changes.
2) ISO C++ does not support %jd. x86_64 does not know about %lld?

Thanks!
Nicolas

Török Edwin wrote:

Török Edwin wrote:

Good point.

I think it would be best to review the code Class by Class to locate
64-bit problems.
  
Indeed, the source code is very x86_64 unfriendly. Most of the errors should
be in the GC and the Allocator though.

Having unit-tests for this code would make this a lot easier ....

Maybe somebody participating at GSoC could take care of this :wink:
  
Yeah, porting to all LLVM supported architectures, that would be great! As well as a test suite. As well as.... :wink:

Nicolas

Nicolas Geoffray wrote:

Very nice Torok! I applied most of the patch. A few comments:
  
Thanks!

1) What is your jni.h file? I can't compile the Jni.cpp file with your
changes.
  
Ouch, did they change 'const'-ness between gcj versions?
I was using gcj-4.2.3, and jni.h is from libgcj8-dev.

2) ISO C++ does not support %jd. x86_64 does not know about %lld?
  
It does, but gcc gives a warning, if I use %lld I get a warning on
x86_64, if I %ld I get a warning on x86-32.
int64_t is long int on x86-64. However sizeof(long int) == sizeof(long
long int), so I don't know why gcc insists it is wrong.
I only found %jd which doesn't give warnings on either:

#include <stdio.h>
#include <stdint.h>
int main()
{
        int64_t x=0;
        printf("%ld",x);
        printf("%lld",x);
        printf("%jd",x);
        return 0;
}

$ gcc -Wall -O2 p.c
p.c: In function ‘main’:
p.c:7: warning: format ‘%lld’ expects type ‘long long int’, but argument
2 has type ‘int64_t’
$ gcc -Wall -O2 p.c -m32
p.c: In function ‘main’:
p.c:6: warning: format ‘%ld’ expects type ‘long int’, but argument 2 has
type ‘int64_t’

Best regards,
--Edwin

1) What is your jni.h file? I can't compile the Jni.cpp file with your
changes.

Ouch, did they change 'const'-ness between gcj versions?
I was using gcj-4.2.3, and jni.h is from libgcj8-dev.

It looks like we did change it, in Classpath, in 2007. I assume it
was for compatibility with the JNI spec; JNI is supposed to be both
source- and binary-compatible across VMs, and we try very hard to
preserve this.

Tom

[...]

2) ISO C++ does not support %jd. x86_64 does not know about %lld?

It does, but gcc gives a warning, if I use %lld I get a warning on
x86_64, if I %ld I get a warning on x86-32.
int64_t is long int on x86-64. However sizeof(long int) == sizeof(long
long int), so I don't know why gcc insists it is wrong.
I only found %jd which doesn't give warnings on either:

#include <stdio.h>
#include <stdint.h>
int main()
{
       int64_t x=0;
       printf("%ld",x);
       printf("%lld",x);
       printf("%jd",x);
       return 0;
}

$ gcc -Wall -O2 p.c
p.c: In function ‘main’:
p.c:7: warning: format ‘%lld’ expects type ‘long long int’, but argument
2 has type ‘int64_t’
$ gcc -Wall -O2 p.c -m32
p.c: In function ‘main’:
p.c:6: warning: format ‘%ld’ expects type ‘long int’, but argument 2 has
type ‘int64_t’

  To print a int64_t value, use PRId64 from inttypes.h if you can.

#include <inttypes.h>

int64_t x = ...;
printf("x=%"PRId64"\n", x);

  It's ugly at first, but portable (provided inttypes.h ...).

  Eric

Unfortunately, inttypes.h isn't portable either :(.

I'd suggest:

   printf("%lld", (long long)x);

which is guaranteed to work and is fine on any system where sizeof(int64_t) == sizeof(long long). LLVM already makes lots of assumptions that this is true already, so one more won't hurt.

-Chris

This looks really exciting but I'm having trouble finding information about
this project. Is there documentation? I am particularly interested in the
GC...

Hi Jon,

Jon Harrop wrote:

  

Hi everyone,

I've just checked in a JVM and a CLI for LLVM (called JnJVM and N3).
Both are placed in the vmkit svn directory.
You can find the source code here:

svn co http://llvm.org/svn/llvm-project/vmkit/trunk vmkit
    
This looks really exciting but I'm having trouble finding information about this project. Is there documentation? I am particularly interested in the GC...

You can find an overview of the project here:
http://pagesperso-systeme.lip6.fr/Gael.Thomas/papers/spe-thomas-java-flexibility.pdf

And if you speak french, a detailed description of the GC
http://pagesperso-systeme.lip6.fr/Gael.Thomas/papers/these-gael.thomas.pdf

Note that things have changed since, and the vms are developped in C++ using LLVM (instead of Lisp using VPU)

Nicolas