nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/FunctionNode.java
author sundar
Mon, 31 Aug 2015 17:51:02 +0530
changeset 32434 769b3d81ae69
parent 28130 433d6755c5f8
child 32435 cfd619ef23a6
permissions -rw-r--r--
8134731: Function.prototype.apply interacts incorrectly with arguments 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;
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
    36
import java.util.EnumSet;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
    37
import java.util.Iterator;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    38
import java.util.List;
26250
84bbd0e8b2b2 8056025: CompilationPhase.setStates() is hot in class installation phase
attila
parents: 26068
diff changeset
    39
import jdk.nashorn.internal.AssertsEnabled;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    40
import jdk.nashorn.internal.codegen.CompileUnit;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    41
import jdk.nashorn.internal.codegen.Compiler;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    42
import jdk.nashorn.internal.codegen.CompilerConstants;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    43
import jdk.nashorn.internal.codegen.Namespace;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    44
import jdk.nashorn.internal.codegen.types.Type;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    45
import jdk.nashorn.internal.ir.annotations.Ignore;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    46
import jdk.nashorn.internal.ir.annotations.Immutable;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    47
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
    48
import jdk.nashorn.internal.parser.Token;
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
    49
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
    50
import jdk.nashorn.internal.runtime.ScriptFunction;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    51
import jdk.nashorn.internal.runtime.Source;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    52
import jdk.nashorn.internal.runtime.UserAccessorProperty;
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
    53
import jdk.nashorn.internal.runtime.linker.LinkerCallSite;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    54
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    55
/**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    56
 * IR representation for function (or script.)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    57
 */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    58
@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
    59
public final class FunctionNode extends LexicalContextExpression implements Flags<FunctionNode>, CompileUnitHolder {
27204
06ec78f29a56 8059843: Make AST serializable
attila
parents: 27102
diff changeset
    60
    private static final long serialVersionUID = 1L;
06ec78f29a56 8059843: Make AST serializable
attila
parents: 27102
diff changeset
    61
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    62
    /** Type used for all FunctionNodes */
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    63
    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
    64
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    65
    /** Function kinds */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    66
    public enum Kind {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    67
        /** a normal function - nothing special */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    68
        NORMAL,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    69
        /** a script function */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    70
        SCRIPT,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    71
        /** a getter, @see {@link UserAccessorProperty} */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    72
        GETTER,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    73
        /** a setter, @see {@link UserAccessorProperty} */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    74
        SETTER
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    75
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    76
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
    77
    /** Compilation states available */
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
    78
    public enum CompilationState {
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
    79
        /** compiler is ready */
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
    80
        INITIALIZED,
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
    81
        /** method has been parsed */
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
    82
        PARSED,
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
    83
        /** method has been parsed */
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
    84
        PARSE_ERROR,
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
    85
        /** constant folding pass */
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
    86
        CONSTANT_FOLDED,
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
    87
        /** method has been lowered */
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
    88
        LOWERED,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    89
        /** program points have been assigned to unique locations */
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    90
        PROGRAM_POINTS_ASSIGNED,
26056
a64f0cd60e66 8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents: 26055
diff changeset
    91
        /** any transformations of builtins have taken place, e.g. apply=&gt;call */
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    92
        BUILTINS_TRANSFORMED,
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
    93
        /** method has been split */
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
    94
        SPLIT,
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
    95
        /** method has had symbols assigned */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
    96
        SYMBOLS_ASSIGNED,
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
    97
        /** computed scope depths for symbols */
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
    98
        SCOPE_DEPTHS_COMPUTED,
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
    99
        /** method has had types calculated*/
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   100
        OPTIMISTIC_TYPES_ASSIGNED,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   101
        /** method has had types calculated */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   102
        LOCAL_VARIABLE_TYPES_CALCULATED,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   103
        /** compile units reused (optional) */
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   104
        COMPILE_UNITS_REUSED,
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   105
        /** method has been emitted to bytecode */
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   106
        BYTECODE_GENERATED,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   107
        /** method has been installed */
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   108
        BYTECODE_INSTALLED
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
   109
    }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   110
17523
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   111
    /** Source of entity. */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   112
    private transient final Source source;
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   113
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   114
    /**
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   115
     * 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
   116
     * to skip parsing inner functions.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   117
     */
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   118
    private final Object endParserState;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   119
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   120
    /** External function identifier. */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   121
    @Ignore
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   122
    private final IdentNode ident;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   123
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   124
    /** The body of the function node */
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   125
    private final Block body;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   126
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   127
    /** Internal function name. */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   128
    private final String name;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   129
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   130
    /** Compilation unit. */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   131
    private final CompileUnit compileUnit;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   132
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   133
    /** Function kind. */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   134
    private final Kind kind;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   135
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   136
    /** List of parameters. */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   137
    private final List<IdentNode> parameters;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   138
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   139
    /** First token of function. **/
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   140
    private final long firstToken;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   141
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   142
    /** Last token of function. **/
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   143
    private final long lastToken;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   144
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   145
    /** Method's namespace. */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   146
    private transient final Namespace namespace;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   147
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   148
    /** Current compilation state */
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   149
    @Ignore
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   150
    private final EnumSet<CompilationState> compilationState;
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   151
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   152
    /** 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
   153
    @Ignore
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   154
    private final int thisProperties;
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   155
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   156
    /** Function flags. */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   157
    private final int flags;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   158
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
   159
    /** Line number of function start */
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   160
    private final int lineNumber;
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   161
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   162
    /** 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
   163
    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
   164
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   165
    /** Is anonymous function flag. */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   166
    public static final int IS_ANONYMOUS                = 1 << 0;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   167
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
   168
    /** 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
   169
    public static final int IS_DECLARED                 = 1 << 1;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   170
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   171
    /** is this a strict mode function? */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   172
    public static final int IS_STRICT                   = 1 << 2;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   173
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   174
    /** Does the function use the "arguments" identifier ? */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   175
    public static final int USES_ARGUMENTS              = 1 << 3;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   176
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   177
    /** Has this function been split because it was too large? */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   178
    public static final int IS_SPLIT                    = 1 << 4;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   179
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17233
diff changeset
   180
    /** 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
   181
     * introduce new variables into this function's scope too.*/
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   182
    public static final int HAS_EVAL                    = 1 << 5;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   183
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17233
diff changeset
   184
    /** 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
   185
    public static final int HAS_NESTED_EVAL             = 1 << 6;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   186
18853
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   187
    /** 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
   188
     * 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
   189
    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
   190
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   191
    /**
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   192
     * 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
   193
     * 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
   194
     * 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
   195
     * ECMAScript 5.1 Chapter 10.5).
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   196
     * @see #needsArguments()
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   197
     */
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   198
    public static final int DEFINES_ARGUMENTS           = 1 << 8;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   199
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   200
    /** 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
   201
    public static final int USES_ANCESTOR_SCOPE         = 1 << 9;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   202
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   203
    /** Does this function have nested declarations? */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   204
    public static final int HAS_FUNCTION_DECLARATIONS   = 1 << 10;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   205
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   206
    /** 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
   207
    public static final int IS_DEOPTIMIZABLE            = 1 << 11;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   208
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   209
    /** 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
   210
    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
   211
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   212
    /**
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   213
     * Is this function the top-level program?
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   214
     */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   215
    public static final int IS_PROGRAM = 1 << 13;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   216
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   217
    /**
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   218
     * 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
   219
     * 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
   220
     * 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
   221
     */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   222
    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
   223
23372
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   224
    /** Does this function use the "this" keyword? */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   225
    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
   226
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
   227
    /** Is this declared in a dynamic context */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   228
    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
   229
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   230
    /**
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   231
     * 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
   232
     * 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
   233
     */
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   234
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26503
diff changeset
   235
    /** parser, print parse tree */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   236
    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
   237
    /** parser, print lower parse tree */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   238
    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
   239
    /** parser, print AST */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   240
    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
   241
    /** parser, print lower AST */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   242
    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
   243
    /** parser, print symbols */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   244
    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
   245
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26503
diff changeset
   246
    // 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
   247
    /** profile callsites in this function? */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   248
    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
   249
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   250
    /** trace callsite enterexit in this function? */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   251
    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
   252
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   253
    /** trace callsite misses in this function? */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   254
    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
   255
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   256
    /** trace callsite values in this function? */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   257
    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
   258
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   259
    /**
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   260
     * 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
   261
     * 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
   262
     * Rather, it is always calculated (see {@link #needsCallee()}). {@link RecompilableScriptFunctionData}
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   263
     * will, however, cache the value of this flag.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   264
     */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   265
    public static final int NEEDS_CALLEE       = 1 << 26;
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   266
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   267
    /** 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
   268
    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
   269
        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
   270
        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
   271
        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
   272
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17233
diff changeset
   273
    /** Does this function or any nested functions contain an eval? */
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17233
diff changeset
   274
    private static final int HAS_DEEP_EVAL = HAS_EVAL | HAS_NESTED_EVAL;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   275
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   276
    /** Does this function need to store all its variables in scope? */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   277
    private static final int HAS_ALL_VARS_IN_SCOPE = HAS_DEEP_EVAL;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   278
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   279
    /** 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
   280
    private static final int MAYBE_NEEDS_ARGUMENTS = USES_ARGUMENTS | HAS_EVAL;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   281
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   282
    /** 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
   283
    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
   284
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   285
    /** 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
   286
    private Type returnType = Type.UNKNOWN;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   287
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   288
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   289
     * Constructor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   290
     *
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   291
     * @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
   292
     * @param lineNumber line number
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   293
     * @param token      token
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   294
     * @param finish     finish
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   295
     * @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
   296
     * @param lastToken  lastToken
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   297
     * @param namespace  the namespace
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   298
     * @param ident      the identifier
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   299
     * @param name       the name of the function
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   300
     * @param parameters parameter list
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   301
     * @param kind       kind of function as in {@link FunctionNode.Kind}
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   302
     * @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
   303
     * @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
   304
     * @param state      The initial state from the parser. Must be one of {@link CompilationState#PARSED} and {@link CompilationState#PARSE_ERROR}
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   305
     * @param endParserState The parser state at the end of the parsing.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   306
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   307
    public FunctionNode(
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   308
        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
   309
        final int lineNumber,
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   310
        final long token,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   311
        final int finish,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   312
        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
   313
        final long lastToken,
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   314
        final Namespace namespace,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   315
        final IdentNode ident,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   316
        final String name,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   317
        final List<IdentNode> parameters,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   318
        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
   319
        final int flags,
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   320
        final Block body,
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   321
        final CompilationState state,
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   322
        final Object endParserState) {
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   323
        super(token, finish);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   324
17523
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   325
        this.source           = source;
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   326
        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
   327
        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
   328
        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
   329
        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
   330
        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
   331
        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
   332
        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
   333
        this.namespace        = namespace;
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   334
        this.compilationState = EnumSet.of(CompilationState.INITIALIZED, state);
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.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
   336
        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
   337
        this.body             = body;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   338
        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
   339
        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
   340
        this.endParserState    = endParserState;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   341
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   342
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
   343
    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
   344
        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
   345
        final long lastToken,
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26503
diff changeset
   346
        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
   347
        final int flags,
17752
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   348
        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
   349
        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
   350
        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
   351
        final EnumSet<CompilationState> compilationState,
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
   352
        final Block body,
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   353
        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
   354
        final int thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   355
        final Class<?> rootClass,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   356
        final Source source, Namespace namespace) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   357
        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
   358
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   359
        this.endParserState    = endParserState;
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   360
        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
   361
        this.flags            = flags;
17752
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   362
        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
   363
        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
   364
        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
   365
        this.lastToken        = lastToken;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   366
        this.compilationState = compilationState;
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
   367
        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
   368
        this.parameters       = parameters;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   369
        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
   370
        this.rootClass        = rootClass;
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   371
        this.source           = source;
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   372
        this.namespace        = namespace;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   373
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   374
        // 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
   375
        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
   376
        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
   377
        this.firstToken      = functionNode.firstToken;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   378
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   379
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   380
    @Override
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
   381
    public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   382
        if (visitor.enterFunctionNode(this)) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   383
            return visitor.leaveFunctionNode(setBody(lc, (Block)body.accept(visitor)));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   384
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   385
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   386
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   387
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   388
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   389
     * Visits the parameter nodes of this function. Parameters are normally not visited automatically.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   390
     * @param visitor the visitor to apply to the nodes.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   391
     * @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
   392
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   393
    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
   394
        return Node.accept(visitor, parameters);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   395
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   396
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   397
    /**
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   398
     * 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
   399
     *
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   400
     * @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
   401
     */
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   402
    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
   403
        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
   404
        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
   405
            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
   406
        }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   407
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   408
        // 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
   409
        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
   410
            return callsiteFlags;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   411
        }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   412
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   413
        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
   414
            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
   415
        }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   416
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   417
        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
   418
            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
   419
        }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   420
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   421
        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
   422
            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
   423
        }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   424
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   425
        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
   426
            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
   427
        }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   428
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   429
        return callsiteFlags;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   430
    }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   431
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   432
    /**
17523
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   433
     * 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
   434
     * @return the source
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   435
     */
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   436
    public Source getSource() {
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   437
        return source;
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   438
    }
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   439
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   440
    /**
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   441
     * 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
   442
     * 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
   443
     * a deserialized function node.
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   444
     * @param source the source for the function.
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   445
     * @param namespace the namespace for the function
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   446
     * @return a new function node with the set source and namespace
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   447
     * @throws IllegalArgumentException if the specified source or namespace is null
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   448
     * @throws IllegalStateException if the function already has either a source or namespace set.
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   449
     */
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   450
    public FunctionNode initializeDeserialized(final Source source, final Namespace namespace) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   451
        if (source == null || namespace == null) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   452
            throw new IllegalArgumentException();
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   453
        } else if (this.source == source && this.namespace == namespace) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   454
            return this;
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   455
        } else if (this.source != null || this.namespace != null) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   456
            throw new IllegalStateException();
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   457
        }
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   458
        return new FunctionNode(
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   459
            this,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   460
            lastToken,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   461
            endParserState,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   462
            flags,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   463
            name,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   464
            returnType,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   465
            compileUnit,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   466
            compilationState,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   467
            body,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   468
            parameters,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   469
            thisProperties,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   470
            rootClass, source, namespace);
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   471
    }
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   472
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   473
    /**
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   474
     * Get the unique ID for this function within the script file.
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   475
     * @return the id
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   476
     */
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   477
    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
   478
        return isProgram() ? -1: Token.descPosition(firstToken);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   479
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   480
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   481
    /**
22390
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   482
     * get source name - sourceURL or name derived from Source.
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   483
     *
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   484
     * @return name for the script source
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   485
     */
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   486
    public String getSourceName() {
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   487
        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
   488
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   489
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   490
    /**
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
   491
     * 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
   492
     *
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   493
     * @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
   494
     * @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
   495
     */
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   496
    public static String getSourceName(final Source source) {
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   497
        final String explicitURL = source.getExplicitURL();
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   498
        return explicitURL != null ? explicitURL : source.getName();
22390
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   499
    }
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   500
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   501
    /**
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   502
     * Function to parse nashorn per-function extension directive comments.
22390
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   503
     *
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   504
     * @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
   505
     * @return integer flag for the given directive.
22390
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   506
     */
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   507
    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
   508
        switch (directive) {
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   509
            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
   510
                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
   511
            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
   512
                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
   513
            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
   514
                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
   515
            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
   516
                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
   517
            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
   518
                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
   519
            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
   520
                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
   521
            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
   522
                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
   523
            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
   524
                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
   525
            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
   526
                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
   527
            default:
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   528
                // 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
   529
                return 0;
22390
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   530
        }
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   531
    }
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   532
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   533
    /**
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   534
     * Returns the line number.
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   535
     * @return the line number.
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   536
     */
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   537
    public int getLineNumber() {
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   538
        return lineNumber;
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   539
    }
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   540
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   541
    /**
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   542
     * Get the compilation state of this function
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   543
     * @return the compilation state
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   544
     */
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   545
    public EnumSet<CompilationState> getState() {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   546
        return compilationState;
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   547
    }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   548
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   549
    /**
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   550
     * Check whether this FunctionNode has reached a give CompilationState.
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   551
     *
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   552
     * @param state the state to check for
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   553
     * @return true of the node is in the given state
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   554
     */
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   555
    public boolean hasState(final EnumSet<CompilationState> state) {
26250
84bbd0e8b2b2 8056025: CompilationPhase.setStates() is hot in class installation phase
attila
parents: 26068
diff changeset
   556
        return !AssertsEnabled.assertsEnabled() || compilationState.containsAll(state);
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   557
    }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   558
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   559
    /**
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   560
     * Add a state to the total CompilationState of this node, e.g. if
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   561
     * FunctionNode has been lowered, the compiler will add
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   562
     * {@code CompilationState#LOWERED} to the state vector
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   563
     *
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   564
     * @param lc lexical context
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   565
     * @param state {@link CompilationState} to add
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   566
     * @return function node or a new one if state was changed
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   567
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   568
    public FunctionNode setState(final LexicalContext lc, final CompilationState state) {
26250
84bbd0e8b2b2 8056025: CompilationPhase.setStates() is hot in class installation phase
attila
parents: 26068
diff changeset
   569
        if (!AssertsEnabled.assertsEnabled() || this.compilationState.contains(state)) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   570
            return this;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   571
        }
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   572
        final EnumSet<CompilationState> newState = EnumSet.copyOf(this.compilationState);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   573
        newState.add(state);
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   574
        return setCompilationState(lc, newState);
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   575
    }
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   576
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   577
    /**
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   578
     * Copy a compilation state from an original function to this function. Used when creating synthetic
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   579
     * function nodes by the splitter.
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   580
     *
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   581
     * @param lc lexical context
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   582
     * @param original the original function node to copy compilation state from
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   583
     * @return function node or a new one if state was changed
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   584
     */
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   585
    public FunctionNode copyCompilationState(final LexicalContext lc, final FunctionNode original) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   586
        final EnumSet<CompilationState> origState = original.compilationState;
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   587
        if (!AssertsEnabled.assertsEnabled() || this.compilationState.containsAll(origState)) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   588
            return this;
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   589
        }
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   590
        final EnumSet<CompilationState> newState = EnumSet.copyOf(this.compilationState);
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   591
        newState.addAll(origState);
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   592
        return setCompilationState(lc, newState);
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   593
    }
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   594
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   595
    private FunctionNode setCompilationState(final LexicalContext lc, final EnumSet<CompilationState> compilationState) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   596
        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
   597
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   598
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   599
                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
   600
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   601
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   602
                        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
   603
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   604
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   605
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   606
                        compileUnit,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   607
                        compilationState,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   608
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   609
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   610
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   611
                        rootClass, source, namespace));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16187
