| C H A P T E R 17 |
|
Programming for the Large Address Space |
This chapter describes two ways in which you can take advantage of large memory storage in smart cards: by using library packages properly and by separating your data properly. This chapter also includes a sample.
The default address space automatically built in the RI is the large address space. Allowing your applications to take advantage of the large address capabilities of the Classic Edition RI requires careful planning and programming. Some size limitations still exist within the reference implementation. The way that you structure large applications, as well as applications that manage large amounts of data, determines how the large address space can be exploited.
The key to writing large applications for the Java Card 3 Platform, Classic Edition is to divide the code into individual package units. The most important limitation on a package is the 64KB limitation on the maximum component size. This is especially true for the Method component: if the size of an application’s Method component exceeds 64KB, then the Java Card converter will not process the package and will return an error.
You can overcome the component size limitation by dividing the application into separate application and library components. The Java Card platform has the ability to support library packages. Library packages contain code which can be linked and reused by several applications. By dividing the functionality of a given application into application and library packages, you can increase the size of the components. Keep in mind that there are important differences between library packages and applet packages:
Therefore, you should not place sensitive or exclusive-use code in a library package. It should be placed in an applet package, instead.
Several applications and API functionality can be installed in the smart card simultaneously by handling each package as a separate code space. This technique will let you exceed the 64KB limit, and provide full Java Card API functionality and support for complex applications requiring larger amounts of code.
The most efficient way to take advantage of the large memory space is to use it to store data. Today's applications are required to securely store ever-growing amounts of information about the cardholder or network identity. This information includes certificates, images, security keys, and biometric and biographical information.
This information sometimes requires large amounts of storage. Before version 2.2.2, versions of the Java Card platform reference implementation had to save downloaded applications or user data in valuable persistent memory space. Sometimes, the amount of memory space required was insufficient for some applications. However, the memory access schemes introduced with version 2.2.2 allow applications to store large amounts of information, while still conforming to the Java Card specification.
The Java Card specification does not impose any requirements on object location or total object heap space used on the card. It specifies only that each object must be accessible by using a 16-bit reference. It also imposes some limitations on the amount of information an individual object is capable of storing, by using the number of fields or the count of array elements. Because of this loose association, it is possible for any given implementation to control how an object’s information is stored, and how much data these objects can collectively hold.
The Java Card 3 Platform, Classic Edition reference implementation, allows you to use all of the available persistent memory space to store object information. By allowing you to separate data storage into distinct array and object types, this reference implementation allows you to store the large amounts of data demanded by today’s applications.
The photocard demo applet, included at samples/classic_applets/PhotoCard, is an example of an application that takes advantage of the large address space capabilities.
The photocard applet performs a very simple task: it stores pictures inside the smart card and retrieves them by using a Java Card RMI interface, see Chapter 15. For more information on the photocard demo applet and how to run it, see PhotoCard Sample. The source code is located in the source code bundle at:
JC_CLASSIC_HOME\samples\classic_applets\PhotoCard\applet\src\com\sun\jcclassic\samples\photocard
The collection of arrays (more than two arrays would be required in this case) can easily hold far more than 64KB of data. Storing this amount of information should not be a problem, provided that enough mutable persistent memory is configured in the RE.
Copyright © 2009 Sun Microsystems, Inc. All rights reserved.