[crac] RFR: Merge jdk:jdk-25+3

Dmitry Cherepanov dcherepanov at openjdk.org
Tue Apr 15 08:16:56 UTC 2025


Merge with jdk-25:3

There are several conflicts between CRaC specific changes (https://github.com/openjdk/crac/pull/10) and incoming JDK changes for https://bugs.openjdk.org/browse/JDK-8342995

https://github.com/openjdk/crac/pull/10 moved some parts from `linux/attachListener_linux.cpp` to 
 - `linux/linuxAttachOperation.hpp` which later were renamed to `posix/posixAttachOperation.hpp`
 - `linux/attachListener_linux.hpp` which later were renamed to `posix/attachListener_posix.hpp`

As a part of this merge, I manually applied JDK changes for `posix/attachListener_posix.cpp` to `posix/posixAttachOperation.hpp` & `posix/attachListener_posix.hpp`
 - new `SocketChannel` class moved to `posix/posixAttachOperation.hpp`
 - changes in `PosixAttachOperation` class incorporated into `posix/posixAttachOperation.hpp`
 - added `#include "os_posix.hpp"` to define `RESTARTABLE`
 - kept `socket()` function in `PosixAttachOperation` class as it’s used by [VM_Crac::is_socket_from_jcmd](https://github.com/openjdk/crac/blob/647105388b66b7acedf03d049dc60323912a8fe7/src/hotspot/os/linux/crac_linux.cpp#L279) 
 - changes in `PosixAttachListener` class incorporated into `posix/attachListener_posix.hpp`

Additional changes in `posix/attachListener_posix.cpp`
 - changes in `PosixAttachOperation::complete` incorporated into `write_operation_result`

<details>

<summary>Conflicts</summary>


commit c54dd827b39e7e0066959e4985e4aaefd5452a10 (HEAD -> merge-jdk, dmitry-crac/merge-jdk)
Merge: 410d0e168c3 23d6f747824
Author: Dmitry Cherepanov <dcherepanov at azul.com>
Date:   Mon Apr 14 13:55:59 2025 +0400

    Merge with jdk:jdk-25+3

diff --git a/.jcheck/conf b/.jcheck/conf
remerge CONFLICT (content): Merge conflict in .jcheck/conf
index 1d117b1d825..25bd8dd0b94 100644
--- a/.jcheck/conf
+++ b/.jcheck/conf
@@ -4,12 +4,7 @@ jbs=JDK
 version=25
 
 [checks]
-<<<<<<< 410d0e168c3 (8353243: [CRaC] Show all options in engine help)
 error=whitespace
-=======
-error=author,committer,reviewers,merge,issues,executable,symlink,message,hg-tag,whitespace,problemlists,copyright
-warning=issuestitle,binary
->>>>>>> 23d6f747824 (8346463: Add test coverage for deploying the default provider as a module)
 
 [checks "reviewers"]
 committers=1
@@ -18,31 +13,3 @@ ignore=duke
 [census]
 version=0
 domain=openjdk.org
-<<<<<<< 410d0e168c3 (8353243: [CRaC] Show all options in engine help)
-=======
-
-[checks "whitespace"]
-files=.*.cpp|.*.hpp|.*.c|.*.h|.*.java|.*.cc|.*.hh|.*.m|.*.mm|.*.S|.*.md|.*.properties|.*.gmk|.*.m4|.*.ac|Makefile
-ignore-tabs=.*.gmk|Makefile
-
-[checks "merge"]
-message=Merge
-
-[checks "reviewers"]
-reviewers=1
-ignore=duke
-
-[checks "committer"]
-role=committer
-
-[checks "issues"]
-pattern=^([124-8][0-9]{6}): (\S.*)$
-
-[checks "problemlists"]
-dirs=test/jdk|test/langtools|test/lib-test|test/hotspot/jtreg|test/jaxp
-
-[checks "copyright"]
-files=^(?!LICENSE|license.txt|.*.bin|.*.gif|.*.jpg|.*.png|.*.icon|.*.tiff|.*.dat|.*.patch|.*.wav|.*.class|.*-header|.*.jar|).*
-oracle_locator=.*Copyright (c)(.*)Oracle and/or its affiliates. All rights reserved.
-oracle_validator=.*Copyright (c) (\d{4})(?:, (\d{4}))?, Oracle and/or its affiliates. All rights reserved.
->>>>>>> 23d6f747824 (8346463: Add test coverage for deploying the default provider as a module)
diff --git a/src/hotspot/os/posix/attachListener_posix.cpp b/src/hotspot/os/posix/attachListener_posix.cpp
remerge CONFLICT (content): Merge conflict in src/hotspot/os/posix/attachListener_posix.cpp
index f1ad8d81a14..49b53130608 100644
--- a/src/hotspot/os/posix/attachListener_posix.cpp
+++ b/src/hotspot/os/posix/attachListener_posix.cpp
@@ -45,10 +45,6 @@
 #if INCLUDE_SERVICES
 #ifndef AIX
 
-#ifndef UNIX_PATH_MAX
-#define UNIX_PATH_MAX   sizeof(sockaddr_un::sun_path)
-#endif
-
 // The attach mechanism on Linux and BSD uses a UNIX domain socket. An attach
 // listener thread is created at startup or is created on-demand via a signal
 // from the client tool. The attach listener creates a socket and binds it to a
@@ -65,102 +61,6 @@
 //    obtain the credentials of client. We check that the effective uid
 //    of the client matches this process.
 
-<<<<<<< 410d0e168c3 (8353243: [CRaC] Show all options in engine help)
-=======
-// forward reference
-class PosixAttachOperation;
-
-class PosixAttachListener: AllStatic {
- private:
-  // the path to which we bind the UNIX domain socket
-  static char _path[UNIX_PATH_MAX];
-  static bool _has_path;
-
-  // the file descriptor for the listening socket
-  static volatile int _listener;
-
-  static bool _atexit_registered;
-
- public:
-  static void set_path(char* path) {
-    if (path == nullptr) {
-      _path[0] = '\0';
-      _has_path = false;
-    } else {
-      strncpy(_path, path, UNIX_PATH_MAX);
-      _path[UNIX_PATH_MAX-1] = '\0';
-      _has_path = true;
-    }
-  }
-
-  static void set_listener(int s)               { _listener = s; }
-
-  // initialize the listener, returns 0 if okay
-  static int init();
-
-  static char* path()                   { return _path; }
-  static bool has_path()                { return _has_path; }
-  static int listener()                 { return _listener; }
-
-  static PosixAttachOperation* dequeue();
-};
-
-class SocketChannel : public AttachOperation::RequestReader, public AttachOperation::ReplyWriter {
-private:
-  int _socket;
-public:
-  SocketChannel(int socket) : _socket(socket) {}
-  ~SocketChannel() {
-    close();
-  }
-
-  bool opened() const {
-    return _socket != -1;
-  }
-
-  void close() {
-    if (opened()) {
-      ::close(_socket);
-      _socket = -1;
-    }
-  }
-
-  // RequestReader
-  int read(void* buffer, int size) override {
-    ssize_t n;
-    RESTARTABLE(::read(_socket, buffer, (size_t)size), n);
-    return checked_cast<int>(n);
-  }
-
-  // ReplyWriter
-  int write(const void* buffer, int size) override {
-    ssize_t n;
-    RESTARTABLE(::write(_socket, buffer, size), n);
-    return checked_cast<int>(n);
-  }
-  // called after writing all data
-  void flush() override {
-    ::shutdown(_socket, SHUT_RDWR);
-  }
-};
-
-class PosixAttachOperation: public AttachOperation {
- private:
-  // the connection to the client
-  SocketChannel _socket_channel;
-
- public:
-  void complete(jint res, bufferedStream* st) override;
-
-  PosixAttachOperation(int socket) : AttachOperation(), _socket_channel(socket) {
-  }
-
-  bool read_request() {
-    return AttachOperation::read_request(&_socket_channel, &_socket_channel);
-  }
-};
-
->>>>>>> 23d6f747824 (8346463: Add test coverage for deploying the default provider as a module)
 // statics
 char PosixAttachListener::_path[UNIX_PATH_MAX];
 bool PosixAttachListener::_has_path;
@@ -318,22 +218,6 @@ PosixAttachOperation* PosixAttachListener::dequeue() {
   }
 }
 
-<<<<<<< 410d0e168c3 (8353243: [CRaC] Show all options in engine help)
-// write the given buffer to the socket
-int PosixAttachListener::write_fully(int s, char* buf, size_t len) {
-  do {
-    ssize_t n = ::write(s, buf, len);
-    if (n == -1) {
-      if (errno != EINTR) return -1;
-    } else {
-      buf += n;
-      len -= n;
-    }
-  }
-  while (len > 0);
-  return 0;
-}
-
 // An operation completion is splitted into two parts.
 // For proper handling the jcmd connection at CRaC checkpoint action.
 // An effectively_complete_raw is called in checkpoint processing, before criu engine calls, for properly closing the socket.
@@ -346,8 +230,6 @@ void PosixAttachOperation::complete(jint result, bufferedStream* st) {
   delete this;
 }
 
-=======
->>>>>>> 23d6f747824 (8346463: Add test coverage for deploying the default provider as a module)
 // Complete an operation by sending the operation result and any result
 // output to the client. At this time the socket is in blocking mode so
 // potentially we can block if there is a lot of data and the client is
@@ -363,7 +245,6 @@ void PosixAttachOperation::effectively_complete_raw(jint result, bufferedStream*
     return;
   }
 
-<<<<<<< 410d0e168c3 (8353243: [CRaC] Show all options in engine help)
   // write operation result
   Thread* thread = Thread::current();
   if (thread->is_Java_thread()) {
@@ -376,24 +257,10 @@ void PosixAttachOperation::effectively_complete_raw(jint result, bufferedStream*
 }
 
 void PosixAttachOperation::write_operation_result(jint result, bufferedStream* st) {
-  char msg[32];
-  os::snprintf_checked(msg, sizeof(msg), "%d\n", result);
-  int rc = PosixAttachListener::write_fully(this->socket(), msg, strlen(msg));
-
-  // write any result data
-  if (rc == 0) {
-    PosixAttachListener::write_fully(this->socket(), (char*) st->base(), st->size());
-    ::shutdown(this->socket(), SHUT_RDWR);
-  }
-
-  // done
-  ::close(this->socket());
-  st->reset();
-=======
   write_reply(&_socket_channel, result, st);
 
-  delete this;
->>>>>>> 23d6f747824 (8346463: Add test coverage for deploying the default provider as a module)
+  _socket_channel.close();
+  st->reset();
 }
 
 static void assert_listener_thread() {
diff --git a/src/hotspot/os/posix/attachListener_posix.hpp b/src/hotspot/os/posix/attachListener_posix.hpp
index b945020e20d..a0fca688b5f 100644
--- a/src/hotspot/os/posix/attachListener_posix.hpp
+++ b/src/hotspot/os/posix/attachListener_posix.hpp
@@ -36,7 +36,7 @@ class PosixAttachListener;
 #include <sys/un.h>
 
 #ifndef UNIX_PATH_MAX
-#define UNIX_PATH_MAX   sizeof(((struct sockaddr_un *)0)->sun_path)
+#define UNIX_PATH_MAX   sizeof(sockaddr_un::sun_path)
 #endif
 
 class PosixAttachListener: AllStatic {
@@ -53,17 +53,7 @@ class PosixAttachListener: AllStatic {
   // this is for proper reporting JDK.Chekpoint processing to jcmd peer
   static PosixAttachOperation* _current_op;
 
-  // reads a request from the given connected socket
-  static PosixAttachOperation* read_request(int s);
-
  public:
-  enum {
-    ATTACH_PROTOCOL_VER = 1                     // protocol version
-  };
-  enum {
-    ATTACH_ERROR_BADVERSION     = 101           // error codes
-  };
-
   static void set_path(char* path) {
     if (path == nullptr) {
       _path[0] = '\0';
@@ -84,9 +74,6 @@ class PosixAttachListener: AllStatic {
   static bool has_path()                { return _has_path; }
   static int listener()                 { return _listener; }
 
-  // write the given buffer to a socket
-  static int write_fully(int s, char* buf, size_t len);
-
   static PosixAttachOperation* dequeue();
   static PosixAttachOperation* get_current_op();
   static void reset_current_op();
diff --git a/src/hotspot/os/posix/posixAttachOperation.hpp b/src/hotspot/os/posix/posixAttachOperation.hpp
index 1d031d882da..10f253a3f76 100644
--- a/src/hotspot/os/posix/posixAttachOperation.hpp
+++ b/src/hotspot/os/posix/posixAttachOperation.hpp
@@ -26,31 +26,79 @@
 #ifndef OS_POSIX_POSIXATTACHOPERATION_HPP
 #define OS_POSIX_POSIXATTACHOPERATION_HPP
 
+#include "os_posix.hpp"
 #include "services/attachListener.hpp"
 
 class PosixAttachOperation;
 
 #if INCLUDE_SERVICES
 
+class SocketChannel : public AttachOperation::RequestReader, public AttachOperation::ReplyWriter {
+private:
+  int _socket;
+public:
+  SocketChannel(int socket) : _socket(socket) {}
+  ~SocketChannel() {
+    close();
+  }
+
+  int socket() const {
+    return _socket;
+  }
+
+  bool opened() const {
+    return _socket != -1;
+  }
+
+  void close() {
+    if (opened()) {
+      ::close(_socket);
+      _socket = -1;
+    }
+  }
+
+  // RequestReader
+  int read(void* buffer, int size) override {
+    ssize_t n;
+    RESTARTABLE(::read(_socket, buffer, (size_t)size), n);
+    return checked_cast<int>(n);
+  }
+
+  // ReplyWriter
+  int write(const void* buffer, int size) override {
+    ssize_t n;
+    RESTARTABLE(::write(_socket, buffer, size), n);
+    return checked_cast<int>(n);
+  }
+  // called after writing all data
+  void flush() override {
+    ::shutdown(_socket, SHUT_RDWR);
+  }
+};
+
 class PosixAttachOperation: public AttachOperation {
  private:
   // the connection to the client
-  int _socket;
+  SocketChannel _socket_channel;
   bool _effectively_completed;
   void write_operation_result(jint result, bufferedStream* st);
 
  public:
-  void complete(jint res, bufferedStream* st);
+  void complete(jint res, bufferedStream* st) override;
   void effectively_complete_raw(jint res, bufferedStream* st);
   bool is_effectively_completed()                      { return _effectively_completed; }
 
-  void set_socket(int s)                                { _socket = s; }
-  int socket() const                                    { return _socket; }
+  int socket() {
+    return _socket_channel.socket();;
+  }
 
-  PosixAttachOperation(char* name) : AttachOperation(name) {
-    set_socket(-1);
+  PosixAttachOperation(int socket) : AttachOperation(), _socket_channel(socket) {
     _effectively_completed = false;
   }
+
+  bool read_request() {
+    return AttachOperation::read_request(&_socket_channel, &_socket_channel);
+  }
 };
 
 #endif // INCLUDE_SERVICES


</details>

<details>

<summary>Conflicts (diff3)</summary>


commit c54dd827b39e7e0066959e4985e4aaefd5452a10 (HEAD -> merge-jdk, dmitry-crac/merge-jdk)
Merge: 410d0e168c3 23d6f747824
Author: Dmitry Cherepanov <dcherepanov at azul.com>
Date:   Mon Apr 14 13:55:59 2025 +0400

    Merge with jdk:jdk-25+3

diff --git a/.jcheck/conf b/.jcheck/conf
remerge CONFLICT (content): Merge conflict in .jcheck/conf
index 4816067cada..25bd8dd0b94 100644
--- a/.jcheck/conf
+++ b/.jcheck/conf
@@ -4,15 +4,7 @@ jbs=JDK
 version=25
 
 [checks]
-<<<<<<< 410d0e168c3 (8353243: [CRaC] Show all options in engine help)
 error=whitespace
-||||||| ceb4366ebf0
-error=author,committer,reviewers,merge,issues,executable,symlink,message,hg-tag,whitespace,problemlists
-warning=issuestitle,binary
-=======
-error=author,committer,reviewers,merge,issues,executable,symlink,message,hg-tag,whitespace,problemlists,copyright
-warning=issuestitle,binary
->>>>>>> 23d6f747824 (8346463: Add test coverage for deploying the default provider as a module)
 
 [checks "reviewers"]
 committers=1
@@ -21,52 +13,3 @@ ignore=duke
 [census]
 version=0
 domain=openjdk.org
-<<<<<<< 410d0e168c3 (8353243: [CRaC] Show all options in engine help)
-||||||| ceb4366ebf0
-
-[checks "whitespace"]
-files=.*.cpp|.*.hpp|.*.c|.*.h|.*.java|.*.cc|.*.hh|.*.m|.*.mm|.*.S|.*.md|.*.properties|.*.gmk|.*.m4|.*.ac|Makefile
-ignore-tabs=.*.gmk|Makefile
-
-[checks "merge"]
-message=Merge
-
-[checks "reviewers"]
-reviewers=1
-ignore=duke
-
-[checks "committer"]
-role=committer
-
-[checks "issues"]
-pattern=^([124-8][0-9]{6}): (\S.*)$
-
-[checks "problemlists"]
-dirs=test/jdk|test/langtools|test/lib-test|test/hotspot/jtreg|test/jaxp
-=======
-
-[checks "whitespace"]
-files=.*.cpp|.*.hpp|.*.c|.*.h|.*.java|.*.cc|.*.hh|.*.m|.*.mm|.*.S|.*.md|.*.properties|.*.gmk|.*.m4|.*.ac|Makefile
-ignore-tabs=.*.gmk|Makefile
-
-[checks "merge"]
-message=Merge
-
-[checks "reviewers"]
-reviewers=1
-ignore=duke
-
-[checks "committer"]
-role=committer
-
-[checks "issues"]
-pattern=^([124-8][0-9]{6}): (\S.*)$
-
-[checks "problemlists"]
-dirs=test/jdk|test/langtools|test/lib-test|test/hotspot/jtreg|test/jaxp
-
-[checks "copyright"]
-files=^(?!LICENSE|license.txt|.*.bin|.*.gif|.*.jpg|.*.png|.*.icon|.*.tiff|.*.dat|.*.patch|.*.wav|.*.class|.*-header|.*.jar|).*
-oracle_locator=.*Copyright (c)(.*)Oracle and/or its affiliates. All rights reserved.
-oracle_validator=.*Copyright (c) (\d{4})(?:, (\d{4}))?, Oracle and/or its affiliates. All rights reserved.
->>>>>>> 23d6f747824 (8346463: Add test coverage for deploying the default provider as a module)
diff --git a/src/hotspot/os/posix/attachListener_posix.cpp b/src/hotspot/os/posix/attachListener_posix.cpp
remerge CONFLICT (content): Merge conflict in src/hotspot/os/posix/attachListener_posix.cpp
index b98f7d437a6..49b53130608 100644
--- a/src/hotspot/os/posix/attachListener_posix.cpp
+++ b/src/hotspot/os/posix/attachListener_posix.cpp
@@ -45,10 +45,6 @@
 #if INCLUDE_SERVICES
 #ifndef AIX
 
-#ifndef UNIX_PATH_MAX
-#define UNIX_PATH_MAX   sizeof(sockaddr_un::sun_path)
-#endif
-
 // The attach mechanism on Linux and BSD uses a UNIX domain socket. An attach
 // listener thread is created at startup or is created on-demand via a signal
 // from the client tool. The attach listener creates a socket and binds it to a
@@ -65,170 +61,6 @@
 //    obtain the credentials of client. We check that the effective uid
 //    of the client matches this process.
 
-<<<<<<< 410d0e168c3 (8353243: [CRaC] Show all options in engine help)
-||||||| ceb4366ebf0
-// forward reference
-class PosixAttachOperation;
-
-class PosixAttachListener: AllStatic {
- private:
-  // the path to which we bind the UNIX domain socket
-  static char _path[UNIX_PATH_MAX];
-  static bool _has_path;
-
-  // the file descriptor for the listening socket
-  static volatile int _listener;
-
-  static bool _atexit_registered;
-
-  // reads a request from the given connected socket
-  static PosixAttachOperation* read_request(int s);
-
- public:
-  enum {
-    ATTACH_PROTOCOL_VER = 1                     // protocol version
-  };
-  enum {
-    ATTACH_ERROR_BADVERSION     = 101           // error codes
-  };
-
-  static void set_path(char* path) {
-    if (path == nullptr) {
-      _path[0] = '\0';
-      _has_path = false;
-    } else {
-      strncpy(_path, path, UNIX_PATH_MAX);
-      _path[UNIX_PATH_MAX-1] = '\0';
-      _has_path = true;
-    }
-  }
-
-  static void set_listener(int s)               { _listener = s; }
-
-  // initialize the listener, returns 0 if okay
-  static int init();
-
-  static char* path()                   { return _path; }
-  static bool has_path()                { return _has_path; }
-  static int listener()                 { return _listener; }
-
-  // write the given buffer to a socket
-  static int write_fully(int s, char* buf, size_t len);
-
-  static PosixAttachOperation* dequeue();
-};
-
-class PosixAttachOperation: public AttachOperation {
- private:
-  // the connection to the client
-  int _socket;
-
- public:
-  void complete(jint res, bufferedStream* st);
-
-  void set_socket(int s)                                { _socket = s; }
-  int socket() const                                    { return _socket; }
-
-  PosixAttachOperation(char* name) : AttachOperation(name) {
-    set_socket(-1);
-  }
-};
-
-=======
-// forward reference
-class PosixAttachOperation;
-
-class PosixAttachListener: AllStatic {
- private:
-  // the path to which we bind the UNIX domain socket
-  static char _path[UNIX_PATH_MAX];
-  static bool _has_path;
-
-  // the file descriptor for the listening socket
-  static volatile int _listener;
-
-  static bool _atexit_registered;
-
- public:
-  static void set_path(char* path) {
-    if (path == nullptr) {
-      _path[0] = '\0';
-      _has_path = false;
-    } else {
-      strncpy(_path, path, UNIX_PATH_MAX);
-      _path[UNIX_PATH_MAX-1] = '\0';
-      _has_path = true;
-    }
-  }
-
-  static void set_listener(int s)               { _listener = s; }
-
-  // initialize the listener, returns 0 if okay
-  static int init();
-
-  static char* path()                   { return _path; }
-  static bool has_path()                { return _has_path; }
-  static int listener()                 { return _listener; }
-
-  static PosixAttachOperation* dequeue();
-};
-
-class SocketChannel : public AttachOperation::RequestReader, public AttachOperation::ReplyWriter {
-private:
-  int _socket;
-public:
-  SocketChannel(int socket) : _socket(socket) {}
-  ~SocketChannel() {
-    close();
-  }
-
-  bool opened() const {
-    return _socket != -1;
-  }
-
-  void close() {
-    if (opened()) {
-      ::close(_socket);
-      _socket = -1;
-    }
-  }
-
-  // RequestReader
-  int read(void* buffer, int size) override {
-    ssize_t n;
-    RESTARTABLE(::read(_socket, buffer, (size_t)size), n);
-    return checked_cast<int>(n);
-  }
-
-  // ReplyWriter
-  int write(const void* buffer, int size) override {
-    ssize_t n;
-    RESTARTABLE(::write(_socket, buffer, size), n);
-    return checked_cast<int>(n);
-  }
-  // called after writing all data
-  void flush() override {
-    ::shutdown(_socket, SHUT_RDWR);
-  }
-};
-
-class PosixAttachOperation: public AttachOperation {
- private:
-  // the connection to the client
-  SocketChannel _socket_channel;
-
- public:
-  void complete(jint res, bufferedStream* st) override;
-
-  PosixAttachOperation(int socket) : AttachOperation(), _socket_channel(socket) {
-  }
-
-  bool read_request() {
-    return AttachOperation::read_request(&_socket_channel, &_socket_channel);
-  }
-};
-
->>>>>>> 23d6f747824 (8346463: Add test coverage for deploying the default provider as a module)
 // statics
 char PosixAttachListener::_path[UNIX_PATH_MAX];
 bool PosixAttachListener::_has_path;
@@ -386,22 +218,6 @@ PosixAttachOperation* PosixAttachListener::dequeue() {
   }
 }
 
-<<<<<<< 410d0e168c3 (8353243: [CRaC] Show all options in engine help)
-// write the given buffer to the socket
-int PosixAttachListener::write_fully(int s, char* buf, size_t len) {
-  do {
-    ssize_t n = ::write(s, buf, len);
-    if (n == -1) {
-      if (errno != EINTR) return -1;
-    } else {
-      buf += n;
-      len -= n;
-    }
-  }
-  while (len > 0);
-  return 0;
-}
-
 // An operation completion is splitted into two parts.
 // For proper handling the jcmd connection at CRaC checkpoint action.
 // An effectively_complete_raw is called in checkpoint processing, before criu engine calls, for properly closing the socket.
@@ -414,24 +230,6 @@ void PosixAttachOperation::complete(jint result, bufferedStream* st) {
   delete this;
 }
 
-||||||| ceb4366ebf0
-// write the given buffer to the socket
-int PosixAttachListener::write_fully(int s, char* buf, size_t len) {
-  do {
-    ssize_t n = ::write(s, buf, len);
-    if (n == -1) {
-      if (errno != EINTR) return -1;
-    } else {
-      buf += n;
-      len -= n;
-    }
-  }
-  while (len > 0);
-  return 0;
-}
-
-=======
->>>>>>> 23d6f747824 (8346463: Add test coverage for deploying the default provider as a module)
 // Complete an operation by sending the operation result and any result
 // output to the client. At this time the socket is in blocking mode so
 // potentially we can block if there is a lot of data and the client is
@@ -447,7 +245,6 @@ void PosixAttachOperation::effectively_complete_raw(jint result, bufferedStream*
     return;
   }
 
-<<<<<<< 410d0e168c3 (8353243: [CRaC] Show all options in engine help)
   // write operation result
   Thread* thread = Thread::current();
   if (thread->is_Java_thread()) {
@@ -460,40 +257,10 @@ void PosixAttachOperation::effectively_complete_raw(jint result, bufferedStream*
 }
 
 void PosixAttachOperation::write_operation_result(jint result, bufferedStream* st) {
-  char msg[32];
-  os::snprintf_checked(msg, sizeof(msg), "%d\n", result);
-  int rc = PosixAttachListener::write_fully(this->socket(), msg, strlen(msg));
-
-  // write any result data
-  if (rc == 0) {
-    PosixAttachListener::write_fully(this->socket(), (char*) st->base(), st->size());
-    ::shutdown(this->socket(), SHUT_RDWR);
-  }
-
-  // done
-  ::close(this->socket());
-  st->reset();
-||||||| ceb4366ebf0
-  // write operation result
-  char msg[32];
-  os::snprintf_checked(msg, sizeof(msg), "%d\n", result);
-  int rc = PosixAttachListener::write_fully(this->socket(), msg, strlen(msg));
-
-  // write any result data
-  if (rc == 0) {
-    PosixAttachListener::write_fully(this->socket(), (char*) st->base(), st->size());
-    ::shutdown(this->socket(), 2);
-  }
-
-  // done
-  ::close(this->socket());
-
-  delete this;
-=======
   write_reply(&_socket_channel, result, st);
 
-  delete this;
->>>>>>> 23d6f747824 (8346463: Add test coverage for deploying the default provider as a module)
+  _socket_channel.close();
+  st->reset();
 }
 
 static void assert_listener_thread() {
diff --git a/src/hotspot/os/posix/attachListener_posix.hpp b/src/hotspot/os/posix/attachListener_posix.hpp
index b945020e20d..a0fca688b5f 100644
--- a/src/hotspot/os/posix/attachListener_posix.hpp
+++ b/src/hotspot/os/posix/attachListener_posix.hpp
@@ -36,7 +36,7 @@ class PosixAttachListener;
 #include <sys/un.h>
 
 #ifndef UNIX_PATH_MAX
-#define UNIX_PATH_MAX   sizeof(((struct sockaddr_un *)0)->sun_path)
+#define UNIX_PATH_MAX   sizeof(sockaddr_un::sun_path)
 #endif
 
 class PosixAttachListener: AllStatic {
@@ -53,17 +53,7 @@ class PosixAttachListener: AllStatic {
   // this is for proper reporting JDK.Chekpoint processing to jcmd peer
   static PosixAttachOperation* _current_op;
 
-  // reads a request from the given connected socket
-  static PosixAttachOperation* read_request(int s);
-
  public:
-  enum {
-    ATTACH_PROTOCOL_VER = 1                     // protocol version
-  };
-  enum {
-    ATTACH_ERROR_BADVERSION     = 101           // error codes
-  };
-
   static void set_path(char* path) {
     if (path == nullptr) {
       _path[0] = '\0';
@@ -84,9 +74,6 @@ class PosixAttachListener: AllStatic {
   static bool has_path()                { return _has_path; }
   static int listener()                 { return _listener; }
 
-  // write the given buffer to a socket
-  static int write_fully(int s, char* buf, size_t len);
-
   static PosixAttachOperation* dequeue();
   static PosixAttachOperation* get_current_op();
   static void reset_current_op();
diff --git a/src/hotspot/os/posix/posixAttachOperation.hpp b/src/hotspot/os/posix/posixAttachOperation.hpp
index 1d031d882da..10f253a3f76 100644
--- a/src/hotspot/os/posix/posixAttachOperation.hpp
+++ b/src/hotspot/os/posix/posixAttachOperation.hpp
@@ -26,31 +26,79 @@
 #ifndef OS_POSIX_POSIXATTACHOPERATION_HPP
 #define OS_POSIX_POSIXATTACHOPERATION_HPP
 
+#include "os_posix.hpp"
 #include "services/attachListener.hpp"
 
 class PosixAttachOperation;
 
 #if INCLUDE_SERVICES
 
+class SocketChannel : public AttachOperation::RequestReader, public AttachOperation::ReplyWriter {
+private:
+  int _socket;
+public:
+  SocketChannel(int socket) : _socket(socket) {}
+  ~SocketChannel() {
+    close();
+  }
+
+  int socket() const {
+    return _socket;
+  }
+
+  bool opened() const {
+    return _socket != -1;
+  }
+
+  void close() {
+    if (opened()) {
+      ::close(_socket);
+      _socket = -1;
+    }
+  }
+
+  // RequestReader
+  int read(void* buffer, int size) override {
+    ssize_t n;
+    RESTARTABLE(::read(_socket, buffer, (size_t)size), n);
+    return checked_cast<int>(n);
+  }
+
+  // ReplyWriter
+  int write(const void* buffer, int size) override {
+    ssize_t n;
+    RESTARTABLE(::write(_socket, buffer, size), n);
+    return checked_cast<int>(n);
+  }
+  // called after writing all data
+  void flush() override {
+    ::shutdown(_socket, SHUT_RDWR);
+  }
+};
+
 class PosixAttachOperation: public AttachOperation {
  private:
   // the connection to the client
-  int _socket;
+  SocketChannel _socket_channel;
   bool _effectively_completed;
   void write_operation_result(jint result, bufferedStream* st);
 
  public:
-  void complete(jint res, bufferedStream* st);
+  void complete(jint res, bufferedStream* st) override;
   void effectively_complete_raw(jint res, bufferedStream* st);
   bool is_effectively_completed()                      { return _effectively_completed; }
 
-  void set_socket(int s)                                { _socket = s; }
-  int socket() const                                    { return _socket; }
+  int socket() {
+    return _socket_channel.socket();;
+  }
 
-  PosixAttachOperation(char* name) : AttachOperation(name) {
-    set_socket(-1);
+  PosixAttachOperation(int socket) : AttachOperation(), _socket_channel(socket) {
     _effectively_completed = false;
   }
+
+  bool read_request() {
+    return AttachOperation::read_request(&_socket_channel, &_socket_channel);
+  }
 };
 
 #endif // INCLUDE_SERVICES


</details>

-------------

Commit messages:
 - Merge with jdk:jdk-25+3
 - 8346463: Add test coverage for deploying the default provider as a module
 - 8346306: Unattached thread can cause crash during VM exit if it calls wait_if_vm_exited
 - 8340401: DcmdMBeanPermissionsTest.java and SystemDumpMapTest.java fail with assert(_stack_base != nullptr) failed: Sanity check
 - 8346475: RISC-V: Small improvement for MacroAssembler::ctzc_bit
 - 8346016: Problemlist vm/mlvm/indy/func/jvmti/mergeCP_indy2manyDiff_a in virtual thread mode
 - 8346132: fallbacklinker.c failed compilation due to unused variable
 - 8346570: SM cleanup of tests for Beans and Serialization
 - 8346532: XXXVector::rearrangeTemplate misses null check
 - 8346300: Add @Test annotation to TCKZoneId.test_constant_OLD_IDS_POST_2024b test
 - ... and 84 more: https://git.openjdk.org/crac/compare/410d0e16...c54dd827

The webrevs contain the adjustments done while merging with regards to each parent branch:
 - crac: https://webrevs.openjdk.org/?repo=crac&pr=224&range=00.0
 - jdk:jdk-25+3: https://webrevs.openjdk.org/?repo=crac&pr=224&range=00.1

Changes: https://git.openjdk.org/crac/pull/224/files
  Stats: 14344 lines in 943 files changed: 9675 ins; 2416 del; 2253 mod
  Patch: https://git.openjdk.org/crac/pull/224.diff
  Fetch: git fetch https://git.openjdk.org/crac.git pull/224/head:pull/224

PR: https://git.openjdk.org/crac/pull/224


More information about the crac-dev mailing list