diff changeset
   612
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   613
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   614
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16187
diff changeset
   615
    /**
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   616
     * Create a unique name in the namespace of this FunctionNode
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   617
     * @param base prefix for name
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   618
     * @return base if no collision exists, otherwise a name prefix with base
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   619
     */
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   620
    public String uniqueName(final String base) {
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   621
        return namespace.uniqueName(base);
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   622
    }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   623
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   624
    @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
   625
    public void toString(final StringBuilder sb, final boolean printTypes) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   626
        sb.append('[').
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   627
            append(returnType).
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   628
            append(']').
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   629
            append(' ');
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16187
diff changeset
   630
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   631
        sb.append("function");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   632
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   633
        if (ident != null) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   634
            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
   635
            ident.toString(sb, printTypes);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   636
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   637
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   638
        sb.append('(');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   639
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   640
        for (final Iterator<IdentNode> iter = parameters.iterator(); iter.hasNext(); ) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   641
            final IdentNode parameter = iter.next();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   642
            if (parameter.getSymbol() != null) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   643
                sb.append('[').append(parameter.getType()).append(']').append(' ');
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   644
            }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   645
            parameter.toString(sb, printTypes);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   646
            if (iter.hasNext()) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   647
                sb.append(", ");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   648
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   649
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   650
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   651
        sb.append(')');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   652
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   653
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   654
    @Override
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   655
    public int getFlags() {
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   656
        return flags;
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
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   659
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   660
    public boolean getFlag(final int flag) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   661
        return (flags & flag) != 0;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   662
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   663
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   664
    @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
   665
    public FunctionNode setFlags(final LexicalContext lc, final int flags) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   666
        if (this.flags == flags) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   667
            return this;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   668
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   669
        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
   670
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   671
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   672
                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
   673
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   674
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   675
                        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
   676
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   677
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   678
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   679
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   680
                        compilationState,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   681
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   682
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   683
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   684
                        rootClass, source, namespace));
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   685
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   686
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   687
    @Override
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   688
    public FunctionNode clearFlag(final LexicalContext lc, final int flag) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   689
        return setFlags(lc, flags & ~flag);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   690
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   691
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   692
    @Override
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   693
    public FunctionNode setFlag(final LexicalContext lc, final int flag) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   694
        return setFlags(lc, flags | flag);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   695
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   696
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   697
    /**
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
   698
     * 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
   699
     * @return True if this function node represents the top-level program.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   700
     */
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
   701
    public boolean isProgram() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   702
        return getFlag(IS_PROGRAM);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   703
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   704
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   705
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   706
     * 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
   707
     * @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
   708
     */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   709
    public boolean canBeDeoptimized() {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   710
        return getFlag(IS_DEOPTIMIZABLE);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   711
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   712
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   713
    /**
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   714
     * 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
   715
     *
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   716
     * @return true if {@code eval} is called.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   717
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   718
    public boolean hasEval() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   719
        return getFlag(HAS_EVAL);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   720
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   721
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   722
    /**
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   723
     * 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
   724
     *
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   725
     * @return true if a nested function calls {@code eval}.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   726
     */
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   727
    public boolean hasNestedEval() {
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   728
        return getFlag(HAS_NESTED_EVAL);
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   729
    }
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   730
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   731
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   732
     * Get the first token for this function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   733
     * @return the first token
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   734
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   735
    public long getFirstToken() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   736
        return firstToken;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   737
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   738
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   739
    /**
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   740
     * Check whether this function has nested function declarations
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   741
     * @return true if nested function declarations exist
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   742
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   743
    public boolean hasDeclaredFunctions() {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   744
        return getFlag(HAS_FUNCTION_DECLARATIONS);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   745
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   746
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   747
    /**
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   748
     * 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
   749
     * 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
   750
     * (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
   751
     * 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
   752
     *
24740
26791be09688 8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents: 24738
diff changeset
   753
     * 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
   754
     * 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
   755
     *
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   756
     * @return true if the function's generated Java method needs a {@code callee} parameter.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   757
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   758
    public boolean needsCallee() {
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   759
        // NOTE: we only need isSplit() here to ensure that :scope can never drop below slot 2 for splitting array units.
24740
26791be09688 8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents: 24738
diff changeset
   760
        return needsParentScope() || usesSelfSymbol() || isSplit() || (needsArguments() && !isStrict()) || hasOptimisticApplyToCall();
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   761
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   762
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   763
    /**
23372
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   764
     * 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
   765
     *
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   766
     * @return true if function uses {@code this} object
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   767
     */
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   768
    public boolean usesThis() {
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   769
        return getFlag(USES_THIS);
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   770
    }
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   771
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   772
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   773
    /**
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   774
     * 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
   775
     * @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
   776
     */
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   777
    public boolean hasOptimisticApplyToCall() {
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   778
        return getFlag(HAS_APPLY_TO_CALL_SPECIALIZATION);
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   779
    }
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   780
23372
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   781
    /**
17752
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   782
     * Get the identifier for this function, this is its symbol.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   783
     * @return the identifier as an IdentityNode
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   784
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   785
    public IdentNode getIdent() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   786
        return ident;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   787
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   788
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   789
    /**
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   790
     * Get the function body
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   791
     * @return the function body
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   792
     */
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   793
    public Block getBody() {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   794
        return body;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   795
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   796
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   797
    /**
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   798
     * Reset the function body
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   799
     * @param lc lexical context
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   800
     * @param body new body
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   801
     * @return new function node if body changed, same if not
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   802
     */
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   803
    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
   804
        if (this.body == body) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   805
            return this;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   806
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   807
        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
   808
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   809
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   810
                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
   811
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   812
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   813
                        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
   814
                        flags |
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   815
                            (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
   816
                                    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
   817
                                    0),
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   818
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   819
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   820
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   821
                        compilationState,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   822
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   823
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   824
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   825
                        rootClass, source, namespace));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   826
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   827
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   828
    /**
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   829
     * 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
   830
     * {@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
   831
     * 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
   832
     * @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
   833
     * @see #needsArguments()
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   834
     * @see LinkerCallSite#ARGLIMIT
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   835
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   836
    public boolean isVarArg() {
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   837
        return needsArguments() || parameters.size() > LinkerCallSite.ARGLIMIT;
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   838
    }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   839
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   840
    /**
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
   841
     * 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
   842
     * 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
   843
     * @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
   844
     */
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
   845
    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
   846
        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
   847
    }
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
   848
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
   849
    /**
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
   850
     * 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
   851
     * 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
   852
     * @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
   853
     */
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
   854
    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
   855
        // 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
   856
        // 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
   857
        // 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
   858
        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
   859
    }
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
   860
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
   861
    /**
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
   862
     * 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
   863
     * @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
   864
     * @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
   865
     */
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
   866
    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
   867
        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
   868
    }
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
   869
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
   870
    /**
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   871
     * 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
   872
     * 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
   873
     * (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
   874
     * 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
   875
     * "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
   876
     * "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
   877
     * @return true if this function needs an arguments object.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   878
     */
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   879
    public boolean needsArguments() {
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   880
        // 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
   881
        // 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
   882
        return getFlag(MAYBE_NEEDS_ARGUMENTS) && !getFlag(DEFINES_ARGUMENTS) && !isProgram();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   883
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   884
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   885
    /**
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   886
     * 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
   887
     * 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
   888
     * 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
   889
     * 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
   890
     * @return true if the function needs parent scope.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   891
     */
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   892
    public boolean needsParentScope() {
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   893
        return getFlag(NEEDS_PARENT_SCOPE);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   894
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   895
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   896
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   897
     * Set the number of properties assigned to the this object in this function.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   898
     * @param lc the current lexical context.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   899
     * @param thisProperties number of properties
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   900
     * @return a potentially modified function node
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   901
     */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   902
    public FunctionNode setThisProperties(final LexicalContext lc, final int thisProperties) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   903
        if (this.thisProperties == thisProperties) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   904
            return this;
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   905
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   906
        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
   907
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   908
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   909
                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
   910
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   911
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   912
                        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
   913
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   914
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   915
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   916
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   917
                        compilationState,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   918
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   919
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   920
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   921
                        rootClass, source, namespace));
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   922
    }
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   923
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   924
    /**
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   925
     * 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
   926
     * @return number of properties
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   927
     */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   928
    public int getThisProperties() {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   929
        return thisProperties;
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   930
    }
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   931
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   932
    /**
18853
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   933
     * 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
   934
     * @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
   935
     */
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   936
    public boolean hasScopeBlock() {
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   937
        return getFlag(HAS_SCOPE_BLOCK);
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   938
    }
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   939
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   940
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   941
     * Return the kind of this function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   942
     * @see FunctionNode.Kind
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   943
     * @return the kind
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   944
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   945
    public Kind getKind() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   946
        return kind;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   947
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   948
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   949
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   950
     * Return the last token for this function's code
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   951
     * @return last token
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   952
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   953
    public long getLastToken() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   954
        return lastToken;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   955
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   956
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   957
    /**
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   958
     * Returns the end parser state for this function.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   959
     * @return the end parser state for this function.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   960
     */
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   961
    public Object getEndParserState() {
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   962
        return endParserState;
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   963
    }
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   964
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   965
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   966
     * Get the name of this function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   967
     * @return the name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   968
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   969
    public String getName() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   970
        return name;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   971
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   972
17752
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   973
    /**
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   974
     * Set the internal name for this function
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   975
     * @param lc    lexical context
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   976
     * @param name new name
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   977
     * @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
   978
     */
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   979
    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
   980
        if (this.name.equals(name)) {
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   981
            return this;
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   982
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   983
        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
   984
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   985
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   986
                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
   987
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   988
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   989
                        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
   990
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   991
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   992
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   993
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   994
                        compilationState,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   995
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   996
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   997
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   998
                        rootClass, source, namespace));
