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

Report checkpoint processing to jcmd #10

Closed
wants to merge 56 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
bb90954
Implementation of reporting
Larry-N Jan 25, 2022
7ab406c
Check the opened socket, if it is UNIX socked from jcmd.
Larry-N Jun 10, 2022
d57cf4c
Properly pass return code to jcmd peer,
Larry-N Jun 11, 2022
3350d50
whitespaces
Larry-N Jun 11, 2022
bb3f6b1
Rework closing the jcmd socket.
Larry-N Jul 7, 2022
75d62e7
ws correction
Larry-N Jul 7, 2022
3d9b0f7
Merge remote-tracking branch 'upstream/crac' into crac
Larry-N Jul 12, 2022
a70b2fb
corrections
Larry-N Jul 12, 2022
e603b5e
address review notes
Larry-N Jul 13, 2022
be9788c
addressing review notes 2
Larry-N Jul 15, 2022
b890d28
reworked socket fd validation -
Larry-N Jul 15, 2022
54e5447
cleanup
Larry-N Jul 18, 2022
db3d0b3
some amendments
Larry-N Jul 18, 2022
816bd99
amend
Larry-N Jul 18, 2022
13ed574
couple of corrections
Larry-N Jul 21, 2022
ac9a221
corrections
Larry-N Jul 21, 2022
183fbc4
corrections
Larry-N Jul 21, 2022
bbdf113
some corrections
Larry-N Jul 21, 2022
ef73617
corrections
Larry-N Jul 22, 2022
51308f6
java code
Larry-N Jul 22, 2022
04fb283
magic
Larry-N Jul 22, 2022
9e0c61e
corrections
Larry-N Jul 22, 2022
4c806fc
corrections
Larry-N Jul 22, 2022
59028cb
re-arranged sources files
Larry-N Jul 25, 2022
3696d49
corrections
Larry-N Jul 25, 2022
918f482
corrections
Larry-N Jul 25, 2022
87ddcba
correction
Larry-N Jul 26, 2022
ccf8446
corrections
Larry-N Jul 26, 2022
56bbaa8
review notes
Larry-N Jul 29, 2022
9ca2c00
corrected initialization ordering
Larry-N Aug 1, 2022
fe6fab9
Skip an assert in
Larry-N Aug 1, 2022
5978c93
corrections for ThreadBlockInVM in effectively_complete
Larry-N Aug 2, 2022
c096d94
corrections
Larry-N Aug 3, 2022
6a2b03b
java core crac corections
Larry-N Aug 5, 2022
fab217f
Revert "java core crac corections"
Larry-N Aug 10, 2022
c58902f
implement checkpointRestoreLocked
Larry-N Aug 10, 2022
36faeeb
style corrections
Larry-N Aug 10, 2022
ba53bdb
review notes address
Larry-N Aug 16, 2022
3ec73c9
corrections
Larry-N Aug 16, 2022
f64b661
replaced strlen with termination character check
Larry-N Aug 18, 2022
e7aea67
Fix style a bit
AntonKozlov Sep 1, 2022
c04100a
Refactor a bit around linux attach op
AntonKozlov Sep 1, 2022
071b7b6
fixup! Fix style a bit
AntonKozlov Sep 1, 2022
75641b9
Fix assert on checkpointRestore API call
AntonKozlov Sep 1, 2022
43e700a
fixup! Refactor a bit around linux attach
AntonKozlov Sep 1, 2022
34a47b9
Print whole exception to jcmd, as for API
AntonKozlov Sep 1, 2022
c1139ac
fixup! Fix style a bit
AntonKozlov Sep 1, 2022
c04d757
Fix another whitespace problem
AntonKozlov Sep 1, 2022
72e489c
Rename stream to jcmd as the only possible
AntonKozlov Sep 1, 2022
72b8cdb
Merge branch 'pr-10' into crac
Larry-N Nov 2, 2022
2936580
Print exceptions to tty if jcmd reporting is 'completed'
Larry-N Nov 3, 2022
f6a2dbd
Correct magic number
Larry-N Nov 3, 2022
9e165dd
Use stringStream for printing
Larry-N Nov 3, 2022
640671e
getter renamed
Larry-N Nov 3, 2022
6a56411
Style fix
Larry-N Nov 3, 2022
94567c5
Replace buffer with stream
Larry-N Nov 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/hotspot/os/linux/attachListener_linux.cpp
Expand Up @@ -76,7 +76,7 @@ class LinuxAttachListener: AllStatic {
static LinuxAttachOperation* read_request(int s);

public:
static AttachOperation* _currentOperation;
static AttachOperation* _jcmdOperation;
enum {
ATTACH_PROTOCOL_VER = 1 // protocol version
};
Expand Down Expand Up @@ -115,7 +115,7 @@ char LinuxAttachListener::_path[UNIX_PATH_MAX];
bool LinuxAttachListener::_has_path;
volatile int LinuxAttachListener::_listener = -1;
bool LinuxAttachListener::_atexit_registered = false;
AttachOperation* LinuxAttachListener::_currentOperation = NULL;
AttachOperation* LinuxAttachListener::_jcmdOperation = NULL;
Larry-N marked this conversation as resolved.
Show resolved Hide resolved

// Supporting class to help split a buffer into individual components
class ArgumentIterator : public StackObj {
Expand Down Expand Up @@ -391,7 +391,7 @@ int LinuxAttachListener::write_fully(int s, char* buf, int len) {

void LinuxAttachOperation::complete(jint result, bufferedStream* st) {
LinuxAttachOperation::effectively_complete(result, st);
AttachListener::set_CurrentOperation(NULL);
AttachListener::set_jcmdOperation(NULL);
delete this;
}

Expand Down Expand Up @@ -432,22 +432,24 @@ void LinuxAttachOperation::effectively_complete(jint result, bufferedStream* st)

// AttachListener functions

AttachOperation* AttachListener::get_CurrentOperation() {
return Atomic::load(&LinuxAttachListener::_currentOperation);
AttachOperation* AttachListener::get_jcmdOperation() {
const char assertion_listener_thread[] = "Attach Listener";
assert(strcmp(assertion_listener_thread, Thread::current()->name()) == 0, "should gets called from Attach Listener thread");
return LinuxAttachListener::_jcmdOperation;
}

void AttachListener::set_CurrentOperation(AttachOperation* s) {
void AttachListener::set_jcmdOperation(AttachOperation* s) {
const char assertion_listener_thread[] = "Attach Listener";
assert(strcmp(assertion_listener_thread, Thread::current()->name()) == 0, "should gets called from Attach Listener thread");
Atomic::store(&LinuxAttachListener::_currentOperation, s);
LinuxAttachListener::_jcmdOperation = s;
}

AttachOperation* AttachListener::dequeue() {
JavaThread* thread = JavaThread::current();
ThreadBlockInVM tbivm(thread);

AttachOperation* op = LinuxAttachListener::dequeue();
AttachListener::set_CurrentOperation(op);
AttachListener::set_jcmdOperation(op);
return op;
}

Expand Down
73 changes: 43 additions & 30 deletions src/hotspot/os/linux/os_linux.cpp
Expand Up @@ -410,6 +410,7 @@ class VM_Crac: public VM_Operation {
}

outputStream* ostream;
LinuxAttachOperation* jcmd_operation;
GrowableArray<CracFailDep>* failures() { return _failures; }
bool ok() { return _ok; }
const char* new_args() { return _restore_parameters->args(); }
Expand All @@ -418,6 +419,10 @@ class VM_Crac: public VM_Operation {
VMOp_Type type() const { return VMOp_VM_Crac; }
void doit();
void read_shm(int shmid);
private:
int is_socket_from_jcmd (int sock_fd);
void report_ok_to_jcmd ();

};

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -5709,20 +5714,22 @@ bool os::supports_map_sync() {
}

static void trace_cr(outputStream * ostream, const char* msg, ... ) {
if ((CRTrace) && (ostream != NULL)){
outputStream * ou = (ostream == NULL) ? tty : ostream;
if (CRTrace){
va_list ap;
va_start(ap, msg);
ostream->print("CR: ");
ostream->vprint_cr(msg, ap);
ou->print("CR: ");
ou->vprint_cr(msg, ap);
va_end(ap);
}
}

static void print_resources(outputStream * ostream, const char* msg, ... ) {
if ((CRPrintResourcesOnCheckpoint) && (ostream != NULL)) {
outputStream * ou = (ostream == NULL) ? tty : ostream;
if (CRPrintResourcesOnCheckpoint) {
va_list ap;
va_start(ap, msg);
ostream->vprint_cr(msg, ap);
ou->vprint_cr(msg, ap);
va_end(ap);
}
}
Expand Down Expand Up @@ -6025,7 +6032,11 @@ static int checkpoint_restore(int *shmid) {
}

if (info.si_code != SI_QUEUE || info.si_int < 0) {
tty->print_cr("JVM: invalid info for restore provided (may be failed checkpoint) si_code %d si_int %d", info.si_code, info.si_int);
tty->print("JVM: invalid info for restore provided: %s", info.si_code == SI_QUEUE ? "queued" : "not queued");
if (info.si_code == SI_QUEUE) {
tty->print(" code %d", info.si_int);
}
tty->cr();
return JVM_CHECKPOINT_ERROR;
}

Expand Down Expand Up @@ -6156,6 +6167,21 @@ void VM_Crac::read_shm(int shmid) {
return;
}

// The checkpoint could be called with an API, so jcmd operation and io stream doesnt exist.
int VM_Crac::is_socket_from_jcmd (int sock){
if (jcmd_operation == 0)
return 0;
int sock_fd = jcmd_operation->socket();
return sock == sock_fd;
}

void VM_Crac::report_ok_to_jcmd (){
if (jcmd_operation == 0)
return;
bufferedStream * buf = static_cast<bufferedStream*>(ostream);
jcmd_operation->effectively_complete(JNI_OK, buf);
}

void VM_Crac::doit() {

AttachListener::abort();
Expand All @@ -6168,7 +6194,6 @@ void VM_Crac::doit() {

// dry-run fails checkpoint
bool ok = !_dry_run;
LinuxAttachOperation * op = (LinuxAttachOperation* )AttachListener::get_CurrentOperation();

for (int i = 0; i < fds.len(); ++i) {
if (fds.get_state(i) == FdsInfo::CLOSED) {
Expand All @@ -6181,7 +6206,6 @@ void VM_Crac::doit() {
print_resources(ostream, "JVM: FD fd=%d type=%s: details1=\"%s\" ",
i, stat2strtype(fds.get_stat(i)->st_mode), details);


if (_vm_inited_fds.get_state(i, FdsInfo::CLOSED) != FdsInfo::CLOSED) {
print_resources(ostream, "OK: inherited from process env");
continue;
Expand All @@ -6207,18 +6231,14 @@ void VM_Crac::doit() {
continue;
}


if (S_ISSOCK(st->st_mode)) {
details = sock_details(details, detailsbuf, sizeof(detailsbuf));
print_resources(ostream, "issock, details2=\"%s\" ", details);

// and sock fd from listener
int sock_fd = op->socket();
if ( i == sock_fd){
if (is_socket_from_jcmd(i)){
print_resources(ostream, "OK: jcmd socket");
ok = true;
continue;
}
details = sock_details(details, detailsbuf, sizeof(detailsbuf));
print_resources(ostream, "issock, details2=\"%s\" ", details);
Larry-N marked this conversation as resolved.
Show resolved Hide resolved
}

print_resources(ostream, "BAD: opened by application");
Expand All @@ -6230,16 +6250,9 @@ void VM_Crac::doit() {
}

if (!ok) {
trace_cr(ostream, "Checkpoint aborted: resources opened by application");
return;
}


if (!ok && CRHeapDumpOnCheckpointException) {
HeapDumper::dump_heap();
}

if (!ok && CRDoThrowCheckpointException) {
if (CRHeapDumpOnCheckpointException){
HeapDumper::dump_heap();
}
return;
}

Expand All @@ -6252,9 +6265,8 @@ void VM_Crac::doit() {
trace_cr(ostream, "Skip Checkpoint");
} else {
trace_cr(ostream, "Checkpoint ...");
bufferedStream * buf = static_cast<bufferedStream*>(ostream);
// Send a result to jcmd
op->effectively_complete(JNI_OK, buf);
// If execution comes here, assumme that further all be ok.
report_ok_to_jcmd();
Larry-N marked this conversation as resolved.
Show resolved Hide resolved
int ret = checkpoint_restore(&shmid);
if (ret == JVM_CHECKPOINT_ERROR) {
PerfMemoryLinux::restore();
Expand Down Expand Up @@ -6355,7 +6367,7 @@ static Handle ret_cr(int ret, Handle new_args, Handle new_props, Handle err_code

/** Checkpoint main entry.
*/
Handle os::Linux::checkpoint(bool dry_run, jlong stream, TRAPS) {
Handle os::Linux::checkpoint(bool dry_run, jlong stream, jlong op, TRAPS) {
if (!CRaCCheckpointTo) {
return ret_cr(JVM_CHECKPOINT_NONE, Handle(), Handle(), Handle(), Handle(), THREAD);
}
Expand All @@ -6371,7 +6383,8 @@ Handle os::Linux::checkpoint(bool dry_run, jlong stream, TRAPS) {

VM_Crac cr(dry_run);
{
cr.ostream = (outputStream*) stream;
cr.jcmd_operation = (LinuxAttachOperation *) op;
cr.ostream = (outputStream *) stream;
MutexLocker ml(Heap_lock);
VMThread::execute(&cr);
}
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/os/linux/os_linux.hpp
Expand Up @@ -173,7 +173,7 @@ class Linux {

static void vm_create_start();
static bool prepare_checkpoint();
static Handle checkpoint(bool dry_run, jlong st, TRAPS);
static Handle checkpoint(bool dry_run, jlong st, jlong op, TRAPS);
static void restore();
static void register_persistent_fd(int fd, int st_dev, int st_ino);
static void deregister_persistent_fd(int fd, int st_dev, int st_ino);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/classfile/vmSymbols.hpp
Expand Up @@ -707,7 +707,7 @@
\
template(jdk_crac_Core, "jdk/crac/Core") \
template(checkpointRestoreInternal_name, "checkpointRestoreInternal") \
template(checkpointRestereInternal_signature, "(J)Ljava/lang/String;") \
template(checkpointRestereInternal_signature, "(JJ)Ljava/lang/String;") \
\
/*end*/

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/include/jvm.h
Expand Up @@ -1143,7 +1143,7 @@ enum cr_fail_type {
};

JNIEXPORT jobjectArray JNICALL
JVM_Checkpoint(JNIEnv *env, jboolean dry_run, jlong stream);
JVM_Checkpoint(JNIEnv *env, jboolean dry_run, jlong stream, jlong op);

JNIEXPORT void JNICALL
JVM_RegisterPersistent(int fd, int st_dev, int st_ino);
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/prims/jvm.cpp
Expand Up @@ -3849,8 +3849,8 @@ JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name))
return os::get_signal_number(name);
JVM_END

JVM_ENTRY(jobjectArray, JVM_Checkpoint(JNIEnv *env, jboolean dry_run, jlong stream))
Handle ret = os::Linux::checkpoint(dry_run, stream, CHECK_NULL);
JVM_ENTRY(jobjectArray, JVM_Checkpoint(JNIEnv *env, jboolean dry_run, jlong stream, jlong op))
Handle ret = os::Linux::checkpoint(dry_run, stream, op, CHECK_NULL);
return (jobjectArray) JNIHandles::make_local(THREAD, ret());
JVM_END

Expand Down
3 changes: 0 additions & 3 deletions src/hotspot/share/runtime/globals.hpp
Expand Up @@ -2113,9 +2113,6 @@ const intx ObjectAlignmentInBytes = 8;
product(bool, CRTraceStartupTime, false, DIAGNOSTIC, \
"Trace startup time") \
\
product(bool, CRDoThrowCheckpointException, true, EXPERIMENTAL, \
"Throw CheckpointException if uncheckpointable resource handle found")\
\
product(bool, CRTrace, true, "Minimal C/R tracing") \

// end of RUNTIME_FLAGS
Expand Down
5 changes: 2 additions & 3 deletions src/hotspot/share/services/attachListener.hpp
Expand Up @@ -107,9 +107,8 @@ class AttachListener: AllStatic {


// save jcmd operation for proper Checkpoint
static AttachOperation* get_CurrentOperation();
static void set_CurrentOperation(AttachOperation* op);

static AttachOperation* get_jcmdOperation();
static void set_jcmdOperation(AttachOperation* op);

// indicates if this VM supports attach-on-demand
static bool is_attach_supported() { return !DisableAttachMechanism; }
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/services/diagnosticCommand.cpp
Expand Up @@ -54,6 +54,8 @@
#include "services/heapDumper.hpp"
#include "services/management.hpp"
#include "services/writeableFlags.hpp"
#include "services/attachListener.hpp"
#include "services/linuxAttachOperation.hpp"
#include "utilities/debug.hpp"
#include "utilities/events.hpp"
#include "utilities/formatBuffer.hpp"
Expand Down Expand Up @@ -1044,6 +1046,7 @@ void CheckpointDCmd::execute(DCmdSource source, TRAPS) {
output()->print_cr("JDK.checkpoint command start processing");
JavaCallArguments args;
args.push_long((jlong )output());
args.push_long((jlong )AttachListener::get_jcmdOperation());
JavaCalls::call_static(&result, k,
vmSymbols::checkpointRestoreInternal_name(),
vmSymbols::checkpointRestereInternal_signature(), &args, CHECK);
Expand Down
28 changes: 28 additions & 0 deletions src/hotspot/share/services/linuxAttachOperation.hpp
@@ -1,3 +1,30 @@
/*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, Azul Systems, Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_SERVICES_LINUXATTACHOPERATION_HPP
#define SHARE_SERVICES_LINUXATTACHOPERATION_HPP

class LinuxAttachOperation: public AttachOperation {
private:
// the connection to the client
Expand All @@ -16,3 +43,4 @@ class LinuxAttachOperation: public AttachOperation {
_effectively_completed = false;
}
};
#endif // SHARE_SERVICES_LINUXATTACHOPERATION_HPP