![](https://csdnimg.cn/release/download_crawler_static/4701340/bg10.jpg)
Adobe ActionScript Virtual Machine 2 (AVM2) Overview 16
3.3.4 Execution mechanics
Execution begins with the first instruction of the code in the method_body_info. The address of this first
instruction is 0. The first byte of each instruction is the opcode, which is followed by zero or more bytes of
operands. The instruction may modify the local data areas as well as objects on the heap, and it may create new
objects on the heap either directly or indirectly. (The AVM2 instruction set is defined in Section 2.5.)
Branch and jump instructions add a signed offset to the program counter to effectuate the branch. The base
value for the program counter is the instruction address following the instruction.
3.3.5 Calling and returning
When one of the call instructions is executed, a new local data area is created for the called function. The called
function has no access to the local data area of its caller. The actual parameter values are coerced to the types
expected by the called function as part of the call protocol.
The return instructions transfer a single value from the returning function’s stack, or the implied value
undefined, to the caller. The returned value is coerced to the returning function’s declared return type as part
of the return protocol. The coerced value replaces the operands of the call instruction in the calling method’s
stack, and the called method’s local data area is destroyed.
3.3.6 Exception handling
Exception handlers are defined by a table associated with each method. The table defines a range of bytecode
addresses across which a particular handler is active, the bytecode address of the handler, and a type which is
used to determine whether the handler will handle a particular exception.
When an exception is thrown, the call stack is unwound until a method is found that contains a handler which
covers the current program counter and whose type is a supertype of the type of the object thrown. The
method containing the handler is reactivated and the program counter is set to point to the first address of the
handler. The value and scope stacks in the handling method are cleared before the handler is entered.
A
finally clause is normally translated as an exception handler that accepts any type of value, which it catches
and rethrows after the body of the
finally block finishes executing.
3.4 Verification
As noted earlier, verification does not happen all at once. Verification is often put off until a datum is actually
needed or until some dependent object has been loaded, so that forward references will be possible.
The following list summarizes some of the verification errors signaled by the AVM2. (Not all verification errors
are listed.)
• There must be no nonzero bits above bit 30 in a u30 value.
• No control flow instruction must cause control to be transferred outside the code vector or into the
middle of another instruction.
• Multiple control flow instructions to the same instruction must have compatible scope stacks, operand
stacks, and register values.
• Named types (for example, in
coerce instructions or in a base class reference) must always be
uniquely resolvable.
• Names may not reference index zero of the name pool unless explicitly specified for that particular
name field.