virtualmachineimpl.c
来自「This is a resource based on j2me embedde」· C语言 代码 · 共 910 行 · 第 1/2 页
C
910 行
static jbooleansetDefaultStratum(PacketInputStream *in, PacketOutputStream *out){ char *stratumId; if (gdata->vmDead) { /* quietly ignore */ return JNI_TRUE; } stratumId = inStream_readString(in); if (inStream_error(in)) { return JNI_TRUE; } else if (strcmp(stratumId, "") == 0) { stratumId = NULL; } setGlobalStratumId(stratumId); return JNI_TRUE;}static jboolean getAllThreads(PacketInputStream *in, PacketOutputStream *out){ JNIEnv *env; if (gdata->vmDead) { outStream_setError(out, JDWP_ERROR(VM_DEAD)); return JNI_TRUE; } env = getEnv(); WITH_LOCAL_REFS(env, 400) { int i; jint threadCount; jthread *theThreads; theThreads = allThreads(&threadCount); if (theThreads == NULL) { outStream_setError(out, JDWP_ERROR(OUT_OF_MEMORY)); } else { /* 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]); } jvmtiDeallocate(theThreads); } } END_WITH_LOCAL_REFS(env); return JNI_TRUE;}static jboolean topLevelThreadGroups(PacketInputStream *in, PacketOutputStream *out){ JNIEnv *env; if (gdata->vmDead) { outStream_setError(out, JDWP_ERROR(VM_DEAD)); return JNI_TRUE; } env = getEnv(); WITH_LOCAL_REFS(env, 1) { jvmtiError error; jint groupCount; jthreadGroup *groups; groups = NULL; error = JVMTI_FUNC_PTR(gdata->jvmti,GetTopThreadGroups) (gdata->jvmti, &groupCount, &groups); if (error != JVMTI_ERROR_NONE) { outStream_setError(out, map2jdwpError(error)); } else { int i; (void)outStream_writeInt(out, groupCount); for (i = 0; i < groupCount; i++) { (void)outStream_writeObjectRef(env, out, groups[i]); } jvmtiDeallocate(groups); } } END_WITH_LOCAL_REFS(env); return JNI_TRUE;}static jboolean dispose(PacketInputStream *in, PacketOutputStream *out){ return JNI_TRUE;}static jboolean idSizes(PacketInputStream *in, PacketOutputStream *out){ (void)outStream_writeInt(out, sizeof(jfieldID)); /* fields */ (void)outStream_writeInt(out, sizeof(jmethodID)); /* methods */ (void)outStream_writeInt(out, sizeof(jlong)); /* objects */ (void)outStream_writeInt(out, sizeof(jlong)); /* referent types */ (void)outStream_writeInt(out, sizeof(FrameID)); /* frames */ return JNI_TRUE;}static jboolean suspend(PacketInputStream *in, PacketOutputStream *out){ jvmtiError error; if (gdata->vmDead) { outStream_setError(out, JDWP_ERROR(VM_DEAD)); return JNI_TRUE; } error = threadControl_suspendAll(); if (error != JVMTI_ERROR_NONE) { outStream_setError(out, map2jdwpError(error)); } return JNI_TRUE;}static jboolean resume(PacketInputStream *in, PacketOutputStream *out){ jvmtiError error; if (gdata->vmDead) { outStream_setError(out, JDWP_ERROR(VM_DEAD)); return JNI_TRUE; } error = threadControl_resumeAll(); if (error != JVMTI_ERROR_NONE) { outStream_setError(out, map2jdwpError(error)); } return JNI_TRUE;}static jboolean doExit(PacketInputStream *in, PacketOutputStream *out){ jint exitCode; exitCode = inStream_readInt(in); if (gdata->vmDead) { /* quietly ignore */ return JNI_FALSE; } /* We send the reply from here because we are about to exit. */ if (inStream_error(in)) { outStream_setError(out, inStream_error(in)); } outStream_sendReply(out); forceExit(exitCode); /* Shouldn't get here */ JDI_ASSERT(JNI_FALSE); /* Shut up the compiler */ return JNI_FALSE;}static jboolean createString(PacketInputStream *in, PacketOutputStream *out){ JNIEnv *env; char *cstring; if (gdata->vmDead) { outStream_setError(out, JDWP_ERROR(VM_DEAD)); return JNI_TRUE; } cstring = inStream_readString(in); if (cstring == NULL) { outStream_setError(out, JDWP_ERROR(OUT_OF_MEMORY)); return JNI_TRUE; } if (inStream_error(in)) { return JNI_TRUE; } env = getEnv(); WITH_LOCAL_REFS(env, 1) { jstring string; string = JNI_FUNC_PTR(env,NewStringUTF)(env, cstring); if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) { outStream_setError(out, JDWP_ERROR(OUT_OF_MEMORY)); } else { (void)outStream_writeObjectRef(env, out, string); } } END_WITH_LOCAL_REFS(env); jvmtiDeallocate(cstring); return JNI_TRUE;}static jboolean capabilities(PacketInputStream *in, PacketOutputStream *out){ jvmtiCapabilities caps; jvmtiError error; if (gdata->vmDead) { outStream_setError(out, JDWP_ERROR(VM_DEAD)); return JNI_TRUE; } error = jvmtiGetCapabilities(&caps); if (error != JVMTI_ERROR_NONE) { outStream_setError(out, map2jdwpError(error)); return JNI_TRUE; } (void)outStream_writeBoolean(out, (jboolean)caps.can_generate_field_modification_events); (void)outStream_writeBoolean(out, (jboolean)caps.can_generate_field_access_events); (void)outStream_writeBoolean(out, (jboolean)caps.can_get_bytecodes); (void)outStream_writeBoolean(out, (jboolean)caps.can_get_synthetic_attribute); (void)outStream_writeBoolean(out, (jboolean)caps.can_get_owned_monitor_info); (void)outStream_writeBoolean(out, (jboolean)caps.can_get_current_contended_monitor); (void)outStream_writeBoolean(out, (jboolean)caps.can_get_monitor_info); return JNI_TRUE;}static jboolean capabilitiesNew(PacketInputStream *in, PacketOutputStream *out){ jvmtiCapabilities caps; jvmtiError error; if (gdata->vmDead) { outStream_setError(out, JDWP_ERROR(VM_DEAD)); return JNI_TRUE; } error = jvmtiGetCapabilities(&caps); if (error != JVMTI_ERROR_NONE) { outStream_setError(out, map2jdwpError(error)); return JNI_TRUE; } (void)outStream_writeBoolean(out, (jboolean)caps.can_generate_field_modification_events); (void)outStream_writeBoolean(out, (jboolean)caps.can_generate_field_access_events); (void)outStream_writeBoolean(out, (jboolean)caps.can_get_bytecodes); (void)outStream_writeBoolean(out, (jboolean)caps.can_get_synthetic_attribute); (void)outStream_writeBoolean(out, (jboolean)caps.can_get_owned_monitor_info); (void)outStream_writeBoolean(out, (jboolean)caps.can_get_current_contended_monitor); (void)outStream_writeBoolean(out, (jboolean)caps.can_get_monitor_info); /* new since JDWP version 1.4 */ (void)outStream_writeBoolean(out, (jboolean)caps.can_redefine_classes); (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE /* can_add_method */ ); (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE /* can_unrestrictedly_redefine_classes */ ); /* 11: canPopFrames */ (void)outStream_writeBoolean(out, (jboolean)caps.can_pop_frame); /* 12: canUseInstanceFilters */ (void)outStream_writeBoolean(out, (jboolean)JNI_TRUE); /* 13: canGetSourceDebugExtension */ (void)outStream_writeBoolean(out, (jboolean)caps.can_get_source_debug_extension); /* 14: canRequestVMDeathEvent */ (void)outStream_writeBoolean(out, (jboolean)JNI_TRUE); /* 15: canSetDefaultStratum */ (void)outStream_writeBoolean(out, (jboolean)JNI_TRUE); /* 16: canGetInstanceInfo */ (void)outStream_writeBoolean(out, (jboolean)caps.can_tag_objects); /* 17: canRequestMonitorEvents */ (void)outStream_writeBoolean(out, (jboolean)caps.can_generate_monitor_events); /* 18: canGetMonitorFrameInfo */ (void)outStream_writeBoolean(out, (jboolean)caps.can_get_owned_monitor_stack_depth_info); /* remaining reserved */ (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 19 */ /* 20 Can get constant pool information */ (void)outStream_writeBoolean(out, (jboolean)caps.can_get_constant_pool); /* 21 Can force early return */ (void)outStream_writeBoolean(out, (jboolean)caps.can_force_early_return); (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 22 */ (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 23 */ (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 24 */ (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 25 */ (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 26 */ (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 27 */ (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 28 */ (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 29 */ (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 30 */ (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 31 */ (void)outStream_writeBoolean(out, (jboolean)JNI_FALSE); /* 32 */ return JNI_TRUE;}static int countPaths(char *string) { int cnt = 1; /* always have one */ char *pos = string; char *ps; ps = gdata->property_path_separator; if ( ps == NULL ) { ps = ";"; } while ((pos = strchr(pos, ps[0])) != NULL) { ++cnt; ++pos; } return cnt;}static void writePaths(PacketOutputStream *out, char *string) { char *pos; char *ps; char *buf; int npaths; int i; buf = jvmtiAllocate((int)strlen(string)+1); npaths = countPaths(string); (void)outStream_writeInt(out, npaths); ps = gdata->property_path_separator; if ( ps == NULL ) { ps = ";"; } pos = string; for ( i = 0 ; i < npaths ; i++ ) { char *psPos; int plen; psPos = strchr(pos, ps[0]); if ( psPos == NULL ) { plen = (int)strlen(pos); } else { plen = (int)(psPos-pos); psPos++; } (void)memcpy(buf, pos, plen); buf[plen] = 0; (void)outStream_writeString(out, buf); pos = psPos; } jvmtiDeallocate(buf);}static jboolean classPaths(PacketInputStream *in, PacketOutputStream *out){ char *ud; char *bp; char *cp; ud = gdata->property_user_dir; if ( ud == NULL ) { ud = ""; } cp = gdata->property_java_class_path; if ( cp == NULL ) { cp = ""; } bp = gdata->property_sun_boot_class_path; if ( bp == NULL ) { bp = ""; } (void)outStream_writeString(out, ud); writePaths(out, cp); writePaths(out, bp); return JNI_TRUE;}static jboolean disposeObjects(PacketInputStream *in, PacketOutputStream *out){ int i; int refCount; jlong id; int requestCount; JNIEnv *env; if (gdata->vmDead) { /* quietly ignore */ return JNI_TRUE; } requestCount = inStream_readInt(in); if (inStream_error(in)) { return JNI_TRUE; } env = getEnv(); for (i = 0; i < requestCount; i++) { id = inStream_readObjectID(in); refCount = inStream_readInt(in); if (inStream_error(in)) { return JNI_TRUE; } commonRef_releaseMultiple(env, id, refCount); } return JNI_TRUE;}static jboolean holdEvents(PacketInputStream *in, PacketOutputStream *out){ eventHelper_holdEvents(); return JNI_TRUE;}static jboolean releaseEvents(PacketInputStream *in, PacketOutputStream *out){ eventHelper_releaseEvents(); return JNI_TRUE;}void *VirtualMachine_Cmds[] = { (void *)21 ,(void *)version ,(void *)classesForSignature ,(void *)allClasses ,(void *)getAllThreads ,(void *)topLevelThreadGroups ,(void *)dispose ,(void *)idSizes ,(void *)suspend ,(void *)resume ,(void *)doExit ,(void *)createString ,(void *)capabilities ,(void *)classPaths ,(void *)disposeObjects ,(void *)holdEvents ,(void *)releaseEvents ,(void *)capabilitiesNew ,(void *)redefineClasses ,(void *)setDefaultStratum ,(void *)allClassesWithGeneric ,(void *)instanceCounts};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?