Skip to content

Commit b88c273

Browse files
author
Andrey Turbanov
committedAug 14, 2023
8313743: Make fields final in sun.nio.ch
Reviewed-by: bpb
1 parent ec0cc63 commit b88c273

9 files changed

+25
-27
lines changed
 

‎src/java.base/share/classes/sun/nio/ch/AsynchronousChannelGroupImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -59,7 +59,7 @@ abstract class AsynchronousChannelGroupImpl
5959
private final AtomicInteger threadCount = new AtomicInteger();
6060

6161
// associated Executor for timeouts
62-
private ScheduledThreadPoolExecutor timeoutExecutor;
62+
private final ScheduledThreadPoolExecutor timeoutExecutor;
6363

6464
// task queue for when using a fixed thread pool. In that case, a thread
6565
// waiting on I/O events must be awoken to poll tasks from this queue.

‎src/java.base/share/classes/sun/nio/ch/AsynchronousServerSocketChannelImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -58,7 +58,7 @@ abstract class AsynchronousServerSocketChannelImpl
5858
private final Object stateLock = new Object();
5959

6060
// close support
61-
private ReadWriteLock closeLock = new ReentrantReadWriteLock();
61+
private final ReadWriteLock closeLock = new ReentrantReadWriteLock();
6262
private volatile boolean closed;
6363

6464
// set true when accept operation is cancelled

‎src/java.base/share/classes/sun/nio/ch/FileLockTable.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -49,7 +49,7 @@ class FileLockTable {
4949
* FileLock (and FileChannel) alive.
5050
*/
5151
private static class FileLockReference extends WeakReference<FileLock> {
52-
private FileKey fileKey;
52+
private final FileKey fileKey;
5353

5454
FileLockReference(FileLock referent,
5555
ReferenceQueue<FileLock> queue,
@@ -66,11 +66,11 @@ FileKey fileKey() {
6666
// The system-wide map is a ConcurrentHashMap that is keyed on the FileKey.
6767
// The map value is a list of file locks represented by FileLockReferences.
6868
// All access to the list must be synchronized on the list.
69-
private static ConcurrentHashMap<FileKey, List<FileLockReference>> lockMap =
70-
new ConcurrentHashMap<FileKey, List<FileLockReference>>();
69+
private static final ConcurrentHashMap<FileKey, List<FileLockReference>> lockMap =
70+
new ConcurrentHashMap<>();
7171

7272
// reference queue for cleared refs
73-
private static ReferenceQueue<FileLock> queue = new ReferenceQueue<FileLock>();
73+
private static final ReferenceQueue<FileLock> queue = new ReferenceQueue<>();
7474

7575
// The connection to which this table is connected
7676
private final Channel channel;

‎src/java.base/share/classes/sun/nio/ch/IOVecWrapper.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -69,7 +69,7 @@ class IOVecWrapper {
6969
final long address;
7070

7171
// Address size in bytes
72-
static int addressSize;
72+
static final int addressSize;
7373

7474
private static class Deallocator implements Runnable {
7575
private final AllocatedNativeObject obj;

‎src/java.base/share/classes/sun/nio/ch/OptionKey.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,8 +30,8 @@
3030
*/
3131

3232
class OptionKey {
33-
private int level;
34-
private int name;
33+
private final int level;
34+
private final int name;
3535

3636
OptionKey(int level, int name) {
3737
this.level = level;

‎src/java.base/share/classes/sun/nio/ch/Util.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class Util {
5353
private static final long MAX_CACHED_BUFFER_SIZE = getMaxCachedBufferSize();
5454

5555
// Per-carrier-thread cache of temporary direct buffers
56-
private static TerminatingThreadLocal<BufferCache> bufferCache = new TerminatingThreadLocal<>() {
56+
private static final TerminatingThreadLocal<BufferCache> bufferCache = new TerminatingThreadLocal<>() {
5757
@Override
5858
protected BufferCache initialValue() {
5959
return new BufferCache();
@@ -112,7 +112,7 @@ private static boolean isBufferTooLarge(ByteBuffer buf) {
112112
*/
113113
private static class BufferCache {
114114
// the array of buffers
115-
private ByteBuffer[] buffers;
115+
private final ByteBuffer[] buffers;
116116

117117
// the number of buffers in the cache
118118
private int count;
@@ -378,7 +378,7 @@ public boolean addAll(Collection<? extends E> coll) {
378378

379379
// -- Unsafe access --
380380

381-
private static Unsafe unsafe = Unsafe.getUnsafe();
381+
private static final Unsafe unsafe = Unsafe.getUnsafe();
382382

383383
private static byte _get(long a) {
384384
return unsafe.getByte(a);

‎src/java.base/windows/classes/sun/nio/ch/PollArrayWrapper.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -51,7 +51,7 @@ class PollArrayWrapper {
5151
@Native private static final short FD_OFFSET = 0; // fd offset in pollfd
5252
@Native private static final short EVENT_OFFSET = 4; // events offset in pollfd
5353

54-
static short SIZE_POLLFD = 8; // sizeof pollfd struct
54+
static final short SIZE_POLLFD = 8; // sizeof pollfd struct
5555

5656
private int size; // Size of the pollArray
5757

‎src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -45,10 +45,9 @@ class WindowsAsynchronousSocketChannelImpl
4545
extends AsynchronousSocketChannelImpl implements Iocp.OverlappedChannel
4646
{
4747
private static final Unsafe unsafe = Unsafe.getUnsafe();
48-
private static int addressSize = unsafe.addressSize();
4948

5049
private static int dependsArch(int value32, int value64) {
51-
return (addressSize == 4) ? value32 : value64;
50+
return (unsafe.addressSize() == 4) ? value32 : value64;
5251
}
5352

5453
/*

‎src/java.base/windows/classes/sun/nio/ch/WindowsSelectorImpl.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -49,14 +49,13 @@
4949

5050
class WindowsSelectorImpl extends SelectorImpl {
5151
private static final Unsafe unsafe = Unsafe.getUnsafe();
52-
private static int addressSize = unsafe.addressSize();
5352

5453
private static int dependsArch(int value32, int value64) {
55-
return (addressSize == 4) ? value32 : value64;
54+
return (unsafe.addressSize() == 4) ? value32 : value64;
5655
}
5756

5857
// Initial capacity of the poll array
59-
private final int INIT_CAP = 8;
58+
private static final int INIT_CAP = 8;
6059
// Maximum number of sockets for select().
6160
// Should be INIT_CAP times a power of 2
6261
private static final int MAX_SELECTABLE_FDS = 1024;
@@ -74,7 +73,7 @@ private static int dependsArch(int value32, int value64) {
7473
private SelectionKeyImpl[] channelArray = new SelectionKeyImpl[INIT_CAP];
7574

7675
// The global native poll array holds file descriptors and event masks
77-
private PollArrayWrapper pollWrapper;
76+
private final PollArrayWrapper pollWrapper;
7877

7978
// The number of valid entries in poll array, including entries occupied
8079
// by wakeup socket handle.

0 commit comments

Comments
 (0)
Please sign in to comment.