Home / Class/ PlatformDependent0 Class — netty Architecture

PlatformDependent0 Class — netty Architecture

Architecture documentation for the PlatformDependent0 class in PlatformDependent0.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  be4c38f2_d236_e498_c295_1033d2617879["PlatformDependent0"]
  ce683201_2423_977c_cd1c_9e834e9b6af4["PlatformDependent0.java"]
  be4c38f2_d236_e498_c295_1033d2617879 -->|defined in| ce683201_2423_977c_cd1c_9e834e9b6af4
  1c283638_3df3_03a0_2d98_df331b427290["MethodHandle()"]
  be4c38f2_d236_e498_c295_1033d2617879 -->|method| 1c283638_3df3_03a0_2d98_df331b427290
  50c9ba14_b276_509d_fa9b_45206abbf4e0["isVirtualThread()"]
  be4c38f2_d236_e498_c295_1033d2617879 -->|method| 50c9ba14_b276_509d_fa9b_45206abbf4e0
  6515eceb_c0e4_e7d1_5b72_d5731274016c["isNativeImage()"]
  be4c38f2_d236_e498_c295_1033d2617879 -->|method| 6515eceb_c0e4_e7d1_5b72_d5731274016c
  e89bee20_bb7a_66e1_2e56_6b2962e5abe9["isExplicitNoUnsafe()"]
  be4c38f2_d236_e498_c295_1033d2617879 -->|method| e89bee20_bb7a_66e1_2e56_6b2962e5abe9
  d58337bd_8745_3d47_ca3a_e9b417558f4e["Throwable()"]
  be4c38f2_d236_e498_c295_1033d2617879 -->|method| d58337bd_8745_3d47_ca3a_e9b417558f4e
  7c92819e_7c4b_d22f_adff_d145fd0ff26a["isUnaligned()"]
  be4c38f2_d236_e498_c295_1033d2617879 -->|method| 7c92819e_7c4b_d22f_adff_d145fd0ff26a
  1d61d760_0ca1_cdd7_e892_85e199f96418["bitsMaxDirectMemory()"]
  be4c38f2_d236_e498_c295_1033d2617879 -->|method| 1d61d760_0ca1_cdd7_e892_85e199f96418
  75b2a39a_3cbf_465e_4a73_5152772dfa50["hasUnsafe()"]
  be4c38f2_d236_e498_c295_1033d2617879 -->|method| 75b2a39a_3cbf_465e_4a73_5152772dfa50
  9dadb7c9_64d8_e833_9ac8_be68eb6593e8["unalignedAccess()"]
  be4c38f2_d236_e498_c295_1033d2617879 -->|method| 9dadb7c9_64d8_e833_9ac8_be68eb6593e8
  a37cd6b4_5c99_6739_4d6e_f885ba07b7ea["throwException()"]
  be4c38f2_d236_e498_c295_1033d2617879 -->|method| a37cd6b4_5c99_6739_4d6e_f885ba07b7ea
  51fda359_7541_9788_fd41_cca2e566b822["throwException0()"]
  be4c38f2_d236_e498_c295_1033d2617879 -->|method| 51fda359_7541_9788_fd41_cca2e566b822
  439949ef_7952_aa6c_a4c6_218338b41d1f["hasDirectBufferNoCleanerConstructor()"]
  be4c38f2_d236_e498_c295_1033d2617879 -->|method| 439949ef_7952_aa6c_a4c6_218338b41d1f
  de83e9dd_14d5_3190_cad1_4b5f263b393d["ByteBuffer()"]
  be4c38f2_d236_e498_c295_1033d2617879 -->|method| de83e9dd_14d5_3190_cad1_4b5f263b393d

Relationship Graph

Source Code

common/src/main/java/io/netty/util/internal/PlatformDependent0.java lines 40–1198

final class PlatformDependent0 {

