< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  32 #include "FrameID.h"
  33 
  34 static jboolean
  35 name(PacketInputStream *in, PacketOutputStream *out)
  36 {
  37     JNIEnv *env;
  38     jthread thread;
  39 
  40     env = getEnv();
  41 
  42     thread = inStream_readThreadRef(env, in);
  43     if (inStream_error(in)) {
  44         return JNI_TRUE;
  45     }
  46 
  47     if (threadControl_isDebugThread(thread)) {
  48         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
  49         return JNI_TRUE;
  50     }
  51 
  52     WITH_LOCAL_REFS(env, 1) {
  53 
  54         jvmtiThreadInfo info;
  55         jvmtiError error;
  56 
  57         (void)memset(&info, 0, sizeof(info));
  58 
  59         error = JVMTI_FUNC_PTR(gdata->jvmti,GetThreadInfo)
  60                                 (gdata->jvmti, thread, &info);







  61 
  62         if (error != JVMTI_ERROR_NONE) {
  63             outStream_setError(out, map2jdwpError(error));


  64         } else {
  65             (void)outStream_writeString(out, info.name);
  66         }





  67 
  68         if ( info.name != NULL )
  69             jvmtiDeallocate(info.name);













  70 
  71     } END_WITH_LOCAL_REFS(env);
  72 
  73     return JNI_TRUE;
  74 }
  75 
  76 static jboolean
  77 suspend(PacketInputStream *in, PacketOutputStream *out)
  78 {
  79     jvmtiError error;
  80     jthread thread;
  81 
  82     thread = inStream_readThreadRef(getEnv(), in);
  83     if (inStream_error(in)) {
  84         return JNI_TRUE;
  85     }
  86 
  87     if (threadControl_isDebugThread(thread)) {
  88         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
  89         return JNI_TRUE;


 153 {
 154     JNIEnv *env;
 155     jthread thread;
 156 
 157     env = getEnv();
 158 
 159     thread = inStream_readThreadRef(env, in);
 160     if (inStream_error(in)) {
 161         return JNI_TRUE;
 162     }
 163 
 164     if (threadControl_isDebugThread(thread)) {
 165         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 166         return JNI_TRUE;
 167     }
 168 
 169     WITH_LOCAL_REFS(env, 1) {
 170 
 171         jvmtiThreadInfo info;
 172         jvmtiError error;
 173 
 174         (void)memset(&info, 0, sizeof(info));
 175 
 176         error = JVMTI_FUNC_PTR(gdata->jvmti,GetThreadInfo)
 177                                 (gdata->jvmti, thread, &info);
 178 
 179         if (error != JVMTI_ERROR_NONE) {
 180             outStream_setError(out, map2jdwpError(error));
 181         } else {
 182             (void)outStream_writeObjectRef(env, out, info.thread_group);
 183         }







 184 
 185         if ( info.name!=NULL )
 186             jvmtiDeallocate(info.name);

 187 
 188     } END_WITH_LOCAL_REFS(env);
 189 
 190     return JNI_TRUE;
 191 }
 192 
 193 static jboolean




 194 validateSuspendedThread(PacketOutputStream *out, jthread thread)
 195 {
 196     jvmtiError error;
 197     jint count;

 198 
 199     error = threadControl_suspendCount(thread, &count);
 200     if (error != JVMTI_ERROR_NONE) {
 201         outStream_setError(out, map2jdwpError(error));
 202         return JNI_FALSE;
 203     }
 204 
 205     if (count == 0) {
 206         outStream_setError(out, JDWP_ERROR(THREAD_NOT_SUSPENDED));
 207         return JNI_FALSE;
 208     }
 209 
 210     return JNI_TRUE;









 211 }
 212 
 213 static jboolean
 214 frames(PacketInputStream *in, PacketOutputStream *out)
 215 {
 216     jvmtiError error;
 217     FrameNumber index;
 218     jint count;
 219     jint filledIn;
 220     JNIEnv *env;
 221     jthread thread;
 222     jint startIndex;
 223     jint length;
 224     jvmtiFrameInfo* frames;

 225 
 226     env = getEnv();
 227 
 228     thread = inStream_readThreadRef(env, in);

 229     if (inStream_error(in)) {
 230         return JNI_TRUE;
 231     }
 232     startIndex = inStream_readInt(in);
 233     if (inStream_error(in)) {
 234         return JNI_TRUE;
 235     }
 236     length = inStream_readInt(in);
 237     if (inStream_error(in)) {
 238         return JNI_TRUE;
 239     }
 240 
 241     if (threadControl_isDebugThread(thread)) {
 242         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 243         return JNI_TRUE;
 244     }
 245 
 246     if (!validateSuspendedThread(out, thread)) {

 247         return JNI_TRUE;
 248     }
 249 
 250     error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameCount)
 251                         (gdata->jvmti, thread, &count);
 252     if (error != JVMTI_ERROR_NONE) {
 253         outStream_setError(out, map2jdwpError(error));
 254         return JNI_TRUE;
 255     }
 256 
 257     if (length == -1) {
 258         length = count - startIndex;
 259     }
 260 
 261     if (length == 0) {
 262         (void)outStream_writeInt(out, 0);
 263         return JNI_TRUE;
 264     }
 265 
 266     if ((startIndex < 0) || (startIndex > count - 1)) {


 280     if (frames == NULL) {
 281         outStream_setError(out, JDWP_ERROR(OUT_OF_MEMORY));
 282         return JNI_TRUE;
 283     }
 284 
 285     error = JVMTI_FUNC_PTR(gdata->jvmti, GetStackTrace)
 286                           (gdata->jvmti, thread, startIndex, length, frames,
 287                            &filledIn);
 288 
 289     /* Should not happen. */
 290     if (error == JVMTI_ERROR_NONE && length != filledIn) {
 291         error = JVMTI_ERROR_INTERNAL;
 292     }
 293 
 294     for (index = 0; index < filledIn && error == JVMTI_ERROR_NONE; ++index) {
 295         WITH_LOCAL_REFS(env, 1) {
 296             jclass clazz;
 297             error = methodClass(frames[index].method, &clazz);
 298 
 299             if (error == JVMTI_ERROR_NONE) {
 300                 FrameID frame = createFrameID(thread, index + startIndex);
 301                 outStream_writeFrameID(out, frame);
 302                 writeCodeLocation(out, clazz, frames[index].method,
 303                                   frames[index].location);
 304             }
 305         } END_WITH_LOCAL_REFS(env);
 306     }
 307 
 308     jvmtiDeallocate(frames);
 309 
 310     if (error != JVMTI_ERROR_NONE) {
 311         outStream_setError(out, map2jdwpError(error));
 312     }
 313     return JNI_TRUE;
 314 }
 315 
 316 static jboolean
 317 getFrameCount(PacketInputStream *in, PacketOutputStream *out)
 318 {
 319     jvmtiError error;
 320     jint count;
 321     jthread thread;
 322 
 323     thread = inStream_readThreadRef(getEnv(), in);
 324     if (inStream_error(in)) {
 325         return JNI_TRUE;
 326     }
 327 
 328     if (threadControl_isDebugThread(thread)) {
 329         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 330         return JNI_TRUE;
 331     }
 332 
 333     if (!validateSuspendedThread(out, thread)) {

 334         return JNI_TRUE;
 335     }
 336 
 337     error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameCount)
 338                         (gdata->jvmti, thread, &count);
 339     if (error != JVMTI_ERROR_NONE) {
 340         outStream_setError(out, map2jdwpError(error));
 341         return JNI_TRUE;
 342     }
 343     (void)outStream_writeInt(out, count);
 344 
 345     return JNI_TRUE;
 346 }
 347 
 348 static jboolean
 349 ownedMonitors(PacketInputStream *in, PacketOutputStream *out)
 350 {
 351     JNIEnv *env;
 352     jthread thread;
 353 
 354     env = getEnv();
 355 
 356     thread = inStream_readThreadRef(env, in);
 357     if (inStream_error(in)) {
 358         return JNI_TRUE;
 359     }
 360 
 361     if (threadControl_isDebugThread(thread)) {
 362         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 363         return JNI_TRUE;
 364     }
 365 
 366     if (!validateSuspendedThread(out, thread)) {

 367         return JNI_TRUE;
 368     }
 369 
 370     WITH_LOCAL_REFS(env, 1) {
 371 
 372         jvmtiError error;
 373         jint count = 0;
 374         jobject *monitors = NULL;
 375 
 376         error = JVMTI_FUNC_PTR(gdata->jvmti,GetOwnedMonitorInfo)
 377                                 (gdata->jvmti, thread, &count, &monitors);
 378         if (error != JVMTI_ERROR_NONE) {
 379             outStream_setError(out, map2jdwpError(error));
 380         } else {
 381             int i;
 382             (void)outStream_writeInt(out, count);
 383             for (i = 0; i < count; i++) {
 384                 jobject monitor = monitors[i];
 385                 (void)outStream_writeByte(out, specificTypeKey(env, monitor));
 386                 (void)outStream_writeObjectRef(env, out, monitor);


 395 }
 396 
 397 static jboolean
 398 currentContendedMonitor(PacketInputStream *in, PacketOutputStream *out)
 399 {
 400     JNIEnv *env;
 401     jthread thread;
 402 
 403     env = getEnv();
 404 
 405     thread = inStream_readThreadRef(env, in);
 406     if (inStream_error(in)) {
 407         return JNI_TRUE;
 408     }
 409 
 410     if (thread == NULL || threadControl_isDebugThread(thread)) {
 411         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 412         return JNI_TRUE;
 413     }
 414 
 415     if (!validateSuspendedThread(out, thread)) {

 416         return JNI_TRUE;
 417     }
 418 
 419     WITH_LOCAL_REFS(env, 1) {
 420 
 421         jobject monitor;
 422         jvmtiError error;
 423 
 424         error = JVMTI_FUNC_PTR(gdata->jvmti,GetCurrentContendedMonitor)
 425                                 (gdata->jvmti, thread, &monitor);
 426 
 427         if (error != JVMTI_ERROR_NONE) {
 428             outStream_setError(out, map2jdwpError(error));
 429         } else {
 430             (void)outStream_writeByte(out, specificTypeKey(env, monitor));
 431             (void)outStream_writeObjectRef(env, out, monitor);
 432         }
 433 
 434     } END_WITH_LOCAL_REFS(env);
 435 


 442     jvmtiError error;
 443     jthread thread;
 444     jobject throwable;
 445     JNIEnv *env;
 446 
 447     env = getEnv();
 448     thread = inStream_readThreadRef(env, in);
 449     if (inStream_error(in)) {
 450         return JNI_TRUE;
 451     }
 452     throwable = inStream_readObjectRef(env, in);
 453     if (inStream_error(in)) {
 454         return JNI_TRUE;
 455     }
 456 
 457     if (threadControl_isDebugThread(thread)) {
 458         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 459         return JNI_TRUE;
 460     }
 461 






 462     error = threadControl_stop(thread, throwable);
 463     if (error != JVMTI_ERROR_NONE) {
 464         outStream_setError(out, map2jdwpError(error));
 465     }
 466     return JNI_TRUE;
 467 }
 468 
 469 static jboolean
 470 interrupt(PacketInputStream *in, PacketOutputStream *out)
 471 {
 472     jvmtiError error;
 473     jthread thread;
 474 
 475     thread = inStream_readThreadRef(getEnv(), in);
 476     if (inStream_error(in)) {
 477         return JNI_TRUE;
 478     }
 479 
 480     if (threadControl_isDebugThread(thread)) {
 481         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 482         return JNI_TRUE;
 483     }
 484 






 485     error = threadControl_interrupt(thread);
 486     if (error != JVMTI_ERROR_NONE) {
 487         outStream_setError(out, map2jdwpError(error));
 488     }
 489     return JNI_TRUE;
 490 }
 491 
 492 static jboolean
 493 suspendCount(PacketInputStream *in, PacketOutputStream *out)
 494 {
 495     jvmtiError error;
 496     jint count;
 497     jthread thread;
 498 
 499     thread = inStream_readThreadRef(getEnv(), in);
 500     if (inStream_error(in)) {
 501         return JNI_TRUE;
 502     }
 503 
 504     if (threadControl_isDebugThread(thread)) {


 515     (void)outStream_writeInt(out, count);
 516     return JNI_TRUE;
 517 }
 518 
 519 static jboolean
 520 ownedMonitorsWithStackDepth(PacketInputStream *in, PacketOutputStream *out)
 521 {
 522     JNIEnv *env;
 523     jthread thread;
 524 
 525     thread = inStream_readThreadRef(getEnv(), in);
 526     if (inStream_error(in)) {
 527         return JNI_TRUE;
 528     }
 529 
 530     if (thread == NULL || threadControl_isDebugThread(thread)) {
 531         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 532         return JNI_TRUE;
 533     }
 534 
 535     if (!validateSuspendedThread(out, thread)) {

 536         return JNI_TRUE;
 537     }
 538 
 539     env = getEnv();
 540 
 541     WITH_LOCAL_REFS(env, 1) {
 542 
 543         jvmtiError error = JVMTI_ERROR_NONE;
 544         jint count = 0;
 545         jvmtiMonitorStackDepthInfo *monitors=NULL;
 546 
 547         error = JVMTI_FUNC_PTR(gdata->jvmti,GetOwnedMonitorStackDepthInfo)
 548                                 (gdata->jvmti, thread, &count, &monitors);
 549 
 550         if (error != JVMTI_ERROR_NONE) {
 551             outStream_setError(out, map2jdwpError(error));
 552         } else {
 553             int i;
 554             (void)outStream_writeInt(out, count);
 555             for (i = 0; i < count; i++) {


 567 
 568     return JNI_TRUE;
 569 }
 570 
 571 static jboolean
 572 forceEarlyReturn(PacketInputStream *in, PacketOutputStream *out)
 573 {
 574     JNIEnv *env;
 575     jthread thread;
 576     jvalue value;
 577     jbyte typeKey;
 578     jvmtiError error;
 579 
 580     env = getEnv();
 581     thread = inStream_readThreadRef(env, in);
 582     if (inStream_error(in)) {
 583         return JNI_TRUE;
 584     }
 585 
 586     if (threadControl_isDebugThread(thread)) {






 587         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 588         return JNI_TRUE;
 589     }
 590 
 591     typeKey = inStream_readByte(in);
 592     if (inStream_error(in)) {
 593         return JNI_TRUE;
 594     }
 595 
 596     if (isObjectTag(typeKey)) {
 597         value.l = inStream_readObjectRef(env, in);
 598         error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnObject)
 599                         (gdata->jvmti, thread, value.l);
 600     } else {
 601         switch (typeKey) {
 602             case JDWP_TAG(VOID):
 603                 error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnVoid)
 604                                 (gdata->jvmti, thread);
 605                 break;
 606             case JDWP_TAG(BYTE):


   1 /*
   2  * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  32 #include "FrameID.h"
  33 
  34 static jboolean
  35 name(PacketInputStream *in, PacketOutputStream *out)
  36 {
  37     JNIEnv *env;
  38     jthread thread;
  39 
  40     env = getEnv();
  41 
  42     thread = inStream_readThreadRef(env, in);
  43     if (inStream_error(in)) {
  44         return JNI_TRUE;
  45     }
  46 
  47     if (threadControl_isDebugThread(thread)) {
  48         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
  49         return JNI_TRUE;
  50     }
  51 
  52     WITH_LOCAL_REFS(env, 3) {
  53         jboolean is_fiber = isFiber(thread);
  54         if (!is_fiber) {
  55             /* Get the thread name */
  56             jvmtiThreadInfo info;
  57             jvmtiError error;
  58 
  59             (void)memset(&info, 0, sizeof(info));
  60             error = JVMTI_FUNC_PTR(gdata->jvmti,GetThreadInfo)
  61                 (gdata->jvmti, thread, &info);
  62 
  63             if (error != JVMTI_ERROR_NONE) {
  64                 outStream_setError(out, map2jdwpError(error));
  65             } else {
  66                 (void)outStream_writeString(out, info.name);
  67             }
  68 
  69             if ( info.name != NULL ) {
  70                 threadControl_setName(thread, info.name);
  71                 jvmtiDeallocate(info.name);
  72             }
  73         } else {
  74             /* Use Fiber.toString() instead of the Thread name. */
  75             jstring fiberName = JNI_FUNC_PTR(env,CallObjectMethod)
  76                 (env, thread, gdata->fiberToString);
  77             if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) {
  78                 JNI_FUNC_PTR(env,ExceptionClear)(env);
  79                 fiberName = NULL;
  80             }
  81 
  82             if (fiberName == NULL) {
  83                 (void)outStream_writeString(out, "<UNKNOWN FIBER>");
  84             } else {
  85                 const char *utf;
  86                 /* Get the UTF8 encoding for this fiberName string. */
  87                 utf = JNI_FUNC_PTR(env,GetStringUTFChars)(env, fiberName, NULL);
  88                 if (!(*env)->ExceptionCheck(env)) {
  89                     (void)outStream_writeString(out, (char*)utf);
  90                     threadControl_setName(thread, utf);
  91                     JNI_FUNC_PTR(env,ReleaseStringUTFChars)(env, fiberName, utf);
  92                 } else {
  93                     (void)outStream_writeString(out, "<UNKNOWN FIBER>");
  94                 }
  95             }
  96         }
  97 
  98     } END_WITH_LOCAL_REFS(env);
  99 
 100     return JNI_TRUE;
 101 }
 102 
 103 static jboolean
 104 suspend(PacketInputStream *in, PacketOutputStream *out)
 105 {
 106     jvmtiError error;
 107     jthread thread;
 108 
 109     thread = inStream_readThreadRef(getEnv(), in);
 110     if (inStream_error(in)) {
 111         return JNI_TRUE;
 112     }
 113 
 114     if (threadControl_isDebugThread(thread)) {
 115         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 116         return JNI_TRUE;


 180 {
 181     JNIEnv *env;
 182     jthread thread;
 183 
 184     env = getEnv();
 185 
 186     thread = inStream_readThreadRef(env, in);
 187     if (inStream_error(in)) {
 188         return JNI_TRUE;
 189     }
 190 
 191     if (threadControl_isDebugThread(thread)) {
 192         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 193         return JNI_TRUE;
 194     }
 195 
 196     WITH_LOCAL_REFS(env, 1) {
 197 
 198         jvmtiThreadInfo info;
 199         jvmtiError error;
 200         jboolean is_fiber = isFiber(thread);
 201         
 202         if (is_fiber) {
 203             /* If it's a fiber, use the well known thread group for Fibers. */
 204             JDI_ASSERT(gdata->fiberThreadGroup != NULL);
 205             (void)outStream_writeObjectRef(env, out, gdata->fiberThreadGroup);


 206         } else {
 207             (void)memset(&info, 0, sizeof(info));
 208             error = JVMTI_FUNC_PTR(gdata->jvmti,GetThreadInfo)
 209                                       (gdata->jvmti, thread, &info);
 210 
 211             if (error != JVMTI_ERROR_NONE) {
 212                 outStream_setError(out, map2jdwpError(error));
 213             } else {
 214                 (void)outStream_writeObjectRef(env, out, info.thread_group);
 215             }
 216 
 217             if ( info.name!=NULL )
 218                 jvmtiDeallocate(info.name);
 219         }
 220 
 221     } END_WITH_LOCAL_REFS(env);
 222 
 223     return JNI_TRUE;
 224 }
 225 
 226 /*
 227  * Validate that the thread or fiber is suspended, and returns a thread that can
 228  * be used for stack operations, even for unmounted fibers.
 229  */
 230 static jthread
 231 validateSuspendedThread(PacketOutputStream *out, jthread thread)
 232 {
 233     jvmtiError error;
 234     jint count;
 235     jthread result = thread;
 236 
 237     error = threadControl_suspendCount(thread, &count);
 238     if (error != JVMTI_ERROR_NONE) {
 239         outStream_setError(out, map2jdwpError(error));
 240         return NULL;
 241     }
 242 
 243     if (count == 0) {
 244         outStream_setError(out, JDWP_ERROR(THREAD_NOT_SUSPENDED));
 245         return NULL;
 246     }
 247 
 248     if (isFiber(thread)) {
 249         /* Make sure the Fiber is mounted on a thread that we can do stack operations on. */
 250         result = threadControl_getFiberCarrierOrHelperThread(thread);
 251         if (result == NULL) {
 252             /* fiber fixme: this should never happen once we get proper unmounted fiber supported. */
 253             (void)outStream_writeInt(out, 0);
 254         }
 255     }
 256 
 257     return result;
 258 }
 259 
 260 static jboolean
 261 frames(PacketInputStream *in, PacketOutputStream *out)
 262 {
 263     jvmtiError error;
 264     FrameNumber index;
 265     jint count;
 266     jint filledIn;
 267     JNIEnv *env;
 268     jthread thread;
 269     jint startIndex;
 270     jint length;
 271     jvmtiFrameInfo* frames;
 272     jthread originalThread;
 273 
 274     env = getEnv();
 275 
 276     thread = inStream_readThreadRef(env, in);
 277     originalThread = thread;
 278     if (inStream_error(in)) {
 279         return JNI_TRUE;
 280     }
 281     startIndex = inStream_readInt(in);
 282     if (inStream_error(in)) {
 283         return JNI_TRUE;
 284     }
 285     length = inStream_readInt(in);
 286     if (inStream_error(in)) {
 287         return JNI_TRUE;
 288     }
 289 
 290     if (threadControl_isDebugThread(thread)) {
 291         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 292         return JNI_TRUE;
 293     }
 294 
 295     thread = validateSuspendedThread(out, thread);
 296     if (thread == NULL) {
 297         return JNI_TRUE;
 298     }
 299 
 300     error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameCount)
 301                         (gdata->jvmti, thread, &count);
 302     if (error != JVMTI_ERROR_NONE) {
 303         outStream_setError(out, map2jdwpError(error));
 304         return JNI_TRUE;
 305     }
 306 
 307     if (length == -1) {
 308         length = count - startIndex;
 309     }
 310 
 311     if (length == 0) {
 312         (void)outStream_writeInt(out, 0);
 313         return JNI_TRUE;
 314     }
 315 
 316     if ((startIndex < 0) || (startIndex > count - 1)) {


 330     if (frames == NULL) {
 331         outStream_setError(out, JDWP_ERROR(OUT_OF_MEMORY));
 332         return JNI_TRUE;
 333     }
 334 
 335     error = JVMTI_FUNC_PTR(gdata->jvmti, GetStackTrace)
 336                           (gdata->jvmti, thread, startIndex, length, frames,
 337                            &filledIn);
 338 
 339     /* Should not happen. */
 340     if (error == JVMTI_ERROR_NONE && length != filledIn) {
 341         error = JVMTI_ERROR_INTERNAL;
 342     }
 343 
 344     for (index = 0; index < filledIn && error == JVMTI_ERROR_NONE; ++index) {
 345         WITH_LOCAL_REFS(env, 1) {
 346             jclass clazz;
 347             error = methodClass(frames[index].method, &clazz);
 348 
 349             if (error == JVMTI_ERROR_NONE) {
 350                 FrameID frame = createFrameID(originalThread, index + startIndex);
 351                 outStream_writeFrameID(out, frame);
 352                 writeCodeLocation(out, clazz, frames[index].method,
 353                                   frames[index].location);
 354             }
 355         } END_WITH_LOCAL_REFS(env);
 356     }
 357 
 358     jvmtiDeallocate(frames);
 359 
 360     if (error != JVMTI_ERROR_NONE) {
 361         outStream_setError(out, map2jdwpError(error));
 362     }
 363     return JNI_TRUE;
 364 }
 365 
 366 static jboolean
 367 getFrameCount(PacketInputStream *in, PacketOutputStream *out)
 368 {
 369     jvmtiError error;
 370     jint count;
 371     jthread thread;
 372 
 373     thread = inStream_readThreadRef(getEnv(), in);
 374     if (inStream_error(in)) {
 375         return JNI_TRUE;
 376     }
 377 
 378     if (threadControl_isDebugThread(thread)) {
 379         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 380         return JNI_TRUE;
 381     }
 382 
 383     thread = validateSuspendedThread(out, thread);
 384     if (thread == NULL) {
 385         return JNI_TRUE;
 386     }
 387 
 388     error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameCount)
 389                         (gdata->jvmti, thread, &count);
 390     if (error != JVMTI_ERROR_NONE) {
 391         outStream_setError(out, map2jdwpError(error));
 392         return JNI_TRUE;
 393     }
 394     (void)outStream_writeInt(out, count);
 395 
 396     return JNI_TRUE;
 397 }
 398 
 399 static jboolean
 400 ownedMonitors(PacketInputStream *in, PacketOutputStream *out)
 401 {
 402     JNIEnv *env;
 403     jthread thread;
 404 
 405     env = getEnv();
 406 
 407     thread = inStream_readThreadRef(env, in);
 408     if (inStream_error(in)) {
 409         return JNI_TRUE;
 410     }
 411 
 412     if (threadControl_isDebugThread(thread)) {
 413         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 414         return JNI_TRUE;
 415     }
 416 
 417     thread = validateSuspendedThread(out, thread);
 418     if (thread == NULL) {
 419         return JNI_TRUE;
 420     }
 421 
 422     WITH_LOCAL_REFS(env, 1) {
 423 
 424         jvmtiError error;
 425         jint count = 0;
 426         jobject *monitors = NULL;
 427 
 428         error = JVMTI_FUNC_PTR(gdata->jvmti,GetOwnedMonitorInfo)
 429                                 (gdata->jvmti, thread, &count, &monitors);
 430         if (error != JVMTI_ERROR_NONE) {
 431             outStream_setError(out, map2jdwpError(error));
 432         } else {
 433             int i;
 434             (void)outStream_writeInt(out, count);
 435             for (i = 0; i < count; i++) {
 436                 jobject monitor = monitors[i];
 437                 (void)outStream_writeByte(out, specificTypeKey(env, monitor));
 438                 (void)outStream_writeObjectRef(env, out, monitor);


 447 }
 448 
 449 static jboolean
 450 currentContendedMonitor(PacketInputStream *in, PacketOutputStream *out)
 451 {
 452     JNIEnv *env;
 453     jthread thread;
 454 
 455     env = getEnv();
 456 
 457     thread = inStream_readThreadRef(env, in);
 458     if (inStream_error(in)) {
 459         return JNI_TRUE;
 460     }
 461 
 462     if (thread == NULL || threadControl_isDebugThread(thread)) {
 463         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 464         return JNI_TRUE;
 465     }
 466 
 467     thread = validateSuspendedThread(out, thread);
 468     if (thread == NULL) {
 469         return JNI_TRUE;
 470     }
 471 
 472     WITH_LOCAL_REFS(env, 1) {
 473 
 474         jobject monitor;
 475         jvmtiError error;
 476 
 477         error = JVMTI_FUNC_PTR(gdata->jvmti,GetCurrentContendedMonitor)
 478                                 (gdata->jvmti, thread, &monitor);
 479 
 480         if (error != JVMTI_ERROR_NONE) {
 481             outStream_setError(out, map2jdwpError(error));
 482         } else {
 483             (void)outStream_writeByte(out, specificTypeKey(env, monitor));
 484             (void)outStream_writeObjectRef(env, out, monitor);
 485         }
 486 
 487     } END_WITH_LOCAL_REFS(env);
 488 


 495     jvmtiError error;
 496     jthread thread;
 497     jobject throwable;
 498     JNIEnv *env;
 499 
 500     env = getEnv();
 501     thread = inStream_readThreadRef(env, in);
 502     if (inStream_error(in)) {
 503         return JNI_TRUE;
 504     }
 505     throwable = inStream_readObjectRef(env, in);
 506     if (inStream_error(in)) {
 507         return JNI_TRUE;
 508     }
 509 
 510     if (threadControl_isDebugThread(thread)) {
 511         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 512         return JNI_TRUE;
 513     }
 514 
 515     /* fiber fixme: add fiber support */
 516     if (isFiber(thread)) {
 517         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 518         return JNI_TRUE;
 519     }
 520 
 521     error = threadControl_stop(thread, throwable);
 522     if (error != JVMTI_ERROR_NONE) {
 523         outStream_setError(out, map2jdwpError(error));
 524     }
 525     return JNI_TRUE;
 526 }
 527 
 528 static jboolean
 529 interrupt(PacketInputStream *in, PacketOutputStream *out)
 530 {
 531     jvmtiError error;
 532     jthread thread;
 533 
 534     thread = inStream_readThreadRef(getEnv(), in);
 535     if (inStream_error(in)) {
 536         return JNI_TRUE;
 537     }
 538 
 539     if (threadControl_isDebugThread(thread)) {
 540         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 541         return JNI_TRUE;
 542     }
 543 
 544     /* fiber fixme: add fiber support */
 545     if (isFiber(thread)) {
 546         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 547         return JNI_TRUE;
 548     }
 549 
 550     error = threadControl_interrupt(thread);
 551     if (error != JVMTI_ERROR_NONE) {
 552         outStream_setError(out, map2jdwpError(error));
 553     }
 554     return JNI_TRUE;
 555 }
 556 
 557 static jboolean
 558 suspendCount(PacketInputStream *in, PacketOutputStream *out)
 559 {
 560     jvmtiError error;
 561     jint count;
 562     jthread thread;
 563 
 564     thread = inStream_readThreadRef(getEnv(), in);
 565     if (inStream_error(in)) {
 566         return JNI_TRUE;
 567     }
 568 
 569     if (threadControl_isDebugThread(thread)) {


 580     (void)outStream_writeInt(out, count);
 581     return JNI_TRUE;
 582 }
 583 
 584 static jboolean
 585 ownedMonitorsWithStackDepth(PacketInputStream *in, PacketOutputStream *out)
 586 {
 587     JNIEnv *env;
 588     jthread thread;
 589 
 590     thread = inStream_readThreadRef(getEnv(), in);
 591     if (inStream_error(in)) {
 592         return JNI_TRUE;
 593     }
 594 
 595     if (thread == NULL || threadControl_isDebugThread(thread)) {
 596         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 597         return JNI_TRUE;
 598     }
 599 
 600     thread = validateSuspendedThread(out, thread);
 601     if (thread == NULL) {
 602         return JNI_TRUE;
 603     }
 604 
 605     env = getEnv();
 606 
 607     WITH_LOCAL_REFS(env, 1) {
 608 
 609         jvmtiError error = JVMTI_ERROR_NONE;
 610         jint count = 0;
 611         jvmtiMonitorStackDepthInfo *monitors=NULL;
 612 
 613         error = JVMTI_FUNC_PTR(gdata->jvmti,GetOwnedMonitorStackDepthInfo)
 614                                 (gdata->jvmti, thread, &count, &monitors);
 615 
 616         if (error != JVMTI_ERROR_NONE) {
 617             outStream_setError(out, map2jdwpError(error));
 618         } else {
 619             int i;
 620             (void)outStream_writeInt(out, count);
 621             for (i = 0; i < count; i++) {


 633 
 634     return JNI_TRUE;
 635 }
 636 
 637 static jboolean
 638 forceEarlyReturn(PacketInputStream *in, PacketOutputStream *out)
 639 {
 640     JNIEnv *env;
 641     jthread thread;
 642     jvalue value;
 643     jbyte typeKey;
 644     jvmtiError error;
 645 
 646     env = getEnv();
 647     thread = inStream_readThreadRef(env, in);
 648     if (inStream_error(in)) {
 649         return JNI_TRUE;
 650     }
 651 
 652     if (threadControl_isDebugThread(thread)) {
 653         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 654         return JNI_TRUE;
 655     }
 656 
 657     /* fiber fixme: add fiber support */
 658     if (isFiber(thread)) {
 659         outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
 660         return JNI_TRUE;
 661     }
 662 
 663     typeKey = inStream_readByte(in);
 664     if (inStream_error(in)) {
 665         return JNI_TRUE;
 666     }
 667 
 668     if (isObjectTag(typeKey)) {
 669         value.l = inStream_readObjectRef(env, in);
 670         error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnObject)
 671                         (gdata->jvmti, thread, value.l);
 672     } else {
 673         switch (typeKey) {
 674             case JDWP_TAG(VOID):
 675                 error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnVoid)
 676                                 (gdata->jvmti, thread);
 677                 break;
 678             case JDWP_TAG(BYTE):


< prev index next >