Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8319055: JCMD should not buffer the whole output of commands #23405

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/hotspot/os/posix/attachListener_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class SocketChannel : public AttachOperation::RequestReader, public AttachOperat

void close() {
if (opened()) {
::shutdown(_socket, SHUT_RDWR);
::close(_socket);
_socket = -1;
}
Expand All @@ -132,9 +133,8 @@ class SocketChannel : public AttachOperation::RequestReader, public AttachOperat
RESTARTABLE(::write(_socket, buffer, size), n);
return checked_cast<int>(n);
}
// called after writing all data

void flush() override {
::shutdown(_socket, SHUT_RDWR);
}
};

Expand All @@ -144,13 +144,17 @@ class PosixAttachOperation: public AttachOperation {
SocketChannel _socket_channel;

public:
PosixAttachOperation(int socket) : AttachOperation(), _socket_channel(socket) {
}

void complete(jint res, bufferedStream* st) override;

PosixAttachOperation(int socket) : AttachOperation(), _socket_channel(socket) {
virtual ReplyWriter* get_reply_writer() override {
return &_socket_channel;
}

bool read_request() {
return AttachOperation::read_request(&_socket_channel, &_socket_channel);
return _socket_channel.read_request(this, &_socket_channel);
}
};

Expand Down Expand Up @@ -318,11 +322,6 @@ PosixAttachOperation* PosixAttachListener::dequeue() {
// socket could be made non-blocking and a timeout could be used.

void PosixAttachOperation::complete(jint result, bufferedStream* st) {
JavaThread* thread = JavaThread::current();
ThreadBlockInVM tbivm(thread);

write_reply(&_socket_channel, result, st);

delete this;
}

Expand Down
18 changes: 8 additions & 10 deletions src/hotspot/os/windows/attachListener_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class PipeChannel : public AttachOperation::RequestReader, public AttachOperatio

void close() {
if (opened()) {
FlushFileBuffers(_hPipe);
CloseHandle(_hPipe);
_hPipe = INVALID_HANDLE_VALUE;
}
Expand Down Expand Up @@ -123,15 +124,13 @@ class PipeChannel : public AttachOperation::RequestReader, public AttachOperatio
&written,
nullptr); // not overlapped
if (!fSuccess) {
log_error(attach)("pipe write error (%d)", GetLastError());
return -1;
log_error(attach)("pipe write error (%d)", GetLastError());
return -1;
}
return (int)written;
}

void flush() override {
assert(opened(), "must be");
FlushFileBuffers(_hPipe);
}
};

Expand All @@ -151,11 +150,15 @@ class Win32AttachOperation: public AttachOperation {
}

bool read_request() {
return AttachOperation::read_request(&_pipe, &_pipe);
return _pipe.read_request(this, &_pipe);
}

public:
void complete(jint result, bufferedStream* result_stream) override;

virtual ReplyWriter* get_reply_writer() override {
return &_pipe;
}
};


Expand Down Expand Up @@ -432,11 +435,6 @@ Win32AttachOperation* Win32AttachListener::dequeue() {
}

void Win32AttachOperation::complete(jint result, bufferedStream* result_stream) {
JavaThread* thread = JavaThread::current();
ThreadBlockInVM tbivm(thread);

write_reply(&_pipe, result, result_stream);

delete this;
}

Expand Down
Loading