Skip to content
Permalink
Browse files
Rename virtual thread exclude filter to platform thread only filter
  • Loading branch information
AlanBateman committed Mar 17, 2021
1 parent 93e116a commit 9d766df42d821af9de143ab2971836c4f9b35df1
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 33 deletions.
@@ -2520,9 +2520,9 @@ JDWP "Java(tm) Debug Wire Protocol"
"\"*.Foo\" or \"java.*\". "
)
)
(Alt VirtualThreadsExclude=13
(Alt PlatformThreadsOnly=13
"For thread start and thread end events, restrict the "
"events so they are not sent for virtual threads."
"events so they are only sent for platform threads."
)

)
@@ -60,10 +60,9 @@ public interface ThreadDeathRequest extends EventRequest {
void addThreadFilter(ThreadReference thread);

/**
* 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}.
* Restricts the events generated by this request to only platform 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}.
@@ -73,7 +72,7 @@ public interface ThreadDeathRequest extends EventRequest {
*
* @since 99
*/
default void addVirtualThreadFilter() {
default void addPlatformThreadsOnlyFilter() {
throw new UnsupportedOperationException("Method not implemented");
}
}
@@ -60,10 +60,9 @@ public interface ThreadStartRequest extends EventRequest {
void addThreadFilter(ThreadReference thread);

/**
* 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}.
* Restricts the events generated by this request to only platform 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}.
@@ -73,7 +72,7 @@ public interface ThreadStartRequest extends EventRequest {
*
* @since 99
*/
default void addVirtualThreadFilter() {
default void addPlatformThreadsOnlyFilter() {
throw new UnsupportedOperationException("Method not implemented");
}
}
@@ -299,7 +299,7 @@ public synchronized void addThreadFilter(ThreadReference thread) {

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

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

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

@Override
synchronized void set() {
// remove ThreadOnly and VirtualThreadsExclude filters
// remove ThreadOnly and PlatformThreads filters
Iterator<Object> iterator = filters.iterator();
while (iterator.hasNext()) {
Object filter = iterator.next();
if (filter instanceof JDWP.EventRequest.Set.Modifier.ThreadOnly ||
filter instanceof JDWP.EventRequest.Set.Modifier.VirtualThreadsExclude) {
filter instanceof JDWP.EventRequest.Set.Modifier.PlatformThreadsOnly) {
iterator.remove();
}
}
if (thread != null) {
filters.add(JDWP.EventRequest.Set.Modifier.ThreadOnly
.create((ThreadReferenceImpl) thread));
} else if (filterVirtualThreads && vm.supportsVirtualThreads()) {
// add filter that excludes virtual threads
filters.add(JDWP.EventRequest.Set.Modifier.VirtualThreadsExclude.create());
} else if (platformThreadsOnly && vm.supportsVirtualThreads()) {
// add filter that restricts events to platform threads only
filters.add(JDWP.EventRequest.Set.Modifier.PlatformThreadsOnly.create());
}
super.set();
}
@@ -207,8 +207,8 @@ readAndSetFilters(JNIEnv *env, PacketInputStream *in, HandlerNode *node,
break;
}

case JDWP_REQUEST_MODIFIER(VirtualThreadsExclude):
serror = map2jdwpError(eventFilter_setVirtualThreadsExcludeFilter(node, i));
case JDWP_REQUEST_MODIFIER(PlatformThreadsOnly):
serror = map2jdwpError(eventFilter_setPlatformThreadsOnlyFilter(node, i));
break;

default:
@@ -92,9 +92,9 @@ typedef struct SourceNameFilter {
char *sourceNamePattern;
} SourceNameFilter;

typedef struct VirtualThreadsExcludeFilter {
typedef struct PlatformThreadsFilter {
char unused; // to avoid an empty struct
} VirtualThreadsExcludeFilter;
} PlatformThreadsFilter;

typedef struct Filter_ {
jbyte modifier;
@@ -111,7 +111,7 @@ typedef struct Filter_ {
struct MatchFilter ClassMatch;
struct MatchFilter ClassExclude;
struct SourceNameFilter SourceNameOnly;
struct VirtualThreadsExcludeFilter VirtualThreadsExclude;
struct PlatformThreadsFilter PlatformThreadsOnly;
} u;
} Filter;

@@ -567,7 +567,7 @@ eventFilterRestricted_passesFilter(JNIEnv *env,
break;
}

case JDWP_REQUEST_MODIFIER(VirtualThreadsExclude): {
case JDWP_REQUEST_MODIFIER(PlatformThreadsOnly): {
jboolean isVirtual = JNI_FUNC_PTR(env, IsVirtualThread)(env, thread);
if (isVirtual) {
return JNI_FALSE;
@@ -996,16 +996,16 @@ eventFilter_setSourceNameMatchFilter(HandlerNode *node,

}

jvmtiError eventFilter_setVirtualThreadsExcludeFilter(HandlerNode *node, jint index)
jvmtiError eventFilter_setPlatformThreadsOnlyFilter(HandlerNode *node, jint index)
{
VirtualThreadsExcludeFilter *filter = &FILTER(node, index).u.VirtualThreadsExclude;
PlatformThreadsFilter *filter = &FILTER(node, index).u.PlatformThreadsOnly;
if (index >= FILTER_COUNT(node)) {
return AGENT_ERROR_ILLEGAL_ARGUMENT;
}
if (NODE_EI(node) != EI_THREAD_START && NODE_EI(node) != EI_THREAD_END) {
return AGENT_ERROR_ILLEGAL_ARGUMENT;
}
FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(VirtualThreadsExclude);
FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(PlatformThreadsOnly);
return JVMTI_ERROR_NONE;

}
@@ -1491,8 +1491,8 @@ eventFilter_dumpHandlerFilters(HandlerNode *node)
tty_message("SourceNameMatch: sourceNamePattern(%s)",
filter->u.SourceNameOnly.sourceNamePattern);
break;
case JDWP_REQUEST_MODIFIER(VirtualThreadsExclude):
tty_message("VirtualThreadsExclude: enabled");
case JDWP_REQUEST_MODIFIER(PlatformThreadsOnly):
tty_message("PlatformThreadsOnly: enabled");
break;
default:
EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT, "Invalid filter modifier");
@@ -69,8 +69,7 @@ jvmtiError eventFilter_setStepFilter(HandlerNode *node,
jvmtiError eventFilter_setSourceNameMatchFilter(HandlerNode *node,
jint index,
char *sourceNamePattern);
jvmtiError eventFilter_setVirtualThreadsExcludeFilter(HandlerNode *node,
jint index);
jvmtiError eventFilter_setPlatformThreadsOnlyFilter(HandlerNode *node, jint index);

/***** misc *****/

0 comments on commit 9d766df

Please sign in to comment.