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

JSR 292: constant pool reconstitution must support pseudo strings

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8u40, 9
    • Fix Version/s: 9
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b50
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        The pseudo-strings are currently not supported in reconstitution of constant pool.

        It does not make sense to copy the whole email exchange here.
        So, just some explanation from John Rose about what the pseudo-strings are:

        "We still need "live" oop constants pre-linked into the constant pool of bytecodes which implement some method handles. We use the anonymous class pseudo-string feature for that. The relevant code is here:
          http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/src/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
        These oops are what "pseudo-strings" are. The odd name refers to the fact that, even though they are random oops, they appear in the constant pool where one would expect (because of class file syntax) to find a string."
                    and ...
        "If you really wanted to reconstitute a class file for an anonymous class, and if that class has oop patching (pseudo-strings), you would need either to (a) reconstitute the patches array handed to Unsafe.defineAnonymousClass, or (b) accept whatever odd strings were there first, as an approximation. The "odd strings" are totally insignificant, and are typically something like "CONSTANT_PLACEHOLDER_42" (see InvokerBytecodeGenerator::constantPlaceholder)."


        Reconstitution of the ConstantPool is needed for both the JVMTI GetConstantPool() and RetransformClasses().
        Finally, it goes to the ConstantPool::copy_cpool_bytes().

        The problem is that a pseudo-string is a patched string that does not have
        a reference to the string symbol anymore:
          unresolved_string_at(idx) == NULL

        This is the place that has to be fixed:

        ConstantPool.cpp:
        int ConstantPool::copy_cpool_bytes(int cpool_size,
              . . .
              case JVM_CONSTANT_String: {
                *bytes = JVM_CONSTANT_String;
                Symbol* sym = unresolved_string_at(idx);
                idx1 = tbl->symbol_to_value(sym);
                assert(idx1 != 0, "Have not found a hashtable entry");
                Bytes::put_Java_u2((address) (bytes+1), idx1);
                DBG(char *str = sym->as_utf8());
                DBG(printf("JVM_CONSTANT_String: idx=#%03hd, %s", idx1, str));
                break;
              }

        The John's suggestion for odd strings is to use either the empty string,
        or something slightly informative such as "patch#42", where 42 is the CP index.
        Something like:
          if (sym == NULL) {
            str = "patch#42";
          }

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  sspitsyn Serguei Spitsyn
                  Reporter:
                  sspitsyn Serguei Spitsyn
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  4 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: