src/jdk.jdwp.agent/share/native/libjdwp/ThreadReferenceImpl.c
changeset 51248 21ce0a9e592a
parent 47216 71c04702a3d5
equal deleted inserted replaced
51247:13e816d02c25 51248:21ce0a9e592a
     1 /*
     1 /*
     2  * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
     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.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   212 
   212 
   213 static jboolean
   213 static jboolean
   214 frames(PacketInputStream *in, PacketOutputStream *out)
   214 frames(PacketInputStream *in, PacketOutputStream *out)
   215 {
   215 {
   216     jvmtiError error;
   216     jvmtiError error;
   217     FrameNumber fnum;
   217     FrameNumber index;
   218     jint count;
   218     jint count;
       
   219     jint filledIn;
   219     JNIEnv *env;
   220     JNIEnv *env;
   220     jthread thread;
   221     jthread thread;
   221     jint startIndex;
   222     jint startIndex;
   222     jint length;
   223     jint length;
       
   224     jvmtiFrameInfo* frames;
   223 
   225 
   224     env = getEnv();
   226     env = getEnv();
   225 
   227 
   226     thread = inStream_readThreadRef(env, in);
   228     thread = inStream_readThreadRef(env, in);
   227     if (inStream_error(in)) {
   229     if (inStream_error(in)) {
   271         return JNI_TRUE;
   273         return JNI_TRUE;
   272     }
   274     }
   273 
   275 
   274     (void)outStream_writeInt(out, length);
   276     (void)outStream_writeInt(out, length);
   275 
   277 
   276     for(fnum = startIndex ; fnum < startIndex+length ; fnum++ ) {
   278     frames = jvmtiAllocate(sizeof(jvmtiFrameInfo) * length);
   277 
   279 
       
   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) {
   278         WITH_LOCAL_REFS(env, 1) {
   295         WITH_LOCAL_REFS(env, 1) {
   279 
       
   280             jclass clazz;
   296             jclass clazz;
   281             jmethodID method;
   297             error = methodClass(frames[index].method, &clazz);
   282             jlocation location;
   298 
   283 
   299             if (error == JVMTI_ERROR_NONE) {
   284             /* Get location info */
   300                 FrameID frame = createFrameID(thread, index + startIndex);
   285             error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameLocation)
   301                 outStream_writeFrameID(out, frame);
   286                 (gdata->jvmti, thread, fnum, &method, &location);
   302                 writeCodeLocation(out, clazz, frames[index].method,
   287             if (error == JVMTI_ERROR_OPAQUE_FRAME) {
   303                                   frames[index].location);
   288                 clazz = NULL;
       
   289                 location = -1L;
       
   290                 error = JVMTI_ERROR_NONE;
       
   291             } else if ( error == JVMTI_ERROR_NONE ) {
       
   292                 error = methodClass(method, &clazz);
       
   293                 if ( error == JVMTI_ERROR_NONE ) {
       
   294                     FrameID frame;
       
   295                     frame = createFrameID(thread, fnum);
       
   296                     (void)outStream_writeFrameID(out, frame);
       
   297                     writeCodeLocation(out, clazz, method, location);
       
   298                 }
       
   299             }
   304             }
   300 
       
   301         } END_WITH_LOCAL_REFS(env);
   305         } END_WITH_LOCAL_REFS(env);
   302 
   306     }
   303         if (error != JVMTI_ERROR_NONE)
   307 
   304             break;
   308     jvmtiDeallocate(frames);
   305 
       
   306     }
       
   307 
   309 
   308     if (error != JVMTI_ERROR_NONE) {
   310     if (error != JVMTI_ERROR_NONE) {
   309         outStream_setError(out, map2jdwpError(error));
   311         outStream_setError(out, map2jdwpError(error));
   310     }
   312     }
   311     return JNI_TRUE;
   313     return JNI_TRUE;