001    /*
002     *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003     *
004     *  This file is licensed to You under the Eclipse Public License (EPL);
005     *  You may not use this file except in compliance with the License. You
006     *  may obtain a copy of the License at
007     *
008     *      http://www.opensource.org/licenses/eclipse-1.0.php
009     *
010     *  See the COPYRIGHT.txt file distributed with this work for information
011     *  regarding copyright ownership.
012     */
013    package org.jikesrvm.scheduler;
014    
015    import org.vmmagic.pragma.Uninterruptible;
016    import org.vmmagic.pragma.Unpreemptible;
017    import org.vmmagic.pragma.NonMoving;
018    import org.vmmagic.pragma.NoOptCompile;
019    import org.vmmagic.pragma.NoInline;
020    import org.jikesrvm.VM;
021    
022    /**
023     * A heavy condition variable and lock that also disables interrupts while
024     * the lock is held.  Extremely useful for any locks that may be acquired,
025     * released, or waited upon in the process of performing a GC.
026     * <p>
027     * Note that calling any of the Nicely methods on an instance of this
028     * class is extremely dangerous.  These methods may cause you to block on
029     * GC, which seemingly goes against the very intent of this being a "no
030     * interrupts" condition variable and lock.  However, it makes a subtle
031     * kind of sense to use these methods, <i>if you're calling them on the
032     * instance of NoInterruptsCondLock that your thread will wait on when
033     * blocking on GC</i>.  This idiom is used quite a bit.
034     * <p>
035     * To ensure that the Nicely methods are used correctly - that is, that
036     * they are only used by the thread that owns the lock - there are assertions
037     * in place to ensure that the caller is the owner.
038     */
039    @Uninterruptible
040    @NonMoving
041    public class NoYieldpointsMonitor extends Monitor {
042      @Override
043      @NoInline
044      @NoOptCompile
045      public void lockNoHandshake() {
046        VM.disableYieldpoints();
047        super.lockNoHandshake();
048      }
049    
050      // This method is strange
051      @Override
052      @Unpreemptible
053      @NoInline
054      @NoOptCompile
055      public void lockWithHandshake() {
056        VM.disableYieldpoints();
057        super.lockWithHandshake();
058      }
059    
060      @Override
061      @NoInline
062      @NoOptCompile
063      public void unlock() {
064        super.unlock();
065        VM.enableYieldpoints();
066      }
067    }
068