J2ME Programming/MIDlet Preverify

< J2ME Programming

A MIDlet is a Java program for embedded devices, more specifically the J2ME virtual machine. Generally, these are games and applications that run on a cell phone.

Introduction

Since class verification in J2SE takes up 50 KB and the lack of space in MIDP devices, the class verification has been broken up to a part that is completed by the developer and apart completed by the Mobile JVM itself. The developer-directed class verification stage is called MIDlet preverification, which occurs after the class is compiled.

What Tasks Preverification Completes

Generally, the preverification task annotates the class files with notes that the small incomplete class verifier in the Mobile VM reads and uses to do a fast class verification to enable the Mobile VM to then run the resulting bytecodes. The resulting bytecodes are valid bytecodes, because the annotations are using attributes of the bytecode to make the notes for the Mobile VM to read in doing its final incomplete class verification.[1].

JVM Class File Verification

According to The Java Virtual Machine Specification,[2] class file verification is completed in four passes before full startup of the JVM occurs in running bytecode of an application:

Pass 1

Pass 2

Pass 3

During linking, the verifier checks the code array of the code attribute by performing a data flow analysis to ensure these items are true:

Pass 4

This is the pass where class loading occurs to finalize the class verification process.

Preverification steps

Conclusion

Preverification preverifies the compiled classes by inserting annotations in the StackMap portion of the Code attribute describing variable types used and operand stack items. This and inlining all subroutines and removing jumps reduces the first three passes of the J2SE verification process to something more manageable with the mobile device memory sizes in completing the last fourth pass on the mobile device within the mobile jvm.

Trademark Notices

J2ME, Java and all Java-based marks are trademarks or registered trademarks of ORACLE in the U.S. and other countries.

References

  1. "What is preverification?". What is preverification? Why do I receive error messages from the CLDC/KVM when I do not preverify my class files?. http://www.jguru.com/faq/view.jsp?EID=201507.
  2. "VM Spec". The Java Virtual Machine Specification. http://java.sun.com/docs/books/vmspec/2nd-edition/html/VMSpecTOC.doc.html. ISBN 0201432943
  3. ("Ubiquitous Services". Ubiquitous Services Services on Mobile Devices. http://www.nm.ifi.lmu.de/Vorlesungen/ws0405/ubiserv/07-devices-10.01.05.pdf.
  4. "J2ME Tutorial, Part 1: Creating MIDlets?". By default, the preverifier will create the preverified version of your class file in a folder called output in the current directory. It will preserve the package structure….. http://today.java.net/pub/a/today/2005/02/09/j2me1.html?page=2#step4.

See also

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.