📄 appa.html
字号:
<!-- All material contained herein is copyright (c) McGraw-Hill Professional Books
All Rights Reserved. No use of this material may be made without express written
permission of the copyright holder. HTML conversions by Mega Space [barry@megaspace.com] -->
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<TITLE>Understanding Digital Signatures: Inside the Java Virtual Machine
by Bill Venners - Beta Version</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<TABLE BORDER="0" WIDTH="100%">
<TR><TD><A HREF="http://www.pbg.mcgraw-hill.com/betabooks/stores.html" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/stores.html" target="bottom"><IMG SRC="hotkey.gif" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/images/hotkey.gif" ALIGN="LEFT" BORDER="0" WIDTH="40" HEIGHT="40" ALT="Orders"></A>
<IMG SRC="order_text.gif" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/images/order_text.gif" WIDTH="103" HEIGHT="41" ALT="Orders"></TD>
<TD ALIGN="RIGHT"><A HREF="chap20.html" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/venners/chap20.html"><IMG SRC="backward.gif" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/images/backward.gif" BORDER="0" ALT="Backward" WIDTH="32" HEIGHT="32"></A> <A HREF="appb.html" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/venners/appb.html"><IMG SRC="forward.gif" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/images/forward.gif" BORDER="0" ALT="Forward" WIDTH="32" HEIGHT="32"></A></TD></TR>
<TR><TD COLSPAN="2"><A HREF="mailto:computing@mcgraw-hill.com"><IMG SRC="hotkey.gif" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/images/hotkey.gif" ALIGN="LEFT" BORDER="0" WIDTH="40" HEIGHT="40" ALT="Comments"></A>
<IMG SRC="comment_text.gif" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/images/comment_text.gif" WIDTH="73" HEIGHT="39" ALT="Comments"></TD></TR>
<TR><TD COLSPAN="2"><FONT FACE="ARIEL,HELVETICA" SIZE="-1"><I>© 1997 The McGraw-Hill Companies, Inc. All rights reserved. <BR>Any use of this Beta Book is subject to the rules stated in the <A HREF="http://www.mcgraw-hill.com/corporate/news_info/copyrttm.htm" tppabs="http://www.mcgraw-hill.com/corporate/news_info/copyrttm.htm" target="_top">Terms of Use</A>.</I></FONT><br>
<script language="javascript">
document.write("<a href='http://banners.linkbuddies.com/click.php?id=237296'><img src='http://banners.linkbuddies.com/image.php?id=237296&ref=" + document.referrer + "' width=468 height=60 alt='Click Here' border=0></a>");
</script></TD></TR>
</TABLE>
<HR>
<P><H1>Appendix A</H1></P>
<P><H2>Instruction Set by Opcode Mnemonic</H2></P>
<P>Appendix A lists Java Virtual Machine instructions in alphabetical order by opcode mnemonic. All 201 instructions that may legally appear in the bytecode streams stored in Java class files are described in detail in Appendix A.</P>
<P>Besides the opcodes for the 201 instructions that may appear in class files, the Java Virtual Machine specification describes two other families of opcodes: the reserved opcodes and the "<FONT FACE="Courier New">_quick</FONT>" opcodes. None of these opcodes can legally appear in the bytecode streams of Java class files.</P>
<P>The Java Virtual Machine specification lists three reserved opcodes, which are shown in Table A-1. These opcodes are reserved for internal use by Java Virtual Machine implementations and tools. The specification guarantees that these three opcodes will not be part of any future extension of the Java Virtual Machine韘 instruction set. As you may have guessed, the intended purpose of the <FONT FACE="Courier New">breakpoint</FONT> opcode is to provide a way for debuggers to implement breakpoints. The intended purpose of the other two reserved opcodes, <FONT FACE="Courier New">impdep1</FONT> and <FONT FACE="Courier New">impdep2</FONT>, is to serve as "back doors" to implementation-dependent software functionality or "traps" to implementation-dependent hardware functionality. </P>
<P>Table A-1. The reserved opcodes</P>
<TABLE WIDTH="500">
<TR><TD VALIGN="TOP"><STRONG>mnemonic</STRONG></TD><TD VALIGN="TOP"><STRONG>byte value</STRONG></TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">breakpoint</FONT></TD><TD VALIGN="TOP">202 (0xca)</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">impdep1</FONT></TD><TD VALIGN="TOP">254 (0xfe)</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">impdep2</FONT></TD><TD VALIGN="TOP">255 (0xff)</TD></TR>
</TABLE>
<P>The Java Virtual Machine specification also lists 25 "<FONT FACE="Courier New">_quick</FONT>" opcodes, which Sun韘 virtual machine implementation uses internally to speed up the interpreted execution of bytecodes. This optimization technique is described in general in this book in Chapter 8, "The Linking Model," but the individual "<FONT FACE="Courier New">_quick</FONT>" instructions are not described in detail in Appendix A. (The "<FONT FACE="Courier New">_quick</FONT>" opcodes do appear in Appendix C, which lists their mnemonics and corresponding opcode byte values.) Like the reserved opcodes, the "<FONT FACE="Courier New">_quick</FONT>" opcodes may not legally appear in Java class files. But unlike the reserved opcodes, the Java Virtual Machine specification leaves open the possibility that these opcodes will take on new meanings in future extensions of the instruction set.</P>
<P>For each instruction listed in Appendix A, you will find the following information:</P>
<UL>
<LI> the mnemonic
<LI> a short description
<LI> the opcode韘 byte value in decimal and hex
<LI> the format of the instruction
<LI> the operand stack before and after the instruction is executed
<LI> a description of any constraints associated with the instruction
<LI> a description of the execution of the instruction
<LI> a description of any exceptions or errors that may be thrown by the instruction
</UL>
<P>The format of each instruction appears as a list of comma-separated items next to the label "Instruction Format," with each item representing one byte in the bytecode stream. The opcode mnemonic appears first (in fixed-width font), followed by any operands (shown in italics).</P>
<P>For each instruction, Appendix A shows two snapshots of the operand stack. One snapshot, labelled "Before," shows the contents of the current method韘 operand stack just before the instruction is executed. The other snapshot, labelled "After," shows the operand stack immediately after execution of the instruction. In both snapshots, the operand stack appears as a list of comma-separated items, with each item representing one word. Although everywhere else in this book the operand stack is shown growing downwards (the top of the stack appears at the bottom of the picture), in Appendix A the operand stack is shown growing sideways, from left to right. In each snapshot, the top of the stack is the rightmost item shown. Unaffected portions of the operand stack are shown as an elipsis, "...".</P>
<P>For each instruction, the section labelled "Description" combines three kinds of information: constraints, the process of execution, and exceptions and errors. As mentioned in Chapter 3, "Security," Java Virtual Machine implementations are required to enforce at run-time certain constraints on the bytecodes of every method they execute. Whenever you see the word "must" in an instruction韘 description in Appendix A, you are reading about a constraint every implementation must enforce when executing the instruction. For example, the <FONT FACE="Courier New">goto</FONT> instruction, which causes an unconditional jump, may only cause a jump to another opcode of the same method. In Appendix A韘 description for <FONT FACE="Courier New">goto</FONT>, this constraint is stated as, "The target address <I>must</I> be the address of an opcode within the same method as the <FONT FACE="Courier New">goto</FONT> opcode."</P>
<P>The designers of each individual Java Virtual Machine implementation can decide how and when to detect violations of the bytecode constraints. If any implementation detects a constraint violation, it must report the violation by throwing a <FONT FACE="Courier New">VerifyError</FONT> when (and if) the running program attempts to execute the instruction.</P>
<P>In addition to describing the constraints placed on each instruction, Appendix A describes the process of executing each instruction and lists any errors or exceptions that may be thrown during the course of executing the instruction. Besides the errors and exceptions explicitly listed in the instruction descriptions, one other family of errors, subclasses of <FONT FACE="Courier New">VirtualMachineError</FONT>, can be thrown at any time as the result of executing any instruction. Four subclasses of <FONT FACE="Courier New">VirtualMachineError</FONT>, and the circumstances under which they will be thrown, are:</P>
<UL>
<LI> <FONT FACE="Courier New">OutOfMemoryError</FONT> - the virtual machine has run out of real or virtual memory, and the garbage collector can韙 reclaim enough space to enable the thread to continue.
<LI> <FONT FACE="Courier New">StackOverflowError</FONT> - a thread has exhausted its supply of memory for stack space (usually because the application has an unbounded recursion).
<LI> <FONT FACE="Courier New">InternalError</FONT> - the virtual machine has encountered a bug in its own implementation that prevents it from properly implementing the semantics of the Java language.
<LI> <FONT FACE="Courier New">UnknownError</FONT> - the virtual machine has encountered some error condition, but is unable to report the actual condition by throwing the appropriate exception or error.
</UL>
<P><H3><FONT FACE="Courier New">aaload</H3></FONT> - Load <FONT FACE="Courier New">reference</FONT> from array</P>
<P><H3>Opcode:</H3> 50 (0x32)</P>
<P><H3>Instruction Format:</H3> <FONT FACE="Courier New">aaload</FONT></P>
<P><H3>Stack:</H3></P>
<P>Before:<I>..., arrayref, index</P></EM></H4>
<P>After:<I>..., value</P></EM></H4>
<P><H3>Description:</H3></P>
<P>To execute the <FONT FACE="Courier New">iaload</FONT> instruction, the Java Virtual Machine first pops two words from the operand stack. The <I>arrayref</I> word must be a <FONT FACE="Courier New">reference</FONT> that refers to an array of <FONT FACE="Courier New">reference</FONT>s. The <I>index</I> word must be an <FONT FACE="Courier New">int</FONT>. The virtual machine retrieves from the <I>arrayref</I> array the <FONT FACE="Courier New">reference</FONT> <I>value</I> specified by <I>index</I> and pushes it onto the operand stack.</P>
<P>If <I>arrayref</I> is <FONT FACE="Courier New">null</FONT>, the Java Virtual Machine throws <FONT FACE="Courier New">NullPointerException</FONT>. Otherwise, if <I>index</I> is not a legal index into the <I>arrayref</I> array, the virtual machine throws <FONT FACE="Courier New">ArrayIndexOutOfBoundsException</FONT>.</P>
<P>For more information about the <FONT FACE="Courier New">aaload</FONT> instruction, see Chapter 15, "Objects and Arrays."</P>
<P><H3><FONT FACE="Courier New">aastore</H3></FONT> - Store <FONT FACE="Courier New">reference</FONT> into array</P>
<P><H3>Opcode:</H3> 83 (0x53)</P>
<P><H3>Instruction Format:</H3> <FONT FACE="Courier New">aastore</FONT></P>
<P><H3>Stack:</H3></P>
<P>Before:<I>..., arrayref, index, value</P></EM></H4>
<P>After:<I>...</P></EM></H4>
<P><H3>Description:</H3></P>
<P>To execute the <FONT FACE="Courier New">aaload</FONT> instruction, the Java Virtual Machine first pops three words from the operand stack. The <I>arrayref</I> word must be a <FONT FACE="Courier New">reference</FONT> that refers to an array of <FONT FACE="Courier New">float</FONT>s. The <I>index</I> word must be an <FONT FACE="Courier New">int</FONT>, and the <I>value</I> word must be a <FONT FACE="Courier New">reference</FONT>. The type of <I>value</I> must be assignment compatible with the component type of the <I>arrayref</I> array. The virtual machine stores <FONT FACE="Courier New">reference</FONT> <I>value</I> into the <I>arrayref</I> array location specified by <I>index</I>.</P>
<P>If <I>arrayref</I> is <FONT FACE="Courier New">null</FONT>, the Java Virtual Machine throws <FONT FACE="Courier New">NullPointerException</FONT>. Else, if <I>index</I> is not a legal index into the <I>arrayref</I> array, the virtual machine throws <FONT FACE="Courier New">ArrayIndexOutOfBoundsException</FONT>. Otherwise, if the actual type of <I>value</I> is not assignment compatible with the actual type of the components of the <I>arrayref</I> array, the virtual machine throws <FONT FACE="Courier New">ArrayStoreException</FONT>.</P>
<P>For more information about the <FONT FACE="Courier New">aastore</FONT> instruction, see Chapter 15, "Objects and Arrays."</P>
<P><H3><FONT FACE="Courier New">aconst_null</H3></FONT> - Push <FONT FACE="Courier New">null</FONT> object reference</P>
<P><H3>Opcode:</H3> 1 (0x1)</P>
<P><H3>Instruction Format:</H3> <FONT FACE="Courier New">aconst_null</FONT></P>
<P><H3>Stack:</H3></P>
<P>Before:<I>...</P></EM></H4>
<P>After:<I>..., null</P></EM></H4>
<P><H3>Description:</H3></P>
<P>To execute the <FONT FACE="Courier New">aconst_null</FONT> instruction, the Java Virtual Machine pushes a <FONT FACE="Courier New">null</FONT> object reference onto the operand stack. (Note that the Java Virtual Machine specification does not dictate any actual value for <FONT FACE="Courier New">null</FONT>. The specification leaves that decision to the designers of each individual implementation.)</P>
<P>For more information about the <FONT FACE="Courier New">aconst_null</FONT> instruction, see Chapter 10, "Stack Operations."</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -