src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/AccessorProperty.java
author hannesw
Wed, 21 Mar 2018 16:55:34 +0100
changeset 49275 c639a6b33c5c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8199869: Missing copyright headers in nashorn source code Reviewed-by: sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     1
/*
16151
97c1e756ae1e 8005663: Update copyright year to 2013
jlaskey
parents: 16147
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     4
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    10
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    15
 * accompanied this code).
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    16
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    20
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    23
 * questions.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    24
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    25
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    26
package jdk.nashorn.internal.runtime;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    27
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    28
import static jdk.nashorn.internal.codegen.ObjectClassGenerator.PRIMITIVE_FIELD_TYPE;
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16224
diff changeset
    29
import static jdk.nashorn.internal.codegen.ObjectClassGenerator.createGetter;
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16224
diff changeset
    30
import static jdk.nashorn.internal.codegen.ObjectClassGenerator.createSetter;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    31
import static jdk.nashorn.internal.codegen.ObjectClassGenerator.getFieldCount;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    32
import static jdk.nashorn.internal.codegen.ObjectClassGenerator.getFieldName;
16277
fd698c5ee684 8009559: clean up method handle lookup code.
sundar
parents: 16275
diff changeset
    33
import static jdk.nashorn.internal.lookup.Lookup.MH;
fd698c5ee684 8009559: clean up method handle lookup code.
sundar
parents: 16275
diff changeset
    34
import static jdk.nashorn.internal.lookup.MethodHandleFactory.stripName;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    35
import static jdk.nashorn.internal.runtime.JSType.getAccessorTypeIndex;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    36
import static jdk.nashorn.internal.runtime.JSType.getNumberOfAccessorTypes;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    37
import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.INVALID_PROGRAM_POINT;
23767
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
    38
import java.io.IOException;
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
    39
import java.io.ObjectInputStream;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    40
import java.lang.invoke.MethodHandle;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    41
import java.lang.invoke.MethodHandles;
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24734
diff changeset
    42
import java.lang.invoke.SwitchPoint;
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
    43
import java.util.function.Supplier;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    44
import java.util.logging.Level;
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16224
diff changeset
    45
import jdk.nashorn.internal.codegen.ObjectClassGenerator;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    46
import jdk.nashorn.internal.codegen.types.Type;
16277
fd698c5ee684 8009559: clean up method handle lookup code.
sundar
parents: 16275
diff changeset
    47
import jdk.nashorn.internal.lookup.Lookup;
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24734
diff changeset
    48
import jdk.nashorn.internal.objects.Global;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    49
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    50
/**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    51
 * An AccessorProperty is the most generic property type. An AccessorProperty is
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    52
 * represented as fields in a ScriptObject class.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    53
 */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    54
public class AccessorProperty extends Property {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    55
    private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
    56
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
    57
    private static final MethodHandle REPLACE_MAP   = findOwnMH_S("replaceMap", Object.class, Object.class, PropertyMap.class);
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26646
diff changeset
    58
    private static final MethodHandle INVALIDATE_SP = findOwnMH_S("invalidateSwitchPoint", Object.class, AccessorProperty.class, Object.class);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    59
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    60
    private static final int NOOF_TYPES = getNumberOfAccessorTypes();
23767
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
    61
    private static final long serialVersionUID = 3371720170182154920L;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    62
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 16523
diff changeset
    63
    /**
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 16523
diff changeset
    64
     * Properties in different maps for the same structure class will share their field getters and setters. This could
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 16523
diff changeset
    65
     * be further extended to other method handles that are looked up in the AccessorProperty constructor, but right now
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 16523
diff changeset
    66
     * these are the most frequently retrieved ones, and lookup of method handle natives only registers in the profiler
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 16523
diff changeset
    67
     * for them.
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 16523
diff changeset
    68
     */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    69
    private static ClassValue<Accessors> GETTERS_SETTERS = new ClassValue<Accessors>() {
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 16523
diff changeset
    70
        @Override
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    71
        protected Accessors computeValue(final Class<?> structure) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    72
            return new Accessors(structure);
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 16523
diff changeset
    73
        }
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 16523
diff changeset
    74
    };
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 16523
diff changeset
    75
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    76
    private static class Accessors {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    77
        final MethodHandle[] objectGetters;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    78
        final MethodHandle[] objectSetters;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    79
        final MethodHandle[] primitiveGetters;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    80
        final MethodHandle[] primitiveSetters;
17770
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
    81
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    82
        /**
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    83
         * Normal
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    84
         * @param structure
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    85
         */
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    86
        Accessors(final Class<?> structure) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    87
            final int fieldCount = getFieldCount(structure);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    88
            objectGetters    = new MethodHandle[fieldCount];
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    89
            objectSetters    = new MethodHandle[fieldCount];
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    90
            primitiveGetters = new MethodHandle[fieldCount];
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    91
            primitiveSetters = new MethodHandle[fieldCount];
18847
31ca64473a86 8011629: Object.defineProperty performance issue
jlaskey
parents: 18615
diff changeset
    92
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    93
            for (int i = 0; i < fieldCount; i++) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    94
                final String fieldName = getFieldName(i, Type.OBJECT);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    95
                final Class<?> typeClass = Type.OBJECT.getTypeClass();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    96
                objectGetters[i] = MH.asType(MH.getter(LOOKUP, structure, fieldName, typeClass), Lookup.GET_OBJECT_TYPE);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    97
                objectSetters[i] = MH.asType(MH.setter(LOOKUP, structure, fieldName, typeClass), Lookup.SET_OBJECT_TYPE);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
    98
            }
18847
31ca64473a86 8011629: Object.defineProperty performance issue
jlaskey
parents: 18615
diff changeset
    99
29834
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents: 27307
diff changeset
   100
            if (!StructureLoader.isSingleFieldStructure(structure.getName())) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   101
                for (int i = 0; i < fieldCount; i++) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   102
                    final String fieldNamePrimitive = getFieldName(i, PRIMITIVE_FIELD_TYPE);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   103
                    final Class<?> typeClass = PRIMITIVE_FIELD_TYPE.getTypeClass();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   104
                    primitiveGetters[i] = MH.asType(MH.getter(LOOKUP, structure, fieldNamePrimitive, typeClass), Lookup.GET_PRIMITIVE_TYPE);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   105
                    primitiveSetters[i] = MH.asType(MH.setter(LOOKUP, structure, fieldNamePrimitive, typeClass), Lookup.SET_PRIMITIVE_TYPE);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   106
                }
18847
31ca64473a86 8011629: Object.defineProperty performance issue
jlaskey
parents: 18615
diff changeset
   107
            }
17770
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
   108
        }
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   109
    }
18847
31ca64473a86 8011629: Object.defineProperty performance issue
jlaskey
parents: 18615
diff changeset
   110
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   111
    /**
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   112
     * Property getter cache
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   113
     *   Note that we can't do the same simple caching for optimistic getters,
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   114
     *   due to the fact that they are bound to a program point, which will
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   115
     *   produce different boun method handles wrapping the same access mechanism
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   116
     *   depending on callsite
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   117
     */
26646
332e9901f0ed 8058304: Non-serializable fields in serializable classes
hannesw
parents: 26377
diff changeset
   118
    private transient MethodHandle[] GETTER_CACHE = new MethodHandle[NOOF_TYPES];
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   119
18855
408663ef8f66 8020015: shared PropertyMaps should not be used without duplication
sundar
parents: 18852
diff changeset
   120
    /**
408663ef8f66 8020015: shared PropertyMaps should not be used without duplication
sundar
parents: 18852
diff changeset
   121
     * Create a new accessor property. Factory method used by nasgen generated code.
408663ef8f66 8020015: shared PropertyMaps should not be used without duplication
sundar
parents: 18852
diff changeset
   122
     *
408663ef8f66 8020015: shared PropertyMaps should not be used without duplication
sundar
parents: 18852
diff changeset
   123
     * @param key           {@link Property} key.
408663ef8f66 8020015: shared PropertyMaps should not be used without duplication
sundar
parents: 18852
diff changeset
   124
     * @param propertyFlags {@link Property} flags.
408663ef8f66 8020015: shared PropertyMaps should not be used without duplication
sundar
parents: 18852
diff changeset
   125
     * @param getter        {@link Property} get accessor method.
408663ef8f66 8020015: shared PropertyMaps should not be used without duplication
sundar
parents: 18852
diff changeset
   126
     * @param setter        {@link Property} set accessor method.
408663ef8f66 8020015: shared PropertyMaps should not be used without duplication
sundar
parents: 18852
diff changeset
   127
     *
408663ef8f66 8020015: shared PropertyMaps should not be used without duplication
sundar
parents: 18852
diff changeset
   128
     * @return  New {@link AccessorProperty} created.
408663ef8f66 8020015: shared PropertyMaps should not be used without duplication
sundar
parents: 18852
diff changeset
   129
     */
36023
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 34732
diff changeset
   130
    public static AccessorProperty create(final Object key, final int propertyFlags, final MethodHandle getter, final MethodHandle setter) {
18855
408663ef8f66 8020015: shared PropertyMaps should not be used without duplication
sundar
parents: 18852
diff changeset
   131
        return new AccessorProperty(key, propertyFlags, -1, getter, setter);
408663ef8f66 8020015: shared PropertyMaps should not be used without duplication
sundar
parents: 18852
diff changeset
   132
    }
408663ef8f66 8020015: shared PropertyMaps should not be used without duplication
sundar
parents: 18852
diff changeset
   133
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   134
    /** Seed getter for the primitive version of this field (in -Dnashorn.fields.dual=true mode) */
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 24880
diff changeset
   135
    transient MethodHandle primitiveGetter;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   136
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   137
    /** Seed setter for the primitive version of this field (in -Dnashorn.fields.dual=true mode) */
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 24880
diff changeset
   138
    transient MethodHandle primitiveSetter;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   139
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   140
    /** Seed getter for the Object version of this field */
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 24880
diff changeset
   141
    transient MethodHandle objectGetter;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   142
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   143
    /** Seed setter for the Object version of this field */
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 24880
diff changeset
   144
    transient MethodHandle objectSetter;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   145
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   146
    /**
23372
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 19105
diff changeset
   147
     * Delegate constructor for bound properties. This is used for properties created by
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 19105
diff changeset
   148
     * {@link ScriptRuntime#mergeScope} and the Nashorn {@code Object.bindProperties} method.
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 19105
diff changeset
   149
     * The former is used to add a script's defined globals to the current global scope while
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 19105
diff changeset
   150
     * still storing them in a JO-prefixed ScriptObject class.
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 19105
diff changeset
   151
     *
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 19105
diff changeset
   152
     * <p>All properties created by this constructor have the {@link #IS_BOUND} flag set.</p>
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   153
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   154
     * @param property  accessor property to rebind
18860
e387fde9322a 8014785: Ability to extend global instance by binding properties of another object
sundar
parents: 18859
diff changeset
   155
     * @param delegate  delegate object to rebind receiver to
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   156
     */
19105
a01ba9d17eab 8021571: @fork tests should use VM options passed from project.properties
sundar
parents: 18860
diff changeset
   157
    AccessorProperty(final AccessorProperty property, final Object delegate) {
24727
attila
parents: 24721 23372
diff changeset
   158
        super(property, property.getFlags() | IS_BOUND);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   159
17770
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
   160
        this.primitiveGetter = bindTo(property.primitiveGetter, delegate);
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
   161
        this.primitiveSetter = bindTo(property.primitiveSetter, delegate);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   162
        this.objectGetter    = bindTo(property.objectGetter, delegate);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   163
        this.objectSetter    = bindTo(property.objectSetter, delegate);
24734
da070553a8e1 8038799: Guard and unbox boxed primitives types on setting them in Properties to avoid megamorphisism
lagergren
parents: 24733
diff changeset
   164
        property.GETTER_CACHE = new MethodHandle[NOOF_TYPES];
23372
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 19105
diff changeset
   165
        // Properties created this way are bound to a delegate
27307
62ed492cbe63 8062401: User accessors require boxing and do not support optimistic types
hannesw
parents: 26768
diff changeset
   166
        setType(property.getType());
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   167
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   168
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   169
    /**
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   170
     * SPILL PROPERTY or USER ACCESSOR PROPERTY abstract constructor
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   171
     *
17770
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
   172
     * Constructor for spill properties. Array getters and setters will be created on demand.
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
   173
     *
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
   174
     * @param key    the property key
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
   175
     * @param flags  the property flags
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
   176
     * @param slot   spill slot
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 24880
diff changeset
   177
     * @param primitiveGetter primitive getter
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 24880
diff changeset
   178
     * @param primitiveSetter primitive setter
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 24880
diff changeset
   179
     * @param objectGetter    object getter
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 24880
diff changeset
   180
     * @param objectSetter    object setter
17770
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
   181
     */
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   182
    protected AccessorProperty(
33690
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents: 29834
diff changeset
   183
            final Object key,
24720
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   184
            final int flags,
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   185
            final int slot,
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   186
            final MethodHandle primitiveGetter,
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   187
            final MethodHandle primitiveSetter,
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   188
            final MethodHandle objectGetter,
75f8388b79df 8035836: Array performance improvements
lagergren
parents: 24719
diff changeset
   189
            final MethodHandle objectSetter) {
17770
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
   190
        super(key, flags, slot);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   191
        assert getClass() != AccessorProperty.class;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   192
        this.primitiveGetter = primitiveGetter;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   193
        this.primitiveSetter = primitiveSetter;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   194
        this.objectGetter    = objectGetter;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   195
        this.objectSetter    = objectSetter;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   196
        initializeType();
17770
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
   197
    }
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
   198
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
   199
    /**
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   200
     * NASGEN constructor
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   201
     *
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   202
     * Constructor. Similar to the constructor with both primitive getters and setters, the difference
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   203
     * here being that only one getter and setter (setter is optional for non writable fields) is given
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   204
     * to the constructor, and the rest are created from those. Used e.g. by Nasgen classes
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   205
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   206
     * @param key    the property key
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   207
     * @param flags  the property flags
16224
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   208
     * @param slot   the property field number or spill slot
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   209
     * @param getter the property getter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   210
     * @param setter the property setter or null if non writable, non configurable
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   211
     */
33690
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents: 29834
diff changeset
   212
    private AccessorProperty(final Object key, final int flags, final int slot, final MethodHandle getter, final MethodHandle setter) {
29834
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents: 27307
diff changeset
   213
        super(key, flags | IS_BUILTIN | DUAL_FIELDS | (getter.type().returnType().isPrimitive() ? IS_NASGEN_PRIMITIVE : 0), slot);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   214
        assert !isSpill();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   215
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   216
        // we don't need to prep the setters these will never be invalidated as this is a nasgen
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   217
        // or known type getter/setter. No invalidations will take place
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   218
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   219
        final Class<?> getterType = getter.type().returnType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   220
        final Class<?> setterType = setter == null ? null : setter.type().parameterType(1);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   221
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   222
        assert setterType == null || setterType == getterType;
29834
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents: 27307
diff changeset
   223
34732
6605efbe8447 8144020: Remove long as an internal numeric type
hannesw
parents: 33690
diff changeset
   224
        if (getterType == int.class) {
29834
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents: 27307
diff changeset
   225
            primitiveGetter = MH.asType(getter, Lookup.GET_PRIMITIVE_TYPE);
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents: 27307
diff changeset
   226
            primitiveSetter = setter == null ? null : MH.asType(setter, Lookup.SET_PRIMITIVE_TYPE);
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents: 27307
diff changeset
   227
        } else if (getterType == double.class) {
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents: 27307
diff changeset
   228
            primitiveGetter = MH.asType(MH.filterReturnValue(getter, ObjectClassGenerator.PACK_DOUBLE), Lookup.GET_PRIMITIVE_TYPE);
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents: 27307
diff changeset
   229
            primitiveSetter = setter == null ? null : MH.asType(MH.filterArguments(setter, 1, ObjectClassGenerator.UNPACK_DOUBLE), Lookup.SET_PRIMITIVE_TYPE);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   230
        } else {
29834
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents: 27307
diff changeset
   231
            primitiveGetter = primitiveSetter = null;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   232
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   233
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   234
        assert primitiveGetter == null || primitiveGetter.type() == Lookup.GET_PRIMITIVE_TYPE : primitiveGetter + "!=" + Lookup.GET_PRIMITIVE_TYPE;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   235
        assert primitiveSetter == null || primitiveSetter.type() == Lookup.SET_PRIMITIVE_TYPE : primitiveSetter;
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 16523
diff changeset
   236
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   237
        objectGetter  = getter.type() != Lookup.GET_OBJECT_TYPE ? MH.asType(getter, Lookup.GET_OBJECT_TYPE) : getter;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   238
        objectSetter  = setter != null && setter.type() != Lookup.SET_OBJECT_TYPE ? MH.asType(setter, Lookup.SET_OBJECT_TYPE) : setter;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   239
29834
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents: 27307
diff changeset
   240
        setType(getterType);
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 16523
diff changeset
   241
    }
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 16523
diff changeset
   242
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   243
    /**
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 24880
diff changeset
   244
     * Normal ACCESS PROPERTY constructor given a structure class.
16224
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   245
     * Constructor for dual field AccessorPropertys.
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   246
     *
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   247
     * @param key              property key
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   248
     * @param flags            property flags
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   249
     * @param structure        structure for objects associated with this property
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   250
     * @param slot             property field number or spill slot
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   251
     */
33690
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents: 29834
diff changeset
   252
    public AccessorProperty(final Object key, final int flags, final Class<?> structure, final int slot) {
16224
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   253
        super(key, flags, slot);
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   254
23767
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
   255
        initGetterSetter(structure);
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 24880
diff changeset
   256
        initializeType();
23767
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
   257
    }
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
   258
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
   259
    private void initGetterSetter(final Class<?> structure) {
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
   260
        final int slot = getSlot();
16224
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   261
        /*
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   262
         * primitiveGetter and primitiveSetter are only used in dual fields mode. Setting them to null also
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   263
         * works in dual field mode, it only means that the property never has a primitive
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   264
         * representation.
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   265
         */
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   266
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   267
        if (isParameter() && hasArguments()) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   268
            //parameters are always stored in an object array, which may or may not be a good idea
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   269
            final MethodHandle arguments = MH.getter(LOOKUP, structure, "arguments", ScriptObject.class);
18859
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 18855
diff changeset
   270
            objectGetter = MH.asType(MH.insertArguments(MH.filterArguments(ScriptObject.GET_ARGUMENT.methodHandle(), 0, arguments), 1, slot), Lookup.GET_OBJECT_TYPE);
7c4d0146ccd5 8009758: reactivate the 8006529 test.
attila
parents: 18855
diff changeset
   271
            objectSetter = MH.asType(MH.insertArguments(MH.filterArguments(ScriptObject.SET_ARGUMENT.methodHandle(), 0, arguments), 1, slot), Lookup.SET_OBJECT_TYPE);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   272
            primitiveGetter = null;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   273
            primitiveSetter = null;
16224
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   274
        } else {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   275
            final Accessors gs = GETTERS_SETTERS.get(structure);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   276
            objectGetter    = gs.objectGetters[slot];
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   277
            primitiveGetter = gs.primitiveGetters[slot];
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   278
            objectSetter    = gs.objectSetters[slot];
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   279
            primitiveSetter = gs.primitiveSetters[slot];
16224
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   280
        }
29834
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents: 27307
diff changeset
   281
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents: 27307
diff changeset
   282
        // Always use dual fields except for single field structures
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents: 27307
diff changeset
   283
        assert hasDualFields() != StructureLoader.isSingleFieldStructure(structure.getName());
16224
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   284
    }
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   285
0c49ad4e3b55 8006222: Move slot from SpillProperty to Property
jlaskey
parents: 16151
diff changeset
   286
    /**
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   287
     * Constructor
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   288
     *
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   289
     * @param key          key
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   290
     * @param flags        flags
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   291
     * @param slot         field slot index
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   292
     * @param owner        owner of property
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   293
     * @param initialValue initial value to which the property can be set
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   294
     */
33690
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents: 29834
diff changeset
   295
    protected AccessorProperty(final Object key, final int flags, final int slot, final ScriptObject owner, final Object initialValue) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   296
        this(key, flags, owner.getClass(), slot);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   297
        setInitialValue(owner, initialValue);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   298
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   299
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   300
    /**
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   301
     * Normal access property constructor that overrides the type
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   302
     * Override the initial type. Used for Object Literals
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   303
     *
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   304
     * @param key          key
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   305
     * @param flags        flags
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   306
     * @param structure    structure to JO subclass
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   307
     * @param slot         field slot index
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   308
     * @param initialType  initial type of the property
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   309
     */
33690
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents: 29834
diff changeset
   310
    public AccessorProperty(final Object key, final int flags, final Class<?> structure, final int slot, final Class<?> initialType) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   311
        this(key, flags, structure, slot);
29834
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents: 27307
diff changeset
   312
        setType(hasDualFields() ? initialType : Object.class);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   313
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   314
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   315
    /**
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   316
     * Copy constructor that may change type and in that case clear the cache. Important to do that before
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   317
     * type change or getters will be created already stale.
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   318
     *
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   319
     * @param property property
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   320
     * @param newType  new type
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   321
     */
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   322
    protected AccessorProperty(final AccessorProperty property, final Class<?> newType) {
24727
attila
parents: 24721 23372
diff changeset
   323
        super(property, property.getFlags());
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   324
27307
62ed492cbe63 8062401: User accessors require boxing and do not support optimistic types
hannesw
parents: 26768
diff changeset
   325
        this.GETTER_CACHE    = newType != property.getLocalType() ? new MethodHandle[NOOF_TYPES] : property.GETTER_CACHE;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   326
        this.primitiveGetter = property.primitiveGetter;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   327
        this.primitiveSetter = property.primitiveSetter;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   328
        this.objectGetter    = property.objectGetter;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   329
        this.objectSetter    = property.objectSetter;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   330
27307
62ed492cbe63 8062401: User accessors require boxing and do not support optimistic types
hannesw
parents: 26768
diff changeset
   331
        setType(newType);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   332
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   333
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   334
    /**
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   335
     * COPY constructor
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   336
     *
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   337
     * @param property  source property
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   338
     */
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   339
    protected AccessorProperty(final AccessorProperty property) {
27307
62ed492cbe63 8062401: User accessors require boxing and do not support optimistic types
hannesw
parents: 26768
diff changeset
   340
        this(property, property.getLocalType());
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   341
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   342
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   343
    /**
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   344
     * Set initial value of a script object's property
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   345
     * @param owner        owner
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   346
     * @param initialValue initial value
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   347
     */
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   348
    protected final void setInitialValue(final ScriptObject owner, final Object initialValue) {
29834
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents: 27307
diff changeset
   349
        setType(hasDualFields() ? JSType.unboxedFieldType(initialValue) : Object.class);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   350
        if (initialValue instanceof Integer) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   351
            invokeSetter(owner, ((Integer)initialValue).intValue());
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   352
        } else if (initialValue instanceof Double) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   353
            invokeSetter(owner, ((Double)initialValue).doubleValue());
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   354
        } else {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   355
            invokeSetter(owner, initialValue);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   356
        }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   357
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   358
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   359
    /**
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   360
     * Initialize the type of a property
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   361
     */
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   362
    protected final void initializeType() {
29834
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents: 27307
diff changeset
   363
        setType(!hasDualFields() ? Object.class : null);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   364
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   365
23767
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
   366
    private void readObject(final ObjectInputStream s) throws IOException, ClassNotFoundException {
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
   367
        s.defaultReadObject();
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
   368
        // Restore getters array
24769
attila
parents: 24751 23767
diff changeset
   369
        GETTER_CACHE = new MethodHandle[NOOF_TYPES];
23767
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
   370
    }
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
   371
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   372
    private static MethodHandle bindTo(final MethodHandle mh, final Object receiver) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   373
        if (mh == null) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   374
            return null;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   375
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   376
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   377
        return MH.dropArguments(MH.bindTo(mh, receiver), 0, Object.class);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   378
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   379
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   380
    @Override
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   381
    public Property copy() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   382
        return new AccessorProperty(this);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   383
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   384
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   385
    @Override
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   386
    public Property copy(final Class<?> newType) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   387
        return new AccessorProperty(this, newType);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   388
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   389
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   390
    @Override
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   391
    public int getIntValue(final ScriptObject self, final ScriptObject owner) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   392
        try {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   393
            return (int)getGetter(int.class).invokeExact((Object)self);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   394
        } catch (final Error | RuntimeException e) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   395
            throw e;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   396
        } catch (final Throwable e) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   397
            throw new RuntimeException(e);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   398
        }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   399
     }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   400
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   401
     @Override
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   402
     public double getDoubleValue(final ScriptObject self, final ScriptObject owner) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   403
        try {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   404
            return (double)getGetter(double.class).invokeExact((Object)self);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   405
        } catch (final Error | RuntimeException e) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   406
            throw e;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   407
        } catch (final Throwable e) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   408
            throw new RuntimeException(e);
17774
0407501fa563 8014219: Make the run-octane harness more deterministic by not measuring elapsed time every iteration. Also got rid of most of the run logic in base.js and call benchmarks directly for the same purpose
lagergren
parents: 17770
diff changeset
   409
        }
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   410
    }
17774
0407501fa563 8014219: Make the run-octane harness more deterministic by not measuring elapsed time every iteration. Also got rid of most of the run logic in base.js and call benchmarks directly for the same purpose
lagergren
parents: 17770
diff changeset
   411
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   412
     @Override
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   413
     public Object getObjectValue(final ScriptObject self, final ScriptObject owner) {
17774
0407501fa563 8014219: Make the run-octane harness more deterministic by not measuring elapsed time every iteration. Also got rid of most of the run logic in base.js and call benchmarks directly for the same purpose
lagergren
parents: 17770
diff changeset
   414
        try {
0407501fa563 8014219: Make the run-octane harness more deterministic by not measuring elapsed time every iteration. Also got rid of most of the run logic in base.js and call benchmarks directly for the same purpose
lagergren
parents: 17770
diff changeset
   415
            return getGetter(Object.class).invokeExact((Object)self);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   416
        } catch (final Error | RuntimeException e) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   417
            throw e;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   418
        } catch (final Throwable e) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   419
            throw new RuntimeException(e);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   420
        }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   421
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   422
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   423
     /**
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   424
      * Invoke setter for this property with a value
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   425
      * @param self  owner
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   426
      * @param value value
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   427
      */
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   428
    protected final void invokeSetter(final ScriptObject self, final int value) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   429
        try {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   430
            getSetter(int.class, self.getMap()).invokeExact((Object)self, value);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   431
        } catch (final Error | RuntimeException e) {
17774
0407501fa563 8014219: Make the run-octane harness more deterministic by not measuring elapsed time every iteration. Also got rid of most of the run logic in base.js and call benchmarks directly for the same purpose
lagergren
parents: 17770
diff changeset
   432
            throw e;
0407501fa563 8014219: Make the run-octane harness more deterministic by not measuring elapsed time every iteration. Also got rid of most of the run logic in base.js and call benchmarks directly for the same purpose
lagergren
parents: 17770
diff changeset
   433
        } catch (final Throwable e) {
0407501fa563 8014219: Make the run-octane harness more deterministic by not measuring elapsed time every iteration. Also got rid of most of the run logic in base.js and call benchmarks directly for the same purpose
lagergren
parents: 17770
diff changeset
   434
            throw new RuntimeException(e);
17770
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
   435
        }
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
   436
    }
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
   437
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   438
    /**
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   439
     * Invoke setter for this property with a value
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   440
     * @param self  owner
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   441
     * @param value value
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   442
     */
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   443
    protected final void invokeSetter(final ScriptObject self, final double value) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   444
        try {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   445
            getSetter(double.class, self.getMap()).invokeExact((Object)self, value);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   446
        } catch (final Error | RuntimeException e) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   447
            throw e;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   448
        } catch (final Throwable e) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   449
            throw new RuntimeException(e);
17770
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
   450
        }
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 18847
diff changeset
   451
    }
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 18847
diff changeset
   452
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   453
    /**
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   454
     * Invoke setter for this property with a value
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   455
     * @param self  owner
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   456
     * @param value value
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   457
     */
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   458
    protected final void invokeSetter(final ScriptObject self, final Object value) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   459
        try {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   460
            getSetter(Object.class, self.getMap()).invokeExact((Object)self, value);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   461
        } catch (final Error | RuntimeException e) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   462
            throw e;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   463
        } catch (final Throwable e) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   464
            throw new RuntimeException(e);
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 18847
diff changeset
   465
        }
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   466
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   467
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   468
    @Override
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   469
    public void setValue(final ScriptObject self, final ScriptObject owner, final int value, final boolean strict)  {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   470
        assert isConfigurable() || isWritable() : getKey() + " is not writable or configurable";
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   471
        invokeSetter(self, value);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   472
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   473
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   474
    @Override
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   475
    public void setValue(final ScriptObject self, final ScriptObject owner, final double value, final boolean strict)  {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   476
        assert isConfigurable() || isWritable() : getKey() + " is not writable or configurable";
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   477
        invokeSetter(self, value);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   478
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   479
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   480
    @Override
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   481
    public void setValue(final ScriptObject self, final ScriptObject owner, final Object value, final boolean strict)  {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   482
        //this is sometimes used for bootstrapping, hence no assert. ugly.
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   483
        invokeSetter(self, value);
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 18847
diff changeset
   484
    }
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 18847
diff changeset
   485
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 18847
diff changeset
   486
    @Override
23767
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
   487
    void initMethodHandles(final Class<?> structure) {
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 24880
diff changeset
   488
        // sanity check for structure class
23767
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
   489
        if (!ScriptObject.class.isAssignableFrom(structure) || !StructureLoader.isStructureClass(structure.getName())) {
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
   490
            throw new IllegalArgumentException();
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
   491
        }
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 24880
diff changeset
   492
        // this method is overridden in SpillProperty
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 24880
diff changeset
   493
        assert !isSpill();
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 24880
diff changeset
   494
        initGetterSetter(structure);
23767
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
   495
    }
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
   496
7c0614b75e23 8038638: Persistent store for compiled scripts
hannesw
parents: 23372
diff changeset
   497
    @Override
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 18847
diff changeset
   498
    public MethodHandle getGetter(final Class<?> type) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   499
        final int i = getAccessorTypeIndex(type);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   500
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   501
        assert type == int.class ||
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   502
                type == double.class ||
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   503
                type == Object.class :
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   504
                "invalid getter type " + type + " for " + getKey();
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 18847
diff changeset
   505
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   506
        checkUndeclared();
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   507
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   508
        //all this does is add a return value filter for object fields only
24880
cac5f6a0a40c 8046025: AccessorProperty.getGetter is not threadsafe
attila
parents: 24769
diff changeset
   509
        final MethodHandle[] getterCache = GETTER_CACHE;
cac5f6a0a40c 8046025: AccessorProperty.getGetter is not threadsafe
attila
parents: 24769
diff changeset
   510
        final MethodHandle cachedGetter = getterCache[i];
cac5f6a0a40c 8046025: AccessorProperty.getGetter is not threadsafe
attila
parents: 24769
diff changeset
   511
        final MethodHandle getter;
cac5f6a0a40c 8046025: AccessorProperty.getGetter is not threadsafe
attila
parents: 24769
diff changeset
   512
        if (cachedGetter != null) {
cac5f6a0a40c 8046025: AccessorProperty.getGetter is not threadsafe
attila
parents: 24769
diff changeset
   513
            getter = cachedGetter;
cac5f6a0a40c 8046025: AccessorProperty.getGetter is not threadsafe
attila
parents: 24769
diff changeset
   514
        } else {
cac5f6a0a40c 8046025: AccessorProperty.getGetter is not threadsafe
attila
parents: 24769
diff changeset
   515
            getter = debug(
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   516
                createGetter(
27307
62ed492cbe63 8062401: User accessors require boxing and do not support optimistic types
hannesw
parents: 26768
diff changeset
   517
                    getLocalType(),
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   518
                    type,
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   519
                    primitiveGetter,
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   520
                    objectGetter,
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   521
                    INVALID_PROGRAM_POINT),
27307
62ed492cbe63 8062401: User accessors require boxing and do not support optimistic types
hannesw
parents: 26768
diff changeset
   522
                getLocalType(),
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   523
                type,
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   524
                "get");
24880
cac5f6a0a40c 8046025: AccessorProperty.getGetter is not threadsafe
attila
parents: 24769
diff changeset
   525
            getterCache[i] = getter;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   526
       }
24880
cac5f6a0a40c 8046025: AccessorProperty.getGetter is not threadsafe
attila
parents: 24769
diff changeset
   527
       assert getter.type().returnType() == type && getter.type().parameterType(0) == Object.class;
cac5f6a0a40c 8046025: AccessorProperty.getGetter is not threadsafe
attila
parents: 24769
diff changeset
   528
       return getter;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   529
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   530
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   531
    @Override
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   532
    public MethodHandle getOptimisticGetter(final Class<?> type, final int programPoint) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   533
        // nasgen generated primitive fields like Math.PI have only one known unchangeable primitive type
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   534
        if (objectGetter == null) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   535
            return getOptimisticPrimitiveGetter(type, programPoint);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   536
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   537
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   538
        checkUndeclared();
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   539
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   540
        return debug(
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   541
            createGetter(
27307
62ed492cbe63 8062401: User accessors require boxing and do not support optimistic types
hannesw
parents: 26768
diff changeset
   542
                getLocalType(),
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   543
                type,
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   544
                primitiveGetter,
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   545
                objectGetter,
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   546
                programPoint),
27307
62ed492cbe63 8062401: User accessors require boxing and do not support optimistic types
hannesw
parents: 26768
diff changeset
   547
            getLocalType(),
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   548
            type,
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   549
            "get");
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   550
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   551
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   552
    private MethodHandle getOptimisticPrimitiveGetter(final Class<?> type, final int programPoint) {
27307
62ed492cbe63 8062401: User accessors require boxing and do not support optimistic types
hannesw
parents: 26768
diff changeset
   553
        final MethodHandle g = getGetter(getLocalType());
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   554
        return MH.asType(OptimisticReturnFilters.filterOptimisticReturnValue(g, type, programPoint), g.type().changeReturnType(type));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   555
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   556
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   557
    private Property getWiderProperty(final Class<?> type) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   558
        return copy(type); //invalidate cache of new property
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   559
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   560
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   561
    private PropertyMap getWiderMap(final PropertyMap oldMap, final Property newProperty) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   562
        final PropertyMap newMap = oldMap.replaceProperty(this, newProperty);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   563
        assert oldMap.size() > 0;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   564
        assert newMap.size() == oldMap.size();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   565
        return newMap;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   566
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   567
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   568
    private void checkUndeclared() {
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   569
        if ((getFlags() & NEEDS_DECLARATION) != 0) {
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   570
            // a lexically defined variable that hasn't seen its declaration - throw ReferenceError
33690
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents: 29834
diff changeset
   571
            throw ECMAErrors.referenceError("not.defined", getKey().toString());
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   572
        }
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   573
    }
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   574
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   575
    // the final three arguments are for debug printout purposes only
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   576
    @SuppressWarnings("unused")
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   577
    private static Object replaceMap(final Object sobj, final PropertyMap newMap) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   578
        ((ScriptObject)sobj).setMap(newMap);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   579
        return sobj;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   580
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   581
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24734
diff changeset
   582
    @SuppressWarnings("unused")
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26646
diff changeset
   583
    private static Object invalidateSwitchPoint(final AccessorProperty property, final Object obj) {
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26646
diff changeset
   584
         if (!property.builtinSwitchPoint.hasBeenInvalidated()) {
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26646
diff changeset
   585
            SwitchPoint.invalidateAll(new SwitchPoint[] { property.builtinSwitchPoint });
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26646
diff changeset
   586
        }
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24734
diff changeset
   587
        return obj;
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24734
diff changeset
   588
    }
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24734
diff changeset
   589
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   590
    private MethodHandle generateSetter(final Class<?> forType, final Class<?> type) {
27307
62ed492cbe63 8062401: User accessors require boxing and do not support optimistic types
hannesw
parents: 26768
diff changeset
   591
        return debug(createSetter(forType, type, primitiveSetter, objectSetter), getLocalType(), type, "set");
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   592
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   593
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   594
    /**
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   595
     * Is this property of the undefined type?
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   596
     * @return true if undefined
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   597
     */
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   598
    protected final boolean isUndefined() {
27307
62ed492cbe63 8062401: User accessors require boxing and do not support optimistic types
hannesw
parents: 26768
diff changeset
   599
        return getLocalType() == null;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   600
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   601
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   602
    @Override
36023
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 34732
diff changeset
   603
    public boolean hasNativeSetter() {
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 34732
diff changeset
   604
        return objectSetter != null;
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 34732
diff changeset
   605
    }
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 34732
diff changeset
   606
528cc67f1289 8147558: Add support for ES6 collections
hannesw
parents: 34732
diff changeset
   607
    @Override
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   608
    public MethodHandle getSetter(final Class<?> type, final PropertyMap currentMap) {
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   609
        checkUndeclared();
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   610
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   611
        final int typeIndex        = getAccessorTypeIndex(type);
27307
62ed492cbe63 8062401: User accessors require boxing and do not support optimistic types
hannesw
parents: 26768
diff changeset
   612
        final int currentTypeIndex = getAccessorTypeIndex(getLocalType());
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   613
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   614
        //if we are asking for an object setter, but are still a primitive type, we might try to box it
17513
b9a691fc1df5 8006220: Simplify PropertyMaps
jlaskey
parents: 17246
diff changeset
   615
        MethodHandle mh;
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   616
        if (needsInvalidator(typeIndex, currentTypeIndex)) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   617
            final Property     newProperty = getWiderProperty(type);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   618
            final PropertyMap  newMap      = getWiderMap(currentMap, newProperty);
24734
da070553a8e1 8038799: Guard and unbox boxed primitives types on setting them in Properties to avoid megamorphisism
lagergren
parents: 24733
diff changeset
   619
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   620
            final MethodHandle widerSetter = newProperty.getSetter(type, newMap);
27307
62ed492cbe63 8062401: User accessors require boxing and do not support optimistic types
hannesw
parents: 26768
diff changeset
   621
            final Class<?>     ct = getLocalType();
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   622
            mh = MH.filterArguments(widerSetter, 0, MH.insertArguments(debugReplace(ct, type, currentMap, newMap) , 1, newMap));
24734
da070553a8e1 8038799: Guard and unbox boxed primitives types on setting them in Properties to avoid megamorphisism
lagergren
parents: 24733
diff changeset
   623
            if (ct != null && ct.isPrimitive() && !type.isPrimitive()) {
da070553a8e1 8038799: Guard and unbox boxed primitives types on setting them in Properties to avoid megamorphisism
lagergren
parents: 24733
diff changeset
   624
                 mh = ObjectClassGenerator.createGuardBoxedPrimitiveSetter(ct, generateSetter(ct, ct), mh);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   625
            }
17513
b9a691fc1df5 8006220: Simplify PropertyMaps
jlaskey
parents: 17246
diff changeset
   626
        } else {
27307
62ed492cbe63 8062401: User accessors require boxing and do not support optimistic types
hannesw
parents: 26768
diff changeset
   627
            final Class<?> forType = isUndefined() ? type : getLocalType();
24749
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24745
diff changeset
   628
            mh = generateSetter(!forType.isPrimitive() ? Object.class : forType, type);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   629
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   630
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26646
diff changeset
   631
        if (isBuiltin()) {
33690
46a1bc24cf2c 8141702: Add support for Symbol property keys
hannesw
parents: 29834
diff changeset
   632
           mh = MH.filterArguments(mh, 0, debugInvalidate(MH.insertArguments(INVALIDATE_SP, 0, this), getKey().toString()));
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24734
diff changeset
   633
        }
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24734
diff changeset
   634
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   635
        assert mh.type().returnType() == void.class : mh.type();
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   636
17770
3c8602ec5565 8011630: JSON parsing performance issue
hannesw
parents: 17513
diff changeset
   637
        return mh;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   638
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   639
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   640
    @Override
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   641
    public final boolean canChangeType() {
29834
f678f348c947 8067215: Disable dual fields when not using optimistic types
hannesw
parents: 27307
diff changeset
   642
        if (!hasDualFields()) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   643
            return false;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   644
        }
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   645
        // Return true for currently undefined even if non-writable/configurable to allow initialization of ES6 CONST.
27307
62ed492cbe63 8062401: User accessors require boxing and do not support optimistic types
hannesw
parents: 26768
diff changeset
   646
        return getLocalType() == null || (getLocalType() != Object.class && (isConfigurable() || isWritable()));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   647
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   648
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   649
    private boolean needsInvalidator(final int typeIndex, final int currentTypeIndex) {
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   650
        return canChangeType() && typeIndex > currentTypeIndex;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   651
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   652
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   653
    private MethodHandle debug(final MethodHandle mh, final Class<?> forType, final Class<?> type, final String tag) {
26060
50a029a28ecb 8044851: nashorn properties leak memory
hannesw
parents: 26055
diff changeset
   654
        if (!Context.DEBUG || !Global.hasInstance()) {
24745
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   655
            return mh;
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   656
        }
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   657
24745
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   658
        final Context context = Context.getContextTrusted();
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   659
        assert context != null;
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   660
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   661
        return context.addLoggingToHandle(
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   662
                ObjectClassGenerator.class,
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   663
                Level.INFO,
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   664
                mh,
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   665
                0,
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   666
                true,
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   667
                new Supplier<String>() {
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   668
                    @Override
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   669
                    public String get() {
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   670
                        return tag + " '" + getKey() + "' (property="+ Debug.id(this) + ", slot=" + getSlot() + " " + getClass().getSimpleName() + " forType=" + stripName(forType) + ", type=" + stripName(type) + ')';
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   671
                    }
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   672
                });
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   673
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   674
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   675
    private MethodHandle debugReplace(final Class<?> oldType, final Class<?> newType, final PropertyMap oldMap, final PropertyMap newMap) {
26060
50a029a28ecb 8044851: nashorn properties leak memory
hannesw
parents: 26055
diff changeset
   676
        if (!Context.DEBUG || !Global.hasInstance()) {
24745
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   677
            return REPLACE_MAP;
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   678
        }
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   679
24745
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   680
        final Context context = Context.getContextTrusted();
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   681
        assert context != null;
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   682
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   683
        MethodHandle mh = context.addLoggingToHandle(
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   684
                ObjectClassGenerator.class,
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   685
                REPLACE_MAP,
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   686
                new Supplier<String>() {
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   687
                    @Override
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   688
                    public String get() {
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   689
                        return "Type change for '" + getKey() + "' " + oldType + "=>" + newType;
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   690
                    }
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   691
                });
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   692
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   693
        mh = context.addLoggingToHandle(
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   694
                ObjectClassGenerator.class,
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   695
                Level.FINEST,
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   696
                mh,
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   697
                Integer.MAX_VALUE,
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   698
                false,
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   699
                new Supplier<String>() {
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   700
                    @Override
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   701
                    public String get() {
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   702
                        return "Setting map " + Debug.id(oldMap) + " => " + Debug.id(newMap) + " " + oldMap + " => " + newMap;
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   703
                    }
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   704
                });
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   705
        return mh;
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   706
    }
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   707
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26646
diff changeset
   708
    private static MethodHandle debugInvalidate(final MethodHandle invalidator, final String key) {
26060
50a029a28ecb 8044851: nashorn properties leak memory
hannesw
parents: 26055
diff changeset
   709
        if (!Context.DEBUG || !Global.hasInstance()) {
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26646
diff changeset
   710
            return invalidator;
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   711
        }
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   712
24745
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   713
        final Context context = Context.getContextTrusted();
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   714
        assert context != null;
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   715
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   716
        return context.addLoggingToHandle(
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   717
                ObjectClassGenerator.class,
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26646
diff changeset
   718
                invalidator,
24745
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   719
                new Supplier<String>() {
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   720
                    @Override
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   721
                    public String get() {
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26646
diff changeset
   722
                        return "Field change callback for " + key + " triggered ";
24745
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   723
                    }
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   724
                });
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   725
    }
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   726
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   727
    private static MethodHandle findOwnMH_S(final String name, final Class<?> rtype, final Class<?>... types) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19105
diff changeset
   728
        return MH.findStatic(LOOKUP, AccessorProperty.class, name, MH.type(rtype, types));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   729
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   730
}