Skip to content
Permalink
Browse files
Change ThreadStartRequest/ThreadDeathRequest to allow opt-out of even…
…ts for virtual threads
  • Loading branch information
AlanBateman committed Mar 16, 2021
1 parent 5f3e2a0 commit e0990a0ce7b210eca87e82470b267a6e426943aa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 28 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. 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
@@ -40,11 +40,6 @@
* The collection of existing ThreadDeathRequests is
* managed by the {@link EventRequestManager}
*
* <p> By default, a {@code ThreadDeathRequest} does not request thread death
* events for {@linkplain Thread#isVirtual() virtual threads}. The {@link
* #removeVirtualThreadFilter()} method removes the filter that restricts the
* generation of {@code ThreadDeathEvent}s for virtual threads.
*
* @see ThreadDeathEvent
* @see EventQueue
* @see EventRequestManager
@@ -56,8 +51,7 @@ public interface ThreadDeathRequest extends EventRequest {

/**
* Restricts the events generated by this request to those in
* the given thread. This method may be used to request a thread death
* event for a virtual thread.
* the given thread.
* @param thread the thread to filter on.
* @throws InvalidRequestStateException if this request is currently
* enabled or has been deleted.
@@ -66,8 +60,10 @@ public interface ThreadDeathRequest extends EventRequest {
void addThreadFilter(ThreadReference thread);

/**
* Removes the filter that restricts the generation of thread death events
* for virtual threads.
* Restricts the events generated by this request to not include thread
* death events for virtual threads. This method has no effect when the
* event is restricted to a {@linkplain #addThreadFilter(ThreadReference)
* specific thread}.
*
* @implSpec
* The default implementation throws {@code UnsupportedOperationException}.
@@ -77,7 +73,7 @@ public interface ThreadDeathRequest extends EventRequest {
*
* @since 99
*/
default void removeVirtualThreadFilter() {
default void addVirtualThreadFilter() {
throw new UnsupportedOperationException("Method not implemented");
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. 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
@@ -40,11 +40,6 @@
* The collection of existing ThreadStartRequests is
* managed by the {@link EventRequestManager}
*
* <p> By default, a {@code ThreadStartRequest} does not request thread start
* events for {@linkplain Thread#isVirtual() virtual threads}. The {@link
* #removeVirtualThreadFilter()} method removes the filter that restricts the
* generation of {@code ThreadStartEvent}s for virtual threads.
*
* @see ThreadStartEvent
* @see EventQueue
* @see EventRequestManager
@@ -56,8 +51,7 @@ public interface ThreadStartRequest extends EventRequest {

/**
* Restricts the events generated by this request to those in
* the given thread. This method may be used to request a thread start
* event for a virtual thread.
* the given thread.
* @param thread the thread to filter on.
* @throws InvalidRequestStateException if this request is currently
* enabled or has been deleted.
@@ -66,8 +60,10 @@ public interface ThreadStartRequest extends EventRequest {
void addThreadFilter(ThreadReference thread);

/**
* Removes the filter that restricts the generation of thread start events
* for virtual threads.
* Restricts the events generated by this request to not include thread
* start events for virtual threads. This method has no effect when the
* event is restricted to a {@linkplain #addThreadFilter(ThreadReference)
* specific thread}.
*
* @implSpec
* The default implementation throws {@code UnsupportedOperationException}.
@@ -77,7 +73,7 @@ public interface ThreadStartRequest extends EventRequest {
*
* @since 99
*/
default void removeVirtualThreadFilter() {
default void addVirtualThreadFilter() {
throw new UnsupportedOperationException("Method not implemented");
}
}
@@ -466,10 +466,8 @@ private void setEventRequests(VirtualMachine vm) {
(new StringTokenizer("uncaught java.lang.Throwable"));

ThreadStartRequest tsr = erm.createThreadStartRequest();
tsr.removeVirtualThreadFilter(); // include events for vthreads
tsr.enable();
ThreadDeathRequest tdr = erm.createThreadDeathRequest();
tdr.removeVirtualThreadFilter(); // include events for vthreads
tdr.enable();
}

@@ -299,7 +299,7 @@ public synchronized void addThreadFilter(ThreadReference thread) {

abstract class ThreadLifecycleEventRequestImpl extends EventRequestImpl {
private ThreadReference thread;
private boolean notifyVirtualThreads;
private boolean filterVirtualThreads;

public synchronized void addThreadFilter(ThreadReference thread) {
validateMirror(thread);
@@ -309,11 +309,11 @@ public synchronized void addThreadFilter(ThreadReference thread) {
this.thread = thread;
}

public synchronized void removeVirtualThreadFilter() {
public synchronized void addVirtualThreadFilter() {
if (isEnabled() || deleted) {
throw invalidState();
}
this.notifyVirtualThreads = true;
this.filterVirtualThreads = true;
}

@Override
@@ -330,7 +330,7 @@ synchronized void set() {
if (thread != null) {
filters.add(JDWP.EventRequest.Set.Modifier.ThreadOnly
.create((ThreadReferenceImpl) thread));
} else if (!notifyVirtualThreads && vm.supportsVirtualThreads()) {
} else if (filterVirtualThreads && vm.supportsVirtualThreads()) {
// add filter that excludes virtual threads
filters.add(JDWP.EventRequest.Set.Modifier.VirtualThreadsExclude.create());
}

0 comments on commit e0990a0

Please sign in to comment.