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