Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4152

Groovy code using constants seems unsuitable for hotswap

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.0
    • 1.7.7, 1.8-beta-4
    • Compiler
    • None

    Description

      When a JVM hotswaps code, it does not re-run static initializers. For some reason (I'm sure it is a good reason, I just don't know what it is), the groovy compiler moves constants referenced in methods into fields initialized from the static initializer. This code:

      class A {
        def foo() {
          def x = 5555
        }
      }
      

      produces bytecode where the 5555 is put into a field called '$const$0' in the static initializer. This means if I change it from 5555 to 6666 and recompile, the change will not be picked up by hotswap because the static initializer will not be rerun.

      This is vaguely similar to the problem of call site caching but that could be addressed by calling the call site array to reinitialize on hotswap. A similar solution would work here (call a reinitialize method for constants on hotswap) if the code to initialize the constants were pulled out into a static method that was invoked from the static initializer instead of being inlined in the initializer. However, the field $const$0 is also currently marked 'final' which complicates things.

      Without a change here, it doesn't appear to be possible to hotswap constant values.

      Attachments

        1. 4152_v18x_Patch.txt
          6 kB
          Roshan Dawrani

        Issue Links

          Activity

            People

              blackdrag Jochen Theodorou
              aclement Andy Clement
              Votes:
              2 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: