tags:

views:

325

answers:

6

Alright everyone, Let's say i wanted to make a system that used only assembly and java, my question would be, as long as i included all of the jvm folders, classes, jars, etc.. java should still function effectively? i understand there are those things that are compiled platform specifically but this is why i am asking, is it possible, using assembly to replicate all of the .exe, or other executable files that java has included into a pure assembly/java system?

+1  A: 

If I understand your question correctly, you mean something like JavaOS. Sure, its possible to implement the JVM raw on the hardware, not sure why you would, though. And if you did, why you wouldn't use C instead of Assembly for most of the work.

Yishai
+2  A: 

Its theoretically possible to implement the jvm in a whole other language. The best example I can think of is Python/Jpython where there is the original C implementation and a pure Java implementation of the language.

The main argumant against this is -- its a ton of work for not much benefit.

The official Sun jvm and supporting jni libraries are written mostly in C, you would need to provide native assembler implementations for most of the C POSIX APIs at the very least.

Also the original design goal of C was 'a portable assembly language' and to a large extent it still meets these goals. C produces efficient machine code and most C compilers will let code machine instructions inline with the C code.

Another benefit of C is the number of cross compilers available, you dont need to run the development environment on tHe target architecture, you can deveop and unit test on your favourite paltform/IDE, when you are ready you can then export your executables to the target platform.

James Anderson
+3  A: 

If you are asking whether it is possible to build a system in Java and assembly language that runs on "bare metal", the answer is yes. There are a couple of current examples:

  • JavaOS is targeted primarily at the embedded systems domain. (Sun consider SunOS to be a "legacy" product line these days.)
  • JNode aims are broader, and encompass embedded systems, desktop systems, servers and cloud computing.

Be aware that building a system of this kind is a multi-year, multi-person project requiring deep understanding of virtual machine internals, compilers, garbage collectors, hardware architectures, device driver writing and so on.

If you are asking about something else, please be more explicit.

EDIT: responding to the OP's followup question:

  1. It is not practical to use the Java and other "exe" files per se. They require a fully fledged operating system underneath them; e.g. Windows, Linux, whatever. If you had access to the source code, you could conceivably rewrite as required to make them run on "bare metal", but that would entail significant architectural changes, especially if you want to write device drivers, etc in Java. (Besides, Sun's JRE is implemented in C ... IIRC).
  2. You cannot directly use the existing Java class library JAR files, because they include a significant amount of platform specific code. However, you can build your own Java class library JARs from an existing open-source version of the Java class libraries (e.g. the OpenJDK 6.0 J2SE libraries). You deal with the platform specific code by providing your own versions as native libraries or (as JNode does) as Java classes.
Stephen C
this is what i was asking and i understand it would be a multi-person job, and it was just a thought. the only reason i asked is because i am not sure how i would make the jvm's executables work using assembly.. the only question i wanted answered here was if it was possible, and thankyou, you answered it perfectly.. without telling me it would better to use c or anything like that
Lonnie Ribordy
Probably most of the non-Java parts are in C, for portability.
starblue
@starblue: for Sun's JRE, that's part of the reason I'm sure. Another part is that they wouldn't want to write / maintain tens of thousands of lines of assembler. For JNode, there is actually no C - the nanokernel is coded in x86 / x86_64 assembler. (I personally don't think that was the best idea, but that's another story. At least JNode no longer has a bytecode interpreter coded in assembler!)
Stephen C
A: 

Jikes RVM and Sun's Maxine provide a JVM implementation with little (of the order of 1 kloc) native code. However, both VMs require an OS and are only research implementations. The process of creating a stream of octets that form machine code, is obviously achievable in Java.

Tom Hawtin - tackline
A: 

Have a look at JNode. They have been working on this for years.

http://www.jnode.org/

Thorbjørn Ravn Andersen
A: 

Why is Sun silent in this direction? Now that they have maxine, why not throw up something into the open source, a java base OS. It will be really cool.

anonymous