diff --git a/all/pom.xml b/all/pom.xml index 08a63e659b..39ac7383cf 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -61,27 +61,6 @@ - - ${project.groupId} - netty-transport-native-unix-common - linux-x86_64 - compile - true - - - ${project.groupId} - netty-transport-native-unix-common - linux-aarch_64 - compile - true - - - ${project.groupId} - netty-transport-native-unix-common - osx-x86_64 - compile - true - ${project.groupId} netty-transport-native-epoll @@ -118,27 +97,6 @@ - - ${project.groupId} - netty-transport-native-unix-common - linux-x86_64 - compile - true - - - ${project.groupId} - netty-transport-native-unix-common - linux-aarch_64 - compile - true - - - ${project.groupId} - netty-transport-native-unix-common - osx-x86_64 - compile - true - ${project.groupId} netty-transport-native-epoll @@ -170,7 +128,7 @@ - @@ -182,14 +140,6 @@ - - ${project.groupId} - netty-transport-native-unix-common - ${project.version} - ${jni.classifier} - compile - true - ${project.groupId} netty-transport-native-epoll @@ -225,14 +175,6 @@ - - ${project.groupId} - netty-transport-native-unix-common - ${project.version} - ${jni.classifier} - compile - true - ${project.groupId} netty-transport-native-kqueue @@ -267,14 +209,6 @@ - - ${project.groupId} - netty-transport-native-unix-common - ${project.version} - ${jni.classifier} - compile - true - ${project.groupId} netty-transport-native-kqueue @@ -302,14 +236,6 @@ - - ${project.groupId} - netty-transport-native-unix-common - ${project.version} - ${jni.classifier} - compile - true - ${project.groupId} netty-transport-native-kqueue diff --git a/pom.xml b/pom.xml index 1b0de5e118..19c9b50c7f 100644 --- a/pom.xml +++ b/pom.xml @@ -1317,33 +1317,6 @@ - - org.codehaus.mojo - flatten-maven-plugin - 1.2.2 - - - - flatten - process-resources - - flatten - - - - - flatten.clean - clean - - clean - - - - - oss - ${project.build.directory} - - maven-surefire-plugin diff --git a/resolver-dns-native-macos/pom.xml b/resolver-dns-native-macos/pom.xml index 7f607b7002..65bf75eb54 100644 --- a/resolver-dns-native-macos/pom.xml +++ b/resolver-dns-native-macos/pom.xml @@ -124,23 +124,11 @@ netty-transport-native-unix-common ${project.version} ${jni.classifier} - - - - - - non-native - - true - - - - io.netty - netty-transport-native-unix-common - ${project.version} + + true @@ -168,16 +156,15 @@ netty-resolver-dns ${project.version} + + io.netty + netty-transport-native-unix-common + ${project.version} + - - - org.codehaus.mojo - flatten-maven-plugin - - maven-jar-plugin diff --git a/resolver-dns-native-macos/src/main/java/io/netty/resolver/dns/macos/MacOSDnsServerAddressStreamProvider.java b/resolver-dns-native-macos/src/main/java/io/netty/resolver/dns/macos/MacOSDnsServerAddressStreamProvider.java index 03b826e02c..71cbbcb0b7 100644 --- a/resolver-dns-native-macos/src/main/java/io/netty/resolver/dns/macos/MacOSDnsServerAddressStreamProvider.java +++ b/resolver-dns-native-macos/src/main/java/io/netty/resolver/dns/macos/MacOSDnsServerAddressStreamProvider.java @@ -15,7 +15,6 @@ */ package io.netty.resolver.dns.macos; -import io.netty.channel.unix.Unix; import io.netty.resolver.dns.DnsServerAddressStream; import io.netty.resolver.dns.DnsServerAddressStreamProvider; import io.netty.resolver.dns.DnsServerAddressStreamProviders; @@ -54,7 +53,6 @@ public final class MacOSDnsServerAddressStreamProvider implements DnsServerAddre static { Throwable cause = null; try { - Unix.ensureAvailability(); loadNativeLibrary(); } catch (Throwable error) { cause = error; diff --git a/testsuite-osgi/pom.xml b/testsuite-osgi/pom.xml index a135242948..815ae15cc6 100644 --- a/testsuite-osgi/pom.xml +++ b/testsuite-osgi/pom.xml @@ -241,7 +241,6 @@ test - ${line.separator} diff --git a/transport-native-epoll/pom.xml b/transport-native-epoll/pom.xml index 5aab163406..8cbf2c9aa3 100644 --- a/transport-native-epoll/pom.xml +++ b/transport-native-epoll/pom.xml @@ -202,6 +202,11 @@ netty-transport-native-unix-common ${project.version} ${jni.classifier} + + true @@ -346,23 +351,11 @@ netty-transport-native-unix-common ${project.version} ${jni.classifier} - - - - - - non-native - - true - - - - io.netty - netty-transport-native-unix-common - ${project.version} + + true @@ -384,6 +377,11 @@ netty-transport ${project.version} + + io.netty + netty-transport-native-unix-common + ${project.version} + io.netty netty-testsuite @@ -407,11 +405,6 @@ - - - org.codehaus.mojo - flatten-maven-plugin - org.codehaus.mojo diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/Epoll.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/Epoll.java index 92a4a4b04f..44ba7f6779 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/Epoll.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/Epoll.java @@ -16,7 +16,6 @@ package io.netty.channel.epoll; import io.netty.channel.unix.FileDescriptor; -import io.netty.channel.unix.Unix; import io.netty.util.internal.SystemPropertyUtil; /** @@ -37,7 +36,6 @@ public final class Epoll { FileDescriptor epollFd = null; FileDescriptor eventFd = null; try { - Unix.ensureAvailability(); epollFd = Native.newEpollCreate(); eventFd = Native.newEventFd(); } catch (Throwable t) { diff --git a/transport-native-kqueue/pom.xml b/transport-native-kqueue/pom.xml index e57e976799..16417a76fa 100644 --- a/transport-native-kqueue/pom.xml +++ b/transport-native-kqueue/pom.xml @@ -62,6 +62,7 @@ + org.fusesource.hawtjni maven-hawtjni-plugin @@ -128,6 +129,11 @@ netty-transport-native-unix-common ${project.version} ${jni.classifier} + + true @@ -229,6 +235,11 @@ netty-transport-native-unix-common ${project.version} ${jni.classifier} + + true @@ -330,23 +341,11 @@ netty-transport-native-unix-common ${project.version} ${jni.classifier} - - - - - - non-native - - true - - - - io.netty - netty-transport-native-unix-common - ${project.version} + + true @@ -382,6 +381,11 @@ netty-transport ${project.version} + + io.netty + netty-transport-native-unix-common + ${project.version} + io.netty netty-testsuite @@ -404,12 +408,6 @@ - - - org.codehaus.mojo - flatten-maven-plugin - - org.codehaus.mojo diff --git a/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueue.java b/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueue.java index 2012b7510a..83cb496251 100644 --- a/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueue.java +++ b/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueue.java @@ -16,7 +16,6 @@ package io.netty.channel.kqueue; import io.netty.channel.unix.FileDescriptor; -import io.netty.channel.unix.Unix; import io.netty.util.internal.SystemPropertyUtil; import io.netty.util.internal.UnstableApi; @@ -35,7 +34,6 @@ public final class KQueue { } else { FileDescriptor kqueueFd = null; try { - Unix.ensureAvailability(); kqueueFd = Native.newKQueue(); } catch (Throwable t) { cause = t; diff --git a/transport-native-unix-common/Makefile b/transport-native-unix-common/Makefile index 1bffba9ae4..50e74a40d3 100644 --- a/transport-native-unix-common/Makefile +++ b/transport-native-unix-common/Makefile @@ -23,13 +23,12 @@ # LIB_NAME - the name of the native library SRC_DIR = src/main/c -SRC_INTERNAL_DIR = src/main/c/internal UTIL_SRC_DIR = target/netty-jni-util JNI_INCLUDE_DIR = $(JAVA_HOME)/include JNI_INCLUDES = -I$(JNI_INCLUDE_DIR) -I$(JNI_INCLUDE_DIR)/$(JNI_PLATFORM) LIB = $(LIB_DIR)/$(LIB_NAME).a -CFLAGS += $(JNI_INCLUDES) -I$(UTIL_SRC_DIR) -I$(SRC_INTERNAL_DIR) +CFLAGS += $(JNI_INCLUDES) -I$(UTIL_SRC_DIR) SRCS = $(wildcard $(SRC_DIR)/*.c) UTIL_SRCS = $(wildcard $(UTIL_SRC_DIR)/*.c) diff --git a/transport-native-unix-common/pom.xml b/transport-native-unix-common/pom.xml index 2da0e9f8c6..21b434e2ac 100644 --- a/transport-native-unix-common/pom.xml +++ b/transport-native-unix-common/pom.xml @@ -43,11 +43,6 @@ ${project.build.directory}/native-lib-only ${project.build.directory}/${project.build.finalName}.jar ${project.build.directory}/${project.build.finalName}-${jni.classifier}.jar - ${project.build.directory}/generated-sources - -O3 -Werror -Wno-attributes -fPIC -fno-omit-frame-pointer -Wunused-variable -fvisibility=hidden -I${project.basedir}/src/main/c - -Wl,--no-as-needed -lrt - ${os.detected.arch} - false @@ -106,69 +101,9 @@ - true clang darwin - - - linux - - - linux - - - - linux - - - - linux-aarch64 - - - aarch_64 - ${os.detected.name}-aarch_64 - linux - aarch64-linux-gnu-gcc - aarch64-linux-gnu-ar - - - - freebsd - - - unix - freebsd - - - - clang - gmake - freebsd - - - - openbsd - - - unix - openbsd - - - - clang - gmake - openbsd - - - - - build.native - - - !windows - - @@ -192,8 +127,7 @@ - - + @@ -219,8 +153,8 @@ - - + + - copy-src + native-jar + package + + run + + + + + + + + + + + + + + + + + + + + + + + + + + build-native-lib generate-sources run - - - - - - - - - + + + + + + + + + + + + + + + linux-aarch64 + + + ${os.detected.name}-aarch_64 + linux + aarch64-linux-gnu-gcc + aarch64-linux-gnu-ar + + + - org.fusesource.hawtjni - maven-hawtjni-plugin + maven-antrun-plugin + + + native-jar + package + + run + + + + + + + + + + + + + + + + + + + + + + + + build-native-lib - - netty_transport_native_unix_${os.detected.name}_${nativeLibArch} - ${generatedSourcesDir} - ${project.build.outputDirectory} - - . - true - true - - MACOSX_DEPLOYMENT_TARGET=10.2 - CFLAGS=${cflags} - - + generate-sources - generate - build + run + + + + + + + + + + + + + + + + + + + + + + freebsd + + + unix + freebsd + + + + clang + gmake + freebsd + + + + + maven-antrun-plugin + + + + native-jar + package + + run + + + + + + + + + + + + + + + + + + + + + + + + + + build-native-lib + generate-sources + + run + + + + + + + + + + + + + + + + + + + + + + + openbsd + + + unix + openbsd + + + + clang + gmake + openbsd + + + + + maven-antrun-plugin + + + + native-jar + package + + run + + + + + + + + + + + + + + + + + + + + + + + + + + build-native-lib + generate-sources + + run + + + + + + + + + + + + + + + - diff --git a/transport-native-unix-common/src/main/c/internal/netty_unix_buffer_internal.h b/transport-native-unix-common/src/main/c/internal/netty_unix_buffer_internal.h deleted file mode 100644 index 720dcce677..0000000000 --- a/transport-native-unix-common/src/main/c/internal/netty_unix_buffer_internal.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2020 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. - */ -#ifndef NETTY_UNIX_BUFFER_INTERNAL_H_ -#define NETTY_UNIX_BUFFER_INTERNAL_H_ - -#include - -// JNI initialization hooks. Users of this file are responsible for calling these in the JNI_OnLoad and JNI_OnUnload methods. -jint netty_unix_buffer_internal_JNI_OnLoad(JNIEnv* env, const char* packagePrefix); -void netty_unix_buffer_internal_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix); - -#endif /* NETTY_UNIX_BUFFER_INTERNAL_H_ */ diff --git a/transport-native-unix-common/src/main/c/internal/netty_unix_errors_internal.h b/transport-native-unix-common/src/main/c/internal/netty_unix_errors_internal.h deleted file mode 100644 index 07d82df48f..0000000000 --- a/transport-native-unix-common/src/main/c/internal/netty_unix_errors_internal.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2020 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. - */ -#ifndef NETTY_UNIX_ERRORS_INTERNAL_H_ -#define NETTY_UNIX_ERRORS_INTERNAL_H_ - -#include - -// JNI initialization hooks. Users of this file are responsible for calling these in the JNI_OnLoad and JNI_OnUnload methods. -jint netty_unix_errors_internal_JNI_OnLoad(JNIEnv* env, const char* packagePrefix); -void netty_unix_errors_internal_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix); - -#endif /* NETTY_UNIX_ERRORS_INTERNAL_H_ */ diff --git a/transport-native-unix-common/src/main/c/internal/netty_unix_filedescriptor_internal.h b/transport-native-unix-common/src/main/c/internal/netty_unix_filedescriptor_internal.h deleted file mode 100644 index be51b87f5a..0000000000 --- a/transport-native-unix-common/src/main/c/internal/netty_unix_filedescriptor_internal.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2020 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. - */ -#ifndef NETTY_UNIX_FILEDESCRIPTOR_INTERNAL_H_ -#define NETTY_UNIX_FILEDESCRIPTOR_INTERNAL_H_ - -#include - -// JNI initialization hooks. Users of this file are responsible for calling these in the JNI_OnLoad and JNI_OnUnload methods. -jint netty_unix_filedescriptor_internal_JNI_OnLoad(JNIEnv* env, const char* packagePrefix); -void netty_unix_filedescriptor_internal_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix); - -#endif /* NETTY_UNIX_FILEDESCRIPTOR_INTERNAL_H_ */ diff --git a/transport-native-unix-common/src/main/c/internal/netty_unix_limits_internal.h b/transport-native-unix-common/src/main/c/internal/netty_unix_limits_internal.h deleted file mode 100644 index 23329c72d1..0000000000 --- a/transport-native-unix-common/src/main/c/internal/netty_unix_limits_internal.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2020 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. - */ -#ifndef NETTY_UNIX_LIMITS_INTERNAL_H_ -#define NETTY_UNIX_LIMITS_INTERNAL_H_ - -#include - -// JNI initialization hooks. Users of this file are responsible for calling these in the JNI_OnLoad and JNI_OnUnload methods. -jint netty_unix_limits_internal_JNI_OnLoad(JNIEnv* env, const char* packagePrefix); -void netty_unix_limits_internal_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix); - -#endif /* NETTY_UNIX_LIMITS_INTERNAL_H_ */ diff --git a/transport-native-unix-common/src/main/c/internal/netty_unix_socket_internal.h b/transport-native-unix-common/src/main/c/internal/netty_unix_socket_internal.h deleted file mode 100644 index 227a9b0301..0000000000 --- a/transport-native-unix-common/src/main/c/internal/netty_unix_socket_internal.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2020 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. - */ -#ifndef NETTY_UNIX_SOCKET_INTERNAL_H_ -#define NETTY_UNIX_SOCKET_INTERNAL_H_ - -#include - -// JNI initialization hooks. Users of this file are responsible for calling these in the JNI_OnLoad and JNI_OnUnload methods. -jint netty_unix_socket_internal_JNI_OnLoad(JNIEnv* env, const char* packagePrefix); -void netty_unix_socket_internal_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix); - -#endif /* NETTY_UNIX_SOCKET_INTERNAL_H_ */ diff --git a/transport-native-unix-common/src/main/c/netty_unix_buffer.c b/transport-native-unix-common/src/main/c/netty_unix_buffer.c index 517cabd5c2..db922ab396 100644 --- a/transport-native-unix-common/src/main/c/netty_unix_buffer.c +++ b/transport-native-unix-common/src/main/c/netty_unix_buffer.c @@ -17,7 +17,6 @@ #include "netty_unix_util.h" #include "netty_unix_buffer.h" #include "netty_jni_util.h" -#include "internal/netty_unix_buffer_internal.h" #define BUFFER_CLASSNAME "io/netty/channel/unix/Buffer" @@ -40,40 +39,19 @@ static const JNINativeMethod statically_referenced_fixed_method_table[] = { static const jint statically_referenced_fixed_method_table_size = sizeof(statically_referenced_fixed_method_table) / sizeof(statically_referenced_fixed_method_table[0]); // JNI Method Registration Table End -static jint netty_unix_buffer_JNI_OnLoad0(JNIEnv* env, const char* packagePrefix, int registerNative) { - if (registerNative) { - // We must register the statically referenced methods first! - if (netty_jni_util_register_natives(env, - packagePrefix, - BUFFER_CLASSNAME, - statically_referenced_fixed_method_table, - statically_referenced_fixed_method_table_size) != 0) { - return JNI_ERR; - } +jint netty_unix_buffer_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) { + // We must register the statically referenced methods first! + if (netty_jni_util_register_natives(env, + packagePrefix, + BUFFER_CLASSNAME, + statically_referenced_fixed_method_table, + statically_referenced_fixed_method_table_size) != 0) { + return JNI_ERR; } return NETTY_JNI_UTIL_JNI_VERSION; } -static void netty_unix_buffer_JNI_OnUnLoad0(JNIEnv* env, const char* packagePrefix, int unregisterNative) { - if (unregisterNative) { - netty_jni_util_unregister_natives(env, packagePrefix, BUFFER_CLASSNAME); - } -} - -jint netty_unix_buffer_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) { - return netty_unix_buffer_JNI_OnLoad0(env, packagePrefix, 0); -} - void netty_unix_buffer_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix) { - netty_unix_buffer_JNI_OnUnLoad0(env, packagePrefix, 0); + netty_jni_util_unregister_natives(env, packagePrefix, BUFFER_CLASSNAME); } - -jint netty_unix_buffer_internal_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) { - return netty_unix_buffer_JNI_OnLoad0(env, packagePrefix, 1); -} - -void netty_unix_buffer_internal_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix) { - netty_unix_buffer_JNI_OnUnLoad0(env, packagePrefix, 1); -} - diff --git a/transport-native-unix-common/src/main/c/netty_unix_errors.c b/transport-native-unix-common/src/main/c/netty_unix_errors.c index b7627b9217..8ecc14760d 100644 --- a/transport-native-unix-common/src/main/c/netty_unix_errors.c +++ b/transport-native-unix-common/src/main/c/netty_unix_errors.c @@ -21,7 +21,6 @@ #include "netty_unix_jni.h" #include "netty_unix_util.h" #include "netty_jni_util.h" -#include "internal/netty_unix_errors_internal.h" #define ERRORS_CLASSNAME "io/netty/channel/unix/ErrorsStaticallyReferencedJniMethods" @@ -213,17 +212,15 @@ static const JNINativeMethod statically_referenced_fixed_method_table[] = { static const jint statically_referenced_fixed_method_table_size = sizeof(statically_referenced_fixed_method_table) / sizeof(statically_referenced_fixed_method_table[0]); // JNI Method Registration Table End -static jint netty_unix_errors_JNI_OnLoad0(JNIEnv* env, const char* packagePrefix, int registerNative) { +jint netty_unix_errors_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) { char* nettyClassName = NULL; - if (registerNative) { - // We must register the statically referenced methods first! - if (netty_jni_util_register_natives(env, - packagePrefix, - ERRORS_CLASSNAME, - statically_referenced_fixed_method_table, - statically_referenced_fixed_method_table_size) != 0) { - return JNI_ERR; - } + // We must register the statically referenced methods first! + if (netty_jni_util_register_natives(env, + packagePrefix, + ERRORS_CLASSNAME, + statically_referenced_fixed_method_table, + statically_referenced_fixed_method_table_size) != 0) { + return JNI_ERR; } NETTY_JNI_UTIL_LOAD_CLASS(env, oomErrorClass, "java/lang/OutOfMemoryError", error); @@ -247,7 +244,7 @@ error: return JNI_ERR; } -static void netty_unix_errors_JNI_OnUnLoad0(JNIEnv* env, const char* packagePrefix, int unregisterNative) { +void netty_unix_errors_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix) { // delete global references so the GC can collect them NETTY_JNI_UTIL_UNLOAD_CLASS(env, oomErrorClass); NETTY_JNI_UTIL_UNLOAD_CLASS(env, runtimeExceptionClass); @@ -256,23 +253,5 @@ static void netty_unix_errors_JNI_OnUnLoad0(JNIEnv* env, const char* packagePref NETTY_JNI_UTIL_UNLOAD_CLASS(env, portUnreachableExceptionClass); NETTY_JNI_UTIL_UNLOAD_CLASS(env, closedChannelExceptionClass); - if (unregisterNative) { - netty_jni_util_unregister_natives(env, packagePrefix, ERRORS_CLASSNAME); - } -} - -jint netty_unix_errors_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) { - return netty_unix_errors_JNI_OnLoad0(env, packagePrefix, 0); -} - -void netty_unix_errors_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix) { - netty_unix_errors_JNI_OnUnLoad0(env, packagePrefix, 0); -} - -jint netty_unix_errors_internal_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) { - return netty_unix_errors_JNI_OnLoad0(env, packagePrefix, 1); -} - -void netty_unix_errors_internal_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix) { - netty_unix_errors_JNI_OnUnLoad0(env, packagePrefix, 1); + netty_jni_util_unregister_natives(env, packagePrefix, ERRORS_CLASSNAME); } diff --git a/transport-native-unix-common/src/main/c/netty_unix_filedescriptor.c b/transport-native-unix-common/src/main/c/netty_unix_filedescriptor.c index 31bb25cc04..d226b7636e 100644 --- a/transport-native-unix-common/src/main/c/netty_unix_filedescriptor.c +++ b/transport-native-unix-common/src/main/c/netty_unix_filedescriptor.c @@ -27,8 +27,6 @@ #include "netty_unix_util.h" #include "netty_jni_util.h" -#include "internal/netty_unix_filedescriptor_internal.h" - #define FILEDESCRIPTOR_CLASSNAME "io/netty/channel/unix/FileDescriptor" static jmethodID posId = NULL; @@ -280,13 +278,11 @@ static const JNINativeMethod method_table[] = { static const jint method_table_size = sizeof(method_table) / sizeof(method_table[0]); // JNI Method Registration Table End -static jint netty_unix_filedescriptor_JNI_OnLoad0(JNIEnv* env, const char* packagePrefix, int registerNative) { +jint netty_unix_filedescriptor_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) { int ret = JNI_ERR; void* mem = NULL; - if (registerNative) { - if (netty_jni_util_register_natives(env, packagePrefix, FILEDESCRIPTOR_CLASSNAME, method_table, method_table_size) != 0) { - goto done; - } + if (netty_jni_util_register_natives(env, packagePrefix, FILEDESCRIPTOR_CLASSNAME, method_table, method_table_size) != 0) { + goto done; } if ((mem = malloc(1)) == NULL) { goto done; @@ -320,24 +316,6 @@ done: return ret; } -static void netty_unix_filedescriptor_JNI_OnUnLoad0(JNIEnv* env, const char* packagePrefix, int unregisterNative) { - if (unregisterNative) { - netty_jni_util_unregister_natives(env, packagePrefix, FILEDESCRIPTOR_CLASSNAME); - } -} - -jint netty_unix_filedescriptor_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) { - return netty_unix_filedescriptor_JNI_OnLoad0(env, packagePrefix, 0); -} - void netty_unix_filedescriptor_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix) { - return netty_unix_filedescriptor_JNI_OnUnLoad0(env, packagePrefix, 0); -} - -jint netty_unix_filedescriptor_internal_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) { - return netty_unix_filedescriptor_JNI_OnLoad0(env, packagePrefix, 1); -} - -void netty_unix_filedescriptor_internal_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix) { - return netty_unix_filedescriptor_JNI_OnUnLoad0(env, packagePrefix, 1); + netty_jni_util_unregister_natives(env, packagePrefix, FILEDESCRIPTOR_CLASSNAME); } diff --git a/transport-native-unix-common/src/main/c/netty_unix_limits.c b/transport-native-unix-common/src/main/c/netty_unix_limits.c index 8d170c9530..26756fba94 100644 --- a/transport-native-unix-common/src/main/c/netty_unix_limits.c +++ b/transport-native-unix-common/src/main/c/netty_unix_limits.c @@ -21,7 +21,6 @@ #include "netty_unix_limits.h" #include "netty_unix_util.h" #include "netty_jni_util.h" -#include "internal/netty_unix_limits_internal.h" #define LIMITS_CLASSNAME "io/netty/channel/unix/LimitsStaticallyReferencedJniMethods" @@ -70,39 +69,19 @@ static const JNINativeMethod statically_referenced_fixed_method_table[] = { static const jint statically_referenced_fixed_method_table_size = sizeof(statically_referenced_fixed_method_table) / sizeof(statically_referenced_fixed_method_table[0]); // JNI Method Registration Table End -static jint netty_unix_limits_JNI_OnLoad0(JNIEnv* env, const char* packagePrefix, int registerNative) { - if (registerNative) { - // We must register the statically referenced methods first! - if (netty_jni_util_register_natives(env, - packagePrefix, - LIMITS_CLASSNAME, - statically_referenced_fixed_method_table, - statically_referenced_fixed_method_table_size) != 0) { - return JNI_ERR; - } +jint netty_unix_limits_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) { + // We must register the statically referenced methods first! + if (netty_jni_util_register_natives(env, + packagePrefix, + LIMITS_CLASSNAME, + statically_referenced_fixed_method_table, + statically_referenced_fixed_method_table_size) != 0) { + return JNI_ERR; } return NETTY_JNI_UTIL_JNI_VERSION; } -static void netty_unix_limits_JNI_OnUnLoad0(JNIEnv* env, const char* packagePrefix, int unregisterNative) { - if (unregisterNative) { - netty_jni_util_unregister_natives(env, packagePrefix, LIMITS_CLASSNAME); - } -} - -jint netty_unix_limits_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) { - return netty_unix_limits_JNI_OnLoad0(env, packagePrefix, 0); -} - void netty_unix_limits_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix) { - netty_unix_limits_JNI_OnUnLoad0(env, packagePrefix, 0); -} - -jint netty_unix_limits_internal_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) { - return netty_unix_limits_JNI_OnLoad0(env, packagePrefix, 1); -} - -void netty_unix_limits_internal_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix) { - netty_unix_limits_JNI_OnUnLoad0(env, packagePrefix, 1); + netty_jni_util_unregister_natives(env, packagePrefix, LIMITS_CLASSNAME); } diff --git a/transport-native-unix-common/src/main/c/netty_unix_native.c b/transport-native-unix-common/src/main/c/netty_unix_native.c deleted file mode 100644 index 5bce1ae431..0000000000 --- a/transport-native-unix-common/src/main/c/netty_unix_native.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2020 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. - */ -#include - -#include "netty_unix_buffer.h" -#include "netty_unix_errors.h" -#include "netty_unix_filedescriptor.h" -#include "netty_unix_jni.h" -#include "netty_unix_limits.h" -#include "netty_unix_socket.h" -#include "netty_unix_util.h" - -#include "internal/netty_unix_buffer_internal.h" -#include "internal/netty_unix_errors_internal.h" -#include "internal/netty_unix_filedescriptor_internal.h" -#include "internal/netty_unix_limits_internal.h" -#include "internal/netty_unix_socket_internal.h" - -// Add define if NETTY_BUILD_STATIC is defined so it is picked up in netty_jni_util.c -#ifdef NETTY_BUILD_STATIC -#define NETTY_JNI_UTIL_BUILD_STATIC -#endif - -static jint netty_unix_native_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) { - int ret = JNI_ERR; - int limitsOnLoadCalled = 0; - int errorsOnLoadCalled = 0; - int filedescriptorOnLoadCalled = 0; - int socketOnLoadCalled = 0; - int bufferOnLoadCalled = 0; - - // Load all c modules that we depend upon - if (netty_unix_limits_internal_JNI_OnLoad(env, packagePrefix) == JNI_ERR) { - goto done; - } - limitsOnLoadCalled = 1; - - if (netty_unix_errors_internal_JNI_OnLoad(env, packagePrefix) == JNI_ERR) { - goto done; - } - errorsOnLoadCalled = 1; - - if (netty_unix_filedescriptor_internal_JNI_OnLoad(env, packagePrefix) == JNI_ERR) { - goto done; - } - filedescriptorOnLoadCalled = 1; - - if (netty_unix_socket_internal_JNI_OnLoad(env, packagePrefix) == JNI_ERR) { - goto done; - } - socketOnLoadCalled = 1; - - if (netty_unix_buffer_internal_JNI_OnLoad(env, packagePrefix) == JNI_ERR) { - goto done; - } - bufferOnLoadCalled = 1; - - ret = NETTY_JNI_UTIL_JNI_VERSION; -done: - if (ret == JNI_ERR) { - if (limitsOnLoadCalled == 1) { - netty_unix_limits_internal_JNI_OnUnLoad(env, packagePrefix); - } - if (errorsOnLoadCalled == 1) { - netty_unix_errors_internal_JNI_OnUnLoad(env, packagePrefix); - } - if (filedescriptorOnLoadCalled == 1) { - netty_unix_filedescriptor_internal_JNI_OnUnLoad(env, packagePrefix); - } - if (socketOnLoadCalled == 1) { - netty_unix_socket_internal_JNI_OnUnLoad(env, packagePrefix); - } - if (bufferOnLoadCalled == 1) { - netty_unix_buffer_internal_JNI_OnUnLoad(env, packagePrefix); - } - } - return ret; -} - -static void netty_unix_native_JNI_OnUnload(JNIEnv* env, const char* packagePrefix) { - netty_unix_limits_internal_JNI_OnUnLoad(env, packagePrefix); - netty_unix_errors_internal_JNI_OnUnLoad(env, packagePrefix); - netty_unix_filedescriptor_internal_JNI_OnUnLoad(env, packagePrefix); - netty_unix_socket_internal_JNI_OnUnLoad(env, packagePrefix); - netty_unix_buffer_internal_JNI_OnUnLoad(env, packagePrefix); -} - -// Invoked by the JVM when statically linked - -// We build with -fvisibility=hidden so ensure we mark everything that needs to be visible with JNIEXPORT -// https://mail.openjdk.java.net/pipermail/core-libs-dev/2013-February/014549.html - -// Invoked by the JVM when statically linked -JNIEXPORT jint JNI_OnLoad_netty_transport_native_unix(JavaVM* vm, void* reserved) { - return netty_jni_util_JNI_OnLoad(vm, reserved, "netty_transport_native_unix", netty_unix_native_JNI_OnLoad); -} - -// Invoked by the JVM when statically linked -JNIEXPORT void JNI_OnUnload_netty_transport_native_unix(JavaVM* vm, void* reserved) { - netty_jni_util_JNI_OnUnload(vm, reserved, netty_unix_native_JNI_OnUnload); -} - -#ifndef NETTY_BUILD_STATIC -JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { - return netty_jni_util_JNI_OnLoad(vm, reserved, "netty_transport_native_unix", netty_unix_native_JNI_OnLoad); -} - -JNIEXPORT void JNI_OnUnload(JavaVM* vm, void* reserved) { - netty_jni_util_JNI_OnUnload(vm, reserved, netty_unix_native_JNI_OnUnload); -} -#endif /* NETTY_BUILD_STATIC */ diff --git a/transport-native-unix-common/src/main/c/netty_unix_socket.c b/transport-native-unix-common/src/main/c/netty_unix_socket.c index b7fac6e639..da313eb65f 100644 --- a/transport-native-unix-common/src/main/c/netty_unix_socket.c +++ b/transport-native-unix-common/src/main/c/netty_unix_socket.c @@ -32,8 +32,6 @@ #include "netty_unix_util.h" #include "netty_jni_util.h" -#include "internal/netty_unix_socket_internal.h" - #define SOCKET_CLASSNAME "io/netty/channel/unix/Socket" // Define SO_REUSEPORT if not found to fix build issues. // See https://github.com/netty/netty/issues/2558 @@ -1055,23 +1053,20 @@ error: // JNI Method Registration Table End -static jint netty_unix_socket_JNI_OnLoad0(JNIEnv* env, const char* packagePrefix, int registerNative) { +jint netty_unix_socket_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) { int ret = JNI_ERR; char* nettyClassName = NULL; void* mem = NULL; - JNINativeMethod* dynamicMethods = NULL; - if (registerNative) { - dynamicMethods = createDynamicMethodsTable(packagePrefix); - if (dynamicMethods == NULL) { - goto done; - } - if (netty_jni_util_register_natives(env, - packagePrefix, - SOCKET_CLASSNAME, - dynamicMethods, - dynamicMethodsTableSize()) != 0) { - goto done; - } + JNINativeMethod* dynamicMethods = createDynamicMethodsTable(packagePrefix); + if (dynamicMethods == NULL) { + goto done; + } + if (netty_jni_util_register_natives(env, + packagePrefix, + SOCKET_CLASSNAME, + dynamicMethods, + dynamicMethodsTableSize()) != 0) { + goto done; } NETTY_JNI_UTIL_PREPEND(packagePrefix, "io/netty/channel/unix/DatagramSocketAddress", nettyClassName, done); @@ -1100,36 +1095,15 @@ static jint netty_unix_socket_JNI_OnLoad0(JNIEnv* env, const char* packagePrefix ret = NETTY_JNI_UTIL_JNI_VERSION; done: - if (registerNative) { - netty_jni_util_free_dynamic_methods_table(dynamicMethods, fixed_method_table_size, dynamicMethodsTableSize()); - } + netty_jni_util_free_dynamic_methods_table(dynamicMethods, fixed_method_table_size, dynamicMethodsTableSize()); free(nettyClassName); free(mem); return ret; } -static void netty_unix_socket_JNI_OnUnLoad0(JNIEnv* env, const char* packagePrefix, int unregisterNative) { +void netty_unix_socket_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix) { NETTY_JNI_UTIL_UNLOAD_CLASS(env, datagramSocketAddressClass); NETTY_JNI_UTIL_UNLOAD_CLASS(env, inetSocketAddressClass); - if (unregisterNative) { - netty_jni_util_unregister_natives(env, packagePrefix, SOCKET_CLASSNAME); - } -} - -jint netty_unix_socket_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) { - return netty_unix_socket_JNI_OnLoad0(env, packagePrefix, 0); -} - -void netty_unix_socket_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix) { - netty_unix_socket_JNI_OnUnLoad0(env, packagePrefix, 0); -} - - -jint netty_unix_socket_internal_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) { - return netty_unix_socket_JNI_OnLoad0(env, packagePrefix, 1); -} - -void netty_unix_socket_internal_JNI_OnUnLoad(JNIEnv* env, const char* packagePrefix) { - netty_unix_socket_JNI_OnUnLoad0(env, packagePrefix, 1); + netty_jni_util_unregister_natives(env, packagePrefix, SOCKET_CLASSNAME); } diff --git a/transport-native-unix-common/src/main/java/io/netty/channel/unix/FileDescriptor.java b/transport-native-unix-common/src/main/java/io/netty/channel/unix/FileDescriptor.java index f26ffaf44f..e397aa3fae 100644 --- a/transport-native-unix-common/src/main/java/io/netty/channel/unix/FileDescriptor.java +++ b/transport-native-unix-common/src/main/java/io/netty/channel/unix/FileDescriptor.java @@ -51,7 +51,6 @@ public class FileDescriptor { final int fd; public FileDescriptor(int fd) { - Unix.ensureAvailability(); checkPositiveOrZero(fd, "fd"); this.fd = fd; } diff --git a/transport-native-unix-common/src/main/java/io/netty/channel/unix/IovArray.java b/transport-native-unix-common/src/main/java/io/netty/channel/unix/IovArray.java index 93fbf092f1..6071cccc9f 100644 --- a/transport-native-unix-common/src/main/java/io/netty/channel/unix/IovArray.java +++ b/transport-native-unix-common/src/main/java/io/netty/channel/unix/IovArray.java @@ -66,7 +66,7 @@ public final class IovArray implements MessageProcessor { private final ByteBuf memory; private int count; private long size; - private long maxBytes; + private long maxBytes = SSIZE_MAX; public IovArray() { this(Unpooled.wrappedBuffer(Buffer.allocateDirectWithNativeOrder(MAX_CAPACITY)).setIndex(0, 0)); @@ -74,7 +74,6 @@ public final class IovArray implements MessageProcessor { @SuppressWarnings("deprecation") public IovArray(ByteBuf memory) { - Unix.ensureAvailability(); assert memory.writerIndex() == 0; assert memory.readerIndex() == 0; this.memory = PlatformDependent.hasUnsafe() ? memory : memory.order( @@ -85,7 +84,6 @@ public final class IovArray implements MessageProcessor { // Fallback to using JNI as we were not be able to access the address otherwise. memoryAddress = Buffer.memoryAddress(memory.internalNioBuffer(0, memory.capacity())); } - maxBytes = SSIZE_MAX; } public void clear() { diff --git a/transport-native-unix-common/src/main/java/io/netty/channel/unix/Unix.java b/transport-native-unix-common/src/main/java/io/netty/channel/unix/Unix.java index b818c80639..f625126cb5 100644 --- a/transport-native-unix-common/src/main/java/io/netty/channel/unix/Unix.java +++ b/transport-native-unix-common/src/main/java/io/netty/channel/unix/Unix.java @@ -15,23 +15,14 @@ */ package io.netty.channel.unix; -import io.netty.util.internal.NativeLibraryLoader; -import io.netty.util.internal.PlatformDependent; -import io.netty.util.internal.SystemPropertyUtil; -import io.netty.util.internal.ThrowableUtil; -import io.netty.util.internal.logging.InternalLogger; -import io.netty.util.internal.logging.InternalLoggerFactory; - import java.io.IOException; import java.nio.channels.Selector; -import java.util.Locale; /** * Tells if {@code netty-transport-native-unix} is * supported. */ public final class Unix { - private static final InternalLogger logger = InternalLoggerFactory.getInstance(Unix.class); private static final Throwable UNAVAILABILITY_CAUSE; static { @@ -51,9 +42,6 @@ public final class Unix { // First, try calling a side-effect free JNI method to see if the library was already // loaded by the application. LimitsStaticallyReferencedJniMethods.udsSunPathSize(); - } catch (UnsatisfiedLinkError ignore) { - // The library was not previously loaded, load it now. - loadNativeLibrary(); } finally { try { if (selector != null) { @@ -63,35 +51,12 @@ public final class Unix { // Just ignore } } - Socket.initialize(); } catch (Throwable error) { cause = error; } UNAVAILABILITY_CAUSE = cause; } - private static void loadNativeLibrary() { - String name = SystemPropertyUtil.get("os.name").toLowerCase(Locale.UK).trim(); - if (!name.startsWith("linux") && !name.startsWith("osx") && !name.startsWith("mac") - && !name.endsWith("bsd")) { - throw new IllegalStateException("Only supported on Linux/MacOS/BSD"); - } - String staticLibName = "netty_transport_native_unix"; - String sharedLibName = staticLibName + '_' + PlatformDependent.normalizedOs() + - '_' + PlatformDependent.normalizedArch(); - ClassLoader cl = PlatformDependent.getClassLoader(Unix.class); - try { - NativeLibraryLoader.load(sharedLibName, cl); - } catch (UnsatisfiedLinkError e1) { - try { - NativeLibraryLoader.load(staticLibName, cl); - logger.debug("Failed to load {}", sharedLibName, e1); - } catch (UnsatisfiedLinkError e2) { - ThrowableUtil.addSuppressed(e1, e2); - throw e1; - } - } - } /** * Returns {@code true} if and only if the {@code * netty_transport_native_unix} is available.