Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4112658

STD: Misuse of jlong types in agent.c

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.2.0
    • core-svc
    • sparc
    • solaris_2.5.1



      Name: mf23781 Date: 02/17/98


      Agent.c
      -------
      src/share/native/sun/tools/debug/agent.c

      Jlong is not necessarily a scalar type, so the jlong conversion macros are
      needed.

      Problems with jlong conversions:

      #if defined IBM_ALL /*ibm*/
      #define TIMEOUT_INFINITY (jint_to_jlong(-1))
      #else /*ibm*/
      #define TIMEOUT_INFINITY -1L
      #endif /*ibm*/

      JNIEXPORT jlong JNICALL Java_sun_tools_agent_Agent_getStackLong
        (JNIEnv *env, jobject this, jobject thread, jint frame, jint slot)
      {
          jframeID frameID = getFrameID(env,thread,frame);
          jlong value;

          if((*env)->ExceptionOccurred(env))
      #if defined IBM_ALL /*ibm*/
              return jlong_zero;
      #else /*ibm*/
              return (jlong)0;
      #endif /*ibm*/

          checkForError(env, JVMDI_GetLocalLong(env, frameID, slot, &value) );
          return value;
      }

      JNIEXPORT jlong JNICALL Java_sun_tools_agent_CachedField_getFieldID
        (JNIEnv *env, jclass clazz, jclass targetClass, jstring name, jstring
      signature)
      {
          jfieldID id;
          char *n,*s;

          n = (char *)JNU_GetStringPlatformChars(env,name,NULL);
          if(n == NULL)
          {
              JNU_ThrowNoSuchFieldError(env,"name is null");
      #if defined IBM_ALL /*ibm*/
              return jlong_zero;
      #else /*ibm*/
              return 0;
      #endif /*ibm*/
          }

          s = (char *)JNU_GetStringPlatformChars(env,signature,NULL);
          if(s == NULL)
          {
              JNU_ReleaseStringPlatformChars(env, name, (const char *)n);
              JNU_ThrowNoSuchFieldError(env,"signature is null");
      #if defined IBM_ALL /*ibm*/
              return jlong_zero;
      #else /*ibm*/
              return 0;
      #endif /*ibm*/
          }

          id = (*env)->GetFieldID(env,targetClass,n,s);
          if (id == NULL) {
              (*env)->ExceptionClear(env);
              id = (*env)->GetStaticFieldID(env,targetClass,n,s);
          }

          JNU_ReleaseStringPlatformChars(env, name, (const char *)n);
          JNU_ReleaseStringPlatformChars(env, signature, (const char *)s);

          return ptr_to_jlong(id);
      }

      static jlong getMethodID(JNIEnv *env, jclass targetClass, jstring name,
                               jstring signature, jboolean isStatic)
      {
          jmethodID id;
          char *nam, *sig;

          nam = (char *)JNU_GetStringPlatformChars(env, name, NULL);
          if(nam == NULL){
              JNU_ThrowNoSuchFieldError(env, "name is null");
      #if defined IBM_ALL /*ibm*/
              return jlong_zero;
      #else /*ibm*/
              return 0;
      #endif /*ibm*/
          }

          sig = (char *)JNU_GetStringPlatformChars(env, signature, NULL);
          if(sig == NULL) {
              JNU_ReleaseStringPlatformChars(env, name, (const char *)nam);
              JNU_ThrowNoSuchFieldError(env, "signature is null");
      #if defined IBM_ALL /*ibm*/
              return jlong_zero;
      #else /*ibm*/
              return 0;
      #endif /*ibm*/
          }

          if (isStatic) {
              id = (*env)->GetStaticMethodID(env, targetClass, nam, sig);
          } else {
              id = (*env)->GetMethodID(env, targetClass, nam, sig);
          }

          JNU_ReleaseStringPlatformChars(env, name, (const char *)nam);
          JNU_ReleaseStringPlatformChars(env, signature, (const char *)sig);

          return ptr_to_jlong(id);
      }

      See also Javasoft bug 4110529

      ======================================================================

            ghirschsunw Gordon Hirsch (Inactive)
            miflemi Mick Fleming
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: