| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | 
 | 2 |  | 
 | 3 | <html> | 
 | 4 |  | 
 | 5 | <head> | 
 | 6 | <title>monitor-exit</title> | 
 | 7 | <link rel=stylesheet href="opcode.css"> | 
 | 8 | </head> | 
 | 9 |  | 
 | 10 | <body> | 
 | 11 |  | 
 | 12 | <h1>monitor-exit</h1> | 
 | 13 |  | 
 | 14 | <h2>Purpose</h2> | 
 | 15 |  | 
 | 16 | <p> | 
 | 17 | Release the monitor for the indicated object. | 
 | 18 | </p> | 
 | 19 | <p> | 
 | 20 | Note: If this instruction needs to throw an exception, it must do so as if the | 
 | 21 | pc has already advanced past the instruction. It may be useful to think of this | 
 | 22 | as the instruction successfully executing (in a sense), and the exception | 
 | 23 | getting thrown after the instruction but before the next one gets a chance to | 
 | 24 | run. This definition makes it possible for a method to use a monitor cleanup | 
 | 25 | catch-all (e.g., finally) block as the monitor cleanup for that block itself, | 
 | 26 | as a way to handle the arbitrary exceptions that might get thrown due to the | 
 | 27 | historical implementation of Thread.stop(), while still managing to have proper | 
| Carl Shapiro | de75089 | 2010-06-08 16:37:12 -0700 | [diff] [blame] | 28 | monitor hygiene. | 
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 29 | </p> | 
 | 30 |  | 
 | 31 | <h2>Details</h2> | 
 | 32 |  | 
 | 33 | <table class="instruc"> | 
 | 34 | <thead> | 
 | 35 | <tr> | 
 | 36 |   <th>Op & Format</th> | 
 | 37 |   <th>Mnemonic / Syntax</th> | 
 | 38 |   <th>Arguments</th> | 
 | 39 | </tr> | 
 | 40 | </thead> | 
 | 41 | <tbody> | 
 | 42 | <tr> | 
 | 43 |   <td>1e 11x</td> | 
 | 44 |   <td>monitor-exit vAA</td> | 
 | 45 |   <td><code>A:</code> reference-bearing register (8 bits)</td> | 
 | 46 | </tr> | 
 | 47 | </tbody> | 
 | 48 | </table> | 
 | 49 |  | 
 | 50 | <h2>Constraints</h2> | 
 | 51 |  | 
 | 52 | <ul> | 
 | 53 |   <li> | 
 | 54 |     A must be a valid register index for the current stack frame. | 
 | 55 |   </li> | 
 | 56 |   <li> | 
 | 57 |     Register vA must contain a reference to an object. | 
 | 58 |   </li> | 
 | 59 | </ul> | 
| Carl Shapiro | de75089 | 2010-06-08 16:37:12 -0700 | [diff] [blame] | 60 |  | 
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 61 | <h2>Behavior</h2> | 
 | 62 |  | 
 | 63 | <ul> | 
 | 64 |   <li> | 
 | 65 |     An attempt is made for the current thread to release the monitor of the | 
 | 66 |     indicated object. | 
 | 67 |   </li> | 
 | 68 |   <li> | 
 | 69 |     If the current thread is the owner, the following happens: | 
 | 70 |     <ul> | 
 | 71 |       <li> | 
 | 72 |         The monitor's entry count is decreased by one. | 
 | 73 |       </li> | 
 | 74 |       <li> | 
 | 75 |         If the entry count has reached zero, the monitor is released. Other | 
 | 76 |         threads waiting for the same monitor have a chance to acquire it. | 
 | 77 |       </li> | 
 | 78 |     </ul> | 
 | 79 |   </li> | 
 | 80 |   <li> | 
 | 81 |     Any exception that gets thrown by this instruction bears the PC of the | 
 | 82 |     instruction following the monitor-exit. That is, from the point of view of | 
 | 83 |     an exception handler it cannot be distinguished from the same type of | 
 | 84 |     exception being thrown immediately after the monitor-exit instruction. | 
 | 85 |   </li> | 
| Carl Shapiro | de75089 | 2010-06-08 16:37:12 -0700 | [diff] [blame] | 86 | </ul> | 
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 87 |  | 
 | 88 | <h2>Exceptions</h2> | 
 | 89 |  | 
 | 90 | <ul> | 
 | 91 |   <li> | 
 | 92 |     NullPointerException is thrown if vA is null. | 
 | 93 |   </li> | 
 | 94 |   <li> | 
 | 95 |     IllegalMonitorStateException is thrown if the current thread is not the | 
 | 96 |     owner of that monitor. | 
 | 97 |   </li> | 
 | 98 | </ul> | 
 | 99 |  | 
 | 100 | </body> | 
 | 101 | </html> |