    private static final InternalLogger logger = InternalLoggerFactory.getInstance(PlatformDependent0.class);
    private static final long ADDRESS_FIELD_OFFSET;
    private static final long BYTE_ARRAY_BASE_OFFSET;
    private static final long INT_ARRAY_BASE_OFFSET;
    private static final long INT_ARRAY_INDEX_SCALE;
    private static final long LONG_ARRAY_BASE_OFFSET;
    private static final long LONG_ARRAY_INDEX_SCALE;
    private static final MethodHandle DIRECT_BUFFER_CONSTRUCTOR;
    private static final MethodHandle ALLOCATE_ARRAY_METHOD;
    private static final MethodHandle ALIGN_SLICE;
    private static final MethodHandle OFFSET_SLICE;
    private static final MethodHandle ABSOLUTE_PUT_BUFFER;
    private static final MethodHandle ABSOLUTE_PUT_ARRAY;
    private static final boolean IS_ANDROID = isAndroid0();
    private static final int JAVA_VERSION = javaVersion0();
    private static final Throwable EXPLICIT_NO_UNSAFE_CAUSE = explicitNoUnsafeCause0();

    private static final Throwable UNSAFE_UNAVAILABILITY_CAUSE;

    // See https://github.com/oracle/graal/blob/master/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/
    // ImageInfo.java
    private static final boolean RUNNING_IN_NATIVE_IMAGE = SystemPropertyUtil.contains(
            "org.graalvm.nativeimage.imagecode");

    private static final boolean IS_EXPLICIT_TRY_REFLECTION_SET_ACCESSIBLE = explicitTryReflectionSetAccessible0();

    // Package-private for testing.
    static final MethodHandle IS_VIRTUAL_THREAD_METHOD_HANDLE = getIsVirtualThreadMethodHandle();

    static final Unsafe UNSAFE;

    // constants borrowed from murmur3
    static final int HASH_CODE_ASCII_SEED = 0xc2b2ae35;
    static final int HASH_CODE_C1 = 0xcc9e2d51;
    static final int HASH_CODE_C2 = 0x1b873593;

    /**
     * Limits the number of bytes to copy per {@link Unsafe#copyMemory(long, long, long)} to allow safepoint polling
     * during a large copy.
     */
    private static final long UNSAFE_COPY_THRESHOLD = 1024L * 1024L;

    private static final boolean UNALIGNED;

    private static final long BITS_MAX_DIRECT_MEMORY;

    static {
        MethodHandles.Lookup lookup = MethodHandles.lookup();
        final ByteBuffer direct;
        Field addressField = null;
        MethodHandle allocateArrayMethod = null;
        Throwable unsafeUnavailabilityCause;
        Unsafe unsafe;
        if ((unsafeUnavailabilityCause = EXPLICIT_NO_UNSAFE_CAUSE) != null) {
            direct = null;
            addressField = null;
            unsafe = null;
        } else {
            direct = ByteBuffer.allocateDirect(1);

            // attempt to access field Unsafe#theUnsafe
            final Object maybeUnsafe = AccessController.doPrivileged(new PrivilegedAction<Object>() {
                @Override
                public Object run() {
                    try {
                        final Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
                        // We always want to try using Unsafe as the access still works on java9 as well and
                        // we need it for out native-transports and many optimizations.
                        Throwable cause = ReflectionUtil.trySetAccessible(unsafeField, false);
                        if (cause != null) {
                            return cause;
                        }
                        // the unsafe instance
                        return unsafeField.get(null);
                    } catch (NoSuchFieldException | IllegalAccessException | SecurityException e) {
                        return e;
                    } catch (NoClassDefFoundError e) {
                        // Also catch NoClassDefFoundError in case someone uses for example OSGI and it made
                        // Unsafe unloadable.

Frequently Asked Questions

What is the PlatformDependent0 class?
PlatformDependent0 is a class in the netty codebase, defined in common/src/main/java/io/netty/util/internal/PlatformDependent0.java.
Where is PlatformDependent0 defined?
PlatformDependent0 is defined in common/src/main/java/io/netty/util/internal/PlatformDependent0.java at line 40.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free