summaryrefslogtreecommitdiff
path: root/java/openjdk20/files
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2025-06-27 16:59:37 +0200
committerBaptiste Daroussin <bapt@FreeBSD.org>2025-06-27 17:14:08 +0200
commit3a407ba074c037ab429e357307016648b4d5ed33 (patch)
tree37dd87a406495866fc7e1b806e1fe3be672ad104 /java/openjdk20/files
parentwww/apache24: Allow overriding USERS and GROUPS via make.conf (diff)
openjdk: remove need for fdescfs(5) and probably procfs(5)
Implement getCommittedVirtualMemorySize() directly using sysctl kern.proc.vmmap Implement getOpenFileDescriptorCount() directly using sysctl kern.proc.nfds Note on openjdk17 use closefrom where possible (note this use case is only in openjdk 17, 21, 23 and 24) Remove the message about the use of fdescfs(5) as this is not needed for sure, keep the information about procfs(5) as I have not analysed enough the source code to make sure it is not used anywhere else, but I don't think it is.
Diffstat (limited to 'java/openjdk20/files')
-rw-r--r--java/openjdk20/files/patch-src_jdk.management_unix_native_libmanagement__ext_OperatingSystemImpl.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/java/openjdk20/files/patch-src_jdk.management_unix_native_libmanagement__ext_OperatingSystemImpl.c b/java/openjdk20/files/patch-src_jdk.management_unix_native_libmanagement__ext_OperatingSystemImpl.c
new file mode 100644
index 000000000000..421548d0f4a5
--- /dev/null
+++ b/java/openjdk20/files/patch-src_jdk.management_unix_native_libmanagement__ext_OperatingSystemImpl.c
@@ -0,0 +1,89 @@
+--- src/jdk.management/unix/native/libmanagement_ext/OperatingSystemImpl.c.orig 2023-10-01 03:54:04 UTC
++++ src/jdk.management/unix/native/libmanagement_ext/OperatingSystemImpl.c
+@@ -58,6 +58,7 @@
+ #include <unistd.h>
+
+ #ifdef __FreeBSD__
++#include <sys/user.h>
+ #include <vm/vm_param.h>
+ #endif
+
+@@ -177,23 +178,43 @@ Java_com_sun_management_internal_OperatingSystemImpl_g
+ }
+ return t_info.virtual_size;
+ #elif defined(__FreeBSD__)
+- FILE *fp;
+- unsigned long end, start;
+- jlong total = 0;
++ int mib[4];
++ struct kinfo_vmentry *kve;
++ long total = 0;
++ size_t len = 0;
++ int error;
++ char *buf, *bp, *eb;
+
+- if ((fp = fopen("/proc/curproc/map", "r")) == NULL) {
+- throw_internal_error(env, "Unable to open /proc/curproc/map");
++ mib[0] = CTL_KERN;
++ mib[1] = KERN_PROC;
++ mib[2] = KERN_PROC_VMMAP;
++ mib[3] = getpid();
++ error = sysctl(mib, 4, NULL, &len, NULL, 0);
++ if (error) {
++ throw_internal_error(env, "Cannot sysctl(kern.proc.vvmap)");
+ return -1;
+ }
+-
+- for (;;) {
+- // Ignore everything except start and end entries
+- if (fscanf(fp, "0x%lx 0x%lx %*[^\n]\n", &start, &end) != 2 || start > end)
+- break;
+- total += end - start;
++ len = len * 4 / 3;
++ buf = malloc(len);
++ if (buf == NULL) {
++ throw_internal_error(env, "Fail to allocate memory");
++ return -1;
+ }
+-
+- fclose(fp);
++ error = sysctl(mib, 4, buf, &len, NULL, 0);
++ if (error) {
++ throw_internal_error(env, "Cannot sysctl(kern.proc.vvmap)");
++ return -1;
++ }
++ bp = buf;
++ eb = buf + len;
++ while (bp < eb) {
++ kve = (struct kinfo_vmentry *)(uintptr_t)bp;
++ if (kve->kve_structsize == 0)
++ break;
++ bp += kve->kve_structsize;
++ total += kve->kve_end - kve->kve_start;
++ }
++ free(buf);
+ return total;
+ #else /* _ALLBSD_SOURCE */
+ /*
+@@ -403,6 +424,21 @@ Java_com_sun_management_internal_OperatingSystemImpl_g
+ return nfiles;
+ #elif defined(__OpenBSD__)
+ return getdtablecount();
++#elif defined(__FreeBSD__)
++ int mib[4];
++ int error;
++ int nfds;
++ size_t len;
++
++ len = sizeof(nfds);
++ mib[0] = CTL_KERN;
++ mib[1] = KERN_PROC;
++ mib[2] = KERN_PROC_NFDS;
++ mib[3] = 0;
++
++ if (sysctl(mib, 4, &nfds, &len, NULL, 0) == -1)
++ return -1;
++ return nfds;
+ #else /* solaris/linux */
+ DIR *dirp;
+ struct dirent* dentp;