< prev index next >

src/java.base/share/classes/jdk/internal/misc/Blocker.java

Print this page

 50     private static final JavaLangAccess JLA;
 51     static {
 52         JLA = SharedSecrets.getJavaLangAccess();
 53         if (JLA == null) {
 54             throw new InternalError("JavaLangAccess not setup");
 55         }
 56     }
 57 
 58     private Blocker() { }
 59 
 60     private static Thread currentCarrierThread() {
 61         return JLA.currentCarrierThread();
 62     }
 63 
 64     /**
 65      * Marks the beginning of a possibly blocking operation.
 66      * @return the return value from the attempt to compensate or -1 if not attempted
 67      */
 68     public static long begin() {
 69         if (VM.isBooted()

 70                 && currentCarrierThread() instanceof CarrierThread ct && !ct.inBlocking()) {
 71             ct.beginBlocking();
 72             boolean completed = false;
 73             try {
 74                 long comp = ForkJoinPools.beginCompensatedBlock(ct.getPool());
 75                 assert currentCarrierThread() == ct;
 76                 completed = true;
 77                 return comp;
 78             } finally {
 79                 if (!completed) {
 80                     ct.endBlocking();
 81                 }
 82             }
 83         }
 84         return -1;
 85     }
 86 
 87     /**
 88      * Marks the beginning of a possibly blocking operation.
 89      * @param blocking true if the operation may block, otherwise false

 50     private static final JavaLangAccess JLA;
 51     static {
 52         JLA = SharedSecrets.getJavaLangAccess();
 53         if (JLA == null) {
 54             throw new InternalError("JavaLangAccess not setup");
 55         }
 56     }
 57 
 58     private Blocker() { }
 59 
 60     private static Thread currentCarrierThread() {
 61         return JLA.currentCarrierThread();
 62     }
 63 
 64     /**
 65      * Marks the beginning of a possibly blocking operation.
 66      * @return the return value from the attempt to compensate or -1 if not attempted
 67      */
 68     public static long begin() {
 69         if (VM.isBooted()
 70                 && Thread.currentThread().isVirtual()
 71                 && currentCarrierThread() instanceof CarrierThread ct && !ct.inBlocking()) {
 72             ct.beginBlocking();
 73             boolean completed = false;
 74             try {
 75                 long comp = ForkJoinPools.beginCompensatedBlock(ct.getPool());
 76                 assert currentCarrierThread() == ct;
 77                 completed = true;
 78                 return comp;
 79             } finally {
 80                 if (!completed) {
 81                     ct.endBlocking();
 82                 }
 83             }
 84         }
 85         return -1;
 86     }
 87 
 88     /**
 89      * Marks the beginning of a possibly blocking operation.
 90      * @param blocking true if the operation may block, otherwise false
< prev index next >