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

shared PropertyMaps should not be used without duplication

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 8
    • None
    • core-libs
    • None
    • b100
    • generic
    • generic

      Shared PropertyMaps are process wide singleton objects. These must be duplicated per-global instance. Also, shared maps should not be listeners to proto objects, should not have property history or proto history. Only per-global duplicated maps should be listeners and should be associated with proto objects, can contain property history etc. If this rule is not followed there will be correctness issues like the one seen in JDK-8019947 or even memory leaks - as shared maps may end up holding history or proto history that points to per-global objects.

      I added code to flag certain maps as shared and added assertions in PropertyMap that shared maps are not listeners, don't have proto history etc.

      Immediately I get the following assertion failure:

      shatest:
         [testng] org.testng.TestNGException:
         [testng] Cannot instantiate class jdk.nashorn.internal.parser.ParserTest
         [testng] at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:38)
         [testng] at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:387)
         [testng] at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:299)
         [testng] at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:110)
         [testng] at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:186)
         [testng] at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:120)
         [testng] at org.testng.TestRunner.initMethods(TestRunner.java:409)
         [testng] at org.testng.TestRunner.init(TestRunner.java:235)
         [testng] at org.testng.TestRunner.init(TestRunner.java:205)
         [testng] at org.testng.TestRunner.<init>(TestRunner.java:153)
         [testng] at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:522)
         [testng] at org.testng.SuiteRunner.init(SuiteRunner.java:157)
         [testng] at org.testng.SuiteRunner.<init>(SuiteRunner.java:111)
         [testng] at org.testng.TestNG.createSuiteRunner(TestNG.java:1273)
         [testng] at org.testng.TestNG.createSuiteRunners(TestNG.java:1260)
         [testng] at org.testng.TestNG.runSuitesLocally(TestNG.java:1114)
         [testng] at org.testng.TestNG.run(TestNG.java:1031)
         [testng] at org.testng.TestNG.privateMain(TestNG.java:1338)
         [testng] at org.testng.TestNG.main(TestNG.java:1307)
         [testng] Caused by: java.lang.reflect.InvocationTargetException
         [testng] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         [testng] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
         [testng] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
         [testng] at java.lang.reflect.Constructor.newInstance(Constructor.java:414)
         [testng] at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29)
         [testng] ... 18 more
         [testng] Caused by: java.lang.AssertionError: proto associated with a shared map
         [testng] at jdk.nashorn.internal.runtime.PropertyMap.changeProto(PropertyMap.java:774)
         [testng] at jdk.nashorn.internal.runtime.ScriptObject.setProto(ScriptObject.java:1084)
         [testng] at jdk.nashorn.internal.objects.ScriptFunctionImpl.init(ScriptFunctionImpl.java:296)
         [testng] at jdk.nashorn.internal.objects.ScriptFunctionImpl.<init>(ScriptFunctionImpl.java:112)
         [testng] at jdk.nashorn.internal.objects.ScriptFunctionImpl.<init>(ScriptFunctionImpl.java:127)
         [testng] at jdk.nashorn.internal.objects.ScriptFunctionImpl.makeFunction(ScriptFunctionImpl.java:232)
         [testng] at jdk.nashorn.internal.objects.ScriptFunctionImpl.makeFunction(ScriptFunctionImpl.java:248)
         [testng] at jdk.nashorn.internal.objects.NativeFunction$Prototype.<init>(Unknown Source)
         [testng] at jdk.nashorn.internal.objects.NativeFunction$Constructor.<init>(Unknown Source)
         [testng] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         [testng] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
         [testng] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
         [testng] at java.lang.reflect.Constructor.newInstance(Constructor.java:414)
         [testng] at java.lang.Class.newInstance(Class.java:444)
         [testng] at jdk.nashorn.internal.objects.Global.initConstructor(Global.java:1847)
         [testng] at jdk.nashorn.internal.objects.Global.initFunctionAndObject(Global.java:1915)
         [testng] at jdk.nashorn.internal.objects.Global.init(Global.java:1548)
         [testng] at jdk.nashorn.internal.objects.Global.initBuiltinObjects(Global.java:476)
         [testng] at jdk.nashorn.internal.runtime.Context.initGlobal(Context.java:656)
         [testng] at jdk.nashorn.internal.runtime.Context.createGlobal(Context.java:623)
         [testng] at jdk.nashorn.internal.parser.ParserTest.<init>(ParserTest.java:67)
         [testng] ... 23 more

      BUILD FAILED
      /home/sundar/src/nashorn-jdk8/nashorn/make/build.xml:310: The tests failed.

      Total time: 46 seconds


      - which showed that "duplicate" call was missing on a "shared" property map!

      So, we need following changes:

      * PropertyMap flag to say a map is "shared".
      * nasgen should generated PropertyMaps with "shared" flag set after filling maps
      * static map fields in objects.* class that are not nasgen instrumented or generated, should set "shared" flag for shared maps.
      * nasgen should avoid property-by-property filling of maps to avoid unnecessary property history -
      instead, it should fill Collection<Property> and use PropertyMap.newMap that accepts collection of properties.
      * PropertyMap should have debug assertions to check shared maps don't have proto associated, no property history and no proto history.

            sundar Sundararajan Athijegannathan
            sundar Sundararajan Athijegannathan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: