Skip to content

Commit b7a6117

Browse files
authored
Merge pull request #136 from SarikaSinha/MergeBETA19
Merge BetaJava 19 to master
2 parents 96cda74 + 16c1eec commit b7a6117

34 files changed

Lines changed: 833 additions & 84 deletions

Jenkinsfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ pipeline {
1818
wrap([$class: 'Xvnc', useXauthority: true]) {
1919
sh """
2020
mvn clean verify --batch-mode --fail-at-end -Dmaven.repo.local=$WORKSPACE/.m2/repository \
21-
-Pbuild-individual-bundles -Pbree-libs -Papi-check \
22-
-Dcompare-version-with-baselines.skip=false \
21+
-Pbuild-individual-bundles -Ptest-on-javase-19 -Pbree-libs -Papi-check\
22+
-Dcompare-version-with-baselines.skip=true \
2323
-Dproject.build.sourceEncoding=UTF-8 \
2424
-DtrimStackTrace=false
2525
"""
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2022 Microsoft Corporation and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Microsoft Corporation - initial API and implementation
13+
*******************************************************************************/
14+
import java.io.OutputStream;
15+
import java.io.PrintWriter;
16+
17+
public class TryVirtualThread implements Runnable {
18+
/**
19+
* A <code>Thread</code> object
20+
*/
21+
public static Thread fThread;
22+
23+
/**
24+
* A <code>Thread</code> object representing the main thread
25+
*/
26+
public static Thread fMainThread;
27+
28+
public static Thread fVirtualThread;
29+
30+
31+
/**
32+
* The instance of the <code>MainClass</code>
33+
*/
34+
public static TryVirtualThread fObject = new TryVirtualThread();
35+
36+
/**
37+
* An integer value
38+
*/
39+
public static int fInt = 0;
40+
41+
/**
42+
* A string initialized to 'hello world'
43+
*/
44+
public static String fString = "Hello World";
45+
46+
/**
47+
* The name of an event type
48+
*/
49+
public static String fEventType = "";
50+
51+
/**
52+
* Runs the test program
53+
* @param args
54+
*/
55+
public static void main(java.lang.String[] args) {
56+
// Ensure at least one carrier thread is created.
57+
fVirtualThread = Thread.startVirtualThread(() -> {
58+
System.out.println("Start a test virtual thread.");
59+
});
60+
61+
ThreadGroup group = new ThreadGroup("Test ThreadGroup");
62+
fThread = new Thread(group, fObject, "Test Thread");
63+
fThread.start();
64+
65+
fMainThread = Thread.currentThread();
66+
67+
// Prevent this thread from dying
68+
while (true) {
69+
try {
70+
Thread.sleep(1000);
71+
} catch (InterruptedException e) {
72+
}
73+
}
74+
}
75+
76+
@Override
77+
public void run() {
78+
try {
79+
while (true) {
80+
printAndSignal();
81+
triggerEvent();
82+
try {
83+
Thread.sleep(1000);
84+
} catch (InterruptedException e) {
85+
}
86+
}
87+
} finally {
88+
System.out.println("Running finally block in MainClass.run()");
89+
}
90+
}
91+
92+
/**
93+
* Prints to System.out and throws an exception to indicate readiness
94+
*/
95+
synchronized public void printAndSignal() {
96+
print(System.out);
97+
// Signal readiness by throwing an exception
98+
try {
99+
throw new NegativeArraySizeException();
100+
} catch (NegativeArraySizeException exc) {
101+
}
102+
}
103+
104+
public void print(OutputStream out) {
105+
String string = fInt++ +". " + fString;
106+
PrintWriter writer = new PrintWriter(out);
107+
writer.println(string);
108+
writer.flush();
109+
}
110+
111+
/**
112+
* Trigger an event for the front-end.
113+
*/
114+
private void triggerEvent() {
115+
/* Ensure we do it only once */
116+
String eventType = fEventType;
117+
fEventType = "";
118+
119+
/* Trigger event according to the field fEventType */
120+
if (eventType.isEmpty()) {
121+
return;
122+
} else if (eventType.equals("ThreadStartEvent")) {
123+
triggerThreadStartEvent();
124+
} else if (eventType.equals("ThreadDeathEvent")) {
125+
triggerThreadDeathEvent();
126+
} else {
127+
System.out.println("Unknown event type: " + eventType);
128+
}
129+
}
130+
131+
/**
132+
* Trigger a thread end event for the front-end.
133+
*/
134+
private void triggerThreadDeathEvent() {
135+
Thread.startVirtualThread(() -> {
136+
System.out.println("Test VirtualThread Death Event");
137+
});
138+
}
139+
140+
/**
141+
* Trigger a thread start event for the front-end.
142+
*/
143+
private void triggerThreadStartEvent() {
144+
Thread.startVirtualThread(() -> {
145+
System.out.println("Test VirtualThread Start Event");
146+
});
147+
}
148+
}

org.eclipse.jdt.debug.jdi.tests/pom.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,33 @@
5858
</plugin>
5959
</plugins>
6060
</build>
61+
<profiles>
62+
<profile>
63+
<id>test-on-javase-19</id>
64+
<build>
65+
<plugins>
66+
<plugin>
67+
<groupId>org.apache.maven.plugins</groupId>
68+
<artifactId>maven-toolchains-plugin</artifactId>
69+
<version>1.1</version>
70+
<executions>
71+
<execution>
72+
<phase>validate</phase>
73+
<goals>
74+
<goal>toolchain</goal>
75+
</goals>
76+
</execution>
77+
</executions>
78+
<configuration>
79+
<toolchains>
80+
<jdk>
81+
<id>JavaSE-19</id>
82+
</jdk>
83+
</toolchains>
84+
</configuration>
85+
</plugin>
86+
</plugins>
87+
</build>
88+
</profile>
89+
</profiles>
6190
</project>

org.eclipse.jdt.debug.jdi.tests/tests/org/eclipse/debug/jdi/tests/AutomatedSuite.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2004, 2012 IBM Corporation and others.
2+
* Copyright (c) 2004, 2022 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
1010
*
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
13+
* Microsoft Corporation - supports virtual threads
1314
*******************************************************************************/
1415
package org.eclipse.debug.jdi.tests;
1516

@@ -88,7 +89,7 @@ public AutomatedSuite() {
8889
addTest(new TestSuite(VMDisconnectEventTest.class));
8990
addTest(new TestSuite(VMDisposeTest.class));
9091

91-
//Java 1.6 capability tests
92+
// Java 1.6 capability tests
9293
addTest(new TestSuite(HeapWalkingTests.class));
9394
addTest(new TestSuite(ConstantPoolTests.class));
9495
addTest(new TestSuite(SourceNameFilterTests.class));
@@ -97,6 +98,11 @@ public AutomatedSuite() {
9798
addTest(new TestSuite(MonitorFrameInfoTests.class));
9899
addTest(new TestSuite(ProvideArgumentsTests.class));
99100
addTest(new TestSuite(ContendedMonitorTests.class));
101+
102+
// Java 19 capability tests
103+
if (Runtime.version().feature() >= 19) {
104+
addTest(new TestSuite(VirtualThreadTest.class));
105+
}
100106
}
101107

102108
}

org.eclipse.jdt.debug.jdi.tests/tests/org/eclipse/debug/jdi/tests/TestAll.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 IBM Corporation and others.
2+
* Copyright (c) 2000, 2022 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
1010
*
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
13+
* Microsoft Corporation - supports virtual threads
1314
*******************************************************************************/
1415
package org.eclipse.debug.jdi.tests;
1516

@@ -62,8 +63,9 @@ protected static Vector<Class<?>> getAllTestCases(VMInformation info) {
6263
classes.addElement(MethodExitRequestTest.class);
6364
classes.addElement(MirrorTest.class);
6465

65-
if (info.fVM.canWatchFieldModification())
66+
if (info.fVM.canWatchFieldModification()) {
6667
classes.addElement(ModificationWatchpointEventTest.class);
68+
}
6769

6870
classes.addElement(ObjectReferenceTest.class);
6971
classes.addElement(PrimitiveValueTest.class);
@@ -85,9 +87,13 @@ protected static Vector<Class<?>> getAllTestCases(VMInformation info) {
8587
classes.addElement(WatchpointRequestTest.class);
8688
}
8789

90+
if (Runtime.version().feature() >= 19) {
91+
classes.addElement(VirtualThreadTest.class);
92+
}
93+
8894
classes.addElement(VirtualMachineExitTest.class);
8995
classes.addElement(VMDisconnectEventTest.class);
90-
classes.addElement(VMDisposeTest.class); // note that this test does not restore the state properly.
96+
classes.addElement(VMDisposeTest.class); // note that this test does not restore the state properly.
9197
return classes;
9298
}
9399
/**
@@ -104,8 +110,9 @@ public static void main(String[] arguments) throws Throwable {
104110
AbstractJDITest test= run(result, VirtualMachineTest.class, arguments, null);
105111

106112
// Was it possible to run the first test?
107-
if (test == null)
113+
if (test == null) {
108114
return;
115+
}
109116

110117
// Get the VM info
111118
VMInformation info = test.getVMInfo();
@@ -149,8 +156,9 @@ private static AbstractJDITest run(junit.framework.TestResult result, Class<?> t
149156
} catch (InvocationTargetException e) {
150157
throw e.getTargetException();
151158
}
152-
if (!AbstractJDITest.parseArgs(arguments))
159+
if (!AbstractJDITest.parseArgs(arguments)) {
153160
return null;
161+
}
154162
test.setVMInfo(info);
155163
test.setInControl(false);
156164

org.eclipse.jdt.debug.jdi.tests/tests/org/eclipse/debug/jdi/tests/ThreadReferenceTest.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2012 IBM Corporation and others.
2+
* Copyright (c) 2000, 2022 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,6 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.debug.jdi.tests;
1515

16+
import java.lang.reflect.InvocationTargetException;
1617
import java.util.List;
1718

1819
import com.sun.jdi.ClassNotLoadedException;
@@ -26,7 +27,10 @@
2627
import com.sun.jdi.StackFrame;
2728
import com.sun.jdi.ThreadReference;
2829
import com.sun.jdi.Value;
30+
import com.sun.jdi.event.ThreadDeathEvent;
2931
import com.sun.jdi.event.ThreadStartEvent;
32+
import com.sun.jdi.request.ThreadDeathRequest;
33+
import com.sun.jdi.request.ThreadStartRequest;
3034

3135
/**
3236
* Tests for JDI com.sun.jdi.ThreadReference
@@ -233,4 +237,40 @@ public void testJDISuspendResume() {
233237
public void testJDIThreadGroup() {
234238
assertNotNull("1", fThread.threadGroup());
235239
}
240+
241+
/**
242+
* Test JDI addPlatformThreadsOnlyFilter() is skipped in old JDK version (<=18).
243+
*/
244+
public void testJDIPlatformThreadsOnlyFilter() {
245+
// Make sure the entire VM is not suspended before we start a new thread
246+
// (otherwise this new thread will start suspended and we will never get the
247+
// ThreadStart event)
248+
fVM.resume();
249+
250+
// Trigger a thread start event
251+
ThreadStartRequest threadStartRequest = fVM.eventRequestManager().createThreadStartRequest();
252+
try {
253+
java.lang.reflect.Method method = threadStartRequest.getClass().getMethod("addPlatformThreadsOnlyFilter");
254+
method.invoke(threadStartRequest);
255+
} catch (NoSuchMethodException | SecurityException e) {
256+
fail("1");
257+
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
258+
fail("2");
259+
}
260+
ThreadStartEvent startEvent = (ThreadStartEvent) triggerAndWait(threadStartRequest, "ThreadStartEvent", true, 3000);
261+
assertNotNull("3", startEvent);
262+
263+
// Trigger a thread death event
264+
ThreadDeathRequest threadDeathRequest = fVM.eventRequestManager().createThreadDeathRequest();
265+
try {
266+
java.lang.reflect.Method method = threadDeathRequest.getClass().getMethod("addPlatformThreadsOnlyFilter");
267+
method.invoke(threadDeathRequest);
268+
} catch (NoSuchMethodException | SecurityException e) {
269+
fail("4");
270+
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
271+
fail("5");
272+
}
273+
ThreadDeathEvent deathEvent = (ThreadDeathEvent) triggerAndWait(threadDeathRequest, "ThreadDeathEvent", true, 3000);
274+
assertNotNull("6", deathEvent);
275+
}
236276
}

0 commit comments

Comments
 (0)