📄 jcvm04naming.html
字号:
<h4 class="Head3"><a name="pgfId-998639"></a>4.3.7.6 <a name="22193"></a>Virtual<a name="marker-998638"></a>Methods</h4><p class="Paragraph"><a name="pgfId-7135"></a>Virtual methods areinstance methods that are resolved dynamically. The set includes allpublic, protected and package-visible instance methods. Privateinstance methods and all constructors are not virtual methods, butinstead are resolved statically during compilation.</p><p class="Paragraph"><a name="pgfId-13233"></a>All virtual methodsdefined in a package are assigned either public or private <a name="marker-14194"></a>virtual method tokens. Virtual method tokenvalues must be in the range from 0 to 127, inclusive. Public andprivate tokens for virtual methods are assigned from differentnamespaces. The high bit of the byte containing a virtual method tokenis set to one if the token is a private token.</p><p class="Paragraph"><a name="pgfId-7136"></a>Public tokens for theexternally visible (public or protected) introduced virtual methods ina class are numbered consecutively starting at one greater than thehighest numbered public virtual method token of the class's superclass.If a method overrides a method implemented in the class's superclass,that method is assigned the same token number as the method in thesuperclass. The high bit of the byte containing a public virtual methodtoken is always set to zero, to indicate it is a public token. Theordering of public virtual method tokens in a class is not specified.</p><p class="Paragraph"><a name="pgfId-7137"></a>Private virtual methodtokens are assigned to package-visible virtual methods. They areassigned differently from public virtual method tokens. If a class andits superclass are defined in the same package, the tokens for thepackage-visible introduced virtual methods in that class are numberedconsecutively starting at one greater than the highest numbered privatevirtual method token of the class's superclass. If the class and itssuperclass are defined in different packages, the tokens for thepackage-visible introduced virtual methods in that class are numberedconsecutively starting at zero. If a method overrides a methodimplemented in the class's superclass, that method uses the same tokennumber as the method in the superclass. The definition of the Javaprogramming language specifies that overriding a package-visiblevirtual method is only possible if both the class and its superclassare defined in the same package. The high bit of the byte containing avirtual method token is always set to one, to indicate it is a privatetoken. The ordering of private virtual method tokens in a class is notspecified.</p><h4 class="Head3"><a name="pgfId-7138"></a>4.3.7.7 <a name="17038"></a>InterfaceMethods</h4><p class="Paragraph"><a name="pgfId-7139"></a>All interface methodsdefined in a package are assigned public<a name="marker-14195"></a>interface method tokens, as interface methods are always public.Interface methods tokens values must be in the range from 0 to 127,inclusive. The tokens for all the interface methods defined in orinherited by an interface are numbered consecutively starting at zero.The token value for an interface method in a given interface isunrelated to the token values of that same method in any of theinterface's superinterfaces. Each interface includes its own tokenvalues for all the methods inherited from super-interfaces as well asits defined methods. The high bit of the byte containing an interfacemethod token is always set to zero, to indicate it is a public token.The ordering of interface method tokens is not specified.</p><h2 class="Head1"><a name="pgfId-8240"></a><div><hr align="left" size="6" width="15%" noshade="noshade"></div>4.4 <a name="36343"></a>Binary <a name="marker-14196"></a>Compatibility</h2><p class="Paragraph"><a name="pgfId-8241"></a>In the Java programminglanguage the granularity of binary compatibility can be between classessince binaries are stored in individual class files. In Java Cardsystems Java packages are processed as a single unit, and therefore thegranularity of binary compatibility is between packages. In Java Cardsystems the binary of a package is represented in a CAP file, and theAPI of a package is represented in an export file.</p><p class="Paragraph"><a name="pgfId-8242"></a>In a Java Card system, achange to a type in a Java package results in a new CAP file. A new CAPfile is binary compatible with (equivalently, does not breakcompatibility with) a preexisting CAP file if another CAP fileconverted using the export file of the preexisting CAP file can linkwith the new CAP file without errors.</p><p class="Paragraph"><a name="pgfId-8243"></a>shows an example ofbinary compatible CAP files, p1 and p1'. The preconditions for theexample are: the package p1 is converted to create the p1 CAP file andp1 export file, and package p1 is modified and converted to create thep1' CAP file. Package p2 imports package p1, and therefore when the p2CAP file is created the export file of p1 is used. In the example, p2is converted using the original p1 export file. Because p1' is binarycompatible with p1, p2 may be linked with either the p1 CAP file or thep1' CAP file.<br><br></p><p class="FigureBox">FIGURE 4-2 Binary Compatibility Example<a name="pgfId-1002353"></a><a name="pgfId-1002354"></a> </p><img src="figures/JCVM04naming-5.jpg" align="bottom"><br><p class="Paragraph"><a name="pgfId-9072"></a>Any modification thatcauses binary incompatibility in the Java programming language alsocauses binary incompatibility in Java Card systems. These modificationsare described as causing a potential error in The Java LanguageSpecification. Any modification that does not cause binaryincompatibility in the Java programming language does not cause binaryincompatibility in a Java Card system, except under the followingconditions:</p><ul> <li class="Bullet1"><a name="pgfId-9074"></a>The value of a tokenassigned to an element in the API of a package is changed. </li> <p class="Linebreak"> </p> <li class="Bullet1"><a name="pgfId-8252"></a>The value of anexternally visible final static field (compile-time constant) ischanged. </li> <p class="Linebreak"> </p> <li class="Bullet1"><a name="pgfId-8254"></a>An externally visiblevirtual method that does not override a preexisting method is added toa non-final public class. </li> <p class="Linebreak"> </p> <li class="Bullet1"><a name="pgfId-996880"></a>An externally visibleinterface method that does not override a preexisting method is addedto a public interface. </li> <p class="Linebreak"> </p></ul><p class="Paragraph"><a name="pgfId-8255"></a>Tokens are used toresolve references to imported elements of a package. If a token valueis modified, a linker on a device is unable to associate the new tokenvalue with the previous token value of the element, and therefore isunable to resolve the reference correctly.</p><p class="Paragraph"><a name="pgfId-12468"></a>Compile-time constantsare not stored as fields in CAP files. Instead their values arerecorded in export files and placed inline in the bytecodes in CAPfiles. These values are said to be pre-linked in a CAP file of apackage that imports those constants. During execution, information isnot available to determine whether the value of an inlined constant isthe same as the value defined by the binary of the imported package.</p><p class="Paragraph"><a name="pgfId-12472"></a>As described above,tokens assigned to public and protected virtual methods are scoped tothe hierarchy of a class. Tokens assigned to public and protectedvirtual methods introduced in a subclass have values starting at onegreater than the maximum token value assigned in a superclass. If anew, non-override, public or protected virtual method is introduced ina superclass it is assigned a token value that would otherwise havebeen assigned in a subclass. Therefore, two unique virtual methodscould be assigned the same token value within the same class hierarchy,making resolution of a reference to one of the methods ambiguous.</p><p class="Paragraph"><a name="pgfId-997060"></a>The addition of anexternally visible, non-override method to a public interface is abinary incompatible change. It allows classes which are not themselvesabstract to contain an abstract method. For example, consider the caseof an interface I implemented by a class C that is not abstract, whereI and C reside in different packages. If a new method is added to I,creating I', then C cannot link with the new version of I' because thiswould result in the class C containing an abstract method without theclass C being abstract. The fact that C can not link with I' means thatI and I' are not binary compatible.</p><h2 class="Head1"><a name="pgfId-9139"></a><div><hr align="left" size="6" width="15%" noshade="noshade"></div>4.5 <a name="12240"></a>Package <a name="marker-14197"></a>Versions</h2><p class="Paragraph"><a name="pgfId-12845"></a>Each implementation of apackage in a Java Card system is assigned a pair of major and minorversion numbers. These version numbers are used to indicate binarycompatibility or incompatibility between successive implementations ofa package.</p><h3 class="Head2"><a name="pgfId-9342"></a>4.5.1 Assigning</h3><p class="Paragraph"><a name="pgfId-12850"></a>The major and minorversions of a package are assigned by the package provider. It isrecommended that the initial implementation of a package be assigned amajor version of 1 and a minor version of 0. However, any values may bechosen. It is also recommended that when either a major or a minorversion is incremented, it is incremented exactly by 1.</p><p class="Paragraph"><a name="pgfId-12855"></a>A major version must bechanged when a new implementation of a package is not binary compatiblewith the previous implementation. The value of the new major versionmust be greater than the major version of the previous implementation.When a major version is changed, the associated minor version must beassigned the value of 0.</p><p class="Paragraph"><a name="pgfId-12860"></a>When a newimplementation of a package is binary compatible with the previousimplementation, it must be assigned a major version equal to the majorversion of the previous implementation. The minor version assigned tothe new implementation must be greater than the minor version of theprevious implementation.</p><h3 class="Head2"><a name="pgfId-9346"></a>4.5.2 Linking<a name="marker-14198"></a></h3><p class="Paragraph"><a name="pgfId-12865"></a>Both an export file anda CAP file contain the major and minor version numbers of the packagedescribed. When a CAP file is installed on a Java Cardtechnology-enabled device a resident imag<a name="marker-14199"></a>eof the package is created, and the major and minor version numbers arerecorded as part of that image. When an export file is used duringpreparation of a CAP file, the version numbers indicated in the exportfile are recorded in the CAP file.</p><p class="Paragraph"><a name="pgfId-12771"></a>During installation,references from the package of the CAP file being installed to animported package can be resolved only when the version numbersindicated in the export file used during preparation of the CAP fileare compatible with the version numbers of the resident image. They arecompatible when the major version numbers are equal and the minorversion of the export file is less than or equal to the minor versionof the resident image.</p><div class="navbar" align="center"><br><br><table dir="ltr" summary="Navigation bar, includes the book title and navigation buttons" width="100%" cellpadding="0" cellspacing="0" border="0"> <colgroup span="3" width="100%"><col id="1" span="1" width="45%"><col id="2" span="1" width="25%"><col id="3" span="1" width="30%"></colgroup><tbody> <tr bgcolor="#cccccc"> <td class="navbartitle" align="left" rowspan="1" colspan="1" abbr="ChapTitle"> Virtual Machine Specification, Java CardPlatform, v2.2.2 </td> <td class="navbartitle" align="right" rowspan="1" colspan="1" abbr="PartNum">3-11-06 </td> <td valign="top" align="right" rowspan="1" colspan="1" abbr="NavButtons"><a href="index.html"><img src="shared/toc01.gif" title="Table Of Contents" alt="Table Of Contents" width="30" height="26" border="0"></a><a href="JCVM03structVM.html"><img src="shared/prev01.gif" title="Previous Chapter" alt="Previous Chapter" width="30" height="26" border="0"></a><a href="JCVM05export.html"><img src="shared/next01.gif" title="Next Chapter" alt="Next Chapter" width="30" height="26" border="0"></a><a href="ix.html"><img src="shared/index01.gif" title="Book Index" alt="Book Index" width="30" height="26" border="0"></a> </td> </tr> </tbody></table><br><br></div><p class="copyrightlink"><a href="copyright.html">Copyright</a> ©2005, Sun Microsystems, Inc. All Rights Reserved.</p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -