nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/FunctionNode.java
author sundar
Mon, 14 Sep 2015 16:13:10 +0530
changeset 32692 8f60bd284bf4
parent 32435 cfd619ef23a6
child 33888 0c7b0ab328e0
permissions -rw-r--r--
8055917: jdk.nashorn.internal.codegen.CompilationPhase$N should be renamed to proper classes Reviewed-by: attila, hannesw
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.ir;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    27
26067
b32ccc3a76c9 8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents: 26065
diff changeset
    28
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_PROFILE;
b32ccc3a76c9 8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents: 26065
diff changeset
    29
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_STRICT;
b32ccc3a76c9 8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents: 26065
diff changeset
    30
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_TRACE;
b32ccc3a76c9 8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents: 26065
diff changeset
    31
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_TRACE_ENTEREXIT;
b32ccc3a76c9 8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents: 26065
diff changeset
    32
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_TRACE_MISSES;
b32ccc3a76c9 8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents: 26065
diff changeset
    33
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_TRACE_VALUES;
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
    34
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    35
import java.util.Collections;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
    36
import java.util.Iterator;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    37
import java.util.List;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    38
import jdk.nashorn.internal.codegen.CompileUnit;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    39
import jdk.nashorn.internal.codegen.Compiler;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    40
import jdk.nashorn.internal.codegen.CompilerConstants;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    41
import jdk.nashorn.internal.codegen.Namespace;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    42
import jdk.nashorn.internal.codegen.types.Type;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    43
import jdk.nashorn.internal.ir.annotations.Ignore;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    44
import jdk.nashorn.internal.ir.annotations.Immutable;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    45
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
    46
import jdk.nashorn.internal.parser.Token;
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
    47
import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData;
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
    48
import jdk.nashorn.internal.runtime.ScriptFunction;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    49
import jdk.nashorn.internal.runtime.Source;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    50
import jdk.nashorn.internal.runtime.UserAccessorProperty;
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
    51
import jdk.nashorn.internal.runtime.linker.LinkerCallSite;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    52
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    53
/**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    54
 * IR representation for function (or script.)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    55
 */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    56
@Immutable
26500
85ea77a73bb8 8057588: Lots of trivial (empty) classes were generated by the Nashorn compiler as part of restOf-method generation
lagergren
parents: 26377
diff changeset
    57
public final class FunctionNode extends LexicalContextExpression implements Flags<FunctionNode>, CompileUnitHolder {
27204
06ec78f29a56 8059843: Make AST serializable
attila
parents: 27102
diff changeset
    58
    private static final long serialVersionUID = 1L;
06ec78f29a56 8059843: Make AST serializable
attila
parents: 27102
diff changeset
    59
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    60
    /** Type used for all FunctionNodes */
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    61
    public static final Type FUNCTION_TYPE = Type.typeFor(ScriptFunction.class);
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
    62
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    63
    /** Function kinds */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    64
    public enum Kind {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    65
        /** a normal function - nothing special */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    66
        NORMAL,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    67
        /** a script function */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    68
        SCRIPT,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    69
        /** a getter, @see {@link UserAccessorProperty} */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    70
        GETTER,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    71
        /** a setter, @see {@link UserAccessorProperty} */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    72
        SETTER
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    73
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    74
17523
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
    75
    /** Source of entity. */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
    76
    private transient final Source source;
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
    77
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
    78
    /**
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
    79
     * Opaque object representing parser state at the end of the function. Used when reparsing outer functions
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
    80
     * to skip parsing inner functions.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
    81
     */
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
    82
    private final Object endParserState;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
    83
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    84
    /** External function identifier. */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    85
    @Ignore
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    86
    private final IdentNode ident;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    87
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    88
    /** The body of the function node */
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    89
    private final Block body;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    90
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    91
    /** Internal function name. */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    92
    private final String name;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    93
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    94
    /** Compilation unit. */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    95
    private final CompileUnit compileUnit;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    96
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    97
    /** Function kind. */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    98
    private final Kind kind;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    99
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   100
    /** List of parameters. */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   101
    private final List<IdentNode> parameters;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   102
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   103
    /** First token of function. **/
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   104
    private final long firstToken;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   105
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   106
    /** Last token of function. **/
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   107
    private final long lastToken;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   108
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   109
    /** Method's namespace. */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   110
    private transient final Namespace namespace;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   111
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   112
    /** Number of properties of "this" object assigned in this function */
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   113
    @Ignore
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   114
    private final int thisProperties;
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   115
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   116
    /** Function flags. */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   117
    private final int flags;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   118
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24720
diff changeset
   119
    /** Line number of function start */
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   120
    private final int lineNumber;
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   121
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   122
    /** Root class for function */
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   123
    private final Class<?> rootClass;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   124
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   125
    /** Is anonymous function flag. */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   126
    public static final int IS_ANONYMOUS                = 1 << 0;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   127
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
   128
    /** Is the function created in a function declaration (as opposed to a function expression) */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   129
    public static final int IS_DECLARED                 = 1 << 1;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   130
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   131
    /** is this a strict mode function? */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   132
    public static final int IS_STRICT                   = 1 << 2;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   133
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   134
    /** Does the function use the "arguments" identifier ? */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   135
    public static final int USES_ARGUMENTS              = 1 << 3;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   136
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   137
    /** Has this function been split because it was too large? */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   138
    public static final int IS_SPLIT                    = 1 << 4;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   139
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17233
diff changeset
   140
    /** Does the function call eval? If it does, then all variables in this function might be get/set by it and it can
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17233
diff changeset
   141
     * introduce new variables into this function's scope too.*/
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   142
    public static final int HAS_EVAL                    = 1 << 5;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   143
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17233
diff changeset
   144
    /** Does a nested function contain eval? If it does, then all variables in this function might be get/set by it. */
23372
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   145
    public static final int HAS_NESTED_EVAL             = 1 << 6;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   146
18853
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   147
    /** Does this function have any blocks that create a scope? This is used to determine if the function needs to
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   148
     * have a local variable slot for the scope symbol. */
23372
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   149
    public static final int HAS_SCOPE_BLOCK             = 1 << 7;
18853
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   150
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   151
    /**
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   152
     * Flag this function as one that defines the identifier "arguments" as a function parameter or nested function
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   153
     * name. This precludes it from needing to have an Arguments object defined as "arguments" local variable. Note that
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   154
     * defining a local variable named "arguments" still requires construction of the Arguments object (see
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   155
     * ECMAScript 5.1 Chapter 10.5).
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   156
     * @see #needsArguments()
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   157
     */
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   158
    public static final int DEFINES_ARGUMENTS           = 1 << 8;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   159
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   160
    /** Does this function or any of its descendants use variables from an ancestor function's scope (incl. globals)? */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   161
    public static final int USES_ANCESTOR_SCOPE         = 1 << 9;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   162
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   163
    /** Does this function have nested declarations? */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   164
    public static final int HAS_FUNCTION_DECLARATIONS   = 1 << 10;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   165
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   166
    /** Does this function have optimistic expressions? (If it does, it can undergo deoptimizing recompilation.) */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   167
    public static final int IS_DEOPTIMIZABLE            = 1 << 11;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   168
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   169
    /** Are we vararg, but do we just pass the arguments along to apply or call */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   170
    public static final int HAS_APPLY_TO_CALL_SPECIALIZATION = 1 << 12;
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   171
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   172
    /**
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   173
     * Is this function the top-level program?
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   174
     */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   175
    public static final int IS_PROGRAM = 1 << 13;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   176
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   177
    /**
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   178
     * Flag indicating whether this function uses the local variable symbol for itself. Only named function expressions
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   179
     * can have this flag set if they reference themselves (e.g. "(function f() { return f })". Declared functions will
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   180
     * use the symbol in their parent scope instead when they reference themselves by name.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   181
     */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   182
    public static final int USES_SELF_SYMBOL = 1 << 14;
17518
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   183
23372
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   184
    /** Does this function use the "this" keyword? */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   185
    public static final int USES_THIS = 1 << 15;
24749
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   186
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   187
    /** Is this declared in a dynamic context */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   188
    public static final int IN_DYNAMIC_CONTEXT = 1 << 16;
23372
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   189
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   190
    /**
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   191
     * The following flags are derived from directive comments within this function.
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   192
     * Note that even IS_STRICT is one such flag but that requires special handling.
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   193
     */
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   194
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26503
diff changeset
   195
    /** parser, print parse tree */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   196
    public static final int IS_PRINT_PARSE       = 1 << 17;
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26503
diff changeset
   197
    /** parser, print lower parse tree */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   198
    public static final int IS_PRINT_LOWER_PARSE = 1 << 18;
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26503
diff changeset
   199
    /** parser, print AST */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   200
    public static final int IS_PRINT_AST         = 1 << 19;
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26503
diff changeset
   201
    /** parser, print lower AST */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   202
    public static final int IS_PRINT_LOWER_AST   = 1 << 20;
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26503
diff changeset
   203
    /** parser, print symbols */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   204
    public static final int IS_PRINT_SYMBOLS     = 1 << 21;
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   205
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26503
diff changeset
   206
    // callsite tracing, profiling within this function
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   207
    /** profile callsites in this function? */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   208
    public static final int IS_PROFILE         = 1 << 22;
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   209
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   210
    /** trace callsite enterexit in this function? */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   211
    public static final int IS_TRACE_ENTEREXIT = 1 << 23;
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   212
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   213
    /** trace callsite misses in this function? */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   214
    public static final int IS_TRACE_MISSES    = 1 << 24;
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   215
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   216
    /** trace callsite values in this function? */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   217
    public static final int IS_TRACE_VALUES    = 1 << 25;
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   218
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   219
    /**
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   220
     * Whether this function needs the callee {@link ScriptFunction} instance passed to its code as a
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   221
     * parameter on invocation. Note that we aren't, in fact using this flag in function nodes.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   222
     * Rather, it is always calculated (see {@link #needsCallee()}). {@link RecompilableScriptFunctionData}
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   223
     * will, however, cache the value of this flag.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   224
     */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   225
    public static final int NEEDS_CALLEE       = 1 << 26;
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   226
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
   227
    /**
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
   228
     * Is the function node cached?
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
   229
     */
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
   230
    public static final int IS_CACHED = 1 << 27;
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
   231
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   232
    /** extension callsite flags mask */
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   233
    public static final int EXTENSION_CALLSITE_FLAGS = IS_PRINT_PARSE |
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   234
        IS_PRINT_LOWER_PARSE | IS_PRINT_AST | IS_PRINT_LOWER_AST |
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   235
        IS_PRINT_SYMBOLS | IS_PROFILE | IS_TRACE_ENTEREXIT |
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   236
        IS_TRACE_MISSES | IS_TRACE_VALUES;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   237
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17233
diff changeset
   238
    /** Does this function or any nested functions contain an eval? */
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17233
diff changeset
   239
    private static final int HAS_DEEP_EVAL = HAS_EVAL | HAS_NESTED_EVAL;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   240
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   241
    /** Does this function need to store all its variables in scope? */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   242
    private static final int HAS_ALL_VARS_IN_SCOPE = HAS_DEEP_EVAL;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   243
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   244
    /** Does this function potentially need "arguments"? Note that this is not a full test, as further negative check of REDEFINES_ARGS is needed. */
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   245
    private static final int MAYBE_NEEDS_ARGUMENTS = USES_ARGUMENTS | HAS_EVAL;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   246
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   247
    /** Does this function need the parent scope? It needs it if either it or its descendants use variables from it, or have a deep eval, or it's the program. */
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   248
    public static final int NEEDS_PARENT_SCOPE = USES_ANCESTOR_SCOPE | HAS_DEEP_EVAL | IS_PROGRAM;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   249
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   250
    /** What is the return type of this function? */
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16187
diff changeset
   251
    private Type returnType = Type.UNKNOWN;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   252
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   253
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   254
     * Constructor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   255
     *
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   256
     * @param source     the source
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17523
diff changeset
   257
     * @param lineNumber line number
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   258
     * @param token      token
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   259
     * @param finish     finish
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   260
     * @param firstToken first token of the function node (including the function declaration)
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   261
     * @param lastToken  lastToken
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   262
     * @param namespace  the namespace
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   263
     * @param ident      the identifier
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   264
     * @param name       the name of the function
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   265
     * @param parameters parameter list
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   266
     * @param kind       kind of function as in {@link FunctionNode.Kind}
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   267
     * @param flags      initial flags
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   268
     * @param body       body of the function
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   269
     * @param endParserState The parser state at the end of the parsing.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   270
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   271
    public FunctionNode(
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   272
        final Source source,
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17523
diff changeset
   273
        final int lineNumber,
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   274
        final long token,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   275
        final int finish,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   276
        final long firstToken,
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   277
        final long lastToken,
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   278
        final Namespace namespace,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   279
        final IdentNode ident,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   280
        final String name,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   281
        final List<IdentNode> parameters,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   282
        final FunctionNode.Kind kind,
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   283
        final int flags,
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   284
        final Block body,
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   285
        final Object endParserState) {
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   286
        super(token, finish);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   287
17523
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   288
        this.source           = source;
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   289
        this.lineNumber       = lineNumber;
17518
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   290
        this.ident            = ident;
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   291
        this.name             = name;
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   292
        this.kind             = kind;
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   293
        this.parameters       = parameters;
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   294
        this.firstToken       = firstToken;
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   295
        this.lastToken        = lastToken;
17518
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   296
        this.namespace        = namespace;
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   297
        this.flags            = flags;
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   298
        this.compileUnit      = null;
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   299
        this.body             = body;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   300
        this.thisProperties   = 0;
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   301
        this.rootClass        = null;
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   302
        this.endParserState    = endParserState;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   303
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   304
17518
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   305
    private FunctionNode(
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   306
        final FunctionNode functionNode,
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   307
        final long lastToken,
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26503
diff changeset
   308
        final Object endParserState,
17518
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   309
        final int flags,
17752
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   310
        final String name,
17518
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   311
        final Type returnType,
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   312
        final CompileUnit compileUnit,
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   313
        final Block body,
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   314
        final List<IdentNode> parameters,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   315
        final int thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   316
        final Class<?> rootClass,
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
   317
        final Source source, final Namespace namespace) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   318
        super(functionNode);
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   319
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   320
        this.endParserState    = endParserState;
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   321
        this.lineNumber       = functionNode.lineNumber;
17518
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   322
        this.flags            = flags;
17752
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   323
        this.name             = name;
17518
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   324
        this.returnType       = returnType;
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   325
        this.compileUnit      = compileUnit;
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   326
        this.lastToken        = lastToken;
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   327
        this.body             = body;
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   328
        this.parameters       = parameters;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   329
        this.thisProperties   = thisProperties;
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   330
        this.rootClass        = rootClass;
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   331
        this.source           = source;
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   332
        this.namespace        = namespace;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   333
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   334
        // the fields below never change - they are final and assigned in constructor
17518
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   335
        this.ident           = functionNode.ident;
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   336
        this.kind            = functionNode.kind;
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   337
        this.firstToken      = functionNode.firstToken;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   338
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   339
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   340
    @Override
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents: 17756
diff changeset
   341
    public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   342
        if (visitor.enterFunctionNode(this)) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   343
            return visitor.leaveFunctionNode(setBody(lc, (Block)body.accept(visitor)));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   344
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   345
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   346
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   347
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   348
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   349
     * Visits the parameter nodes of this function. Parameters are normally not visited automatically.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   350
     * @param visitor the visitor to apply to the nodes.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   351
     * @return a list of parameter nodes, potentially modified from original ones by the visitor.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   352
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   353
    public List<IdentNode> visitParameters(final NodeVisitor<? extends LexicalContext> visitor) {
25821
fbb51e67d2a7 8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents: 24993
diff changeset
   354
        return Node.accept(visitor, parameters);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   355
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   356
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   357
    /**
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   358
     * Get additional callsite flags to be used specific to this function.
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   359
     *
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   360
     * @return callsite flags
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   361
     */
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   362
    public int getCallSiteFlags() {
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   363
        int callsiteFlags = 0;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   364
        if (getFlag(IS_STRICT)) {
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   365
            callsiteFlags |= CALLSITE_STRICT;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   366
        }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   367
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   368
        // quick check for extension callsite flags turned on by directives.
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   369
        if ((flags & EXTENSION_CALLSITE_FLAGS) == 0) {
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   370
            return callsiteFlags;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   371
        }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   372
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   373
        if (getFlag(IS_PROFILE)) {
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   374
            callsiteFlags |= CALLSITE_PROFILE;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   375
        }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   376
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   377
        if (getFlag(IS_TRACE_MISSES)) {
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   378
            callsiteFlags |= CALLSITE_TRACE | CALLSITE_TRACE_MISSES;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   379
        }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   380
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   381
        if (getFlag(IS_TRACE_VALUES)) {
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   382
            callsiteFlags |= CALLSITE_TRACE | CALLSITE_TRACE_ENTEREXIT | CALLSITE_TRACE_VALUES;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   383
        }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   384
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   385
        if (getFlag(IS_TRACE_ENTEREXIT)) {
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   386
            callsiteFlags |= CALLSITE_TRACE | CALLSITE_TRACE_ENTEREXIT;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   387
        }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   388
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   389
        return callsiteFlags;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   390
    }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   391
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   392
    /**
17523
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   393
     * Get the source for this function
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   394
     * @return the source
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   395
     */
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   396
    public Source getSource() {
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   397
        return source;
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   398
    }
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   399
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   400
    /**
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   401
     * Sets the source and namespace for this function. It can only set a non-null source and namespace for a function
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   402
     * that currently has both a null source and a null namespace. This is used to re-set the source and namespace for
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   403
     * a deserialized function node.
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   404
     * @param source the source for the function.
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   405
     * @param namespace the namespace for the function
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   406
     * @return a new function node with the set source and namespace
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   407
     * @throws IllegalArgumentException if the specified source or namespace is null
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   408
     * @throws IllegalStateException if the function already has either a source or namespace set.
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   409
     */
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   410
    public FunctionNode initializeDeserialized(final Source source, final Namespace namespace) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   411
        if (source == null || namespace == null) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   412
            throw new IllegalArgumentException();
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   413
        } else if (this.source == source && this.namespace == namespace) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   414
            return this;
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   415
        } else if (this.source != null || this.namespace != null) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   416
            throw new IllegalStateException();
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   417
        }
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   418
        return new FunctionNode(
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   419
            this,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   420
            lastToken,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   421
            endParserState,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   422
            flags,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   423
            name,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   424
            returnType,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   425
            compileUnit,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   426
            body,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   427
            parameters,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   428
            thisProperties,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   429
            rootClass, source, namespace);
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   430
    }
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   431
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   432
    /**
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   433
     * Get the unique ID for this function within the script file.
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   434
     * @return the id
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   435
     */
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   436
    public int getId() {
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   437
        return isProgram() ? -1: Token.descPosition(firstToken);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   438
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   439
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   440
    /**
22390
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   441
     * get source name - sourceURL or name derived from Source.
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   442
     *
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   443
     * @return name for the script source
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   444
     */
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   445
    public String getSourceName() {
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   446
        return getSourceName(source);
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   447
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   448
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   449
    /**
24993
b707d46bae40 8046898: Make sure that lazy compilation is the default, remove redundant "enable lazy compilation" flags, added warning message if compile logging is enabled and lazy is switched off. Verified existing test suite code coverage equivalence between lazy and eager.
lagergren
parents: 24778
diff changeset
   450
     * Static source name getter
b707d46bae40 8046898: Make sure that lazy compilation is the default, remove redundant "enable lazy compilation" flags, added warning message if compile logging is enabled and lazy is switched off. Verified existing test suite code coverage equivalence between lazy and eager.
lagergren
parents: 24778
diff changeset
   451
     *
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   452
     * @param source the source
24993
b707d46bae40 8046898: Make sure that lazy compilation is the default, remove redundant "enable lazy compilation" flags, added warning message if compile logging is enabled and lazy is switched off. Verified existing test suite code coverage equivalence between lazy and eager.
lagergren
parents: 24778
diff changeset
   453
     * @return source name
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   454
     */
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   455
    public static String getSourceName(final Source source) {
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   456
        final String explicitURL = source.getExplicitURL();
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   457
        return explicitURL != null ? explicitURL : source.getName();
22390
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   458
    }
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   459
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   460
    /**
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   461
     * Function to parse nashorn per-function extension directive comments.
22390
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   462
     *
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   463
     * @param directive nashorn extension directive string
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   464
     * @return integer flag for the given directive.
22390
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   465
     */
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   466
    public static int getDirectiveFlag(final String directive) {
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   467
        switch (directive) {
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   468
            case "nashorn callsite trace enterexit":
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   469
                return IS_TRACE_ENTEREXIT;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   470
            case "nashorn callsite trace misses":
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   471
                return IS_TRACE_MISSES;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   472
            case "nashorn callsite trace objects":
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   473
                return IS_TRACE_VALUES;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   474
            case "nashorn callsite profile":
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   475
                return IS_PROFILE;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   476
            case "nashorn print parse":
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   477
                return IS_PRINT_PARSE;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   478
            case "nashorn print lower parse":
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   479
                return IS_PRINT_LOWER_PARSE;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   480
            case "nashorn print ast":
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   481
                return IS_PRINT_AST;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   482
            case "nashorn print lower ast":
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   483
                return IS_PRINT_LOWER_AST;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   484
            case "nashorn print symbols":
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   485
                return IS_PRINT_SYMBOLS;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   486
            default:
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   487
                // unknown/unsupported directive
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   488
                return 0;
22390
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   489
        }
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   490
    }
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   491
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   492
    /**
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   493
     * Returns the line number.
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   494
     * @return the line number.
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   495
     */
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   496
    public int getLineNumber() {
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   497
        return lineNumber;
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   498
    }
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   499
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   500
    /**
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   501
     * Create a unique name in the namespace of this FunctionNode
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   502
     * @param base prefix for name
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   503
     * @return base if no collision exists, otherwise a name prefix with base
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   504
     */
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   505
    public String uniqueName(final String base) {
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   506
        return namespace.uniqueName(base);
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   507
    }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   508
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   509
    @Override
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   510
    public void toString(final StringBuilder sb, final boolean printTypes) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   511
        sb.append('[').
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   512
            append(returnType).
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   513
            append(']').
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   514
            append(' ');
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16187
diff changeset
   515
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   516
        sb.append("function");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   517
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   518
        if (ident != null) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   519
            sb.append(' ');
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   520
            ident.toString(sb, printTypes);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   521
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   522
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   523
        sb.append('(');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   524
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   525
        for (final Iterator<IdentNode> iter = parameters.iterator(); iter.hasNext(); ) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   526
            final IdentNode parameter = iter.next();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   527
            if (parameter.getSymbol() != null) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   528
                sb.append('[').append(parameter.getType()).append(']').append(' ');
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   529
            }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   530
            parameter.toString(sb, printTypes);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   531
            if (iter.hasNext()) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   532
                sb.append(", ");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   533
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   534
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   535
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   536
        sb.append(')');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   537
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   538
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   539
    @Override
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   540
    public int getFlags() {
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   541
        return flags;
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   542
    }
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   543
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   544
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   545
    public boolean getFlag(final int flag) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   546
        return (flags & flag) != 0;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   547
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   548
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   549
    @Override
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24720
diff changeset
   550
    public FunctionNode setFlags(final LexicalContext lc, final int flags) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   551
        if (this.flags == flags) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   552
            return this;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   553
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   554
        return Node.replaceInLexicalContext(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   555
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   556
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   557
                new FunctionNode(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   558
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   559
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   560
                        endParserState,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   561
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   562
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   563
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   564
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   565
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   566
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   567
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   568
                        rootClass, source, namespace));
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   569
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   570
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   571
    @Override
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   572
    public FunctionNode clearFlag(final LexicalContext lc, final int flag) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   573
        return setFlags(lc, flags & ~flag);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   574
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   575
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   576
    @Override
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   577
    public FunctionNode setFlag(final LexicalContext lc, final int flag) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   578
        return setFlags(lc, flags | flag);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   579
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   580
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   581
    /**
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
   582
     * Returns true if the function is the top-level program.
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
   583
     * @return True if this function node represents the top-level program.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   584
     */
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
   585
    public boolean isProgram() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   586
        return getFlag(IS_PROGRAM);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   587
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   588
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   589
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   590
     * Returns true if the function contains at least one optimistic operation (and thus can be deoptimized).
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   591
     * @return true if the function contains at least one optimistic operation (and thus can be deoptimized).
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   592
     */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   593
    public boolean canBeDeoptimized() {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   594
        return getFlag(IS_DEOPTIMIZABLE);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   595
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   596
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   597
    /**
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   598
     * Check if this function has a call expression for the identifier "eval" (that is, {@code eval(...)}).
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   599
     *
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   600
     * @return true if {@code eval} is called.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   601
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   602
    public boolean hasEval() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   603
        return getFlag(HAS_EVAL);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   604
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   605
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   606
    /**
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   607
     * Returns true if a function nested (directly or transitively) within this function {@link #hasEval()}.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   608
     *
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   609
     * @return true if a nested function calls {@code eval}.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   610
     */
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   611
    public boolean hasNestedEval() {
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   612
        return getFlag(HAS_NESTED_EVAL);
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   613
    }
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   614
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   615
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   616
     * Get the first token for this function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   617
     * @return the first token
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   618
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   619
    public long getFirstToken() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   620
        return firstToken;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   621
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   622
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   623
    /**
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   624
     * Check whether this function has nested function declarations
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   625
     * @return true if nested function declarations exist
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   626
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   627
    public boolean hasDeclaredFunctions() {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   628
        return getFlag(HAS_FUNCTION_DECLARATIONS);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   629
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   630
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   631
    /**
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   632
     * Check if this function's generated Java method needs a {@code callee} parameter. Functions that need access to
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   633
     * their parent scope, functions that reference themselves, and non-strict functions that need an Arguments object
19084
daddbeee0058 8020356: ClassCastException Undefined->Scope on spiltter class generated for a large switch statement
hannesw
parents: 18867
diff changeset
   634
     * (since it exposes {@code arguments.callee} property) will need to have a callee parameter. We also return true
daddbeee0058 8020356: ClassCastException Undefined->Scope on spiltter class generated for a large switch statement
hannesw
parents: 18867
diff changeset
   635
     * for split functions to make sure symbols slots are the same in the main and split methods.
16523
af8b30edebce 8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents: 16252
diff changeset
   636
     *
24740
26791be09688 8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents: 24738
diff changeset
   637
     * A function that has had an apply(this,arguments) turned into a call doesn't need arguments anymore, but still
26791be09688 8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents: 24738
diff changeset
   638
     * has to fit the old callsite, thus, we require a dummy callee parameter for those functions as well
26791be09688 8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents: 24738
diff changeset
   639
     *
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   640
     * @return true if the function's generated Java method needs a {@code callee} parameter.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   641
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   642
    public boolean needsCallee() {
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   643
        // NOTE: we only need isSplit() here to ensure that :scope can never drop below slot 2 for splitting array units.
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
   644
        return needsParentScope() || usesSelfSymbol() || isSplit() || (needsArguments() && !isStrict()) || hasApplyToCallSpecialization();
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   645
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   646
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   647
    /**
23372
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   648
     * Return {@code true} if this function makes use of the {@code this} object.
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   649
     *
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   650
     * @return true if function uses {@code this} object
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   651
     */
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   652
    public boolean usesThis() {
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   653
        return getFlag(USES_THIS);
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   654
    }
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   655
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   656
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   657
    /**
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   658
     * Return true if function contains an apply to call transform
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   659
     * @return true if this function has transformed apply to call
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   660
     */
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
   661
    public boolean hasApplyToCallSpecialization() {
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   662
        return getFlag(HAS_APPLY_TO_CALL_SPECIALIZATION);
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   663
    }
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   664
23372
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   665
    /**
17752
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   666
     * Get the identifier for this function, this is its symbol.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   667
     * @return the identifier as an IdentityNode
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   668
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   669
    public IdentNode getIdent() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   670
        return ident;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   671
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   672
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   673
    /**
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   674
     * Get the function body
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   675
     * @return the function body
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   676
     */
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   677
    public Block getBody() {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   678
        return body;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   679
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   680
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   681
    /**
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   682
     * Reset the function body
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   683
     * @param lc lexical context
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   684
     * @param body new body
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   685
     * @return new function node if body changed, same if not
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   686
     */
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   687
    public FunctionNode setBody(final LexicalContext lc, final Block body) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   688
        if (this.body == body) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   689
            return this;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   690
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   691
        return Node.replaceInLexicalContext(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   692
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   693
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   694
                new FunctionNode(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   695
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   696
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   697
                        endParserState,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   698
                        flags |
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   699
                            (body.needsScope() ?
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   700
                                    FunctionNode.HAS_SCOPE_BLOCK :
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   701
                                    0),
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   702
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   703
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   704
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   705
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   706
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   707
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   708
                        rootClass, source, namespace));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   709
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   710
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   711
    /**
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   712
     * Does this function's method needs to be variable arity (gather all script-declared parameters in a final
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   713
     * {@code Object[]} parameter. Functions that need to have the "arguments" object as well as functions that simply
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   714
     * declare too many arguments for JVM to handle with fixed arity will need to be variable arity.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   715
     * @return true if the Java method in the generated code that implements this function needs to be variable arity.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   716
     * @see #needsArguments()
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   717
     * @see LinkerCallSite#ARGLIMIT
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   718
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   719
    public boolean isVarArg() {
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   720
        return needsArguments() || parameters.size() > LinkerCallSite.ARGLIMIT;
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   721
    }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   722
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   723
    /**
24749
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   724
     * Was this function declared in a dynamic context, i.e. in a with or eval style
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   725
     * chain
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   726
     * @return true if in dynamic context
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   727
     */
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   728
    public boolean inDynamicContext() {
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   729
        return getFlag(IN_DYNAMIC_CONTEXT);
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   730
    }
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   731
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   732
    /**
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   733
     * Check whether a function would need dynamic scope, which is does if it has
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   734
     * evals and isn't strict.
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   735
     * @return true if dynamic scope is needed
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   736
     */
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   737
    public boolean needsDynamicScope() {
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   738
        // Function has a direct eval in it (so a top-level "var ..." in the eval code can introduce a new
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   739
        // variable into the function's scope), and it isn't strict (as evals in strict functions get an
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   740
        // isolated scope).
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   741
        return hasEval() && !isStrict();
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   742
    }
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   743
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   744
    /**
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   745
     * Flag this function as declared in a dynamic context
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   746
     * @param lc lexical context
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   747
     * @return new function node, or same if unmodified
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   748
     */
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   749
    public FunctionNode setInDynamicContext(final LexicalContext lc) {
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   750
        return setFlag(lc, IN_DYNAMIC_CONTEXT);
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   751
    }
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   752
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   753
    /**
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   754
     * Returns true if this function needs to have an Arguments object defined as a local variable named "arguments".
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   755
     * Functions that use "arguments" as identifier and don't define it as a name of a parameter or a nested function
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   756
     * (see ECMAScript 5.1 Chapter 10.5), as well as any function that uses eval or with, or has a nested function that
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   757
     * does the same, will have an "arguments" object. Also, if this function is a script, it will not have an
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   758
     * "arguments" object, because it does not have local variables; rather the Global object will have an explicit
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   759
     * "arguments" property that provides command-line arguments for the script.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   760
     * @return true if this function needs an arguments object.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   761
     */
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   762
    public boolean needsArguments() {
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   763
        // uses "arguments" or calls eval, but it does not redefine "arguments", and finally, it's not a script, since
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   764
        // for top-level script, "arguments" is picked up from Context by Global.init() instead.
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   765
        return getFlag(MAYBE_NEEDS_ARGUMENTS) && !getFlag(DEFINES_ARGUMENTS) && !isProgram();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   766
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   767
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   768
    /**
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   769
     * Returns true if this function needs access to its parent scope. Functions referencing variables outside their
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   770
     * scope (including global variables), as well as functions that call eval or have a with block, or have nested
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   771
     * functions that call eval or have a with block, will need a parent scope. Top-level script functions also need a
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   772
     * parent scope since they might be used from within eval, and eval will need an externally passed scope.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   773
     * @return true if the function needs parent scope.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   774
     */
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   775
    public boolean needsParentScope() {
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   776
        return getFlag(NEEDS_PARENT_SCOPE);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   777
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   778
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   779
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   780
     * Set the number of properties assigned to the this object in this function.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   781
     * @param lc the current lexical context.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   782
     * @param thisProperties number of properties
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   783
     * @return a potentially modified function node
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   784
     */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   785
    public FunctionNode setThisProperties(final LexicalContext lc, final int thisProperties) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   786
        if (this.thisProperties == thisProperties) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   787
            return this;
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   788
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   789
        return Node.replaceInLexicalContext(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   790
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   791
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   792
                new FunctionNode(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   793
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   794
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   795
                        endParserState,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   796
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   797
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   798
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   799
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   800
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   801
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   802
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   803
                        rootClass, source, namespace));
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   804
    }
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   805
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   806
    /**
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   807
     * Get the number of properties assigned to the this object in this function.
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   808
     * @return number of properties
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   809
     */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   810
    public int getThisProperties() {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   811
        return thisProperties;
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   812
    }
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   813
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   814
    /**
18853
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   815
     * Returns true if any of the blocks in this function create their own scope.
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   816
     * @return true if any of the blocks in this function create their own scope.
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   817
     */
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   818
    public boolean hasScopeBlock() {
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   819
        return getFlag(HAS_SCOPE_BLOCK);
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   820
    }
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   821
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   822
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   823
     * Return the kind of this function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   824
     * @see FunctionNode.Kind
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   825
     * @return the kind
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   826
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   827
    public Kind getKind() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   828
        return kind;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   829
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   830
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   831
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   832
     * Return the last token for this function's code
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   833
     * @return last token
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   834
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   835
    public long getLastToken() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   836
        return lastToken;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   837
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   838
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   839
    /**
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   840
     * Returns the end parser state for this function.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   841
     * @return the end parser state for this function.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   842
     */
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   843
    public Object getEndParserState() {
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   844
        return endParserState;
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   845
    }
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   846
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   847
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   848
     * Get the name of this function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   849
     * @return the name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   850
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   851
    public String getName() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   852
        return name;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   853
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   854
17752
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   855
    /**
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   856
     * Set the internal name for this function
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   857
     * @param lc    lexical context
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   858
     * @param name new name
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   859
     * @return new function node if changed, otherwise the same
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   860
     */
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   861
    public FunctionNode setName(final LexicalContext lc, final String name) {
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   862
        if (this.name.equals(name)) {
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   863
            return this;
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   864
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   865
        return Node.replaceInLexicalContext(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   866
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   867
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   868
                new FunctionNode(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   869
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   870
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   871
                        endParserState,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   872
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   873
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   874
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   875
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   876
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   877
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   878
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   879
                        rootClass, source, namespace));
17752
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   880
    }
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   881
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   882
    /**
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26250
diff changeset
   883
     * Check if this function should have all its variables in its own scope. Split sub-functions, and
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   884
     * functions having with and/or eval blocks are such.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   885
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   886
     * @return true if all variables should be in scope
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   887
     */
16252
3bfe9b68a0fa 8008648: Lazy JIT scope and callee semantics bugfixes. Broke out wallclock timer.
lagergren
parents: 16245
diff changeset
   888
    public boolean allVarsInScope() {
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26250
diff changeset
   889
        return getFlag(HAS_ALL_VARS_IN_SCOPE);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   890
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   891
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   892
    /**
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   893
     * Checks if this function is split into several smaller fragments.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   894
     *
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   895
     * @return true if this function is split into several smaller fragments.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   896
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   897
    public boolean isSplit() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   898
        return getFlag(IS_SPLIT);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   899
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   900
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   901
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   902
     * Get the parameters to this function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   903
     * @return a list of IdentNodes which represent the function parameters, in order
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   904
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   905
    public List<IdentNode> getParameters() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   906
        return Collections.unmodifiableList(parameters);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   907
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   908
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   909
    /**
32434
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
   910
     * Return the number of parameters to this function
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
   911
     * @return the number of parameters
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
   912
     */
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
   913
    public int getNumOfParams() {
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
   914
        return parameters.size();
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
   915
    }
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
   916
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
   917
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   918
     * Returns the identifier for a named parameter at the specified position in this function's parameter list.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   919
     * @param index the parameter's position.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   920
     * @return the identifier for the requested named parameter.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   921
     * @throws IndexOutOfBoundsException if the index is invalid.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   922
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   923
    public IdentNode getParameter(final int index) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   924
        return parameters.get(index);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   925
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   926
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   927
    /**
17518
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   928
     * Reset the compile unit used to compile this function
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   929
     * @see Compiler
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   930
     * @param  lc lexical context
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   931
     * @param  parameters the compile unit
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   932
     * @return function node or a new one if state was changed
16523
af8b30edebce 8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents: 16252
diff changeset
   933
     */
17518
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   934
    public FunctionNode setParameters(final LexicalContext lc, final List<IdentNode> parameters) {
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   935
        if (this.parameters == parameters) {
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   936
            return this;
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17255
diff changeset
   937
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   938
        return Node.replaceInLexicalContext(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   939
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   940
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   941
                new FunctionNode(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   942
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   943
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   944
                        endParserState,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   945
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   946
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   947
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   948
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   949
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   950
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   951
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   952
                        rootClass, source, namespace));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   953
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   954
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   955
    /**
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
   956
     * Check if this function is created as a function declaration (as opposed to function expression)
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
   957
     * @return true if function is declared.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   958
     */
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
   959
    public boolean isDeclared() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   960
        return getFlag(IS_DECLARED);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   961
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   962
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   963
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   964
     * Check if this function is anonymous
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   965
     * @return true if function is anonymous
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   966
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   967
    public boolean isAnonymous() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   968
        return getFlag(IS_ANONYMOUS);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   969
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   970
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   971
    /**
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   972
     * Does this function use its self symbol - this is needed only for self-referencing named function expressions.
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   973
     * Self-referencing declared functions won't have this flag set, as they can access their own symbol through the
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   974
     * scope (since they're bound to the symbol with their name in their enclosing scope).
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   975
     * @return true if this function node is a named function expression that uses the symbol for itself.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   976
     */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   977
    public boolean usesSelfSymbol() {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   978
        return getFlag(USES_SELF_SYMBOL);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   979
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   980
27822
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
   981
    /**
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
   982
     * Returns true if this is a named function expression (that is, it isn't a declared function, it isn't an
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
   983
     * anonymous function expression, and it isn't a program).
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
   984
     * @return true if this is a named function expression
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
   985
     */
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
   986
    public boolean isNamedFunctionExpression() {
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
   987
        return !getFlag(IS_PROGRAM | IS_ANONYMOUS | IS_DECLARED);
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
   988
    }
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
   989
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   990
    @Override
28130
433d6755c5f8 8067774: Use a stack of types when calculating local variable types
attila
parents: 27822
diff changeset
   991
    public Type getType() {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   992
        return FUNCTION_TYPE;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   993
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   994
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   995
    @Override
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   996
    public Type getWidestOperationType() {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
   997
        return FUNCTION_TYPE;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   998
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   999
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1000
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1001
     * Get the return type for this function. Return types can be specialized
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1002
     * if the compiler knows them, but parameters cannot, as they need to go through
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1003
     * appropriate object conversion
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1004
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1005
     * @return the return type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1006
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1007
    public Type getReturnType() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1008
        return returnType;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1009
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1010
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1011
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1012
     * Set the function return type
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1013
     * @param lc lexical context
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1014
     * @param returnType new return type
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1015
     * @return function node or a new one if state was changed
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1016
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1017
    public FunctionNode setReturnType(final LexicalContext lc, final Type returnType) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1018
        //we never bother with object types narrower than objects, that will lead to byte code verification errors
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1019
        //as for instance even if we know we are returning a string from a method, the code generator will always
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1020
        //treat it as an object, at least for now
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1021
        final Type type = returnType.isObject() ? Type.OBJECT : returnType;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1022
        if (this.returnType == type) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1023
            return this;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1024
        }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1025
        return Node.replaceInLexicalContext(
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1026
            lc,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1027
            this,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1028
            new FunctionNode(
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1029
                this,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1030
                lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
  1031
                endParserState,
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1032
                flags,
17752
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
  1033
                name,
19095
0b215bda525d 8020718: RETURN symbol has wrong type in split functions
hannesw
parents: 19084
diff changeset
  1034
                type,
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1035
                compileUnit,
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1036
                body,
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1037
                parameters,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1038
                thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
  1039
                rootClass, source, namespace
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24720
diff changeset
  1040
                ));
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
  1041
   }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1042
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1043
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1044
     * Check if the function is generated in strict mode
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1045
     * @return true if strict mode enabled for function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1046
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1047
    public boolean isStrict() {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1048
        return getFlag(IS_STRICT);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1049
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1050
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1051
    /**
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1052
     * Returns true if this function node has been cached.
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1053
     * @return true if this function node has been cached.
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1054
     */
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1055
    public boolean isCached() {
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1056
        return getFlag(IS_CACHED);
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1057
    }
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1058
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1059
    /**
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1060
     * Mark this function node as having been cached.
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1061
     * @param lc the current lexical context
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1062
     * @return a function node equivalent to this one, with the flag set.
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1063
     */
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1064
    public FunctionNode setCached(final LexicalContext lc) {
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1065
        return setFlag(lc, IS_CACHED);
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1066
    }
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1067
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1068
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1069
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1070
     * Get the compile unit used to compile this function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1071
     * @see Compiler
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1072
     * @return the compile unit
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1073
     */
26500
85ea77a73bb8 8057588: Lots of trivial (empty) classes were generated by the Nashorn compiler as part of restOf-method generation
lagergren
parents: 26377
diff changeset
  1074
    @Override
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1075
    public CompileUnit getCompileUnit() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1076
        return compileUnit;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1077
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1078
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1079
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1080
     * Reset the compile unit used to compile this function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1081
     * @see Compiler
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1082
     * @param lc lexical context
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1083
     * @param compileUnit the compile unit
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1084
     * @return function node or a new one if state was changed
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1085
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1086
    public FunctionNode setCompileUnit(final LexicalContext lc, final CompileUnit compileUnit) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1087
        if (this.compileUnit == compileUnit) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1088
            return this;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1089
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1090
        return Node.replaceInLexicalContext(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1091
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1092
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1093
                new FunctionNode(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1094
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1095
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
  1096
                        endParserState,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1097
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1098
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1099
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1100
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1101
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1102
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1103
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
  1104
                        rootClass, source, namespace));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1105
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1106
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1107
    /**
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1108
     * Create a temporary variable to the current frame.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1109
     *
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1110
     * @param block that needs the temporary
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1111
     * @param type  Strong type of symbol.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1112
     * @param node  Primary node to use symbol.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1113
     *
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1114
     * @return Symbol used.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1115
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1116
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1117
    /**
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1118
     * Get the symbol for a compiler constant, or null if not available (yet)
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1119
     * @param cc compiler constant
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1120
     * @return symbol for compiler constant, or null if not defined yet (for example in Lower)
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1121
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1122
    public Symbol compilerConstant(final CompilerConstants cc) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1123
        return body.getExistingSymbol(cc.symbolName());
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1124
    }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1125
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1126
    /**
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1127
     * Get the root class that this function node compiles to
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1128
     * @return root class
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1129
     */
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1130
    public Class<?> getRootClass() {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1131
        return rootClass;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1132
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1133
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1134
    /**
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1135
     * Reset the root class that this function is compiled to
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1136
     * @see Compiler
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1137
     * @param lc lexical context
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1138
     * @param rootClass root class
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1139
     * @return function node or a new one if state was changed
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1140
     */
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1141
    public FunctionNode setRootClass(final LexicalContext lc, final Class<?> rootClass) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1142
        if (this.rootClass == rootClass) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1143
            return this;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1144
        }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1145
        return Node.replaceInLexicalContext(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1146
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1147
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1148
                new FunctionNode(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1149
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1150
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
  1151
                        endParserState,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1152
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1153
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1154
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1155
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1156
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1157
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1158
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
  1159
                        rootClass, source, namespace));
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1160
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1161
}