8058179: Global constants get in the way of self-modifying properties

Thu, 11 Sep 2014 18:06:40 +0200

author
hannesw
date
Thu, 11 Sep 2014 18:06:40 +0200
changeset 1007
39ba6d257e4c
parent 1006
e94bfa3c6c6c
child 1008
1196f17cf7bc
child 1011
3d30873e13d7

8058179: Global constants get in the way of self-modifying properties
Reviewed-by: attila, jlaskey, sundar, lagergren

src/jdk/nashorn/internal/runtime/GlobalConstants.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptObject.java file | annotate | diff | comparison | revisions
test/script/basic/JDK-8058179.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8058179.js.EXPECTED file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/runtime/GlobalConstants.java	Thu Sep 11 18:04:54 2014 +0200
     1.2 +++ b/src/jdk/nashorn/internal/runtime/GlobalConstants.java	Thu Sep 11 18:06:40 2014 +0200
     1.3 @@ -28,6 +28,8 @@
     1.4  import static jdk.nashorn.internal.codegen.CompilerConstants.staticCall;
     1.5  import static jdk.nashorn.internal.codegen.CompilerConstants.virtualCall;
     1.6  import static jdk.nashorn.internal.lookup.Lookup.MH;
     1.7 +import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.INVALID_PROGRAM_POINT;
     1.8 +import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.getProgramPoint;
     1.9  import static jdk.nashorn.internal.runtime.logging.DebugLogger.quote;
    1.10  
    1.11  import java.lang.invoke.MethodHandle;
    1.12 @@ -370,22 +372,19 @@
    1.13       * @param find      property lookup
    1.14       * @param receiver  receiver
    1.15       * @param desc      callsite descriptor
    1.16 -     * @param request   link request
    1.17 -     * @param operator  operator
    1.18       *
    1.19       * @return resulting getter, or null if failed to create constant
    1.20       */
    1.21 -    synchronized GuardedInvocation findGetMethod(final FindProperty find, final ScriptObject receiver, final CallSiteDescriptor desc, final LinkRequest request, final String operator) {
    1.22 -        if (GLOBAL_ONLY && !find.getOwner().isGlobal()) {
    1.23 +    synchronized GuardedInvocation findGetMethod(final FindProperty find, final ScriptObject receiver, final CallSiteDescriptor desc) {
    1.24 +        // Also return null if property may have side effects
    1.25 +        if ((GLOBAL_ONLY && !find.getOwner().isGlobal()) || find.getProperty() instanceof UserAccessorProperty) {
    1.26              return null;
    1.27          }
    1.28  
    1.29 -        final int programPoint         = NashornCallSiteDescriptor.isOptimistic(desc) ?
    1.30 -            NashornCallSiteDescriptor.getProgramPoint(desc) :
    1.31 -            UnwarrantedOptimismException.INVALID_PROGRAM_POINT;
    1.32 -        final boolean     isOptimistic = programPoint != UnwarrantedOptimismException.INVALID_PROGRAM_POINT;
    1.33 -        final Class<?>    retType      = desc.getMethodType().returnType();
    1.34 -        final String      name         = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
    1.35 +        final boolean  isOptimistic = NashornCallSiteDescriptor.isOptimistic(desc);
    1.36 +        final int      programPoint = isOptimistic ? getProgramPoint(desc) : INVALID_PROGRAM_POINT;
    1.37 +        final Class<?> retType      = desc.getMethodType().returnType();
    1.38 +        final String   name         = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
    1.39  
    1.40          final Access acc = getOrCreateSwitchPoint(name);
    1.41  
     2.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java	Thu Sep 11 18:04:54 2014 +0200
     2.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java	Thu Sep 11 18:06:40 2014 +0200
     2.3 @@ -1971,7 +1971,7 @@
     2.4              }
     2.5          }
     2.6  
     2.7 -        final GuardedInvocation cinv = Global.getConstants().findGetMethod(find, this, desc, request, operator);
     2.8 +        final GuardedInvocation cinv = Global.getConstants().findGetMethod(find, this, desc);
     2.9          if (cinv != null) {
    2.10              return cinv;
    2.11          }
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/script/basic/JDK-8058179.js	Thu Sep 11 18:06:40 2014 +0200
     3.3 @@ -0,0 +1,48 @@
     3.4 +/*
     3.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + * 
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + * 
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + * 
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + * 
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + */
    3.26 +
    3.27 +/**
    3.28 + * JDK-8058179: Global constants get in the way of self-modifying properties
    3.29 + *
    3.30 + * @test
    3.31 + * @run
    3.32 + */
    3.33 +
    3.34 +var global = this;
    3.35 +
    3.36 +Object.defineProperty(global, "value", {
    3.37 +    get: function() {
    3.38 +        print("getting value");
    3.39 +        global["value"] = "value 2";
    3.40 +        return "value 1";
    3.41 +    },
    3.42 +    set: function(value) {
    3.43 +        print("setting value: " + value);
    3.44 +        delete global["value"];
    3.45 +        global["value"] = value;
    3.46 +    },
    3.47 +    configurable: true
    3.48 +});
    3.49 +
    3.50 +print(value);
    3.51 +print(value);
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/script/basic/JDK-8058179.js.EXPECTED	Thu Sep 11 18:06:40 2014 +0200
     4.3 @@ -0,0 +1,4 @@
     4.4 +getting value
     4.5 +setting value: value 2
     4.6 +value 1
     4.7 +value 2

mercurial