Skip to content

Commit

Permalink
Merge pull request #803 from JasonFengJ9/jdwpoptionfile
Browse files Browse the repository at this point in the history
CRIU supports Java debugger during checkpoint and restore
  • Loading branch information
keithc-ca committed Aug 28, 2024
2 parents 91d00df + b66fc55 commit 3c24a4f
Show file tree
Hide file tree
Showing 21 changed files with 552 additions and 7 deletions.
8 changes: 8 additions & 0 deletions closed/GensrcJ9JCL.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ $(eval $(call SetupCopyFiles,COPY_OVERLAY_FILES, \
SRC := $(TOPDIR), \
DEST := $(SUPPORT_OUTPUTDIR)/overlay, \
FILES := \
make/data/jdwp/jdwp.spec \
src/java.base/share/classes/com/sun/crypto/provider/HmacCore.java \
src/java.base/share/classes/java/lang/ClassValue.java \
src/java.base/share/classes/java/net/InetAddress.java \
Expand All @@ -55,6 +56,13 @@ $(eval $(call SetupCopyFiles,COPY_OVERLAY_FILES, \
src/java.base/share/classes/sun/security/provider/SecureRandom.java \
src/java.base/unix/classes/java/lang/ProcessEnvironment.java \
src/java.base/unix/classes/sun/security/provider/NativePRNG.java \
src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/EventHandler.java \
src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/EventNotifier.java \
src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTY.java \
src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTYResources.java \
src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTYResources_ja.java \
src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTYResources_zh_CN.java \
src/jdk.jdi/share/classes/com/sun/tools/jdi/EventSetImpl.java \
))

IncludeIfUnsure := -includeIfUnsure -noWarnIncludeIf
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*[INCLUDE-IF CRIU_SUPPORT]*/
/*
* ===========================================================================
* (c) Copyright IBM Corp. 2023, 2024 All Rights Reserved
* ===========================================================================
*
* 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.
*
* IBM designates this particular file as subject to the "Classpath" exception
* as provided by IBM in the LICENSE file that accompanied this code.
*
* 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, see <http://www.gnu.org/licenses/>.
*
* ===========================================================================
*/
package com.sun.jdi.event;

import com.sun.jdi.ThreadReference;
import com.sun.jdi.VirtualMachine;

/**
* Notification of when the VM is restored from a checkpoint. Similar to
* VMStartEvent this occurs before application code has run, including any
* application hooks for the restore event.
* The event is generated even if not explicitly requested.
*
* @see VMStartEvent
* @see VMDeathEvent
* @see EventQueue
* @see VirtualMachine
*/
public interface VMRestoreEvent extends Event {

/**
* Returns the thread which is restoring the VM from a checkpoint.
*
* @return a {@link ThreadReference} representing the restore thread
* on the target VM.
*/
public ThreadReference thread();
}
20 changes: 20 additions & 0 deletions make/data/jdwp/jdwp.spec
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2023, 2024 All Rights Reserved
* ===========================================================================
*/

JDWP "Java(tm) Debug Wire Protocol"
(CommandSet VirtualMachine=1
(Command Version=1
Expand Down Expand Up @@ -3094,6 +3100,17 @@ JDWP "Java(tm) Debug Wire Protocol"
(int requestID
"Request that generated event")
)
/*[IF CRIU_SUPPORT]*/
(Alt VMRestore=JDWP.EventKind.VM_RESTORE
"Notification of when the VM is restored from a checkpoint. Similar to"
"VMStartEvent this occurs before application code has run, including any"
"application hooks for the restore event."
"The event is generated even if not explicitly requested."

(int requestID "Request that generated event")
(threadObject thread "The thread restoring the VM from a checkpoint.")
)
/*[ENDIF] CRIU_SUPPORT */
)
)
)
Expand Down Expand Up @@ -3223,6 +3240,9 @@ JDWP "Java(tm) Debug Wire Protocol"
(Constant VM_INIT =90 "obsolete - was used in jvmdi")
(Constant VM_DEATH =99 )
(Constant VM_DISCONNECTED =100 "Never sent across JDWP")
/*[IF CRIU_SUPPORT]*/
(Constant VM_RESTORE =101 "OpenJ9 VM Restored")
/*[ENDIF] CRIU_SUPPORT */
)

(ConstantSet ThreadStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
* this sample code.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2023, 2024 All Rights Reserved
* ===========================================================================
*/

package com.sun.tools.example.debug.tty;

Expand Down Expand Up @@ -118,6 +123,10 @@ private boolean handleEvent(Event event) {
return threadDeathEvent(event);
} else if (event instanceof VMStartEvent) {
return vmStartEvent(event);
/*[IF CRIU_SUPPORT]*/
} else if (event instanceof VMRestoreEvent) {
return vmRestoreEvent((VMRestoreEvent)event);
/*[ENDIF] CRIU_SUPPORT */
} else {
return handleExitEvent(event);
}
Expand Down Expand Up @@ -179,6 +188,10 @@ private ThreadReference eventThread(Event event) {
return ((ThreadDeathEvent)event).thread();
} else if (event instanceof VMStartEvent) {
return ((VMStartEvent)event).thread();
/*[IF CRIU_SUPPORT]*/
} else if (event instanceof VMRestoreEvent) {
return ((VMRestoreEvent)event).thread();
/*[ENDIF] CRIU_SUPPORT */
} else {
return null;
}
Expand Down Expand Up @@ -210,6 +223,13 @@ private boolean vmStartEvent(Event event) {
return stopOnVMStart;
}

/*[IF CRIU_SUPPORT]*/
private boolean vmRestoreEvent(VMRestoreEvent restoreEvent) {
notifier.vmRestoreEvent(restoreEvent);
return stopOnVMStart;
}
/*[ENDIF] CRIU_SUPPORT */

private boolean breakpointEvent(Event event) {
BreakpointEvent be = (BreakpointEvent)event;
notifier.breakpointEvent(be);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2023, 2024 All Rights Reserved
* ===========================================================================
*/

/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
Expand All @@ -38,6 +44,9 @@

interface EventNotifier {
void vmStartEvent(VMStartEvent e);
/*[IF CRIU_SUPPORT]*/
void vmRestoreEvent(VMRestoreEvent e);
/*[ENDIF] CRIU_SUPPORT */
void vmDeathEvent(VMDeathEvent e);
void vmDisconnectEvent(VMDisconnectEvent e);

Expand Down
14 changes: 14 additions & 0 deletions src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTY.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2023, 2024 All Rights Reserved
* ===========================================================================
*/

/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
Expand Down Expand Up @@ -73,6 +79,14 @@ public void vmStartEvent(VMStartEvent se) {
MessageOutput.lnprint("VM Started:");
}

/*[IF CRIU_SUPPORT]*/
@Override
public void vmRestoreEvent(VMRestoreEvent re) {
Thread.yield(); // fetch output
MessageOutput.lnprint("VM Restored:");
}
/*[ENDIF] CRIU_SUPPORT */

@Override
public void vmDeathEvent(VMDeathEvent e) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2023, 2024 All Rights Reserved
* ===========================================================================
*/

/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
Expand Down Expand Up @@ -456,6 +462,9 @@ public Object[][] getContents() {
"<arguments> are the arguments passed to the main() method of <class>\n" +
"\n" +
"For command help type ''help'' at {0} prompt"},
/*[IF CRIU_SUPPORT]*/
{"VM Restored:", "VM restored from checkpoint:"},
/*[ENDIF] CRIU_SUPPORT */
// END OF MATERIAL TO LOCALIZE
};

Expand Down
Loading

0 comments on commit 3c24a4f

Please sign in to comment.