tags:

views:

1016

answers:

16

Is it necessary to code RTOS in C language always? Why can't that be coded in java or some other technology..?? Is that because of the absence of pointer concept in java?

+3  A: 

I think the biggest problem with java for this purpose is the automatic garbage collection. Here's a link on creating realtime systems in java.

Andreas Brinck
+8  A: 

Real time systems can be programmed in other languages too. Java has a Java RTS System for example.

Contrary to other answers, there is reasonable amount of work on real-time garbage collections. However, these don't get bundled in your typical distributions.

The concern is that other languages usually have features that make determinism and reliability hard to achieve, e.g traditional garbage collection, JIT, run-time optimizations, etc.

notnoop
You'll note though that the Java RTS System has to run on top of a RTOS - no-one's built a realtime baremetal Java system yet.
caf
Have a look at JNode - http://www.jnode.org/ - which is an OS written in Java.
Thorbjørn Ravn Andersen
@notnoop: people have done it already, for example http://www.jnode.org/ and http://cjos.sourceforge.net/archive/
viraptor
Cool.. Didn't know of those before. Live and learn =).
notnoop
Ajile systems (www.ajile.com) make realtime Java CPU's. They run Java on bare metal hardware. Interrupt response latency is under 1 microsecond. Thread-to thread context switches take less than 1 microsecond. Power consumption is 100milliwatts maximum at 100% cpu. Performance is on par with a Pentium at 400Mhz. Companies that use them do not advertise it. For them,it is a competitive advantage. Finding people to do embedded Java real-time, now that's a bit harder. I like their hardware. It is fun to use and has solved real world problems for real companies and is in use around the world.
Tim Williscroft
+10  A: 

Garbage collection is the big reason against Java being Real Time. JIT is another, but it could be overcome.

In general though, C being effectively portable assembly gives very predicable run-time performance, and that's essential for reliable real-time execution.

TheManWithNoName
Java does have an RTS system, and there is some good research and work on real-time garbage collection.
notnoop
@TheManWithNoName: Whats do you mean by Garbage collection? And whats JIT?
wrapperm
JIT is the "Just-In-TIme compiler" which massively changes the runtime chracteristics of code http://en.wikipedia.org/wiki/Just-in-time_compilationGarbage Collection is the automatic memory-sweeping that Java implements.
Thrawn
Garbage collection is automatic freeing of unused objects - this normally has the potential to pause the running application (the pause can be reduced but is very difficult to fully eliminate, without risking out of memory scenarios).JIT is the Just In Time compiler which converts heavily used java bytecode into native code as needed - this obviously dramatically changes the performance but itself requires time to perform, and you may need to force complete compilation to meet the real time goals to begin with.
TheManWithNoName
very true... Thanks for the explainations...
wrapperm
Realtime garbage collectors have existed for decades, now. And JIT is in no way required for Java. In fact, in pretty much every single Java implementation in existence, there is no JIT compiler. Often, there is one in the JVM implementation, but a) a JVM is not required for Java and b) a JIT isn't required for the JVM, either.
Jörg W Mittag
A: 

A garbage-collected language like Java is highly unsuited for real-time programming. The reasons for this should be obvious.

Anon.
There is such a thing as Real-time garbage collection: http://www.ibm.com/developerworks/java/library/j-rtj4/index.html
notnoop
Isn't the answer to every question on SO obvious?
Pod
Sun has a commercial Real Time version of Java.
Thorbjørn Ravn Andersen
In the spirit of answering questions, perhaps it would be helpful to list the reasons. There are all levels of users and what is obvious to some may not be to others.
semaj
@semaj: But in this case, the answer *is* obvious: @Anon has clearly never heard of realtime garbage collectors.
Jörg W Mittag
A real-time garbage collector is going to require a fair amount of support, which means it's something a Java RTOS will need and a C RTOS won't. Really, though, garbage collection is largely irrelevant here.
David Thornley
+9  A: 

At first RTOS aren't just coded in C. They can also be coded in other languages. However the language used for an RTOS needs to offer deterministic behaviour. This means that the latency for a specific action must always be under a specific amount of time. This rules out for example garbage collection, which in most implementations will stop the execution of all threads for an undetermined time.

kgiannakakis
+2  A: 

There's Real Time in Java, but it requires support from the OS. See: http://java.sun.com/javase/technologies/realtime/index.jsp

rmn
+5  A: 
  • Availability of highly optimized c-compilers for all hardware that RTOS-es typically run on.
  • The relative ease with which you can include very low level optimizations in c-code.
  • Availability of c-code for a lot of useful low-level system tools which hence can easily be incorporated.
jilles de wit
+1 for your second reason. In writing any sort of OS, you're going to have to get really up close and personal with the hardware now and then. Java was designed with the intention of glossing over the really low-level stuff, and it shows.
David Thornley
+3  A: 

Because C-based RTOS are well known and have been used for many decades. Their behaviour is predictable for many specific situations and you can find many experts for developing with these systems.

I know no Java-based RTOS having reached a level such that a company making safety critical realtime applications would adopt it.

Technically, there is no argument against a Java-based RTOS, but research, engineering and products on the subject is not yet mature.

mouviciel
+2  A: 

Is it necessary to code RTOS in C language always?

No. You can code RTOS also in assembler, Ada and few other.

Why can't that be coded in java or some other technology..?? Is that because of the absence of pointer concept in java?

No. Unpredictable time of code execution.

vitaly.v.ch
+1  A: 

C was designed for writing operating systems, hence the common wording "portable assembler", so it is to be expected that it is used for that purpose.

If you want to have real time Java, Sun has a commercial offering.

Thorbjørn Ravn Andersen
A: 

Is it necessary to code RTOS in C language always?

No. There are RTOS written in Lisp or Smalltalk, for example.

Why can't that be coded in java or some other technology..??

What makes you think it can't?

Is that because of the absence of pointer concept in java?

No, it's because there is a myth that Operating Systems can only be written in C. A myth that can be trivially proven false, yet still refuses to die.

This myth is so pervasive, that people who want to write a new OS, are simply too afraid to try anything other than C.

Jörg W Mittag
If the proof is so trivial, how about some links?
Norman Ramsey
More to the point, where's the myth? What answers to this question claim that OSs can only be written in C?
David Thornley
@Jörg: This was not about writing an OS but writing an RTOS. The whole point with an RTOS is that it is deterministic. To have a truly deterministic java you need to remove quite a lot of the things that are good with java (even if you use Java RTS) and that would sort of defeat the purpose of using it. You can get pretty darn close if you code things right and use something like JRRT but you will not be as realtime as you need to be when writing a RTOS. At least not yet.
Fredrik
I suppose I should point out that the only widely used Lisp OSs I ever heard of were on specially designed hardware, and nobody ever told me they were real-time. Were there actual real-time OSs written in Lisp or Smalltalk?
David Thornley
+3  A: 

By definition an RTOS must support deterministic scheduling and execution. Generally low interrupt latency, and direct hardware access are also a desirable factor. Technologies used in Java such as garbage collection, JIT compilation, and bytecode execution make these goals hard to achieve.

Java may be used in real-time systems, but typically it runs on an RTOS rather than being used in its implementation.

All that said, it would equally be untrue to suggest that RTOS are always implemented in C. Any systems level language would be suitable including assembler. In most cases at least some part of the kernel would be in assembler in any case. C++ would be a suitable language (rather obviously since it is essentially a C superset), many commercial RTOSs have C++ wrappers in any case; I habitually develop C++ abstraction layers for RTOS to support portability.

The other reason C is typically used is because a C (often a C/C++) compiler is generally the first and often the only language (other than assembler) available for a new architecture (frequently these days in the form of a GNU compiler implementation). So if you want to be able to port your RTOS to the widest number of platforms, it makes sense to use the most ubiquitous language.

Clifford
+3  A: 

Not "necessary", but a lot more practical

As a language Java could be used, and there are various wacky cases of it actually happening.

But a few fringe cases and demonstrations are really more "the exception(s) that prove the rule".

In general, Java is a big elaborate system intended for business logic and not OS kernels.

If we did not already have C, Java might have developed in a different direction, or in multiple directions.

But we do have C, which is nearly perfect for an OS kernel and quite a challenge for business logic.

Arguments that Java is just as good as C for a kernel are about as realistic as arguments that C is just as good as Java for applications. Experience, minus a few fringe examples, proves overwhelmingly what each language is good for.

DigitalRoss
+1  A: 

If anything, it's because of pointers. In Java, everything except fundamental data types is allocated on the heap, and any variable that isn't something like int is a pointer. That's not a good way to write an operating system, because it imposes one layer of indirection over most operations, and in OS writing that layer can kill you.

The OS kernel is a place where you want optimization and high performance, since you don't know what will run on it. This is particularly true of real-time OSs, in which a half-millisecond delay can be critical. This requires getting really chummy with the CPU and other hardware, and the ability to write highly microoptimized code that will execute specific things with great predictability.

For this reason, C is a very good tool to build a RTOS kernel with, and Java isn't. That doesn't mean you couldn't do it with Java, but it would be harder and probably not as successful.

I am curious as to why you ask the question. If you're using a RTOS, it doesn't really matter what it was written in. If you want to hack one, it does matter what it was written in, but the concepts and implementation of the OS are sufficiently hard in themselves that learning a new language is trivial to learn. (Moreover, if you study OS design and implementation, you're almost certain to find that the resources you use will use C as a teaching language.)

David Thornley
+4  A: 

Because RTOS developers, most likely, don't know C++ well enough.

C++ in Embedded Systems: Myth and Reality

Some perceive that C++ has overheads and costs that render it somehow unsuited to embedded systems programming, that it lacks the control and brevity of C, or that, while it may be suited to some niche applications, it will never displace C as the language of choice for embedded systems.

These perceptions are wrong. Where compilers and other tools are adequate, C++ is always preferable to C as an implementation language for embedded systems. While doing everything that C does, it offers greater opportunities for expression, encapsulation, re-use, and it even allows size and speed improvements that are impractical in C.

> Why, then, do these perceptions persist? The main reason is that when people form their opinions, they know a lot more about C than about C++. They have read some books, written some code, and are competent at using the features of C++, but they lack the knowledge of what is happening under the hood, the familiarity that allows one to visualize the disassembly while typing source or even while formulating a design.

Guidelines for using C++ as an alternative to C in embedded designs

Embedded software applications are most commonly written in C. For many years, C++ has been seen as the natural successor and has found greater acceptance, but the increase in its usage has been much slower than anticipated.

There are a number of reasons for this. Firstly, embedded developers are quite conservative and prefer to use solutions that are proven rather than novel " "if it ain't broke, don't fix it".

There is also the lesson of experience. Many developers have attempted to use C++ for embedded applications and failed. Such failures may sometimes be attributed to shortcomings in development tools, but most often it is the inappropriate use of the language " treating an embedded system like a desktop computer " that is to blame.

Limitations of C Although C is widely used, it has limitations, as it was not designed for embedded applications or for projects of a scale that is now commonplace. Key limitations include:

1) C is extremely powerful and flexible and can therefore be dangerous.(It has low level capabilities - which are useful for embedded " but also represent many pitfalls for the unwary.)

2) Programmers need to be very methodical and disciplined

3) Programmers need to understand how the program behaves at low and high levels (large projects are thus hard to maintain)

4) Programmers need an expert knowledge of the application

However, C++ has powerful object oriented capabilities which can help significantly with addressing the limitations of C:

1) it encapsulates and hides areas of high expertise from non-experts into "objects;" (A test case will demonstrate the encapsulation of expertise later in Part 2 in this series).

2) Objects can be used intuitively by non-experts to implement conceptual designs at a high-level

Comptrol
A: 

j'ai cherché et vraiment j'ai dégouté, je trouve pas un système d'exploitation temps réel conçu en java, sauf le Ajile RTOS que je trouve pas comment le télécharger.si quelqu'un trouve un rtos ou un rtems en java, prière de m'informer à l'e-mail : [email protected]. SVP c vraiment urgent. Merci d'avance.

Laurent Paulet