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

(1.1) Performance problem due to GC heap compaction fix (4065018)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P1 P1
    • 1.1.8
    • 1.1.8
    • hotspot
    • 1.1.8
    • generic
    • generic
    • Verified

      When allocating a large Java object using the Invocation API, gc kicks in a lot more frequently than before the fix for 4065018 was integrated in 1.1.8 (build F). This can have a severe impact on performance. For example, tests so far have revealed that instantiating a number of large Java objects can take over 200 times as long as with using build E. This performance degradation has only been observed when using the Invocation API (i.e. not when using the java command).

      Here's a test case:

      public class BigObject {

          public BigObject() {
              System.out.println("Hello from BigObject.<init>");
              StringBuffer[] s = new StringBuffer[1000];
              for (int i = 0; i < s.length; i++)
                  s[i] = new StringBuffer(1024);
              Runtime rt = Runtime.getRuntime();
              System.out.println("Free mem = " + rt.freeMemory());
              System.out.println("Tot mem = " + rt.totalMemory());
          }

          public static void main(String args[]) {
              new BigObject();
          }

      }

      /* CreateBigObject.c Stuart Lawrence
         Creates JVM and instantiates a large Java object.
       */

      #include <jni.h>

      int main() {
          JNIEnv *env;
          JavaVM *jvm;
          JDK1_1InitArgs vm_args;
          jint res;
          jclass cls;
          jmethodID cid;
          char classpath[1024];
          jobject ajobj;

          vm_args.version = 0x00010001;
          JNI_GetDefaultJavaVMInitArgs(&vm_args);

          /* Assume BigObject.class is located in . */
          sprintf(classpath, "%s%s", vm_args.classpath, ":.");
          vm_args.classpath = classpath;

          /* Enable GC messages */
          vm_args.enableVerboseGC = 1;

          /* Create the Java VM */
          res = JNI_CreateJavaVM(&jvm,&env,&vm_args);
          if (res < 0) {
              fprintf(stderr, "Can't create Java VM\n");
              return 1;
          }
          cls = (*env)->FindClass(env, "BigObject");
          if (cls == 0) {
              fprintf(stderr, "Can't find BigObject class\n");
              return 1;
          }
          cid = (*env)->GetMethodID(env, cls, "<init>", "()V");
          if (cid == 0) {
              fprintf(stderr, "Can't find BigObject.<init>\n");
              return 1;
          }

          ajobj = (*env)->NewObject(env, cls, cid);
          if (NULL == ajobj)
          {
              fprintf(stdout, "Failed to create object.");
          }

          /* release the object */
          (*env)->DeleteLocalRef(env, ajobj);

          fprintf(stdout, "Finished\n");

          (*jvm)->DestroyJavaVM(jvm);
          return 0;

      }

      and here's the script I used to run the test:

      echo Start `date`
      export LD_LIBRARY_PATH=/export/ws/118F/build/lib/sparc/green_threads
      cc -I/export/ws/118F/build/include -I/export/ws/118F/src/solaris/java/include -L/export/ws/118F/build/lib/sparc/green_threads -ljava CreateBigObject.c
      a.out
      echo End `date`

      Compare the number of gc messages with 118E.

      stuart.lawrence@eng 1999-01-22

            duke J. Duke
            slawson Stuart Lawson
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: