The memory model might be a problem with C. C allows to get
(and sometimes print) the addresses of objects and functions
and to allocate structures on the heap, to get the offset of
structure members and so on.
or add pointers, sizeof, offsetof, ..., to the VM...
Java doesn't need to use them, and possibly something like in .NET can
be done to deal with their existence:
untrusted code trying to use these features is immediately rejected.
nearly everything else then will pretend they don't exist.
I have already added struct support, and have considered some idle ideas
as to how to deal with unions (currently involving hacks with structs).
note: these pointers will be non-boxed "raw pointers".
currently, some notable restrictions are also placed on them (currently,
no pointer-based types support virtual methods, for possibly
obvious-enough reasons, ...).
the C compiler code may allow some extensions to ease working with
non-pointer reference types (and possibly extensions to support "opaque
strings"), hence some amount of code may be written which can gloss over
whether it is running in native land or tweaked-JVM land (I already do
this to some extent in my framework for other reasons).
hence, with pointer-free code it may be possible to produce non-extended
bytecode (and thus be usable on the standard JVM).
other extensions may also be used to ease interaction with the Java
object model, ...
so, IOW, something along vaguely similar lines to C++/CLI (although
starting with a C base, and adapting it to JVM-based technology).
admittedly, the above is a lot of why I am doing my own implementation:
there is probably little hope that Oracle would at all cooperate with
something like this (nor am I that inclined to wait for things to cycle
through their "process").
note, another reason for this:
it may help C code also gloss over whether it is running on a 32 or 64
bit target, which is currently an issue (I am imagining supporting
common binary code runnable on both Windows and Linux and in both 32 and
64 bit mode...).
There is at least one Intel-PC-Emulator (386 based) for the
JVM: This will allow you to run 386 code which can come from
a C or C++ compiler on the JVM. An approach without such an
additional layer might not be possible. Possibly, you also
could install Microsoft® Windows and then run C# code.
However, it should be very difficult to access the real
environment in this case.
yes...
this is exactly the sort of thing I don't want to do.
AFAIK, many prior "C to JVM" compilers have gone the route of simulating
byte addressable memory via arrays and similar, but this sucks too hard IMO.
direct access to the real environment is personally important (among
other things), and the awkwardness of this has actually been part of why
I have not used the JVM much in the past. (and my existing C codebase is
not exactly small...).
so, the C implementation needs to be all of memory, data, and ABI
compatible with native C code.
We already have this in the JDK (but not in the JRE).
yeah, because JDK includes javac and JRE does not?...
This should take a lot of time, but are you getting paid
for it? If not, it is really admirable if your are able to
manage your life in such a way that there even is enough
time for such projects!
well, I am a hobbyist...
but also a college student (currently going for a CS major), and
probably college students have a bit more free time than people with a
job...
it is being based on JavaME though, as there is little chance of me
writing an entire JavaSE implementation by myself (and I don't really
have much need to burn myself out trying to make AWT and Swing and so on
work...).
another issue is that there are some newer JVM features (generics, ...)
for which I don't have much up-to-date information regarding how they
are implemented (currently, I am not using them).
also, I have been fiddling around with compiler and VM technologies for
much of a decade, so I have a bit of a head start. for example, I ended
up more just writing a "JVM-like skin" for my existing stuff, rather
than having to start clean (implementing an entire VM framework from the
ground up).
similarly, I already have both a C compiler in place (for native code
though), as well as much of what is needed for a Java and C# compiler,
and for compiling to JBC (the main part needing work, not yet complete).
so, mostly the work is in bridging things and making it all work.
but, all of this is at-best "experimental"...