Re: 答复: What is a structured locking in the JVM specification?

joe darcy joe.darcy at oracle.com
Thu May 18 00:15:12 UTC 2017


This is not an alias for question about the JVM specification.

Please direct your questions to a more suitable forum.

Regards,

-Joe Darcy


On 5/17/2017 5:00 PM, 陈雨亭 wrote:
> The original explanation is given as: "Structured locking is the situation
> when, during a method invocation, every exit on a given monitor matches a
> preceding entry on that monitor. Since there is no assurance that all code
> submitted to the Java Virtual Machine will perform structured locking,
> implementations of the Java Virtual Machine are permitted but not required
> to enforce both of the following two rules guaranteeing structured locking.
> Let T be a thread and M be a monitor. Then: (1) The number of monitor
> entries performed by T on M during a method invocation must equal the number
> of monitor exits performed by T on M during the method invocation whether
> the method invocation completes normally or abruptly. (2) At no point during
> a method invocation may the number of monitor exits performed by T on M
> since the method invocation exceed the number of monitor entries performed
> by T on M since the method invocation."
>
> I retested some programs on HotSpot and IBM's J9. It seems that HotSpot
> takes Rule 1 (rule1 is stricter than rule2, and J9 throws out an
> IllegalMonitorStateException at runtime) and J9 only takes Rule 2 (accepting
> the program). As the exception can be caught (with further exception
> handlings), some of my programs run quite differently on the two platforms.
>
> f(){
>     monitorenter r0;
> }
> g(){
>     f();
>     monitorexit r0;
> }
>
> -----邮件原件-----
> 发件人: csr-discuss [mailto:csr-discuss-bounces at openjdk.java.net] 代表 陈雨
>> 发送时间: 2017年5月17日 14:08
> 收件人: csr-discuss at openjdk.java.net
> 主题: What is a structured locking in the JVM specification?
>
> According to the definition, it seems that a structured locking appears
> like: Monitorenter r0; …monitorenter r0; …; monitorexit r0; …monitorexit
> r0;
>
>    * The definition is given as follows: Structured locking is the situation
> when, during a method invocation, every exit on a given monitor matches a
> preceding entry on that monitor.
> (https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-2.html#jvms-2.11.10
> )
>
>   
>
> I’m a little curious whether a structured locking can be composed by the
> following instructions:
>
> Monitorenter r0; monitorenter r2; …; monitorexit r0; monitorexit r2;
>
>   
>
> In addition, should this sequence be accepted or rejected? At runtime or
> during the verification time?
>
>   
>
> Yuting
>
>   
>



More information about the csr-discuss mailing list