threadreferenceimpl.c

来自「This is a resource based on j2me embedde」· C语言 代码 · 共 684 行 · 第 1/2 页

C
684
字号
    return JNI_TRUE;}static jboolean ownedMonitors(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;    }    if (!validateSuspendedThread(out, thread)) {        return JNI_TRUE;    }    WITH_LOCAL_REFS(env, 1) {                jvmtiError error;        jint count = 0;        jobject *monitors = NULL;                error = JVMTI_FUNC_PTR(gdata->jvmti,GetOwnedMonitorInfo)                                (gdata->jvmti, thread, &count, &monitors);        if (error != JVMTI_ERROR_NONE) {            outStream_setError(out, map2jdwpError(error));        } else {            int i;            (void)outStream_writeInt(out, count);            for (i = 0; i < count; i++) {                jobject monitor = monitors[i];                (void)outStream_writeByte(out, specificTypeKey(env, monitor));                (void)outStream_writeObjectRef(env, out, monitor);            }        }        if (monitors != NULL)            jvmtiDeallocate(monitors);    } END_WITH_LOCAL_REFS(env);        return JNI_TRUE;}static jboolean currentContendedMonitor(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;    }    if (!validateSuspendedThread(out, thread)) {        return JNI_TRUE;    }    WITH_LOCAL_REFS(env, 1) {                jobject monitor;        jvmtiError error;                error = JVMTI_FUNC_PTR(gdata->jvmti,GetCurrentContendedMonitor)                                (gdata->jvmti, thread, &monitor);                if (error != JVMTI_ERROR_NONE) {            outStream_setError(out, map2jdwpError(error));        } else {            (void)outStream_writeByte(out, specificTypeKey(env, monitor));            (void)outStream_writeObjectRef(env, out, monitor);        }        } END_WITH_LOCAL_REFS(env);        return JNI_TRUE;}static jboolean stop(PacketInputStream *in, PacketOutputStream *out) {    jvmtiError error;    jthread thread;    jobject throwable;    JNIEnv *env;        env = getEnv();    thread = inStream_readThreadRef(env, in);    if (inStream_error(in)) {        return JNI_TRUE;    }    throwable = inStream_readObjectRef(env, in);    if (inStream_error(in)) {        return JNI_TRUE;    }    if (threadControl_isDebugThread(thread)) {        outStream_setError(out, JDWP_ERROR(INVALID_THREAD));        return JNI_TRUE;    }    error = threadControl_stop(thread, throwable);    if (error != JVMTI_ERROR_NONE) {        outStream_setError(out, map2jdwpError(error));    }    return JNI_TRUE;}static jboolean interrupt(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_interrupt(thread);    if (error != JVMTI_ERROR_NONE) {        outStream_setError(out, map2jdwpError(error));    }    return JNI_TRUE;}static jboolean suspendCount(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;    }    error = threadControl_suspendCount(thread, &count);    if (error != JVMTI_ERROR_NONE) {        outStream_setError(out, map2jdwpError(error));        return JNI_TRUE;    }    (void)outStream_writeInt(out, count);    return JNI_TRUE;}static jboolean ownedMonitorsWithStackDepth(PacketInputStream *in, PacketOutputStream *out){    JNIEnv *env;    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;    }    env = getEnv();        WITH_LOCAL_REFS(env, 1) {                jvmtiError error = JVMTI_ERROR_NONE;        jint count = 0;        jvmtiMonitorStackDepthInfo *monitors=NULL;                error = JVMTI_FUNC_PTR(gdata->jvmti,GetOwnedMonitorStackDepthInfo)                                (gdata->jvmti, thread, &count, &monitors);        if (error != JVMTI_ERROR_NONE) {            outStream_setError(out, map2jdwpError(error));        } else {            int i;            (void)outStream_writeInt(out, count);            for (i = 0; i < count; i++) {                jobject monitor = monitors[i].monitor;                (void)outStream_writeByte(out, specificTypeKey(env, monitor));                (void)outStream_writeObjectRef(getEnv(), out, monitor);                (void)outStream_writeInt(out,monitors[i].stack_depth);            }        }        if (monitors != NULL) {            jvmtiDeallocate(monitors);        }    } END_WITH_LOCAL_REFS(env);        return JNI_TRUE;}static jboolean forceEarlyReturn(PacketInputStream *in, PacketOutputStream *out) {    JNIEnv *env;    jthread thread;    jvalue value;    jbyte typeKey;    jvmtiError error;    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;    }    typeKey = inStream_readByte(in);    if (inStream_error(in)) {        return JNI_TRUE;    }    if (isObjectTag(typeKey)) {        value.l = inStream_readObjectRef(env, in);        error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnObject)                        (gdata->jvmti, thread, value.l);    } else {        switch (typeKey) {            case JDWP_TAG(VOID):                error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnVoid)                                (gdata->jvmti, thread);                break;            case JDWP_TAG(BYTE):                value.b = inStream_readByte(in);                error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnInt)                                (gdata->jvmti, thread, value.b);                break;                case JDWP_TAG(CHAR):                value.c = inStream_readChar(in);                error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnInt)                                (gdata->jvmti, thread, value.c);                break;                case JDWP_TAG(FLOAT):                value.f = inStream_readFloat(in);                error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnFloat)                                (gdata->jvmti, thread, value.f);                break;                case JDWP_TAG(DOUBLE):                value.d = inStream_readDouble(in);                error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnDouble)                                (gdata->jvmti, thread, value.d);                break;                case JDWP_TAG(INT):                value.i = inStream_readInt(in);                error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnInt)                                (gdata->jvmti, thread, value.i);                break;                case JDWP_TAG(LONG):                value.j = inStream_readLong(in);                error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnLong)                                (gdata->jvmti, thread, value.j);                break;                case JDWP_TAG(SHORT):                value.s = inStream_readShort(in);                error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnInt)                                (gdata->jvmti, thread, value.s);                break;                case JDWP_TAG(BOOLEAN):                value.z = inStream_readBoolean(in);                error = JVMTI_FUNC_PTR(gdata->jvmti,ForceEarlyReturnInt)                                (gdata->jvmti, thread, value.z);                break;                default:              error = JDWP_ERROR(INVALID_TAG);              break;        }    }    {      jdwpError serror = map2jdwpError(error);      if (serror != JDWP_ERROR(NONE)) {        outStream_setError(out, serror);      }    }    return JNI_TRUE;}void *ThreadReference_Cmds[] = { (void *)14,    (void *)name,    (void *)suspend,    (void *)resume,    (void *)status,    (void *)threadGroup,    (void *)frames,    (void *)getFrameCount,    (void *)ownedMonitors,    (void *)currentContendedMonitor,    (void *)stop,    (void *)interrupt,    (void *)suspendCount,    (void *)ownedMonitorsWithStackDepth,    (void *)forceEarlyReturn    };

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?