Skip to content

Commit 8315876

Browse files
Alex Menkovpull[bot]
authored andcommitted
8319055: JCMD should not buffer the whole output of commands
Reviewed-by: stuefe, jsjolen
1 parent 3ea07ec commit 8315876

File tree

12 files changed

+563
-132
lines changed

12 files changed

+563
-132
lines changed

src/hotspot/os/posix/attachListener_posix.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class SocketChannel : public AttachOperation::RequestReader, public AttachOperat
114114

115115
void close() {
116116
if (opened()) {
117+
::shutdown(_socket, SHUT_RDWR);
117118
::close(_socket);
118119
_socket = -1;
119120
}
@@ -132,9 +133,8 @@ class SocketChannel : public AttachOperation::RequestReader, public AttachOperat
132133
RESTARTABLE(::write(_socket, buffer, size), n);
133134
return checked_cast<int>(n);
134135
}
135-
// called after writing all data
136+
136137
void flush() override {
137-
::shutdown(_socket, SHUT_RDWR);
138138
}
139139
};
140140

@@ -144,13 +144,16 @@ class PosixAttachOperation: public AttachOperation {
144144
SocketChannel _socket_channel;
145145

146146
public:
147+
PosixAttachOperation(int socket) : AttachOperation(), _socket_channel(socket) {}
148+
147149
void complete(jint res, bufferedStream* st) override;
148150

149-
PosixAttachOperation(int socket) : AttachOperation(), _socket_channel(socket) {
151+
ReplyWriter* get_reply_writer() override {
152+
return &_socket_channel;
150153
}
151154

152155
bool read_request() {
153-
return AttachOperation::read_request(&_socket_channel, &_socket_channel);
156+
return _socket_channel.read_request(this, &_socket_channel);
154157
}
155158
};
156159

@@ -318,11 +321,6 @@ PosixAttachOperation* PosixAttachListener::dequeue() {
318321
// socket could be made non-blocking and a timeout could be used.
319322

320323
void PosixAttachOperation::complete(jint result, bufferedStream* st) {
321-
JavaThread* thread = JavaThread::current();
322-
ThreadBlockInVM tbivm(thread);
323-
324-
write_reply(&_socket_channel, result, st);
325-
326324
delete this;
327325
}
328326

src/hotspot/os/windows/attachListener_windows.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class PipeChannel : public AttachOperation::RequestReader, public AttachOperatio
9292

9393
void close() {
9494
if (opened()) {
95+
FlushFileBuffers(_hPipe);
9596
CloseHandle(_hPipe);
9697
_hPipe = INVALID_HANDLE_VALUE;
9798
}
@@ -123,15 +124,13 @@ class PipeChannel : public AttachOperation::RequestReader, public AttachOperatio
123124
&written,
124125
nullptr); // not overlapped
125126
if (!fSuccess) {
126-
log_error(attach)("pipe write error (%d)", GetLastError());
127-
return -1;
127+
log_error(attach)("pipe write error (%d)", GetLastError());
128+
return -1;
128129
}
129130
return (int)written;
130131
}
131132

132133
void flush() override {
133-
assert(opened(), "must be");
134-
FlushFileBuffers(_hPipe);
135134
}
136135
};
137136

@@ -151,11 +150,15 @@ class Win32AttachOperation: public AttachOperation {
151150
}
152151

153152
bool read_request() {
154-
return AttachOperation::read_request(&_pipe, &_pipe);
153+
return _pipe.read_request(this, &_pipe);
155154
}
156155

157156
public:
158157
void complete(jint result, bufferedStream* result_stream) override;
158+
159+
ReplyWriter* get_reply_writer() override {
160+
return &_pipe;
161+
}
159162
};
160163

161164

@@ -432,11 +435,6 @@ Win32AttachOperation* Win32AttachListener::dequeue() {
432435
}
433436

434437
void Win32AttachOperation::complete(jint result, bufferedStream* result_stream) {
435-
JavaThread* thread = JavaThread::current();
436-
ThreadBlockInVM tbivm(thread);
437-
438-
write_reply(&_pipe, result, result_stream);
439-
440438
delete this;
441439
}
442440

0 commit comments

Comments
 (0)