📄 jcvm07instr.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"><HTML LANG="en"><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"><META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"><META NAME="GENERATOR" CONTENT="Adobe FrameMaker 7.0/HTML Export Filter"><LINK REL="STYLESHEET" HREF="unx_unstr_styles.css" CHARSET="ISO-8859-1" TYPE="text/css"><META name="DC.TITLE" content="Virtual Machine Specification, Java Card Platform, v2.2.2"><TITLE>C H A P T E R 7 - Java Card Virtual Machine Instruction Set </TITLE></HEAD><BODY BGCOLOR="#ffffff"><DIV><div class="navbar" align="center"><table dir="LTR" summary="Navigation bar, includes the book title and navigation buttons" width=100% cellpadding="0" cellspacing="0" border="0"><colgroup span="2" width="100%"><col id="1" span="1" width="50%"><col id="2" span="1" width="50%"><tr bgcolor="#cccccc"><td class="navbartitle" align=left rowspan="1" colspan="1" abbr="ChapTitle"> Virtual Machine Specification, Java Card Platform, v2.2.2</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="JCVM06cap.html"><img src="shared/prev01.gif" title="Previous Chapter" alt="Previous Chapter" width="30" height="26" border="0"></a><a href="JCVM08instrTables.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></table><br><br></div></DIV><TABLE DIR="LTR" SUMMARY="Chapter Number" ABBR="ChapNum" WIDTH="100%" BORDER="0"><COLGROUP SPAN="1" WIDTH="100%"><COL ID="1" SPAN="1"><TR><TD ALIGN="right" CLASS="ChapNumber"><SPAN CLASS="ChapNumPrefix"><A NAME="pgfId-6948"></A>C H A P T E R </SPAN> <SPAN CLASS="ChapNumNum">7</SPAN><A NAME="83338"></A></TD></TR></TABLE><TABLE DIR="LTR" SUMMARY="Chapter Title" ABBR="ChapTitle" WIDTH="100%" BORDER="0"><COLGROUP SPAN="1" WIDTH="100%"><COL ID="1" SPAN="1" WIDTH="100%"><TR><TD ALIGN="right" CLASS="ChapTitle"><HR SIZE=7 NOSHADE><A NAME="pgfId-6949"></A><A NAME="11178"></A>Java Card Virtual Machine <A NAME="marker-54552"></A>Instruction Set</TD></TR></TABLE><P CLASS="Paragraph"><A NAME="pgfId-6950"></A>A Java Card virtual machine instruction consists of an opcode specifying the operation to be performed, followed by zero or more operands embodying values to be operated upon. This chapter gives details about the format of each Java Card virtual machine instruction and the operation it performs.</P><H2 CLASS="Head1"><A NAME="pgfId-6951"></A><DIV><HR ALIGN=left SIZE=6 WIDTH=15% noshade></DIV>7.1 Assumptions: The Meaning of "<A NAME="marker-54553"></A>Must"</H2><P CLASS="Paragraph"><A NAME="pgfId-26294"></A>The description of each instruction is always given in the context of Java Card virtual machine code that satisfies the static and structural constraints of <A HREF="JCVM06cap.html#74217" CLASS="XRef">Chapter 6</A>, "The CAP File Format".</P><P CLASS="Paragraph"><A NAME="pgfId-26295"></A>In the description of individual Java Card virtual machine instructions, we frequently state that some situation "must" or "must not" be the case: "The value2 must be of type int." The constraints of <A HREF="JCVM06cap.html#74217" CLASS="XRef">Chapter 6</A> "The CAP File Format" guarantee that all such expectations will in fact be met. If some constraint (a "must" or "must not") in an instruction description is not satisfied at run time, the behavior of the Java Card virtual machine is undefined.</P><H2 CLASS="Head1"><A NAME="pgfId-6960"></A><DIV><HR ALIGN=left SIZE=6 WIDTH=15% noshade></DIV>7.2 Reserved <A NAME="marker-54554"></A>Opcodes</H2><P CLASS="Paragraph"><A NAME="pgfId-6961"></A>In addition to the opcodes of the instructions specified later this chapter, which are used in Java Card CAP files (see <A HREF="JCVM06cap.html#74217" CLASS="XRef">Chapter 6</A>, "The CAP File Format"), two opcodes are reserved for internal use by a Java Card virtual machine implementation. If Sun Microsystems, Inc. extends the instruction set of the Java Card virtual machine in the future, these reserved opcodes are guaranteed not to be used.</P><P CLASS="Paragraph"><A NAME="pgfId-6962"></A>The two reserved opcodes, numbers 254 (0xfe) and 255 (0xff), have the mnemonics impdep1 and impdep2, respectively. These instructions are intended to provide "back doors" or traps to implementation-specific functionality implemented in software and hardware, respectively.</P><P CLASS="Paragraph"><A NAME="pgfId-6963"></A>Although these opcodes have been reserved, they may only be used inside a Java Card virtual machine implementation. They cannot appear in valid CAP files.</P><H2 CLASS="Head1"><A NAME="pgfId-6964"></A><DIV><HR ALIGN=left SIZE=6 WIDTH=15% noshade></DIV>7.3 Virtual Machine <A NAME="marker-54555"></A>Errors</H2><P CLASS="Paragraph"><A NAME="pgfId-1006533"></A>A Java Card virtual machine may encounter internal errors or resource limitations that prevent it from executing correctly written Java programs. While The Java Virtual Machine Specification allows reporting and handling of virtual machine errors, it also states that they cannot ordinarily be handled by application code. This Virtual Machine Specification for the Java Card Platform, v2.2.2 is more restrictive in that it does not allow for any reporting or handling of unrecoverable virtual machine errors at the application code level. A virtual machine error is considered unrecoverable if further execution could compromise the security or correct operation of the virtual machine or underlying system software. When an unrecoverable error occurs, the virtual machine will halt bytecode execution. Responses beyond halting the virtual machine are implementation-specific policies and are not mandated in this specification.</P><P CLASS="Paragraph"><A NAME="pgfId-27036"></A>In the case where the virtual machine encounters a recoverable error, such as insufficient memory to allocate a new object, it will throw a SystemException with an error code describing the error condition. The Virtual Machine Specification for the Java Card Platform, v2.2.2 cannot predict where resource limitations or internal errors may be encountered and does not mandate precisely when they can be reported. Thus, a SystemException may be thrown at any time during the operation of the Java Card virtual machine.</P><H2 CLASS="Head1"><A NAME="pgfId-6969"></A><DIV><HR ALIGN=left SIZE=6 WIDTH=15% noshade></DIV>7.4 Security <A NAME="marker-54556"></A>Exceptions</H2><P CLASS="Paragraph"><A NAME="pgfId-6970"></A>Instructions of the Java Card virtual machine throw an instance of the class SecurityException when a security violation has been detected. The Java Card virtual machine does not mandate the complete set of security violations that can or will result in an exception being thrown. However, there is a minimum set that must be supported.</P><P CLASS="Paragraph"><A NAME="pgfId-1003636"></A>In the general case, any instruction that de-references an object reference must throw a SecurityException if the context (<A HREF="JCVM03structVM.html#33311" CLASS="XRef">Section 3.4, Contexts</A>) in which the instruction is executing is different than the owning context (<A HREF="JCVM03structVM.html#33311" CLASS="XRef">Section 3.4, Contexts</A>) of the referenced object. The list of instructions includes the instance field get and put instructions, the array load and store instructions, as well as the arraylength, invokeinterface, invokespecial, invokevirtual, checkcast, instanceof and athrow instructions.</P><P CLASS="Paragraph"><A NAME="pgfId-26037"></A>There are several exceptions to this general rule that allow cross-context use of objects or arrays. These exceptions are detailed in Chapter 6 of the <EM CLASS="Emphasis">Runtime Environment Specification for the Java Card Platform, Version 2.2.2</EM>. An important detail to note is that any cross-context method invocation will result in a context switch (<A HREF="JCVM03structVM.html#33311" CLASS="XRef">Section 3.4, Contexts</A>).</P><P CLASS="Paragraph"><A NAME="pgfId-6972"></A>The Java Card virtual machine may also throw a SecurityException if an instruction violates any of the static constraints of <A HREF="JCVM06cap.html#74217" CLASS="XRef">Chapter 6</A>, "The CAP File Format". The <EM CLASS="Emphasis">Virtual Machine Specification for the Java Card Platform, Version 2.2.2</EM> does not mandate which instructions must implement these additional security checks, or to what level. Therefore, a <KBD CLASS="Filename-Command">SecurityException</KBD> may be thrown at any time during the operation of the Java Card virtual machine.</P><H2 CLASS="Head1"><A NAME="pgfId-6979"></A><DIV><HR ALIGN=left SIZE=6 WIDTH=15% noshade></DIV>7.5 The Java Card Virtual Machine Instruction Set</H2><P CLASS="Paragraph"><A NAME="pgfId-6980"></A>Java virtual machine instructions are represented in this chapter by entries of the form shown in <A HREF="JCVM07instr.html#38563" CLASS="XRef">TABLE 7-1</A>, an example instruction page, in alphabetical order.</P><TABLE CLASS="TitledNoRules" BORDER=0 BORDERCOLORLIGHT="#FFFFFF" BORDERCOLORDARK="#000000" CELLPADDING=5 CELLSPACING=0><CAPTION CLASS="TableCaption"><A NAME="pgfId-1017850"> </A> TABLE 7-1 <A NAME="38563"> </A> Example Instruction Page </CAPTION><TR><TD ROWSPAN="1" COLSPAN="1"><P CLASS="TableText"><A NAME="pgfId-1017770"></A>mnemonic</P><P CLASS="TableText"><A NAME="pgfId-1017800"></A>Short description of the instruction.</P><P CLASS="TableText"><A NAME="pgfId-1017807"></A>Format</P><P CLASS="TableText"><A NAME="pgfId-1017808"></A>mnemonic</P><P CLASS="TableText"><A NAME="pgfId-1017809"></A>operand1</P><P CLASS="TableText"><A NAME="pgfId-1017810"></A>operand2</P><P CLASS="TableText"><A NAME="pgfId-1017812"></A>...</P><P CLASS="TableText"><A NAME="pgfId-1017813"></A>Forms</P><P CLASS="TableText"><A NAME="pgfId-1017875"></A>mnemonic = opcode</P><P CLASS="TableText"><A NAME="pgfId-1017832"></A>Stack</P><P CLASS="TableText"><A NAME="pgfId-1017833"></A>..., value1, value2 -></P><P CLASS="TableText"><A NAME="pgfId-1017834"></A>.../ value3</P><P CLASS="TableText"><A NAME="pgfId-1017840"></A>Description</P><P CLASS="TableText"><A NAME="pgfId-1017841"></A>A longer description detailing constraints on operand stack contents or constant pool entries, the operation performed, the type of the results, and so on.</P><P CLASS="TableText"><A NAME="pgfId-1017842"></A>Runtime Exception</P><P CLASS="TableText"><A NAME="pgfId-1017843"></A>If any runtime exceptions can be thrown by the execution of an instruction, that instruction must not throw any runtime exceptions except for instances of System Exception.</P><P CLASS="TableText"><A NAME="pgfId-1017844"></A>Notes </P><P CLASS="TableText"><A NAME="pgfId-1017848"></A>Commands not strictly part of the specification of an instruction are set aside as notes at the end of the description.</P></TD></TR></TABLE><ENDTABLEOBJECT CLASS="EndTableObject"><A NAME="pgfId-1024223"></A> </ENDTABLEOBJECT><P CLASS="Paragraph"><A NAME="pgfId-1006773"></A>Each cell in the instruction format diagram represents a single 8-bit byte. The instruction's <A NAME="marker-1006774"></A>mnemonic is its name. Its opcode is its numeric representation and is given in both decimal and hexadecimal forms. Only the numeric representation is actually present in the Java Card virtual machine code in a CAP file.</P><P CLASS="Paragraph"><A NAME="pgfId-7006"></A>Keep in mind that there are "operands" generated at compile time and embedded within Java Card virtual machine instructions, as well as "operands" calculated at run time and supplied on the operand stack. Although they are supplied from several different areas, all these operands represent the same thing: values to be operated upon by the Java Card virtual machine instruction being executed. By implicitly taking many of its operands from its operand stack, rather than representing them explicitly in its compiled code as additional operand bytes, register numbers, etc., the Java Card virtual machine's code stays compact.</P><P CLASS="Paragraph"><A NAME="pgfId-7007"></A>Some instructions are presented as members of a family of related instructions sharing a single description, format, and operand stack diagram. As such, a family of instructions includes several opcodes and opcode mnemonics; only the family mnemonic appears in the instruction format diagram, and a separate forms line lists all member mnemonics and opcodes. For example, the forms line for the sconst_<s> family of instructions, giving mnemonic and opcode information for the two instructions in that family (sconst_0 and sconst_1), is</P><P CLASS="Paragraph"><A NAME="pgfId-26189"></A>Forms sconst_0 = 3 (0x3), <BR> sconst_1 = 4 (0x4)</P><P CLASS="Paragraph"><A NAME="pgfId-26191"></A>In the description of the Java Card virtual machine instructions, the effect of an instruction's execution on the operand stack (<A HREF="JCVM03structVM.html#13656" CLASS="XRef">Section 3.5, Frames</A>) of the current frame (<A HREF="JCVM03structVM.html#13656" CLASS="XRef">Section 3.5, Frames</A>) is represented textually, with the stack growing from left to right and each word represented separately. Thus,</P><P CLASS="Paragraph"><A NAME="pgfId-7013"></A>Stack..., value1, value2 -><BR> ..., result</P><P CLASS="Paragraph"><A NAME="pgfId-7015"></A>shows an operation that begins by having a one-word value2 on top of the operand stack with a one-word value1 just beneath it. As a result of the execution of the instruction, value1 and value2 are popped from the operand stack and replaced by a one-word result, which has been calculated by the instruction. The remainder of the operand stack, represented by an ellipsis (...), is unaffected by the instruction's execution.</P><P CLASS="Paragraph"><A NAME="pgfId-7016"></A>The type int takes two words on the operand stack. In the operand stack representation, each word is represented separately using a dot notation:</P><P CLASS="Paragraph"><A NAME="pgfId-7018"></A>Stack..., value1.word1, value1.word2, value2.word1, value2.word2 -><BR> ..., result.word1, result.word2</P><P CLASS="Paragraph"><A NAME="pgfId-7020"></A>The Virtual Machine Specification for the Java Card Platform, v2.2.2 does not mandate how the two words are used to represent the 32-bit int value; it only requires that a particular implementation be internally consistent.</P><H3 CLASS="Head2"><A NAME="pgfId-7021"></A>7.5.1 <A NAME="marker-54559"></A>aaload</H3><P CLASS="Paragraph"><A NAME="pgfId-7022"></A>Load reference from array</P><P CLASS="Paragraph"><A NAME="pgfId-7023"></A>Format</P><BR><TABLE CLASS="Titled" BORDER=1 BORDERCOLORLIGHT="#FFFFFF" BORDERCOLORDARK="#000000" CELLPADDING=5 CELLSPACING=0 BORDER="1" DIR="LTR"><CAPTION></CAPTION><TBODY><TR><TD SCOPE="ROW" ROWSPAN="1" COLSPAN="1"><P CLASS="TableText"><A NAME="pgfId-997849"></A><I CLASS="Variable">aaload</I></P></TD></TR></TBODY></TABLE><BR><P CLASS="Paragraph"><A NAME="pgfId-7025"></A>Forms</P><P CLASS="Paragraph"><A NAME="pgfId-7026"></A>aaload = 36 (0x24)</P><P CLASS="Paragraph"><A NAME="pgfId-7027"></A>Stack</P><P CLASS="Paragraph"><A NAME="pgfId-7028"></A>..., arrayref, index -><BR>..., value</P><P CLASS="Paragraph"><A NAME="pgfId-7029"></A>Description</P><P CLASS="Paragraph"><A NAME="pgfId-7030"></A>The arrayref must be of type reference and must refer to an array whose components are of type reference. The index must be of type short. Both arrayref and index are popped from the operand stack. The reference value in the component of the array at index is retrieved and pushed onto the top of the operand stack.</P><P CLASS="Paragraph"><A NAME="pgfId-7031"></A>Runtime Exceptions</P><P CLASS="Paragraph"><A NAME="pgfId-7032"></A>If arrayref is null, aaload throws a NullPointerException.</P><P CLASS="Paragraph"><A NAME="pgfId-7033"></A>Otherwise, if index is not within the bounds of the array referenced by arrayref, the aaload instruction throws an ArrayIndexOutOfBoundsException.</P><P CLASS="Paragraph"><A NAME="pgfId-26607"></A>Notes</P><P CLASS="Paragraph"><A NAME="pgfId-54243"></A>In some circumstances, the aaload instruction may throw a SecurityException if the current context (<A HREF="JCVM03structVM.html#33311" CLASS="XRef">Section 3.4, Contexts</A>) is not the owning context (<A HREF="JCVM03structVM.html#33311" CLASS="XRef">Section 3.4, Contexts</A>) of the array referenced by arrayref. The exact circumstances when the exception will be thrown are specified in Chapter 6 of the <EM CLASS="Emphasis">Runtime Environment Specification, Java Card Platform, Version 2.2.2</EM>.</P><H3 CLASS="Head2"><A NAME="pgfId-54253"></A>7.5.2 <A NAME="marker-54560"></A>aastore</H3><P CLASS="Paragraph"><A NAME="pgfId-50790"></A>Store into reference array</P><P CLASS="Paragraph"><A NAME="pgfId-7036"></A>Format </P><BR><TABLE CLASS="Titled" BORDER=1 BORDERCOLORLIGHT="#FFFFFF" BORDERCOLORDARK="#000000" CELLPADDING=5 CELLSPACING=0 BORDER="1" DIR="LTR"><CAPTION></CAPTION><TBODY><TR><TD SCOPE="ROW" ROWSPAN="1" COLSPAN="1"><P CLASS="TableText"><A NAME="pgfId-18662"></A><I CLASS="Variable">aastore</I></P></TD></TR></TBODY></TABLE><BR><P CLASS="Paragraph"><A NAME="pgfId-7038"></A>Forms</P><P CLASS="Paragraph"><A NAME="pgfId-7039"></A>aastore = 55 (0x37)</P><P CLASS="Paragraph"><A NAME="pgfId-7040"></A>Stack</P><P CLASS="Paragraph"><A NAME="pgfId-7041"></A>..., arrayref, index, value -><BR>...</P><P CLASS="Paragraph"><A NAME="pgfId-7042"></A>Description</P><P CLASS="Paragraph"><A NAME="pgfId-7043"></A>The arrayref must be of type reference and must refer to an array whose components are of type reference. The index must be of type short and the value must be of type reference. The arrayref, index and value are popped from the operand stack. The reference value is stored as the component of the array at index.</P><P CLASS="Paragraph"><A NAME="pgfId-7044"></A>At runtime the type of value must be confirmed to be assignment compatible with the type of the components of the array referenced by arrayref. Assignment of a value of reference type S (source) to a variable of reference type T (target) is allowed only when the type S supports all of the operations defined on type T. The detailed rules follow:</P><UL><LI CLASS="Bullet1"><A NAME="pgfId-48247"></A>If S is a class type, then:</LI><P CLASS="Linebreak"></P><UL><LI CLASS="Bullet2"><A NAME="pgfId-48248"></A>If T is a class type, then S must be the same class as T, or S must be a subclass of T;</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet2"><A NAME="pgfId-48249"></A>If T is an interface type, then S must implement interface T.</LI><P CLASS="Linebreak"></P></UL><LI CLASS="Bullet1"><A NAME="pgfId-48250"></A>If S is an interface type<A NAME="fnote1"></A><A HREF="#pgfId-53399" CLASS="footnote"><SUP>[1]</SUP></A>, then:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -