Skip to content

Commit

Permalink
[Wisp] Fix WispEventPump epollWait IllegalArgumentException
Browse files Browse the repository at this point in the history
Summary: In wisp Monolithic Epoll, we clear Epoll fd after the park.
But at shutdown, an interruption may break this and leave an uncleared
epoll array on wise task, IllegalArgumentException may happen when reuse
this wispTask.

Test Plan: jtreg test/wisp2

Reviewed-by: yuleil, zhengxiaolinX

Issue: dragonwell-project/dragonwell8#208
  • Loading branch information
joeyleeeeeee97 authored and joeyleeeeeee97 committed Mar 9, 2021
1 parent fd35688 commit 4e51c2b
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/linux/classes/com/alibaba/wisp/engine/WispCarrier.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ final WispTask runTaskInternal(Runnable target, String name, Thread thread, Clas
void taskExit() { // and exit
current.countExecutionTime(switchTimestamp);
switchTimestamp = 0;
current.setEpollArray(0);

unregisterEvent();
boolean cached = returnTaskToCache(current);
Expand Down
74 changes: 74 additions & 0 deletions test/com/alibaba/wisp2/TestEpollArrayClear.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* @test
* @library /lib/testlibrary
* @build TestEpollArrayClear
* @summary test RCM TestEpollArrayClearcontrol
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseWisp2 -XX:ActiveProcessorCount=4 TestEpollArrayClear
*/

import com.alibaba.wisp.engine.WispTask;
import sun.misc.SharedSecrets;
import sun.misc.WispEngineAccess;
import sun.nio.ch.EPollSelectorProvider;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.channels.Selector;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import static jdk.testlibrary.Asserts.*;

public class TestEpollArrayClear {

private static volatile int started = 0;
private static WispEngineAccess WEA = SharedSecrets.getWispEngineAccess();
private static AtomicReference<WispTask> atomicReference = new AtomicReference<>();


private static Runnable IO = () -> {
while (true) {
started = 1;
try {
Selector selector = EPollSelectorProvider.provider().openSelector();
atomicReference.set(WEA.getCurrentTask());

Field f = Thread.class.getDeclaredField("inheritedResourceContainer");
f.setAccessible(true);
f.set(Thread.currentThread(), null);
while (true) {
selector.select(10000L);
}
} catch (Exception exception) {
exception.printStackTrace();
continue;
}
}
};

public static void main(String[] args) throws Exception {
started = 0;
Class<?> wispControlGroupClazz = Class.forName("com.alibaba.wisp.engine.WispControlGroup");
Method createMethod = wispControlGroupClazz.getDeclaredMethod("newInstance", int.class);
createMethod.setAccessible(true);
ExecutorService cg = (ExecutorService) createMethod.invoke(null, 50);

cg.execute(IO);
while (0 == started) {
}
Thread.sleep(100);
cg.shutdown();
while (!cg.isTerminated()) {
try {
cg.awaitTermination(1, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new InternalError(e);
}
}

Field f = WispTask.class.getDeclaredField("epollArray");
f.setAccessible(true);
assertTrue(0L == (Long) f.get(atomicReference.get()));
}
}

0 comments on commit 4e51c2b

Please sign in to comment.