< prev index next >

src/jdk.jdwp.agent/share/native/libjdwp/ThreadGroupReferenceImpl.c

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 1998, 2020, 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
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this
--- 1,7 ---
  /*
!  * 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
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this

*** 23,10 ***
--- 23,11 ---
   * questions.
   */
  
  #include "util.h"
  #include "ThreadGroupReferenceImpl.h"
+ #include "threadControl.h"
  #include "inStream.h"
  #include "outStream.h"
  
  static jboolean
  name(PacketInputStream *in, PacketOutputStream *out)

*** 87,49 ***
  static jboolean
  children(PacketInputStream *in, PacketOutputStream *out)
  {
       JNIEnv *env;
       jthreadGroup group;
  
       env = getEnv();
  
       group = inStream_readThreadGroupRef(env, in);
       if (inStream_error(in)) {
           return JNI_TRUE;
       }
  
!      WITH_LOCAL_REFS(env, 1) {
  
!          jvmtiError error;
           jint threadCount;
           jint groupCount;
           jthread *theThreads;
           jthread *theGroups;
  
!          error = JVMTI_FUNC_PTR(gdata->jvmti,GetThreadGroupChildren)(gdata->jvmti, group,
                                                &threadCount,&theThreads,
                                                &groupCount, &theGroups);
           if (error != JVMTI_ERROR_NONE) {
               outStream_setError(out, map2jdwpError(error));
           } else {
- 
               int i;
  
               /* Squish out all of the debugger-spawned threads */
               threadCount = filterDebugThreads(theThreads, threadCount);
  
!              (void)outStream_writeInt(out, threadCount);
               for (i = 0; i < threadCount; i++) {
                   (void)outStream_writeObjectRef(env, out, theThreads[i]);
               }
               (void)outStream_writeInt(out, groupCount);
               for (i = 0; i < groupCount; i++) {
                   (void)outStream_writeObjectRef(env, out, theGroups[i]);
               }
  
               jvmtiDeallocate(theGroups);
               jvmtiDeallocate(theThreads);
           }
  
       } END_WITH_LOCAL_REFS(env);
  
       return JNI_TRUE;
--- 88,71 ---
  static jboolean
  children(PacketInputStream *in, PacketOutputStream *out)
  {
       JNIEnv *env;
       jthreadGroup group;
+      jboolean is_vthread_group;
  
       env = getEnv();
  
       group = inStream_readThreadGroupRef(env, in);
       if (inStream_error(in)) {
           return JNI_TRUE;
       }
  
!      is_vthread_group = isSameObject(env, group, gdata->vthreadThreadGroup);
  
!      WITH_LOCAL_REFS(env, 2) {
+ 
+          jvmtiError error = JVMTI_ERROR_NONE;
           jint threadCount;
+          jint vthreadCount = 0;
           jint groupCount;
           jthread *theThreads;
+          jthread *theVThreads = NULL;
           jthread *theGroups;
  
!          if (is_vthread_group) {
+              if (gdata->enumerateVThreads) {
+                  /* Get all the VThreads so we can return them. */
+                  theVThreads = threadControl_allVThreads(&vthreadCount);
+                  if (theVThreads == NULL && vthreadCount != 0) {
+                      error = JVMTI_ERROR_OUT_OF_MEMORY;
+                  }
+              }
+          }
+ 
+          if (error == JVMTI_ERROR_NONE) {
+              /* Get all the threads in this group so we can return them. */
+              error = JVMTI_FUNC_PTR(gdata->jvmti,GetThreadGroupChildren)(gdata->jvmti, group,
                                                &threadCount,&theThreads,
                                                &groupCount, &theGroups);
+          }
+ 
           if (error != JVMTI_ERROR_NONE) {
               outStream_setError(out, map2jdwpError(error));
           } else {
               int i;
  
               /* Squish out all of the debugger-spawned threads */
               threadCount = filterDebugThreads(theThreads, threadCount);
  
!              (void)outStream_writeInt(out, threadCount + vthreadCount);
               for (i = 0; i < threadCount; i++) {
                   (void)outStream_writeObjectRef(env, out, theThreads[i]);
               }
+              for (i = 0; i < vthreadCount; i++) {
+                  (void)outStream_writeObjectRef(env, out, theVThreads[i]);
+              }
               (void)outStream_writeInt(out, groupCount);
               for (i = 0; i < groupCount; i++) {
                   (void)outStream_writeObjectRef(env, out, theGroups[i]);
               }
  
               jvmtiDeallocate(theGroups);
               jvmtiDeallocate(theThreads);
+              jvmtiDeallocate(theVThreads);
           }
  
       } END_WITH_LOCAL_REFS(env);
  
       return JNI_TRUE;
< prev index next >