17752
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   999
    }
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
  1000
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1001
    /**
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26250
diff changeset
  1002
     * 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
  1003
     * functions having with and/or eval blocks are such.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1004
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1005
     * @return true if all variables should be in scope
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1006
     */
16252
3bfe9b68a0fa 8008648: Lazy JIT scope and callee semantics bugfixes. Broke out wallclock timer.
lagergren
parents: 16245
diff changeset
  1007
    public boolean allVarsInScope() {
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26250
diff changeset
  1008
        return getFlag(HAS_ALL_VARS_IN_SCOPE);
16147
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
    /**
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
  1012
     * Checks if this function is split into several smaller fragments.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1013
     *
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
  1014
     * @return true if this function is split into several smaller fragments.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1015
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1016
    public boolean isSplit() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1017
        return getFlag(IS_SPLIT);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1018
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1019
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1020
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1021
     * Get the parameters to this function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1022
     * @return a list of IdentNodes which represent the function parameters, in order
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1023
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1024
    public List<IdentNode> getParameters() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1025
        return Collections.unmodifiableList(parameters);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1026
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1027
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1028
    /**
32434
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
  1029
     * Return the number of parameters to this function
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
  1030
     * @return the number of parameters
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
  1031
     */
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
  1032
    public int getNumOfParams() {
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
  1033
        return parameters.size();
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
  1034
    }
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
  1035
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
  1036
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1037
     * 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
  1038
     * @param index the parameter's position.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1039
     * @return the identifier for the requested named parameter.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1040
     * @throws IndexOutOfBoundsException if the index is invalid.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1041
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1042
    public IdentNode getParameter(final int index) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1043
        return parameters.get(index);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1044
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1045
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1046
    /**
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
  1047
     * 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
  1048
     * @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
  1049
     * @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
  1050
     * @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
  1051
     * @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
  1052
     */
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
  1053
    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
  1054
        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
  1055
            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
  1056
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1057
        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
  1058
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1059
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1060
                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
  1061
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1062
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
  1063
                        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
  1064
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1065
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1066
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1067
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1068
                        compilationState,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1069
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1070
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1071
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
  1072
                        rootClass, source, namespace));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1073
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1074
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1075
    /**
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
  1076
     * 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
  1077
     * @return true if function is declared.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1078
     */
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
  1079
    public boolean isDeclared() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1080
        return getFlag(IS_DECLARED);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1081
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1082
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1083
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1084
     * Check if this function is anonymous
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1085
     * @return true if function is anonymous
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1086
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1087
    public boolean isAnonymous() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1088
        return getFlag(IS_ANONYMOUS);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1089
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1090
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1091
    /**
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
  1092
     * 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
  1093
     * 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
  1094
     * scope (since they're bound to the symbol with their name in their enclosing scope).
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
  1095
     * @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
  1096
     */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
  1097
    public boolean usesSelfSymbol() {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1098
        return getFlag(USES_SELF_SYMBOL);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1099
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1100
27822
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
  1101
    /**
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
  1102
     * 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
  1103
     * anonymous function expression, and it isn't a program).
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
  1104
     * @return true if this is a named function expression
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
  1105
     */
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
  1106
    public boolean isNamedFunctionExpression() {
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
  1107
        return !getFlag(IS_PROGRAM | IS_ANONYMOUS | IS_DECLARED);
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
  1108
    }
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
  1109
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1110
    @Override
28130
433d6755c5f8 8067774: Use a stack of types when calculating local variable types
attila
parents: 27822
diff changeset
  1111
    public Type getType() {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1112
        return FUNCTION_TYPE;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1113
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1114
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1115
    @Override
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1116
    public Type getWidestOperationType() {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
  1117
        return FUNCTION_TYPE;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1118
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1119
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1120
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1121
     * Get the return type for this function. Return types can be specialized
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1122
     * if the compiler knows them, but parameters cannot, as they need to go through
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1123
     * appropriate object conversion
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1124
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1125
     * @return the return type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1126
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1127
    public Type getReturnType() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1128
        return returnType;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1129
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1130
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1131
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1132
     * Set the function return type
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1133
     * @param lc lexical context
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1134
     * @param returnType new return type
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1135
     * @return function node or a new one if state was changed
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1136
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1137
    public FunctionNode setReturnType(final LexicalContext lc, final Type returnType) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1138
        //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
  1139
        //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
  1140
        //treat it as an object, at least for now
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1141
        final Type type = returnType.isObject() ? Type.OBJECT : returnType;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1142
        if (this.returnType == type) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1143
            return this;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1144
        }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1145
        return Node.replaceInLexicalContext(
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1146
            lc,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1147
            this,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1148
            new FunctionNode(
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1149
                this,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1150
                lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
  1151
                endParserState,
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1152
                flags,
17752
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
  1153
                name,
19095
0b215bda525d 8020718: RETURN symbol has wrong type in split functions
hannesw
parents: 19084
diff changeset
  1154
                type,
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1155
                compileUnit,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1156
                compilationState,
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1157
                body,
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1158
                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
  1159
                thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
  1160
                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
  1161
                ));
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
  1162
   }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1163
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1164
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1165
     * Check if the function is generated in strict mode
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1166
     * @return true if strict mode enabled for function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1167
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1168
    public boolean isStrict() {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1169
        return getFlag(IS_STRICT);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1170
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1171
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1172
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1173
     * Get the compile unit used to compile this function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1174
     * @see Compiler
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1175
     * @return the compile unit
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1176
     */
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
  1177
    @Override
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1178
    public CompileUnit getCompileUnit() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1179
        return compileUnit;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1180
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1181
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1182
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1183
     * Reset the compile unit used to compile this function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1184
     * @see Compiler
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1185
     * @param lc lexical context
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1186
     * @param compileUnit the compile unit
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1187
     * @return function node or a new one if state was changed
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1188
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1189
    public FunctionNode setCompileUnit(final LexicalContext lc, final CompileUnit compileUnit) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1190
        if (this.compileUnit == compileUnit) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1191
            return this;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1192
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1193
        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
  1194
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1195
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1196
                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
  1197
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1198
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
  1199
                        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
  1200
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1201
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1202
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1203
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1204
                        compilationState,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1205
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1206
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1207
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
  1208
                        rootClass, source, namespace));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1209
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1210
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1211
    /**
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1212
     * Create a temporary variable to the current frame.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1213
     *
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1214
     * @param block that needs the temporary
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1215
     * @param type  Strong type of symbol.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1216
     * @param node  Primary node to use symbol.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1217
     *
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1218
     * @return Symbol used.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1219
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1220
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1221
    /**
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1222
     * Get the symbol for a compiler constant, or null if not available (yet)
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1223
     * @param cc compiler constant
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1224
     * @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
  1225
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1226
    public Symbol compilerConstant(final CompilerConstants cc) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1227
        return body.getExistingSymbol(cc.symbolName());
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1228
    }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1229
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1230
    /**
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1231
     * 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
  1232
     * @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
  1233
     */
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1234
    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
  1235
        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
  1236
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1237
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1238
    /**
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1239
     * 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
  1240
     * @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
  1241
     * @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
  1242
     * @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
  1243
     * @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
  1244
     */
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1245
    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
  1246
        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
  1247
            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
  1248
        }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1249
        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
  1250
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1251
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1252
                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
  1253
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1254
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
  1255
                        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
  1256
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1257
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1258
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1259
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1260
                        compilationState,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1261
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1262
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1263
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
  1264
                        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
  1265
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1266
}