Sun Microsystems, Inc.
4150 Network Circle
Santa Clara, California 95054
U.S.A. 650-960-1300
KVM Porting Guide
CLDC, Version 1.1
Java™ 2 Platform, Micro Edition
March, 2003
Please
Recycle
Copyright © 2003 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved.
Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is described in this
document. In particular, and without limitation, these intellectual property rights may include one or more of the U.S. patents listed
at http://www.sun.com/patents and one or more additional patents or pending patent applications in the U.S. and in other
countries.
This document and the product to which it pertains are distributed under licenses restricting their use, copying, distribution, and
decompilation. No part of the product or of this document may be reproduced in any form by any means without prior written
authorization of Sun and its licensors, if any.
Third-party software, including font technology, is copyrighted and licensed from Sun suppliers.
Sun, Sun Microsystems, the Sun logo, Java, J2ME, K Virtual Machine (KVM), and Java Developer Connection are trademarks or
registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
The Adobe® logo is a registered trademark of Adobe Systems, Incorporated.
Federal Acquisitions: Commercial Software - Government Users Subject to Standard License Terms and Conditions.
DOCUMENTATION IS PROVIDED "AS IS" AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR FOR A PARTICULAR
PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD
TO BE LEGALLY INVALID.
Copyright © 2003 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, Etats-Unis. Tous droits réservés.
Sun Microsystems, Inc. a les droits de propriété intellectuels relatants à la technologie incorporée dans le produit qui est décrit dans
ce document. En particulier, et sans la limitation, ces droits de propriété intellectuels peuvent inclure un ou plus des brevets
américains énumérés à http://www.sun.com/patents et un ou les brevets plus supplémentaires ou les applications de brevet
en attente dans les Etats - Unis et dans les autres pays.
Ce produit ou document est protégé par un copyright et distribué avec des licences qui en restreignent l’utilisation, la copie, la
distribution, et la décompilation. Aucune partie de ce produit ou document ne peut être reproduite sous aucune forme, parquelque
moyen que ce soit, sans l’autorisation préalable et écrite de Sun et de ses bailleurs de licence, s’il y ena.
Le logiciel détenu par des tiers, et qui comprend la technologie relative aux polices de caractères, est protégé par un copyright et
licencié par des fournisseurs de Sun.
Sun, Sun Microsystems, le logo Sun, Java, J2ME, K Virtual Machine (KVM), et Java Developer Connection sont des marques de
fabrique ou des marques déposées de Sun Microsystems, Inc. aux Etats-Unis et dans d’autres pays.
Le logo Adobe® est une marque déposée de Adobe Systems, Incorporated.
LA DOCUMENTATION EST FOURNIE "EN L’ÉTAT" ET TOUTES AUTRES CONDITIONS, DECLARATIONS ET GARANTIES
EXPRESSES OU TACITES SONT FORMELLEMENT EXCLUES, DANS LA MESURE AUTORISEE PAR LA LOI APPLICABLE, Y
COMPRIS NOTAMMENT TOUTE GARANTIE IMPLICITE RELATIVE A LA QUALITE MARCHANDE, A L’APTITUDE A UNE
UTILISATION PARTICULIERE OU A L’ABSENCE DE CONTREFAÇON.
iii
Contents
1. About This Document 1
1.1 Who should use this document 1
1.2 Related documentation 1
2. Introduction to KVM 3
2.1 K Virtual Machine (KVM) 3
2.2 Differences between KVM 1.1 and KVM 1.0.3/4 4
3. Compiler Requirements 7
4. Required Port-Specific Files and Functions 9
4.1 File machine_md.h 9
4.2 File main.c 10
4.3 Runtime functions that require porting efforts 10
4.4 Required C library functions 12
5. Directory Structure 13
5.1 Overview 13
5.2 Directory kvm/VmCommon 14
5.3 Directory kvm/VmExtra 16
5.4 Directory kvm/VmExtra/src/fp 17
6. Compilation Flags, Definitions and Macros 19
6.1 General compilation options 19
iv KVM Porting Guide • March, 2003
6.2 General system configuration options 20
6.3 Palm-specific system configuration options 21
6.4 Memory allocation settings 22
6.5 Garbage collection options 23
6.6 Class loading options 23
6.7 Interpreter execution options (since KVM 1.0) 23
6.8 Interpreter execution techniques (after KVM 1.0.2) 24
6.8.1 Copying the virtual machine registers to local variables 25
6.8.2 Splitting uncommon bytecodes into a separate subroutine 26
6.8.3 Moving the test for thread rescheduling to branchpoints 27
6.8.4 Padding out the bytecode space 27
6.9 Java-level debugging options 27
6.10 VM-level debugging and tracing options 28
6.10.1 Including and excluding debugging code 28
6.10.2 Tracing options 29
6.11 Error handling macros 30
6.12 Miscellaneous macros and options 31
6.13 Overriding the compilation flags and other options from makefiles 31
7. Virtual Machine Startup 33
7.1 Command line startup 33
7.2 Alternative VM startup strategies 34
7.3 Using a JAM (Java Application Manager) 34
8. Class Loading, JAR Files, and Inflation 37
8.1 Porting the class file loading interface 38
8.2 JAR file reader 39
8.2.1 Opening a JAR file 39
8.2.2 Closing a JAR file 40
8.2.3 Reading a JAR file entry 40
8.2.4 Reading multiple JAR file directory 41
8.3 Inflation 42
Contents v
9. 64-bit Support 43
9.1 Setup 43
9.2 Alignment issues 44
10. Floating-Point Support 47
10.1 Introduction 47
10.1.1 IEEE 754 floating-point 47
10.1.2 Implementing Java virtual machine floating-point semantics 48
10.1.3 Java virtual machine floating-point semantics: strictfp 49
10.1.4 Floating-point architectures 50
10.1.4.2.2Generating FP-strict code in C 53
10.1.4.2.3Default floating-point 53
10.1.4.3 Other architectures 53
10.2 Floating-point support in the virtual machine 54
10.2.1 Floating-point bytecodes implementation 54
10.3 CLDC 1.1 floating-point libraries and trigonometric functions 54
10.4 Porting 55
10.4.1 SPARC 56
10.4.2 ARM 56
10.4.3 x86 56
11. Native Code 59
11.1 Using the K Native Interface (KNI) 60
11.2 Implementing old-style native methods 60
11.2.1 Include files 61
11.2.2 Accessing arguments from old-style native methods 61
11.2.3 Returning a result from an old-style native function 62
11.2.4 Shortcuts 62
11.2.5 Callbacks 63
11.2.6 Exception handling in old-style native code 63
11.2.7 Useful functions in old-style native code 63
11.2.8 Garbage collection issues 64
11.2.9 Initialization and reinitialization of global variables 69