Chapter 17 anomalies

javac produce the following sequence of bytecodes is REMAINDER () Method:

// The main bytecode sequence for remainder ();
// Push local variable 0 {arg passed as
0 iload_0 // dividend)
// Push the minimum integer value
1 ldc #1 <Integer -2147483648>

// If the dividend isn't equal to the minimum
// integer, jump to the remainder calculation
3 if_icmpne 19

// Push local variable 1 (arg pased as

6 iload_l // divisor)

// Push -1

7 iconst_ml

// If the divisor isn't equal to -1, jump
// to the remainder calculation

8 if_icmpne 19

// This is an overflow case, bo throw an
// exception. Create a new OverflowException,
// push reference to it onto the stack

11 new #4 <ClaBS OverflowException>
14 dup //make a copy of the reference

//Pop one copy of the reference and invoke
// the <init> method of new OverflowException
// object

15 invokeapecial #10 <Method OverflowException()>

// Pop the other reference to the
// OverflowException and throw it

18 athrow

// Calculate the remainder
// Puab local variable 0 (arg passed as
19 iload_0 // dividend)
// Push local variable 1 (arg passed as
20 iload_l // divisor)
// Pop divisor; pop dividend; calculate,push
21 irem // remainder
22 ireturn // Return int on top of stack (the remainder)

// The bytecode sequence for the
// catch (ArithmeticBxception) clause:

// Pop the reference to the
// ArithmoticException because it isn't used

23 pop //by this catch clause.

24 new #2 <Class DivideByZeroException>
// Create and push reference to new object of
// class DivideByZeroException.
// Duplicate the reference to the new object
// on the top of the stack because it must be
// both initialized and thrown. The
// initialization will consume the copy of the

27 dup // reference created by the dup,

// Call the no-arg <init> method for the
// DivideByZeroException to initialize it.

// This instruction will pop the top reference
// to the object.

28 invokespecial #9 <Method DivideByZeroException()>

// Fop the reference to a Throwable object, in
// this case the DivideByZeroException,

31 athrow // and throw the exception.
Method REMAINDER () bytecode sequence comprises two parts: the first is the normal method execution path, the portion refers to a pc pointer offset, 0-22; second part catch clause, the section refers pc pointer offset, 23-31.

// Overflow can occur in division when dividing
// the negative integer of the largest possible
// magnitude (Integer.MIN_VALUE) by -1, because
// this would Juat flip the sign, but there is no
// way to represent that nunber in an int.
if((dividend Integer.MIN_VALUE> &&(divisor==-1)){
throw new OverflowException();
}
所有作为Error和RuntimeException的子类的异常都是未检验的。

17.2 exception table
primary sequence of bytecodes in instruction ArithmeticException irem may throw an exception. If this occurs, Java virtual machine will look for abnormalities in the table, then jump to the byte code sequence implements the catch clause. Each method of capturing an abnormality is associated with the exception table, to the Class file byte code sequence along with the methods and exception table. Each of corresponding exceptions are captured with a try block entry (entry) in the exception table. Each entry in the exception table includes four pieces of information:

•starting point.

•end.

• pc offset pointer to jump to the byte code sequence.

• constant pool index exception classes captured.

The following is a table of exceptions remainder NitPickyMath class () method:

Exception table:

from to target type

I9 23 23 <Class java.lang.ArithmeticException>

Exception table described above, ArithmeticException abnormality pc pointer offset 19 to 22 (inclusive) are capturing. End value of the try block are listed in the "to" field. This value is always the end of the maximum-ratio-trapping pc pointer offset of a larger unusual locations. In this example, the end point is 23, the maximum offset catch exceptions pc position 22. Statement offset between 19 to 22 (inclusive) corresponding to a sequence of bytecodes implemented remainder () within the try block of code. target listed in column in the table indicates the throws exception if the pc ArithmeticException pointer offset, 19 to 22 (inclusive), pc pointer offset position to be jumped.

If an exception is thrown in the method of execution, Java virtual machine will search for items that match the entire exception table. If the current program counter exception table entry within the specified range, and the thrown exception is the class entry pointed to class (or subclass specified), then the entry is the desired entry search. Retrieve the Java virtual machine for each entry in the order appearing in the table. When faced with the first match, the virtual machine program counter to the new pc pointer offset position, and then continue from that location. If no match is found the item, the virtual machine will eject the current stack frame from the stack, the same exception is thrown again. When the Java Virtual Machine pop-up current stack frame, the virtual machine immediately terminate execution of the current method, and the method returns to the calling of this method, but this method does not proceed normally, but throw the same exception in this method, this makes the virtual machine to perform the same search operation exception table again in the process.

Java programmers can use the throw statement to throw an exception, as the remainder () methods catch (Arithmetic Exception) clause here to create an exception DivideByZcjroExceplion, and throw it. Throwing an exception operation performed byte code as shown in Table 17-1.

Athrow instruction stack is popped from the top of buildings, and it is assumed that a reference to an object, the object instance (or is an instance of the class Throwable) subclass of Throwable. The type of thrown objects referenced by the pop-up type of decision.

Guess you like

Origin www.cnblogs.com/mongotea/p/11980084.html