Ten advantages and five limitations of Java for Embedded Systems

Source: Internet
Author: User
Tags finally block

 

The advantage of the Java language is that it was initially designed by a small and focused development group that understands and believes in the dream of network computing. Although the original implementation scheme of the language is somewhat flawed, however, for the sake of this dream, they rarely compromise in technology, and the result is a special aim for communication.
The language of the device. Many technical advantages may guide embedded system developers to select Java.

1. irrelevant to the processor

The first advantage of Java is that it has nothing to do with the processor. This advantage seems to have nothing to do with embedded systems. Traditionally, embedded programs are designed and run on specific microprocessors, and the portability of C language programs can be ensured through compilation or cross-compilation.

However, in Sun's model, a program may be stored on one system and downloaded and run on another completely different system; devices may download programs from different locations to run on a single processor, or different Processors may run a program to transmit data between each other over the network. Using Java, an embedded system may become a common communication device that can download and run programs that can complete specific tasks.

For embedded systems, this is a new model, and some developers are moving closer to it. For example, the TV set-top box supplier has announced that it is incorporated into the JVM so that users can use Java applets to support some content of the TV program while they watch the TV. In this way, when you watch a football match, the support content you see can be technical statistics on players. If you are watching a movie, The support content you see can be the background information of the actors. The JVM is also transplanted to mobile phones so that users can receive stock quotes, game scores, and other real-time information.

This is an appropriate design and implementation model. First, it can make the selection of the Development Platform more flexible, without the need to develop on the same platform as the target, or worry about cross-compilation issues, because Java bytecode can be run in any operating system with JVM. The second advantage of this model is that almost all detection and debugging can be performed independently of the target device. However, some data input and hardware interactions require testing on the target (or a good simulation system. Since some JVMs sometimes have compatibility issues, you should test it on all platforms that will use the program. But in general, you are not an advanced and expensive development environment with logic probes, ice, and other debugging tools for the target platform.

2. Improved development speed and maintainability through object-oriented

Java is a pure object-oriented language. All code and data are part of a class. There is no global variable or code independent from the class. An object is an instance of a class, and an object is called through an operation method, or functions, and these methods or functions are also part of the class. Object Methods Operate on object data. A Java class is organized into a hierarchy. In a hierarchy, a subclass can inherit its superclasses and extend its superclasses by using some special functions of the subclass. The object model allows you to define the data structure corresponding to real things, so that the conversion between task and task implementers becomes basically transparent.

Java class layers have six main classes (a total of 23 classes) into class packages ). To apply any object in any package, you only need to declare that package. You also have full inheritance in the class hierarchy. objects at any level can use all the methods defined at a higher level in the hierarchy.

The advantages of object-oriented design and programming are their development speed and code maintainability. Many object-oriented development can be done by using and changing existing class libraries, rather than creating a new structure. This accelerates development. Sun's Java workshop (an IDE fully written in Java) it is a good evidence that developers can build a fully functional graphic IDE within a few months. The object-oriented method also tries its best to use the natural structure to make it highly readable and can be easily changed and enhanced.

3. High Security

With JVM, a Java application is completely isolated from the operating system or hardware, so it is difficult for computer viruses or other code to gain control over the device. Virtual machines are a protective layer between host devices and software that may be difficult to determine their quality and reliability.

In addition, the Java designer removes the pointer variable concept from the language. Java cannot access the memory at will. It can only read and write objects created by the Java Memory Allocation Management System. Due to the strict classification mechanism enforced by the Java compiler, theoretically speaking, it is impossible to access the memory areas not allocated to the program. This restriction makes it very difficult for programs that want to write malicious code. Of course, this protection is not complete. Some of the vulnerabilities have been found in the Java security model, and some of them have been handled by Sun. Some talented but unscrupulous programmers may write programs, intentionally but without directly changing the memory content, or getting a password or other information from the host. However, the JVM does provide some protection, making it almost impossible to run code directly on the hardware.

The restrictions imposed on Java applets are more strict. A Java applet is designed to be downloaded from the Internet and is considered untrusted unless it includes a digital fingerprint of a host that you have recognized as trustworthy. JVM runs Untrusted code such as Applet in a region called sandbox in the memory. It assigns resources and privileges to each Applet and limits them to the scope of these allocation areas. In addition to these restrictions, the Sandbox Model also applies the following restrictions: Prohibit reading and writing local computer file systems; restrict network operations and prohibit Untrusted code from establishing network connections with any computer, except for the computer downloaded from it, it cannot listen to or accept connections on any port number smaller than 1024 (the port range reserved by the famous ports used for standard network protocols; access or creation of threads is prohibited from running the thread group of Untrusted code.

4. Easy Memory Management

Java memory management is far simpler than other languages because it does not use pointers. When an object is instantiated, the memory is dynamically allocated. As we have analyzed earlier, access to some memory addresses is considered a potential danger to security by Java designers. Therefore, access is also prohibited. Moreover, sun's network model assumes that you may not know the target processor, and it is unnecessary to reference a dedicated memory address. Removing the pointer not only improves security, but also simplifies programming and reduces errors.

To understand how Java allocates memory, we can compare it with the C language. In C, you can use values or references to access data. In fact, for flexibility and control, non-original data types are accessed by reference, that is, access through pointers. Therefore, the differences between values and references become very clear, especially because you have to use different symbols (* and &) to access data. To use these two different access methods, you must understand what they are and why you should use them instead of using them.

In Java, values and references are stored seamlessly, especially because their symbols are the same. The only difference between the two lies in the Data Type itself: All original data types are always accessed by values; all objects, including strings, arrays, and file streams, are always accessed by reference. Declared as the original data variable type contains the value of this variable, declared as an object variable contains a reference to this object (that is, the object's address), rather than the object's own reference. Declaring only one object variable does not allocate memory to the object. You must use the "new" keyword to allocate memory and create an object.

The most fundamental difference between the two methods is that it is impossible to perform pointer arithmetic or other operations on the Java memory address as in C. In Java, the object address is relative (or virtual), which is randomly allocated by the Virtual Machine. Therefore, you have no reason to still want the pointer address.

5. Garbage Collection

Garbage collection automatically collects memory unreferenced in memory and returns it to the idle memory linked list. JVM uses this function to return unused memory to the system. When a Java program describes and instantiates an object or array, it only makes a JVM request, accesses the system memory under it (usually through the host operating system) and allocates the memory, java's garbage collection system collects objects through memory and then checks their reference chains. Java garbage collection systems generally search for objects in memory and check their reference tables. It calculates the number of variables in the program that are currently referencing each object. If the number of objects referenced is zero, it knows that the object is no longer in use and its memory can be reclaimed. As a result, you do not have to manually release the allocated memory as you did in the C language. In C, releasing memory is a necessary, time-consuming, and error-prone detail. Java automatically and accurately handles this process, removing the common error cause in the C/C ++ program.

6. Convenient network implementation

Because today's embedded systems are usually network-oriented, the use of built-in network-Supported languages saves a lot of time and effort in implementing network protocols and communication programs. In Java, network classes include TCP/IP streams and datagram programs using TCP and UDP. They are used for HTTP and URL services, as well as error check code and recovery functions. Although the implementation of the network may also use other languages, such as the C language, but those languages require special attachment software packages, DLL, or other program modules that must be sold by the operating system or a third party, special attachments usually require knowledge of operating systems or third-party tools. Unlike Java, they have standard and built-in network support. Java includes network packages as necessary, because designers cannot make any assumptions about the network facilities of a basic operating system. They must include the integrated network library, to ensure that Java programs can work on all platforms.

7. dynamic configuration can be implemented

Dynamic configuration refers to the configuration or reconfiguration made by the user at system startup. Systems that require loading special hardware configurations, network parameters, or utilities that support specific purposes during boot often use dynamic configurations. JAVA supports dynamic configuration with dynamic bundling. When you compile various class files of a program into bytecode, You can reference between your class files or the classes (shapes, networks, and core languages) of the JVM package, not resolved yet. When the JVM loads your program, it dynamically loads and binds (that is, links) all the classes referenced by your program. Therefore, to change the system configuration, all you need to do is to correct the corresponding class file. Next time, the JVM automatically binds a new file to your program, and the new configuration takes effect.

8. You can easily trap and handle errors.

Unlike many operating systems and programs, restarting embedded systems is usually unacceptable, just as we don't want to make calls or watch TV without a technical interruption. This means that in fact all embedded systems must be solid enough to intercept errors to prevent them from causing programs or worse, causing the entire device to crash.

There are many causes of program errors. Relatively speaking, it is rarely because of inheritance logic errors, and most programs crash because of unexpected input, or because the program cannot call system resources to complete a specific operation. Therefore, you must be able to anticipate these problems and trap them to avoid larger problems. Although errors can be captured and handled in almost any programming language, it would be of great help if there are built-in facilities to do such work, such as Java.

In Java, an error is thrown (generated) by an exception. When a program uses a specially designed Statement (keyword try, catch, and finally) for exception handling, the program can arrange its error handling code in several concentrated areas, the try block is a normal process of program execution. When an exception occurs in the try block (including the sub-programs of each layer in the nested block), the control is handed over to the Catch Block. No matter whether an exception occurs or not, the code in the Finally block is always executed. Unhandled exceptions will be propagated from the call stack to the JVM from the bottom up and the program will be terminated. No need for hands-on programming to return the error status through several layers of function calls. However, when an error occurs, the code that detects the error directly throws an exception. This greatly simplifies the error handling code in the application, so as to get better error handling results and more solid and reliable code.

9. Linear support for thread management

Most operating systems provide a process with the ability to generate and manage multiple threads. These threads perform different tasks independently of each other. However, the program language rarely provides linear support for thread management. Generally, the operating system function needs to be called directly. Java, on the contrary, provides the function of generating, managing, and coordinating synchronization threads directly in the language. Like other features of Java, this function is necessary because the designer is not sure whether the underlying operating system supports multithreading.

Developers are increasingly using threads in their programs as a means to satisfy tasks that cannot be completed by a program. Because JAVA supports the built-in thread language, it is easier and more natural to create multiple threads in Java than other languages.

10. powerful graphics

JVM includes a large graph and window support package called abstract wing Toolkit (AWT ). With AWT, you can quickly and easily create exquisite and powerful graphic user interfaces in applications. For embedded systems that require refined user interfaces, AWT can save a lot of development time, from faster product development to market.
 
In some cases, many advantages of Java may become a stumbling block for its wide application in embedded systems. Therefore, continuous improvement is required. Here, the author puts forward some improvement suggestions for some limitations based on my own research.

Limitation 1: low performance

Because Java bytecode is 5 to 10 times slower than a similar C or C ++ Write Program, for some embedded systems that are not subject to CPU, this performance disadvantage is not a problem, but a slower speed will lead to unacceptable response times.

Solution

There are several possible solutions to ease the slow speed problem.

● Use a faster and more powerful processor to narrow the system response time to an acceptable range. However, this method will increase the cost of each system.

● Use the mother-tongue Java compiler to achieve better performance. However, in this way, the advantages irrelevant to the Java platform are abandoned. Fortunately, most embedded systems only run on one platform.

● Incorporate a JIT compiler into the system so that the Java class is compiled when loaded. However, if you have to add additional memory to accept the JIT compiler, this method will also increase system costs. In addition, if each part of the system is gradually added as needed, the program loading time should be controlled so that the pause generated when the class is loaded for compilation will not affect the system response time.

Limit 2: the overhead of the garbage collection system is too large.

Java's Automatic Memory Allocation and garbage collection performance are very affordable. However, from the perspective of a real-time system, the problem is that it is automatic. When garbage collection is in progress, developers have limited control over the system. Because it freezes the processing of the rest of the system during the garbage collection operation. This is because it must move objects in the memory and update all program variables that reference (point to) those objects before the program runs again. The time needed for garbage collection to be frozen depends on the amount of memory and the speed of the processor. Obviously, this is unacceptable for hard real-time systems. In extreme cases, it is also a problem for soft real-time systems.

Solution

Garbage collection is enabled in three ways. First, the JVM has a background garbage collection thread. This thread tends to start garbage collection as soon as it sees the system idle. If an event wants to wake up another thread, the background garbage collection will be occupied by this thread, but it will not be immediately occupied first. It must update all references to the objects that have been moved before a thread can run. Second, if the JVM does not find enough memory to meet a memory allocation request, it will start a garbage collection that will not be in the first place. Before this operation is completed, the rest of the system will be disabled. Finally, an application can start garbage collection by calling the systev. GC () method. Therefore, if you know that the system does not execute any key tasks in the time sequence, you can start garbage collection to avoid collection at a later time period.

Limitation 3: JVM memory overhead is too large

We have also discussed many built-in JVM features, such as the ratio and network, which allow Java programs to go public faster. The negative of all these features is the JVM memory overhead. Because JVM is a whole block (it must be completely adopted to achieve Java's portable purpose), the memory usage of JVM cannot be reduced. The current JVM requires at least 2 MB of memory.

Solution

If Java programs are also using some memory-consuming functions, each Java application can write a little less because there are so many functions in a JVM. If you create a system that dynamically downloads and runs multiple programs from the network, this will be a great advantage. However, Java is still not configurable and scalable.

Limitation 4: lack of direct hardware interface capabilities

Java lacks the ability to directly communicate with hardware interfaces. JVM is just a virtual machine, a software abstraction of hardware, Virtual Machine Control and the interface of actual hardware, and we can only deal with virtual machines.

Solution

However, this is not an insurmountable limitation. Many C programs use embedded assembly to avoid performance bottlenecks. Therefore, Java programs can also use C to obtain direct access to hardware.

There are two ways to let Java and C work together. First, you can use the local method. They are written in C/C ++ or another language, but when called, they are loaded into the same memory space as the JVM, run in the same environment. Because they are compiled into machine code, they run faster locally and can directly access the hardware. The local process and Java code communicate with each other through intercommunication, just as the intercommunication endpoint in the network. However, after the mixed language method is selected, Java has no platform-independent or security features.

In addition, you can consider using the Java processor mentioned above as the interpreter of the software JVM as a hardware implementation solution. Java programs can directly run and manipulate hardware on these processors. Note that special instructions must be added to the language to work directly with the processor.

Limit 5: the language is not mature enough

From the perspective of the standard programming language, Java is still very young and rough. If Java is not developed by a group, some errors and negligence may have been discovered and solved. After the appearance of Java, it was immediately used in more places than originally expected. All of this means that Java was initially conceived and implemented. Although solid and useful, it still lacks security, size, and performance.

In its further development, Sun took three steps to promote Java to become a common language and computer platform. First, Java programming is used to implement some functional activities of existing businesses and enterprises, such as email, calendar, and word processing programs. Second, Java is provided to enterprises, making it a method for writing internal applications. The last step is to define Java APIs and language functions for traditional embedded devices, such as mobile phones, set-top boxes, and printers.

It can be seen that the embedded applications of Java are at the end of Sun's schedule. Sun continues to develop the language for these purposes, but it will continue to develop for desktop and enterprise purposes. According to Sun's priority, it may take some time to solve some problems related to embedded applications. Prior to that, programmers of embedded systems may have to turn around, compromise, and use third-party solutions.

Java programming tools are still under development. Several manufacturers provide compilers and development tools, such as Symantec, Microsoft, and sun. Sun is no longer the only vendor of JVM and JIT, and the products of several other vendors are also very competitive. The jtest software of parasoft automatically generates test cases for the Java module, while the jcheck of numbench provides certain visibility for program behavior in JVM. However, both of them can only process a small part of the debugging program, and are designed for desktop system development, although they can also be used to embed the development process.

Currently, Java still has no cross-debugging solution, that is, the solution traditionally embedded into system developers to process programs on the target platform, therefore, you may need to use C/C ++ to write the hardware-specific part of the program. In any case, it is best for developers to use a C/C ++ interactive debugger to debug those code, and use a pop-up dialog box on the target system to maintain a record file or other skills to debug Java. (The author is a doctor of the School of mechanical and electrical engineering and automation, Shanghai University, e-mail: alanltnew@163.com)

Link: Java background

Java was initially designed to control consumer electronics, such as pagers, which are typical embedded devices. Java designers attempt to build a simple, object-oriented, intelligent, interpreted, powerful, secure, reasonably structured, portable, high-performance, multi-thread, dynamic Language. To make Java attractive to developers, Sun integrates the syntax and structure similar to the C language. However, regardless of the target, Java is proven to be unsuitable for small electronic devices, largely because it is too large and too slow. The processing capability and memory required by Java applications are too expensive for such devices.

Again, sun's most important design for Java is platform independence and network integration. A program that can run on several different hardware and software platforms without modification, for the network environment (in this environment, the user wants to be able to upload, download, and run programs on any machine in the Office) it is an ideal program. For developers who want to build distributed programs that communicate over the network and utilize online resources, a language with built-in and standard network support on any platform is a great benefit.

Fortunately, at the final stage of Java Development, the interest in the emerging commercial Internet reached a level of fanaticism. Therefore, Sun took the opportunity to advocate that Java was designed for the Internet. Many people have considered Java a tool that will bring Internet functions to the next level. Although Java has never been as common as originally expected on the internet, Java and its cousin JavaScript (a type created by Netscape, similar to the Java language used to write scripts on webpages) is already a Common Essential language for most commercial websites today.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.