threadreferenceimpl.c
来自「This is a resource based on j2me embedde」· C语言 代码 · 共 684 行 · 第 1/2 页
C
684 行
/* * @(#)ThreadReferenceImpl.c 1.62 06/10/25 * * Copyright 1990-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program 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. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */#include "util.h"#include "ThreadReferenceImpl.h"#include "eventHandler.h"#include "threadControl.h"#include "inStream.h"#include "outStream.h"#include "FrameID.h"static jboolean name(PacketInputStream *in, PacketOutputStream *out) { JNIEnv *env; jthread thread; env = getEnv(); thread = inStream_readThreadRef(env, in); if (inStream_error(in)) { return JNI_TRUE; } if (threadControl_isDebugThread(thread)) { outStream_setError(out, JDWP_ERROR(INVALID_THREAD)); return JNI_TRUE; } WITH_LOCAL_REFS(env, 3) { jvmtiThreadInfo info; jvmtiError error; (void)memset(&info, 0, sizeof(info)); error = JVMTI_FUNC_PTR(gdata->jvmti,GetThreadInfo) (gdata->jvmti, thread, &info); if (error != JVMTI_ERROR_NONE) { outStream_setError(out, map2jdwpError(error)); } else { (void)outStream_writeString(out, info.name); } if ( info.name != NULL ) jvmtiDeallocate(info.name); } END_WITH_LOCAL_REFS(env); return JNI_TRUE;}static jboolean suspend(PacketInputStream *in, PacketOutputStream *out) { jvmtiError error; jthread thread; thread = inStream_readThreadRef(getEnv(), in); if (inStream_error(in)) { return JNI_TRUE; } if (threadControl_isDebugThread(thread)) { outStream_setError(out, JDWP_ERROR(INVALID_THREAD)); return JNI_TRUE; } error = threadControl_suspendThread(thread, JNI_FALSE); if (error != JVMTI_ERROR_NONE) { outStream_setError(out, map2jdwpError(error)); } return JNI_TRUE;}static jboolean resume(PacketInputStream *in, PacketOutputStream *out) { jvmtiError error; jthread thread; thread = inStream_readThreadRef(getEnv(), in); if (inStream_error(in)) { return JNI_TRUE; } if (threadControl_isDebugThread(thread)) { outStream_setError(out, JDWP_ERROR(INVALID_THREAD)); return JNI_TRUE; } /* true means it is okay to unblock the commandLoop thread */ error = threadControl_resumeThread(thread, JNI_TRUE); if (error != JVMTI_ERROR_NONE) { outStream_setError(out, map2jdwpError(error)); } return JNI_TRUE;}static jboolean status(PacketInputStream *in, PacketOutputStream *out) { jdwpThreadStatus threadStatus; jint statusFlags; jvmtiError error; jthread thread; thread = inStream_readThreadRef(getEnv(), in); if (inStream_error(in)) { return JNI_TRUE; } if (threadControl_isDebugThread(thread)) { outStream_setError(out, JDWP_ERROR(INVALID_THREAD)); return JNI_TRUE; } error = threadControl_applicationThreadStatus(thread, &threadStatus, &statusFlags); if (error != JVMTI_ERROR_NONE) { outStream_setError(out, map2jdwpError(error)); return JNI_TRUE; } (void)outStream_writeInt(out, threadStatus); (void)outStream_writeInt(out, statusFlags); return JNI_TRUE;}static jboolean threadGroup(PacketInputStream *in, PacketOutputStream *out) { JNIEnv *env; jthread thread; env = getEnv(); thread = inStream_readThreadRef(env, in); if (inStream_error(in)) { return JNI_TRUE; } if (threadControl_isDebugThread(thread)) { outStream_setError(out, JDWP_ERROR(INVALID_THREAD)); return JNI_TRUE; } WITH_LOCAL_REFS(env, 3) { jvmtiThreadInfo info; jvmtiError error; (void)memset(&info, 0, sizeof(info)); error = JVMTI_FUNC_PTR(gdata->jvmti,GetThreadInfo) (gdata->jvmti, thread, &info); if (error != JVMTI_ERROR_NONE) { outStream_setError(out, map2jdwpError(error)); } else { (void)outStream_writeObjectRef(env, out, info.thread_group); } if ( info.name!=NULL ) jvmtiDeallocate(info.name); } END_WITH_LOCAL_REFS(env); return JNI_TRUE;}static jboolean validateSuspendedThread(PacketOutputStream *out, jthread thread){ jvmtiError error; jint count; error = threadControl_suspendCount(thread, &count); if (error != JVMTI_ERROR_NONE) { outStream_setError(out, map2jdwpError(error)); return JNI_FALSE; } if (count == 0) { outStream_setError(out, JDWP_ERROR(THREAD_NOT_SUSPENDED)); return JNI_FALSE; } return JNI_TRUE;}static jboolean frames(PacketInputStream *in, PacketOutputStream *out) { jvmtiError error; FrameNumber fnum; jint count; JNIEnv *env; jthread thread; jint startIndex; jint length; env = getEnv(); thread = inStream_readThreadRef(env, in); if (inStream_error(in)) { return JNI_TRUE; } startIndex = inStream_readInt(in); if (inStream_error(in)) { return JNI_TRUE; } length = inStream_readInt(in); if (inStream_error(in)) { return JNI_TRUE; } if (threadControl_isDebugThread(thread)) { outStream_setError(out, JDWP_ERROR(INVALID_THREAD)); return JNI_TRUE; } if (!validateSuspendedThread(out, thread)) { return JNI_TRUE; } error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameCount) (gdata->jvmti, thread, &count); if (error != JVMTI_ERROR_NONE) { outStream_setError(out, map2jdwpError(error)); return JNI_TRUE; } if (length == -1) { length = count - startIndex; } if (length == 0) { (void)outStream_writeInt(out, 0); return JNI_TRUE; } if ((startIndex < 0) || (startIndex > count - 1)) { outStream_setError(out, JDWP_ERROR(INVALID_INDEX)); return JNI_TRUE; } if ((length < 0) || (length + startIndex > count)) { outStream_setError(out, JDWP_ERROR(INVALID_LENGTH)); return JNI_TRUE; } (void)outStream_writeInt(out, length); for(fnum = startIndex ; fnum < startIndex+length ; fnum++ ) { WITH_LOCAL_REFS(env, 1) { jclass clazz; jmethodID method; jlocation location; /* Get location info */ error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameLocation) (gdata->jvmti, thread, fnum, &method, &location); if (error == JVMTI_ERROR_OPAQUE_FRAME) { clazz = NULL; location = -1L; error = JVMTI_ERROR_NONE; } else if ( error == JVMTI_ERROR_NONE ) { error = methodClass(method, &clazz); if ( error == JVMTI_ERROR_NONE ) { FrameID frame; frame = createFrameID(thread, fnum); (void)outStream_writeFrameID(out, frame); writeCodeLocation(out, clazz, method, location); } } } END_WITH_LOCAL_REFS(env); if (error != JVMTI_ERROR_NONE) break; } if (error != JVMTI_ERROR_NONE) { outStream_setError(out, map2jdwpError(error)); } return JNI_TRUE;}static jboolean getFrameCount(PacketInputStream *in, PacketOutputStream *out) { jvmtiError error; jint count; jthread thread; thread = inStream_readThreadRef(getEnv(), in); if (inStream_error(in)) { return JNI_TRUE; } if (threadControl_isDebugThread(thread)) { outStream_setError(out, JDWP_ERROR(INVALID_THREAD)); return JNI_TRUE; } if (!validateSuspendedThread(out, thread)) { return JNI_TRUE; } error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameCount) (gdata->jvmti, thread, &count); if (error != JVMTI_ERROR_NONE) { outStream_setError(out, map2jdwpError(error)); return JNI_TRUE; } (void)outStream_writeInt(out, count);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?