Skip to content

Commit f3ae713

Browse files
committed
core: OperationLOCK: Limit scope of addDisposeListener lambda
When specifying lambdas for cleanup operations, it is good practice to reduce the scope of instances referenced ("pinned") in the lambda scope. Right now, we reference unnecessary objects, adding to heap fragmentation. Reduce the scope of referenced objects by accessing the required references before entering the dispose listener lambda. Signed-off-by: Christian Kohlschütter <[email protected]>
1 parent e01d9f8 commit f3ae713

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

core/src/main/java/org/dcache/nfs/v4/OperationLOCK.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
import org.dcache.nfs.status.InvalException;
2525
import org.dcache.nfs.status.OpenModeException;
2626
import org.dcache.nfs.status.ServerFaultException;
27+
import org.dcache.nfs.util.Opaque;
2728
import org.dcache.nfs.v4.nlm.LockDeniedException;
2829
import org.dcache.nfs.v4.nlm.LockException;
30+
import org.dcache.nfs.v4.nlm.LockManager;
2931
import org.dcache.nfs.v4.nlm.NlmLock;
3032
import org.dcache.nfs.v4.xdr.LOCK4denied;
3133
import org.dcache.nfs.v4.xdr.LOCK4resok;
@@ -118,12 +120,12 @@ public void process(CompoundContext context, nfs_resop4 result) throws ChimeraNF
118120

119121
NlmLock lock = new NlmLock(lockOwner, _args.oplock.locktype, _args.oplock.offset.value,
120122
_args.oplock.length.value);
121-
context.getLm().lock(inode.getLockKey(), lock);
123+
Opaque lockKey = inode.getLockKey();
124+
LockManager lm = context.getLm();
125+
lm.lock(lockKey, lock);
122126

123127
// ensure, that on close locks will be released
124-
lock_state.addDisposeListener(s -> {
125-
context.getLm().unlockIfExists(inode.getLockKey(), lock);
126-
});
128+
lock_state.addDisposeListener(s -> lm.unlockIfExists(lockKey, lock));
127129

128130
// FIXME: we might run into race condition, thus updating sedid must be fenced!
129131
lock_state.bumpSeqid();

0 commit comments

Comments
 (0)