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

Interned strings in old classes are not stored in CDS archive

XMLWordPrintable

    • b27

      I both of the following classes are stored in a static CDS archive, the "xxxx123yyyy456" string is not stored in the interned string table. As a result, the test will fail with the RuntimeException

      public super class OldClassWithStaticString
          version 49:0
      {
          public static final Field s:"Ljava/lang/String;" = String "xxxx123yyyy456";
          public static final Field t:"Ljava/lang/String;" = String "OldClassWithStaticString";

          Method "<init>":"()V"
              stack 1 locals 1
          {
              aload_0;
              invokespecial Method java/lang/Object."<init>":"()V";
              return;
          }
      }

      class StaticStringInOldClassApp {
          static String a = "xxxx123";
          public static void main(String args[]) throws Exception {
              System.out.println("Hello");
              String x = (a + "yyyy456").intern();
              Class c = OldClassWithStaticString.class;
              Field f = c.getField("s");
              String y = (String)(f.get(null));
              if (x != y) {
                  throw new RuntimeException("Interned strings not equal: " +
                                             "\"" + x + "\" @ " + System.identityHashCode(x) + " vs " +
                                             "\"" + y + "\" @ " + System.identityHashCode(y));
              }
          }
      }

            iklam Ioi Lam
            iklam Ioi Lam
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: