Java in Embedded Systems

Java in Embedded Linux Systems Michael Opdenacker Free Electrons http://free­electrons.com/

Created with OpenOffice.org 2.0

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 1 Rights to copy

Attribution – ShareAlike 2.0 © Copyright 2006­2004 You are free Michael Opdenacker to copy, distribute, display, and perform the work michael@free­electrons.com to make derivative works to make commercial use of the work Document sources, updates and translations: Under the following conditions http://free­electrons.com/articles/java Attribution. You must give the original author credit. Corrections, suggestions, contributions and Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license translations are welcome! identical to this one. For any reuse or distribution, you must make clear to others the license terms of this work. Any of these conditions can be waived if you get permission from the copyright holder. Your fair use and other rights are in no way affected by the above. License text: http://creativecommons.org/licenses/by­sa/2.0/legalcode

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 2 Best viewed with...

This document is best viewed with a recent PDF reader or with OpenOffice.org itself! Take advantage of internal or external hyperlinks. So, don’t hesitate to click on them! Find pages quickly thanks to automatic search Use thumbnails to navigate in the document in a quick way If you’re reading a paper or HTML copy, you should get your copy in PDF or OpenOffice.org format on http://free­electrons.com/articles/java!

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 3 Contents

Java history Java implementations Key concepts and features JVM implementations Issues with Java Java hardware Java's strengths for acceleration and Linux embedded systems Conclusion Glossary Useful reading

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 4 Java history (1)

1991: Sun started working on a project to anticipate the next wave of computing: the convergence of digitally controlled consumer devices and computers. 1992: Implemented home entertainment control demos with a processor independent language: Oak. 1992­1994: focus moving from digital cable television network to the Internet as a way to publish and share content. 1994: Oak renamed as Java 1994: HotJava web browser with dynamic, executable content. 1995: First public release of Java. Great success

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 5 Java history (2)

1995: Netscape announced support for Java 1996: Java 1.0 release 1996: Microsoft takes a Java license 1997­2001: Sun sues Microsoft for trying violating its license and trying to enforce its own Java standard. 2001: Microsoft loses the right to advertise its products as “Java Compatible”. Microsoft's licensed terminated but can continue to use its own implementations. 1998: Java 1.2. Renamed as “Java 2” 2002: Java 1.4

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 6 Java key concepts

WORE Write Once, Run Everywhere Java applications are compiled in (JVM) . Can be run on any platform with a JVM implementation.

Java Java JVM Developer binary environment

JVM JVM User binary Interpreter environment

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 7 Java features

See http://java.sun.com/docs/overviews/java/java­overview­1.html for details Simple Portable Automatic garbage collection, small footprint No architecture dependent data sizes (int: 32 bit, float: 32 bit). Portable VM source C code. Object oriented For well defined, reusable sw components Interpreted On the fly conversion to native Network­Savvy Support for network protocols (http, ftp...) High performance VM code designed for simple machine code Robust generation. Optimized bytecode generated by the No pointers, no memory corruption, true compiler. VM interpreter optimizations. arrays. Strict compile and run time checking. Multithreaded Secure Multithread support in the language itself. But Built for security in networking environments. Real­time performance limited by OS RT perf. Data protection (no pointers). Dynamic Architecture neutral Upgrading a class doesn't force to recompile the Code runs anywhere a VM is available applications using it.

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 8 JNI:

Helps to understand how you can access the hardware with the JVM! The JNI lets code running on the JVM operate with applications and libraries written in other languages such as C, C++ or assembly. Needed to use system dependent routines handling hardware access.

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 9 Issues with Java

Though sources are available, Java is not Open Source Must purchase support from Sun to access the Java Compatibility Kit, mandatory if you release a product with changes to the Java sources. Commercial applications must purchase a license for the Java Compatible logo. Limitations of the Write Once Run Everywhere paradigm: the availability of a JVM is not enough Also need the full set of JDK libraries Can't run Sun's JDK classes on any JVM: they assume that a bunch of native methods are implemented. These methods are undocumented!

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 10 Java's strengths in embedded systems

Hides the specificities of the device and the embedded OS Provides a number of features beyond those offered by the OS Allows to build network interoperable embedded systems, whatever their hardware architecture. Simplifies product development. The software can easily be developed on workstations in parallel with the hardware. Makes it possible to reuse code Easy integration of Java Code and native code Smaller applications footprint: more compact bytecode and higher level class availability.

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 11 Java products / Glossary

See http://java.sun.com/products/ JDK: JVM: Java Virtual Machine J2RE: Java2 Release Environment Everything needed to run Java applets and applications: JVM, classes... J2SE: Java 2 Standard Edition J2RE + development tools (JDK) J2EE: Java 2 Enterprise Edition Java tools for building enterprise­class server­side applications J2ME: Java 2 Micro Environment Highly optimized Java runtime environment and for a wide range of consumer electronics products.

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 12 Java in Embedded Linux Systems

Java implementations for Linux

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 13 Blackdown project http://www.blackdown.org/ Complete JDE and JRE releases for Linux Just ports Sun's Java tools to Linux, entirely based on Sun sources (because of the license) Just distributes binaries, no source code. Did its own for several years, until Sun started supporting Linux and used their work Now works together with Sun (who granted a special noncommercial license)

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 14 Sun's Java or Blackdown on Linux?

Reasons for choosing Sun Java for Linux Sun Java on Linux is mostly based on Blackdown's work Commercial support Supports only 32bit and Sparc Linux Reasons for choosing for Linux Vendor independent, non commercial, focusing only on technical issues No commercial support Available on other architectures (ARM, PowerPC, MIPS...) Provide additional packages for Java2: Java3D, Java Advanced Imaging, (audio, video)

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 15 GNU and Java http://www.gnu.org/software/java/ 2 components: Java Compiler: gcj and libgcj GNU

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 16 GNU compiler for Java http://gcc.gnu.org/java/ libgcj: runtime for gcj compiled gcj can compile: applications Java source code directly to native core class libraries machine code garbage collector Java source code to bytecode interpreter (class files) Java bytecode to native machine Most Java API classes supported code. (AWT not yet). Merge in progress with Classpath. gcj can also be configured as a cross­compiler! gdb is supported

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 17 GNU Classpath http://www.gnu.org/software/classpath/ Java classes implementation from the GNU project License: GNU GPL, which an exception for linking with this . So, no license issue with proprietary Java programs. Exhaustive Java API implementation. Even AWT and a preliminary implementation are available in the snapshot releases.

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 18 IBM's Java on Linux http://www­106.ibm.com/developerworks/java/jdk/linux140/ Complete implementation from IBM: J2SE, J2EE, J2ME, including IBM's VM. Supported Linux platforms (only in 32 bit mode) IA32, AMD64, Itanium, PowerPC 64 bit, zSeries IBM's implementations Re­engineered Java Machine, IBM's Just In Time compiler... Java is at the core of IBM's strategy (WebSphere in particular)

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 19 Java in Embedded Linux Systems

Free Software JVMs

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 20 http://www.kaffe.org/ Clean­room JVM implementation plus associated class libraries needed by a Java runtime environment (didn't use Sun sources) Not an officially licensed JVM implementation. Not fully compatible with Java specs and lacks some key features (security, etc.) Supported in several platforms: x86, arm, mips, m68k, ppc... Great for VM education or research, or in a Java distribution. License: GNU General Public License

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 21 SableVM http://sablevm.org/ “A robust, clean, easy to maintain and extend, extremely portable, efficient, and specification­compliant Java virtual machine” Clean room JVM implementation Roughly supported on most architectures supported by Linux (ARM in particular) Compatible with JVM and Java Language specifications License: GNU Lesser General Public License Uses GNU Classpath (GPL with an exception for linking)

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 22 Jikes RVM http://oss.software.ibm.com/developerworks/opensource/jikesrvm/ RVM: Research Virtual Machine Open Source (Common Public License) implementation from IBM Implemented on Java, running on itself without requiring a second virtual machine Supported Linux Platforms: x86 and PowerPC Relies on GNU Classpath.

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 23 Java hardware acceleration in Linux

Some ARM cores directly support Java bytecode execution ( technology): http://www.arm.com/products/solutions/Jazelle.html Those cores are supported by Linux However, Linux currently doesn't support their Java capabilities Actually, several specific JVMs are said to take care this by themselves, without involving the OS. Not enough details available!

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 24 Conclusion

Java has great competitive advantages for developing applications for operating systems Sun's Java is not Free Software However, Free Software implementations for GNU / Linux are available now and satisfy most needs Unfortunately, Java hardware acceleration is not supported yet by Linux.

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 25 Useful reading

Embedded Java+Linux reference: http://www.linuxdevices.com/articles/AT8918758707.html Java overview and history: http://en.wikipedia.org/wiki/Java_programming_language

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 26 Related documents

This document belongs to the more than 1000 page materials of an embedded GNU / Linux training from Free Electrons, available under a free documentation license. http://free­electrons.com/training Linux on TI OMAP processors Introduction to Unix and GNU/Linux Free Software development tools Embedded Linux kernel and driver development Introduction to uClinux Free Software tools for embedded Linux systems Real­time in embedded Linux systems Audio in embedded Linux systems What's new in Linux 2.6? Multimedia in embedded Linux systems Java in embedded Linux systems How to port Linux on a new PDA http://free­electrons.com/articles

Embedded Linux optimizations Embedded Linux from Scratch... in 40 min!

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 27 How to help

If you support this work, you can help ... By sending corrections, suggestions, contributions and translations By asking your organization to order training sessions performed by the author of these documents (see http://free­electrons.com/training) By speaking about it to your friends, colleagues and local Free Software community. By adding links to our on­line materials on your website, to increase their visibility in search engine results.

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 28 Thanks

To the OpenOffice.org project, for their presentation and word processor tools which satisfied all my needs. To the Handhelds.org community, for giving me so much help and so many opportunities to help. To the members of the whole Free Software and Open Source community, for sharing the best of themselves: their work, their knowledge, their friendship. To people who sent corrections: Matti Aaltonen

Java in Embedded Linux Systems © Copyright 2006­2004, Michael Opdenacker, Creative Commons Attribution­ShareAlike 2.0 license http://free­electrons.com Aug 9, 2006 29 Embedded Linux Training Free Electrons services Unix and GNU/Linux basics Linux kernel and drivers development Real­time Linux uClinux Custom Development Development and profiling tools System integration Lightweight tools for embedded systems Embedded Linux demos and prototypes Root filesystem creation System optimization Audio and multimedia Linux kernel drivers System optimization Application and interface development

Consulting Technical Support Help in decision making Development tool and application support System architecture Issue investigation and solution follow­up with Identification of suitable technologies mainstream developers Managing licensing requirements Help getting started System design and performance review http://free­electrons.com