Testing a JVM implementation

P

Pedro Brandao

Greetings!

I've recently developed a simple JVM in C++ as a university
assignment; by simple I really do mean simple! There is no support for
strings, longs or doubles, multi-dimensional arrays, any Java classes
besides output (which is emulated), inheritance or other fancy OO
features.

More importantly what it is capable of doing is working with floats,
integers, doing proper flow control, converting between floats and
integers, working with static and non-static fields and methods, be it
through instantiation or otherwise. Single-dimensional arrays are
supported. In other words: all the fun Java stuff is left out, but it
is nonetheless a workable programming language.

But the thing is, it's really hard to find Java programs with these
constraints! (Not so in C, for example.) I've written a few simple
examples which get their job done while testing individual features,
but does anyone have any suggestions on a more complex program to test
it more thoroughly? The idea is to use it to showcase the VM's
(little) functionality. Either source code or ideas would be
appreciated.

Thanks in advance!

Pedro.
 
B

bugbear

Pedro said:
Greetings!

I've recently developed a simple JVM in C++ as a university
assignment; by simple I really do mean simple! There is no support for
strings, longs or doubles, multi-dimensional arrays, any Java classes
besides output (which is emulated), inheritance or other fancy OO
features.

More importantly what it is capable of doing is working with floats,
integers, doing proper flow control, converting between floats and
integers, working with static and non-static fields and methods, be it
through instantiation or otherwise. Single-dimensional arrays are
supported. In other words: all the fun Java stuff is left out, but it
is nonetheless a workable programming language.

But the thing is, it's really hard to find Java programs with these
constraints! (Not so in C, for example.) I've written a few simple
examples which get their job done while testing individual features,
but does anyone have any suggestions on a more complex program to test
it more thoroughly? The idea is to use it to showcase the VM's
(little) functionality. Either source code or ideas would be
appreciated.

http://weblogs.java.net/blog/kgh/archive/2004/12/j2se_compatibil.html

BugBear
 
R

Roedy Green

Greetings!

I've recently developed a simple JVM in C++ as a university
assignment; by simple I really do mean simple! There is no support for
strings, longs or doubles, multi-dimensional arrays, any Java classes
besides output (which is emulated), inheritance or other fancy OO
features.

More importantly what it is capable of doing is working with floats,
integers, doing proper flow control, converting between floats and
integers, working with static and non-static fields and methods, be it
through instantiation or otherwise. Single-dimensional arrays are
supported. In other words: all the fun Java stuff is left out, but it
is nonetheless a workable programming language.

But the thing is, it's really hard to find Java programs with these
constraints! (Not so in C, for example.) I've written a few simple
examples which get their job done while testing individual features,
but does anyone have any suggestions on a more complex program to test
it more thoroughly? The idea is to use it to showcase the VM's
(little) functionality. Either source code or ideas would be
appreciated.

Thanks in advance!

Pedro.

You restrictions are extremely onerous . No IO either. So all you can
do is write your own test code or look for some computationally
intensive code and modify it to remove all strings.

See http://mindprod.com/products.html#PRIMES
for example.
 
O

Oliver Wong

Pedro Brandao said:
Greetings!

I've recently developed a simple JVM in C++ as a university
assignment; by simple I really do mean simple! There is no support for
strings, longs or doubles, multi-dimensional arrays, any Java classes
besides output (which is emulated), inheritance or other fancy OO
features.

More importantly what it is capable of doing is working with floats,
integers, doing proper flow control, converting between floats and
integers, working with static and non-static fields and methods, be it
through instantiation or otherwise. Single-dimensional arrays are
supported. In other words: all the fun Java stuff is left out, but it
is nonetheless a workable programming language.

But the thing is, it's really hard to find Java programs with these
constraints! (Not so in C, for example.) I've written a few simple
examples which get their job done while testing individual features,
but does anyone have any suggestions on a more complex program to test
it more thoroughly? The idea is to use it to showcase the VM's
(little) functionality. Either source code or ideas would be
appreciated.

Without support for strings, it's hard to make interesting output (and
thus interesting programs). If you can emulate strings (perhaps with
arrays of chars), then the following programs might become feasible:

* Hello World
* 99 Bottles of Beer
* Tower of Hanoi
* Factorials

- Oliver
 
P

Patricia Shanahan

Pedro said:
Greetings!

I've recently developed a simple JVM in C++ as a university
assignment; by simple I really do mean simple! There is no support for
strings, longs or doubles, multi-dimensional arrays, any Java classes
besides output (which is emulated), inheritance or other fancy OO
features.

More importantly what it is capable of doing is working with floats,
integers, doing proper flow control, converting between floats and
integers, working with static and non-static fields and methods, be it
through instantiation or otherwise. Single-dimensional arrays are
supported. In other words: all the fun Java stuff is left out, but it
is nonetheless a workable programming language.

But the thing is, it's really hard to find Java programs with these
constraints! (Not so in C, for example.) I've written a few simple
examples which get their job done while testing individual features,
but does anyone have any suggestions on a more complex program to test
it more thoroughly? The idea is to use it to showcase the VM's
(little) functionality. Either source code or ideas would be
appreciated.

Even in C, programs that use float but not double are rare. If I were
only going to implement one of float and double I would pick double.

Maybe you should write a Turing machine emulator. That would prove that
your mini-JVM is Turing-complete.

I'm a bit confused about how you can have instantiation without having
any Java classes.

Patricia
 
P

Pedro Brandao

Even in C, programs that use float but not double are rare. If I were
only going to implement one of float and double I would pick double.

Maybe you should write a Turing machine emulator. That would prove that
your mini-JVM is Turing-complete.

I'm a bit confused about how you can have instantiation without having
any Java classes.

Patricia

My bad, I meant I didn't implement the Java library. Classses written
within the constraints imposed are properly instantiated.

I didn't implement doubles and longs yet simply because I want to
ensure the rest is working thoroughly before going further; the
implementation itself is really very simple.

As for the Turing machine, that's a great idea! Fits in with the idea
perfectly. How about a Brainfuck interpreter? I'll think about it....
 
R

Roedy Green

Without support for strings, it's hard to make interesting output (and
thus interesting programs).

You might kludge in a string implementation with just the basic string
methods and perhaps some temporary Mickey Mouse implementation -- e.g.
all backed by fixed length static char arrays.
 
P

Patricia Shanahan

Roedy said:
You might kludge in a string implementation with just the basic string
methods and perhaps some temporary Mickey Mouse implementation -- e.g.
all backed by fixed length static char arrays.

The OP didn't mention char data type, but one could use an int array
instead.

Patricia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top