📄 cvm.c
字号:
}CNIEXPORT CNIResultCodeCNIsun_misc_CVM_parseXoptOptions(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){ jobject opts = &arguments[0].j.r; char* kind = CVMconvertJavaStringToCString(ee, opts); CVMBool result; if (kind == NULL) { result = CVM_FALSE; } else { /* parse -Xopt options here */ result = CVMoptParseXoptOptions(kind); free(kind); } arguments[0].j.i = result; return CNI_SINGLE;}CNIEXPORT CNIResultCodeCNIsun_misc_CVM_parseXssOption(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){ jobject opts = &arguments[0].j.r; char* kind = CVMconvertJavaStringToCString(ee, opts); CVMBool result; if (kind == NULL) { result = CVM_FALSE; } else { /* parse -Xss options here */ result = CVMoptParseXssOption(kind); free(kind); } arguments[0].j.i = result; return CNI_SINGLE;}CNIEXPORT CNIResultCodeCNIsun_misc_CVM_parseXgcOptions(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){ jobject opts = &arguments[0].j.r; char* kind = CVMconvertJavaStringToCString(ee, opts); CVMBool result; if (kind == NULL) { result = CVM_FALSE; } else { /* parse -Xgc options here */#ifdef CVM_MTASK result = CVMgcParseXgcOptions(ee, kind);#else result = CVM_FALSE;#endif free(kind); } arguments[0].j.i = result; return CNI_SINGLE;}CNIEXPORT CNIResultCodeCNIsun_misc_CVM_parseAssertionOptions(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){ jobject opts = &arguments[0].j.r; char* str = CVMconvertJavaStringToCString(ee, opts); CVMBool result; if (str == NULL) { result = CVM_FALSE; } else { /* parse assertion related options here */#ifdef CDC_10 result = CVM_FALSE;#else /* java assertion handling */ if (!strncmp(str, "-ea:", 4)) { CVMBool success = CVMJavaAssertions_addOption( str + 4, CVM_TRUE, &CVMglobals.javaAssertionsClasses, &CVMglobals.javaAssertionsPackages); if (!success) goto addOption_failed; } else if (!strncmp(str, "-enableassertions:", 18)) { CVMBool success = CVMJavaAssertions_addOption( str + 18, CVM_TRUE, &CVMglobals.javaAssertionsClasses, &CVMglobals.javaAssertionsPackages); if (!success) goto addOption_failed; } else if (!strncmp(str, "-da:", 4)) { CVMBool success = CVMJavaAssertions_addOption( str + 4, CVM_FALSE, &CVMglobals.javaAssertionsClasses, &CVMglobals.javaAssertionsPackages); if (!success) goto addOption_failed; } else if (!strncmp(str, "-disableassertions:", 18)) { CVMBool success; success = CVMJavaAssertions_addOption( str + 19, CVM_FALSE, &CVMglobals.javaAssertionsClasses, &CVMglobals.javaAssertionsPackages); if (!success) { addOption_failed: CVMconsolePrintf("out of memory " "while parsing assertion option\n"); result = CVM_FALSE; goto done; } } else if (!strcmp(str, "-ea") | !strcmp(str, "-enableassertions")) { CVMglobals.javaAssertionsUserDefault = CVM_TRUE; } else if (!strcmp(str, "-da") | !strcmp(str, "-disableassertions")) { CVMglobals.javaAssertionsUserDefault = CVM_FALSE; } else if (!strcmp(str, "-esa") | !strcmp(str, "-enablesystemassertions")) { CVMglobals.javaAssertionsSysDefault = CVM_TRUE; } else if (!strcmp(str, "-dsa") | !strcmp(str, "-disablesystemassertions")) { CVMglobals.javaAssertionsSysDefault = CVM_FALSE; } result = CVM_TRUE;#endifdone: free(str); } arguments[0].j.i = result; return CNI_SINGLE;}CNIEXPORT CNIResultCodeCNIsun_misc_CVM_agentlibSupported(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){#ifdef CVM_AGENTLIB arguments[0].j.i = CVM_TRUE;#else arguments[0].j.i = CVM_FALSE;#endif return CNI_SINGLE;}CNIEXPORT CNIResultCodeCNIsun_misc_CVM_agentlibInitialize(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){#ifdef CVM_AGENTLIB CVMJavaInt numArgs = arguments[0].j.i; if (CVMAgentInitTable(&CVMglobals.agentTable, numArgs)) { arguments[0].j.i = CVM_TRUE; } else { arguments[0].j.i = CVM_FALSE; }#else arguments[0].j.i = CVM_FALSE;#endif return CNI_SINGLE;}CNIEXPORT CNIResultCodeCNIsun_misc_CVM_agentlibProcess(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){ jobject agentArgStr = &arguments[0].j.r; char* agentArg = CVMconvertJavaStringToCString(ee, agentArgStr); CVMBool result = CVM_FALSE; if (agentArg == NULL) { result = CVM_FALSE; } else {#ifdef CVM_AGENTLIB JNIEnv* env = CVMexecEnv2JniEnv(ee); CVMAgentlibArg_t agentlibArgument; agentlibArgument.is_absolute = CVM_FALSE; agentlibArgument.str = agentArg; if (!strncmp(agentArg, "-agentpath:", 11)) { agentlibArgument.is_absolute = CVM_TRUE; } CVMD_gcSafeExec(ee, { if ((*env)->PushLocalFrame(env, 16) == JNI_OK) { result = CVMAgentHandleArgument(&CVMglobals.agentTable, env, &agentlibArgument); (*env)->PopLocalFrame(env, NULL); } });#else result = CVM_FALSE;#endif free(agentArg); } arguments[0].j.i = result; return CNI_SINGLE;}CNIEXPORT CNIResultCodeCNIsun_misc_CVM_xrunSupported(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){#ifdef CVM_XRUN arguments[0].j.i = CVM_TRUE;#else arguments[0].j.i = CVM_FALSE;#endif return CNI_SINGLE;}CNIEXPORT CNIResultCodeCNIsun_misc_CVM_xrunInitialize(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){#ifdef CVM_XRUN CVMJavaInt numArgs = arguments[0].j.i; if (CVMXrunInitTable(&CVMglobals.onUnloadTable, numArgs)) { arguments[0].j.i = CVM_TRUE; } else { arguments[0].j.i = CVM_FALSE; }#else arguments[0].j.i = CVM_FALSE;#endif return CNI_SINGLE;}CNIEXPORT CNIResultCodeCNIsun_misc_CVM_xrunProcess(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){ jobject xrunArgStr = &arguments[0].j.r; char* xrunArg = CVMconvertJavaStringToCString(ee, xrunArgStr); CVMBool result = CVM_FALSE; if (xrunArg == NULL) { result = CVM_FALSE; } else {#ifdef CVM_XRUN JNIEnv* env = CVMexecEnv2JniEnv(ee); CVMD_gcSafeExec(ee, { if ((*env)->PushLocalFrame(env, 16) == JNI_OK) { result = CVMXrunHandleArgument(&CVMglobals.onUnloadTable, env, xrunArg); (*env)->PopLocalFrame(env, NULL); } });#else result = CVM_FALSE;#endif free(xrunArg); } arguments[0].j.i = result; return CNI_SINGLE;}CNIEXPORT CNIResultCodeCNIsun_misc_CVM_xdebugSet(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){ arguments[0].j.i = CVM_FALSE;#ifdef CVM_JVMTI /* * NOTE: JVMTI uses -Xdebug to signal that this is a debugging * session vs. profiling. This flag causes several jvmti * capabilities to be turned off. See jvmtiCapabilities.c */ CVMjvmtiSetDebugOption(CVM_TRUE); arguments[0].j.i = CVM_TRUE; #endif return CNI_SINGLE;}#include "javavm/include/localroots.h"#include "jni_util.h"CNIEXPORT CNIResultCodeCNIsun_misc_CVM_00024Preloader_getClassLoaderNames(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){ CNIResultCode result = CNI_SINGLE; CVMID_localrootBeginGcUnsafe(ee) { CVMID_localrootDeclareGcUnsafe(CVMObjectICell, namesICell); CVMD_gcSafeExec(ee, { JNIEnv* env = CVMexecEnv2JniEnv(ee); if ((*env)->PushLocalFrame(env, 16) == JNI_OK) { jstring names = JNU_NewStringPlatform(env, CVMpreloaderGetClassLoaderNames(ee)); if ((*env)->ExceptionOccurred(env)) { result = CNI_EXCEPTION; } else { CVMID_icellAssign(ee, namesICell, names); } (*env)->PopLocalFrame(env, NULL); } }); if (result != CNI_EXCEPTION) { CVMID_icellAssignDirect(ee, &arguments[0].j.r, namesICell); } } CVMID_localrootEndGcUnsafe(); return result;}CNIEXPORT CNIResultCodeCNIsun_misc_CVM_00024Preloader_registerClassLoader0(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){ CVMpreloaderRegisterClassLoaderUnsafe(ee, arguments[0].j.i, /* index */ &arguments[1].j.r /* cl */ ); return CNI_VOID;}CNIEXPORT CNIResultCodeCNIsun_misc_CVM_nanoTime(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){ jlong time;#ifdef CVM_JVMTI time = CVMtimeNanosecs();#else time = (jlong)(((CVMInt64)CVMtimeMillis()) * 1000000);#endif CVMlong2Jvm((CVMAddr*)&arguments[0].j, time); return CNI_DOUBLE;}#if 1/* * The following should never be called. These APIs are only called * in JIT'd code that support CVMJIT_SIMPLE_SYNC_METHODS, and in this * case they are implemented as intrinsics emitters. */CNIEXPORT CNIResultCodeCNIsun_misc_CVM_simpleLockGrab(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb) { CVMassert(CVM_FALSE); arguments[0].j.i = CVM_FALSE; return CNI_SINGLE;}CNIEXPORT CNIResultCodeCNIsun_misc_CVM_simpleLockRelease(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){ CVMassert(CVM_FALSE); return CNI_SINGLE;}#else/* * CNI versions of CVM.simpleLockGrab and CVM.simpleLockRelease. * These are disabled by default and are only used to gather stats * about how often the simple sync methods are called. In order * to use them you must also declare these methods native in CVM.java * and disabled the intrinsics in ccmintrinsics_risc.c. */#define CVM_MAX_SYNC_PROF_MBS 50static CVMMethodBlock* mbs[CVM_MAX_SYNC_PROF_MBS];static int slow[CVM_MAX_SYNC_PROF_MBS];static int fast[CVM_MAX_SYNC_PROF_MBS];static int findMB(CVMMethodBlock* mb) { int i = 0; while (i < CVM_MAX_SYNC_PROF_MBS) { if (mbs[i] == mb) { return i; } if (mbs[i] == NULL) { mbs[i] = mb; return i; } i++; } CVMassert(CVM_FALSE); return 0;}extern void dumpMBs() { int i = 0; CVMconsolePrintf(" fast slow\n"); while (mbs[i] != NULL) { CVMconsolePrintf("%10d %10d %C.%M\n", fast[i], slow[i], CVMmbClassBlock(mbs[i]), mbs[i]); i++; }}/* NOTE: this code is disabled. See comment above */CNIEXPORT CNIResultCodeCNIsun_misc_CVM_simpleLockGrab(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){ jobject obj = &arguments[0].j.r; CVMObject* directObj = CVMID_icellDirect(ee, obj); CVMMethodBlock* mb = ee->interpreterStack.currentFrame->mb; int mbslot = findMB(mb); if (CVMglobals.objGlobalMicroLock.lockWord == CVM_MICROLOCK_UNLOCKED && CVMobjMonitorState(directObj) == CVM_LOCKSTATE_UNLOCKED) { fast[mbslot]++; } else { slow[mbslot]++; //CVMdumpStack(&ee->interpreterStack,0,0,10); //CVMconsolePrintf("\n"); } arguments[0].j.i = CVM_FALSE; return CNI_SINGLE;}/* NOTE: this code is disabled. See comment above */CNIEXPORT CNIResultCodeCNIsun_misc_CVM_simpleLockRelease(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){ return CNI_VOID;}#endif/* Gets the VM build options as a Java string. */CNIEXPORT CNIResultCodeCNIsun_misc_CVM_getBuildOptionString(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){ jobject result = NULL; CVMD_gcSafeExec(ee, { JNIEnv *env = CVMexecEnv2JniEnv(ee); if ((*env)->PushLocalFrame(env, 4) == 0) { result = (*env)->NewStringUTF(env, CVM_BUILD_OPTIONS); if (result != NULL) { CVMID_icellAssign(ee, &arguments[0].j.r, result); } (*env)->PopLocalFrame(env, NULL); } }); if (CVMexceptionOccurred(ee)) { return CNI_EXCEPTION; } return CNI_SINGLE;}/* * Sets java.net.URLConnection.defaultUseCaches to the boolean * argument passed in. */CNIEXPORT CNIResultCodeCNIsun_misc_CVM_setURLConnectionDefaultUseCaches(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){ CVMClassBlock* cb = CVMsystemClass(java_net_URLConnection); CVMFieldTypeID fieldTypeID = CVMtypeidLookupFieldIDFromNameAndSig( ee, "defaultUseCaches", "Z"); CVMFieldBlock* fb = CVMclassGetStaticFieldBlock(cb, fieldTypeID); CVMassert(fb != NULL); CVMfbStaticField(ee, fb).i = arguments[0].j.i; return CNI_VOID;}/* * Clears the ucp field of the URLClassLoader passed in, which allows * the JarFiles opened by the URLClassLoader to be gc'd and closed, * even if the URLClassLoader is kept live. */#include "generated/offsets/java_net_URLClassLoader.h"extern const CVMClassBlock java_net_URLConnection_Classblock;CNIEXPORT CNIResultCodeCNIsun_misc_CVM_clearURLClassLoaderUcpField(CVMExecEnv* ee, CVMStackVal32 *arguments, CVMMethodBlock **p_mb){ CVMObjectICell* classLoaderICell = &arguments[0].j.r; CVMD_fieldWriteRef(CVMID_icellDirect(ee, classLoaderICell), CVMoffsetOfjava_net_URLClassLoader_ucp, NULL); return CNI_VOID;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -