180 |
|
volatile Completion stack; // Top of Treiber stack of dependent actions |
181 |
|
|
182 |
|
final boolean internalComplete(Object r) { // CAS from null to r |
183 |
< |
return UNSAFE.compareAndSwapObject(this, RESULT, null, r); |
183 |
> |
return U.compareAndSwapObject(this, RESULT, null, r); |
184 |
|
} |
185 |
|
|
186 |
|
final boolean casStack(Completion cmp, Completion val) { |
187 |
< |
return UNSAFE.compareAndSwapObject(this, STACK, cmp, val); |
187 |
> |
return U.compareAndSwapObject(this, STACK, cmp, val); |
188 |
|
} |
189 |
|
|
190 |
|
/** Returns true if successfully pushed c onto stack. */ |
191 |
|
final boolean tryPushStack(Completion c) { |
192 |
|
Completion h = stack; |
193 |
|
lazySetNext(c, h); |
194 |
< |
return UNSAFE.compareAndSwapObject(this, STACK, h, c); |
194 |
> |
return U.compareAndSwapObject(this, STACK, h, c); |
195 |
|
} |
196 |
|
|
197 |
|
/** Unconditionally pushes c onto stack, retrying if necessary. */ |
211 |
|
|
212 |
|
/** Completes with the null value, unless already completed. */ |
213 |
|
final boolean completeNull() { |
214 |
< |
return UNSAFE.compareAndSwapObject(this, RESULT, null, |
214 |
> |
return U.compareAndSwapObject(this, RESULT, null, |
215 |
|
NIL); |
216 |
|
} |
217 |
|
|
222 |
|
|
223 |
|
/** Completes with a non-exceptional result, unless already completed. */ |
224 |
|
final boolean completeValue(T t) { |
225 |
< |
return UNSAFE.compareAndSwapObject(this, RESULT, null, |
225 |
> |
return U.compareAndSwapObject(this, RESULT, null, |
226 |
|
(t == null) ? NIL : t); |
227 |
|
} |
228 |
|
|
237 |
|
|
238 |
|
/** Completes with an exceptional result, unless already completed. */ |
239 |
|
final boolean completeThrowable(Throwable x) { |
240 |
< |
return UNSAFE.compareAndSwapObject(this, RESULT, null, |
240 |
> |
return U.compareAndSwapObject(this, RESULT, null, |
241 |
|
encodeThrowable(x)); |
242 |
|
} |
243 |
|
|
265 |
|
* existing CompletionException. |
266 |
|
*/ |
267 |
|
final boolean completeThrowable(Throwable x, Object r) { |
268 |
< |
return UNSAFE.compareAndSwapObject(this, RESULT, null, |
268 |
> |
return U.compareAndSwapObject(this, RESULT, null, |
269 |
|
encodeThrowable(x, r)); |
270 |
|
} |
271 |
|
|
295 |
|
* If exceptional, r is first coerced to a CompletionException. |
296 |
|
*/ |
297 |
|
final boolean completeRelay(Object r) { |
298 |
< |
return UNSAFE.compareAndSwapObject(this, RESULT, null, |
298 |
> |
return U.compareAndSwapObject(this, RESULT, null, |
299 |
|
encodeRelay(r)); |
300 |
|
} |
301 |
|
|
407 |
|
} |
408 |
|
|
409 |
|
static void lazySetNext(Completion c, Completion next) { |
410 |
< |
UNSAFE.putOrderedObject(c, NEXT, next); |
410 |
> |
U.putOrderedObject(c, NEXT, next); |
411 |
|
} |
412 |
|
|
413 |
|
/** |
2318 |
|
} |
2319 |
|
|
2320 |
|
// Unsafe mechanics |
2321 |
< |
private static final sun.misc.Unsafe UNSAFE; |
2321 |
> |
private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe(); |
2322 |
|
private static final long RESULT; |
2323 |
|
private static final long STACK; |
2324 |
|
private static final long NEXT; |
2325 |
|
static { |
2326 |
|
try { |
2327 |
< |
final sun.misc.Unsafe u; |
2328 |
< |
UNSAFE = u = sun.misc.Unsafe.getUnsafe(); |
2329 |
< |
Class<?> k = CompletableFuture.class; |
2330 |
< |
RESULT = u.objectFieldOffset(k.getDeclaredField("result")); |
2331 |
< |
STACK = u.objectFieldOffset(k.getDeclaredField("stack")); |
2332 |
< |
NEXT = u.objectFieldOffset |
2327 |
> |
RESULT = U.objectFieldOffset |
2328 |
> |
(CompletableFuture.class.getDeclaredField("result")); |
2329 |
> |
STACK = U.objectFieldOffset |
2330 |
> |
(CompletableFuture.class.getDeclaredField("stack")); |
2331 |
> |
NEXT = U.objectFieldOffset |
2332 |
|
(Completion.class.getDeclaredField("next")); |
2333 |
|
} catch (ReflectiveOperationException e) { |
2334 |
|
throw new Error(e); |