RefCnt.java — netty Source File
Architecture documentation for RefCnt.java, a java file in the netty codebase.
Entity Profile
Relationship Graph
Source Code
/*
* Copyright 2025 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.util.internal;
import io.netty.util.IllegalReferenceCountException;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import static io.netty.util.internal.ObjectUtil.checkPositive;
/**
* Monomorphic reference counter implementation that always use the most efficient available atomic updater.
* This implementation is easier for the JIT compiler to optimize,
* compared to when {@link ReferenceCountUpdater} is used.
*/
@SuppressWarnings("deprecation")
public final class RefCnt {
private static final int UNSAFE = 0;
private static final int VAR_HANDLE = 1;
private static final int ATOMIC_UPDATER = 2;
private static final int REF_CNT_IMPL;
static {
if (PlatformDependent.hasUnsafe()) {
REF_CNT_IMPL = UNSAFE;
} else if (PlatformDependent.hasVarHandle()) {
REF_CNT_IMPL = VAR_HANDLE;
} else {
REF_CNT_IMPL = ATOMIC_UPDATER;
}
}
/*
* Implementation notes:
*
* For the updated int field:
* Even => "real" refcount is (refCnt >>> 1)
* Odd => "real" refcount is 0
*
* This field is package-private so that the AtomicRefCnt implementation can reach it, even on native-image.
*/
volatile int value;
public RefCnt() {
// ... (417 more lines)
Domain
Subdomains
Source
Frequently Asked Questions
What does RefCnt.java do?
RefCnt.java is a source file in the netty codebase, written in java. It belongs to the CommonUtil domain, Internal subdomain.
Where is RefCnt.java in the architecture?
RefCnt.java is located at common/src/main/java/io/netty/util/internal/RefCnt.java (domain: CommonUtil, subdomain: Internal, directory: common/src/main/java/io/netty/util/internal).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free