Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0cf638f
Add support for breakpoint-to-breakpoint dependencies
SougandhS May 26, 2026
445180b
Introduce org.eclipse.jdt.launching.javaagent25, a new javaagent module
SougandhS Sep 7, 2026
89ff2b6
Attempt to reconnect on BindException during MultipleConnectionsTest
trancexpress Oct 9, 2026
c0fad73
Add support for stepping out of code blocks
SougandhS Aug 28, 2026
7d47baa
Respect "without test code" for projects contributed by a container
sajeevkr2 Oct 10, 2026
0b8fd89
Add file based configuration of installed JREs and EE defaults
peterkir Oct 26, 2026
c6e0486
Do not ask the VM for classes by signature on each class unload #1056
lagar84 Nov 12, 2026
8bf2de8
Clean up breakpoints after marker loss
carstenartur Nov 13, 2026
bbdca45
Do not keep mirrors cached during a class redefinition #1059
lagar84 Nov 13, 2026
944fdd9
Show exit-only method breakpoint annotation at the closing brace
SougandhS Nov 14, 2026
ff8f4be
Fold up967 into the superset
hsoliwal Nov 16, 2026
6d5d52e
Fold up990 into the superset
hsoliwal Nov 16, 2026
a347f44
Fold up994 into the superset
hsoliwal Nov 16, 2026
f802146
Fold up999 into the superset
hsoliwal Nov 16, 2026
d54fa66
Fold up1038 into the superset
hsoliwal Nov 16, 2026
8bcf122
Fold up1041 into the superset
hsoliwal Nov 16, 2026
709354d
Fold up1047 into the superset
hsoliwal Nov 16, 2026
a14e64e
Fold up1057 into the superset
hsoliwal Nov 16, 2026
1240912
Fold up1060 into the superset
hsoliwal Nov 16, 2026
d49ee91
Fold up1061 into the superset
hsoliwal Nov 16, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public AutomatedSuite() { //FLLDCIM: MARK — ML METHOD_SPLIT METHOD
addTest(new TestSuite(ClassPrepareEventTest.class));
addTest(new TestSuite(ClassPrepareRequestTest.class));
addTest(new TestSuite(ClassTypeTest.class));
addTest(new TestSuite(ClassUnloadEventTest.class));
addTest(new TestSuite(DoubleValueTest.class));
addTest(new TestSuite(EventRequestManagerTest.class));
addTest(new TestSuite(EventRequestTest.class));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/*******************************************************************************
* Copyright (c) 2026 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.debug.jdi.tests;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.eclipse.jdi.internal.ReferenceTypeImpl;
import org.eclipse.jdi.internal.VirtualMachineImpl;

import com.sun.jdi.ReferenceType;
import com.sun.jdi.ThreadReference;
import com.sun.jdi.event.ClassPrepareEvent;
import com.sun.jdi.event.ClassUnloadEvent;
import com.sun.jdi.event.Event;
import com.sun.jdi.request.ClassPrepareRequest;
import com.sun.jdi.request.ClassUnloadRequest;
import com.sun.jdi.request.EventRequest;

/**
* Tests for JDI com.sun.jdi.event.ClassUnloadEvent.
*/
@SuppressWarnings("restriction")
public class ClassUnloadEventTest extends AbstractJDITest {
private static final String UNLOADED_CLASS = "org.eclipse.debug.jdi.tests.program.UnloadedClass";

private ClassPrepareRequest fPrepareRequest;
private EventWaiter fPrepareWaiter;
/** The types of the class prepare events that came in. */
private final List<ReferenceType> fPreparedTypes = Collections.synchronizedList(new ArrayList<>());

/**
* Creates a new test.
*/
public ClassUnloadEventTest() {
super();
}

public ClassUnloadEventTest(String name) {
super(name);
}

/**
* Init the fields that are used by this test only.
*/
@Override
public void localSetUp() {
// Reading a class prepare event puts the mirror of the class in the
// cache of the VM
fPrepareRequest = fVM.eventRequestManager().createClassPrepareRequest();
fPrepareRequest.addClassFilter(UNLOADED_CLASS);
fPrepareRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE);
fPrepareRequest.enable();
fPrepareWaiter = new EventWaiter(fPrepareRequest, true) {
@Override
public boolean classPrepare(ClassPrepareEvent event) {
if (fRequest.equals(event.request())) {
fPreparedTypes.add(event.referenceType());
}
return true;
}
};
fEventReader.addEventListener(fPrepareWaiter);
}

/**
* Make sure the test leaves the VM in the same state it found it.
*/
@Override
public void localTearDown() {
fEventReader.removeEventListener(fPrepareWaiter);
fVM.eventRequestManager().deleteEventRequest(fPrepareRequest);
}

/**
* Run all tests and output to standard output.
*/
public static void main(java.lang.String[] args) {
new ClassUnloadEventTest().runSuite(args);
}

/**
* Triggers the given event in the target VM and waits for the class unload
* event.
*/
private ClassUnloadEvent triggerAndWaitForUnload(String eventType) {
fPreparedTypes.clear();
ClassUnloadRequest request = fVM.eventRequestManager().createClassUnloadRequest();
request.addClassFilter(UNLOADED_CLASS);
request.setSuspendPolicy(EventRequest.SUSPEND_NONE);
request.enable();
EventWaiter waiter = new EventWaiter(request, true);
fEventReader.addEventListener(waiter);

triggerEvent(eventType);
// The target VM does not unload the classes that are known to the
// debugger while all of its threads are suspended
for (ThreadReference thread : fVM.allThreads()) {
while (thread.suspendCount() > 0) {
fVM.resume();
}
}

Event event = waitForEvent(waiter, TIMEOUT);
fEventReader.removeEventListener(waiter);
waitUntilReady();
fVM.eventRequestManager().deleteEventRequest(request);
assertNotNull("ClassUnloadEvent for " + UNLOADED_CLASS + " did not come in", event);
return (ClassUnloadEvent) event;
}

private boolean isCached(ReferenceType type) {
return ((VirtualMachineImpl) fVM).getCachedMirror(((ReferenceTypeImpl) type).getRefTypeID()) != null;
}

/**
* Test JDI className() and classSignature(), and that the unloaded class
* is no longer known to the VM mirror.
*/
public void testJDIClassUnload() {
ClassUnloadEvent event = triggerAndWaitForUnload("ClassUnloadEvent");
assertEquals("1", UNLOADED_CLASS, event.className());
assertEquals("2", "Lorg/eclipse/debug/jdi/tests/program/UnloadedClass;", event.classSignature());
assertEquals("3", 1, fPreparedTypes.size());
assertFalse("4", isCached(fPreparedTypes.get(0)));
}

/**
* Test that only the unloaded class is forgotten when another class with
* the same name is still loaded. The class that stays loaded is only
* prepared the first time.
*/
public void testJDIClassUnloadWithSameNameLoaded() {
ClassUnloadEvent event = triggerAndWaitForUnload("ClassUnloadEvent1");
assertEquals("1", UNLOADED_CLASS, event.className());
assertFalse("2", fPreparedTypes.isEmpty());
// Asking the VM for the loaded classes puts their mirrors in the cache,
// so look at the cache first
List<ReferenceType> cached = new ArrayList<>();
for (ReferenceType type : fPreparedTypes) {
if (isCached(type)) {
cached.add(type);
}
}
List<ReferenceType> loaded = fVM.classesByName(UNLOADED_CLASS);
assertEquals("3", 1, loaded.size());
for (ReferenceType type : fPreparedTypes) {
assertEquals("4", loaded.contains(type), cached.contains(type));
}
}

/**
* Test that an unloaded class is forgotten when its mirror was not created
* for a class prepare event, but by asking the VM for the classes with its
* name.
*/
public void testJDIClassUnloadOfLookedUpClass() {
fPrepareRequest.disable();
try {
List<ReferenceType> loadedBefore = fVM.classesByName(UNLOADED_CLASS);
triggerEvent("ClassUnloadEvent2");
waitUntilReady();
List<ReferenceType> lookedUp = new ArrayList<>(fVM.classesByName(UNLOADED_CLASS));
lookedUp.removeAll(loadedBefore);
assertEquals("1", 1, lookedUp.size());
assertTrue("2", isCached(lookedUp.get(0)));

triggerAndWaitForUnload("ClassUnloadEvent3");
assertTrue("3", fPreparedTypes.isEmpty());
assertFalse("4", isCached(lookedUp.get(0)));
} finally {
fPrepareRequest.enable();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected static Vector<Class<?>> getAllTestCases(VMInformation info) { //FLLDCI
classes.addElement(ClassPrepareEventTest.class);
classes.addElement(ClassPrepareRequestTest.class);
classes.addElement(ClassTypeTest.class);
classes.addElement(ClassUnloadEventTest.class);
classes.addElement(DoubleValueTest.class);
classes.addElement(EventRequestManagerTest.class);
classes.addElement(EventRequestTest.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,14 @@ else if(eventType.equals("refclass4load")) {
triggerClassPrepareEvent7();
} else if (eventType.equals("ClassPrepareEvent8")) {
triggerClassPrepareEvent8();
} else if (eventType.equals("ClassUnloadEvent")) {
UnloadedClassLoader.triggerClassUnloadEvent(false);
} else if (eventType.equals("ClassUnloadEvent1")) {
UnloadedClassLoader.triggerClassUnloadEvent(true);
} else if (eventType.equals("ClassUnloadEvent2")) {
UnloadedClassLoader.loadClassToUnload();
} else if (eventType.equals("ClassUnloadEvent3")) {
UnloadedClassLoader.triggerClassUnloadEventForLoadedClass();
} else if (eventType.equals("ExceptionEvent")) {
triggerExceptionEvent();
} else if (eventType.equals("ModificationWatchpointEvent")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright (c) 2026 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.debug.jdi.tests.program;

/**
* Empty test class that is only loaded by instances of
* {@link UnloadedClassLoader}, so that it can be unloaded.
*/
public class UnloadedClass {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*******************************************************************************
* Copyright (c) 2026 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.debug.jdi.tests.program;

import java.lang.ref.WeakReference;
import java.net.URL;
import java.net.URLClassLoader;

/**
* Class loader that loads its own copy of {@link UnloadedClass}, so that the
* class can be unloaded.
*/
public class UnloadedClassLoader extends URLClassLoader {

/** A class loader of which the copy of UnloadedClass stays loaded. */
static UnloadedClassLoader fKeptLoader;

/** A class loader of which the copy of UnloadedClass is unloaded later. */
static UnloadedClassLoader fLoaderToUnload;

private UnloadedClassLoader() throws ClassNotFoundException {
super(new URL[] { UnloadedClassLoader.class.getProtectionDomain().getCodeSource().getLocation() }, null);
// Initializing the class also prepares it
Class.forName("org.eclipse.debug.jdi.tests.program.UnloadedClass", true, this);
}

/**
* Trigger a class unload event for the front-end: loads a copy of
* UnloadedClass and waits until its class loader is collected. If asked,
* another copy is loaded first (once), with a class loader that stays
* alive.
*/
static void triggerClassUnloadEvent(boolean keepSameNameLoaded) {
try {
if (keepSameNameLoaded && fKeptLoader == null) {
fKeptLoader = new UnloadedClassLoader();
}
waitUntilCollected(new WeakReference<>(new UnloadedClassLoader()));
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Loads a copy of UnloadedClass that stays loaded until
* {@link #triggerClassUnloadEventForLoadedClass()} is called.
*/
static void loadClassToUnload() {
try {
fLoaderToUnload = new UnloadedClassLoader();
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Trigger a class unload event for the front-end, for the class that was
* loaded by {@link #loadClassToUnload()}.
*/
static void triggerClassUnloadEventForLoadedClass() {
try {
WeakReference<ClassLoader> loader = new WeakReference<>(fLoaderToUnload);
fLoaderToUnload = null;
waitUntilCollected(loader);
} catch (Exception e) {
e.printStackTrace();
}
}

private static void waitUntilCollected(WeakReference<ClassLoader> loader) throws InterruptedException {
for (int i = 0; i < 50 && loader.get() != null; i++) {
System.gc();
Thread.sleep(100);
}
}
}
Loading
Loading