Skip to content

Commit

Permalink
Remove unguarded volatile load
Browse files Browse the repository at this point in the history
  • Loading branch information
franz1981 committed Feb 13, 2024
1 parent a25c127 commit 92bc2e5
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,16 @@ private void implementComputeIfAbsent(ClassCreator contextInstances, List<BeanIn
// }
// Lock lock = lazy1l();
// lock.lock();
// copy = this.1;
// if (copy != null) {
// lock.unlock();
// return copy;

// try {
// if (this.1 == null) {
// this.1 = supplier.get();
// }
// copy = supplier.get();
// this.1 = copy;
// lock.unlock();
// return this.1;
// return copy;
// } catch(Throwable t) {
// lock.unlock();
// throw t;
Expand All @@ -304,17 +308,18 @@ private void implementComputeIfAbsent(ClassCreator contextInstances, List<BeanIn
compute.ifNotNull(copy).trueBranch().returnValue(copy);
ResultHandle lock = compute.invokeVirtualMethod(lazyLocks.get(bean.getIdentifier()), compute.getThis());
compute.invokeInterfaceMethod(MethodDescriptors.LOCK_LOCK, lock);
copy = compute.readInstanceField(fields.instance, compute.getThis());
BytecodeCreator nonNullCopy = compute.ifNotNull(copy).trueBranch();
nonNullCopy.invokeInterfaceMethod(MethodDescriptors.LOCK_UNLOCK, lock);
nonNullCopy.returnValue(copy);
TryBlock tryBlock = compute.tryBlock();
ResultHandle val = tryBlock.readInstanceField(fields.instance, compute.getThis());
BytecodeCreator isNull = tryBlock.ifNull(val).trueBranch();
ResultHandle newVal = isNull.invokeInterfaceMethod(MethodDescriptors.SUPPLIER_GET,
compute.getMethodParam(0));
isNull.writeInstanceField(fields.instance, compute.getThis(), newVal);
copy = tryBlock.invokeInterfaceMethod(MethodDescriptors.SUPPLIER_GET, compute.getMethodParam(0));
tryBlock.writeInstanceField(fields.instance, compute.getThis(), copy);
tryBlock.invokeInterfaceMethod(MethodDescriptors.LOCK_UNLOCK, lock);
tryBlock.returnValue(copy);
CatchBlockCreator catchBlock = tryBlock.addCatch(Throwable.class);
catchBlock.invokeInterfaceMethod(MethodDescriptors.LOCK_UNLOCK, lock);
catchBlock.throwException(catchBlock.getCaughtException());
compute.returnValue(compute.readInstanceField(fields.instance, compute.getThis()));

strSwitch.caseOf(bean.getIdentifier(), bc -> {
bc.returnValue(bc.invokeVirtualMethod(compute.getMethodDescriptor(), bc.getThis(), bc.getMethodParam(1)));
Expand Down

0 comments on commit 92bc2e5

Please sign in to comment.