author | hannesw |
Wed, 07 Mar 2018 18:36:21 +0100 | |
changeset 49145 | 2854589fd853 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
16147 | 1 |
/* |
47038
f57fa7f112a0
8177691: Labeled break in catch and finally works wrongly, when invoked through nashorn
sdama
parents:
37732
diff
changeset
|
2 |
* Copyright (c) 2010, 2017, 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 |
||
28 |
import java.io.PrintWriter; |
|
29 |
import java.util.ArrayList; |
|
17233 | 30 |
import java.util.Arrays; |
16147 | 31 |
import java.util.Collections; |
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16168
diff
changeset
|
32 |
import java.util.Comparator; |
17233 | 33 |
import java.util.LinkedHashMap; |
16147 | 34 |
import java.util.List; |
17233 | 35 |
import java.util.Map; |
16240
e1468b33e201
8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents:
16234
diff
changeset
|
36 |
import jdk.nashorn.internal.codegen.Label; |
17233 | 37 |
import jdk.nashorn.internal.ir.annotations.Immutable; |
16147 | 38 |
import jdk.nashorn.internal.ir.visitor.NodeVisitor; |
39 |
||
40 |
/** |
|
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
41 |
* IR representation for a list of statements. |
16147 | 42 |
*/ |
17233 | 43 |
@Immutable |
25244
627d7e86f3b5
8047357: More precise synthetic return + unreachable throw
attila
parents:
24759
diff
changeset
|
44 |
public class Block extends Node implements BreakableNode, Terminal, Flags<Block> { |
27204 | 45 |
private static final long serialVersionUID = 1L; |
46 |
||
16147 | 47 |
/** List of statements */ |
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
|
48 |
protected final List<Statement> statements; |
16147 | 49 |
|
17233 | 50 |
/** Symbol table - keys must be returned in the order they were put in. */ |
51 |
protected final Map<String, Symbol> symbols; |
|
16147 | 52 |
|
53 |
/** Entry label. */ |
|
24719 | 54 |
private final Label entryLabel; |
16147 | 55 |
|
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
56 |
/** Break label. */ |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
57 |
private final Label breakLabel; |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
58 |
|
29407 | 59 |
/** Does the block/function need a new scope? Is this synthetic? */ |
17233 | 60 |
protected final int flags; |
61 |
||
24751 | 62 |
/** |
63 |
* @see JoinPredecessor |
|
64 |
*/ |
|
65 |
private final LocalVariableConversion conversion; |
|
66 |
||
17233 | 67 |
/** Flag indicating that this block needs scope */ |
37732 | 68 |
public static final int NEEDS_SCOPE = 1 << 0; |
16147 | 69 |
|
17233 | 70 |
/** |
71 |
* Is this block tagged as terminal based on its contents |
|
72 |
* (usually the last statement) |
|
73 |
*/ |
|
37732 | 74 |
public static final int IS_TERMINAL = 1 << 2; |
16147 | 75 |
|
76 |
/** |
|
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:
24719
diff
changeset
|
77 |
* Is this block the eager global scope - i.e. the original program. This isn't true for the |
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:
24719
diff
changeset
|
78 |
* outermost level of recompiles |
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:
24719
diff
changeset
|
79 |
*/ |
37732 | 80 |
public static final int IS_GLOBAL_SCOPE = 1 << 3; |
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:
24719
diff
changeset
|
81 |
|
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:
24719
diff
changeset
|
82 |
/** |
29407 | 83 |
* Is this block a synthetic one introduced by Parser? |
84 |
*/ |
|
37732 | 85 |
public static final int IS_SYNTHETIC = 1 << 4; |
86 |
||
87 |
/** |
|
88 |
* Is this the function body block? May not be the first, if parameter list contains expressions. |
|
89 |
*/ |
|
90 |
public static final int IS_BODY = 1 << 5; |
|
91 |
||
92 |
/** |
|
93 |
* Is this the parameter initialization block? If present, must be the first block, immediately wrapping the function body block. |
|
94 |
*/ |
|
95 |
public static final int IS_PARAMETER_BLOCK = 1 << 6; |
|
96 |
||
97 |
/** |
|
98 |
* Marks the variable declaration block for case clauses of a switch statement. |
|
99 |
*/ |
|
100 |
public static final int IS_SWITCH_BLOCK = 1 << 7; |
|
29407 | 101 |
|
102 |
/** |
|
47038
f57fa7f112a0
8177691: Labeled break in catch and finally works wrongly, when invoked through nashorn
sdama
parents:
37732
diff
changeset
|
103 |
* Is this block tagged as breakable based on its contents |
f57fa7f112a0
8177691: Labeled break in catch and finally works wrongly, when invoked through nashorn
sdama
parents:
37732
diff
changeset
|
104 |
* (block having labelled break statement) |
f57fa7f112a0
8177691: Labeled break in catch and finally works wrongly, when invoked through nashorn
sdama
parents:
37732
diff
changeset
|
105 |
*/ |
f57fa7f112a0
8177691: Labeled break in catch and finally works wrongly, when invoked through nashorn
sdama
parents:
37732
diff
changeset
|
106 |
public static final int IS_BREAKABLE = 1 << 8; |
f57fa7f112a0
8177691: Labeled break in catch and finally works wrongly, when invoked through nashorn
sdama
parents:
37732
diff
changeset
|
107 |
|
f57fa7f112a0
8177691: Labeled break in catch and finally works wrongly, when invoked through nashorn
sdama
parents:
37732
diff
changeset
|
108 |
/** |
16147 | 109 |
* Constructor |
110 |
* |
|
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
111 |
* @param token The first token of the block |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
112 |
* @param finish The index of the last character |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
113 |
* @param flags The flags of the block |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
114 |
* @param statements All statements in the block |
16147 | 115 |
*/ |
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
116 |
public Block(final long token, final int finish, final int flags, final Statement... statements) { |
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
117 |
super(token, finish); |
16147 | 118 |
|
17233 | 119 |
this.statements = Arrays.asList(statements); |
120 |
this.symbols = new LinkedHashMap<>(); |
|
16147 | 121 |
this.entryLabel = new Label("block_entry"); |
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
122 |
this.breakLabel = new Label("block_break"); |
19100
62d400be5b44
8021244: Inconsistent stackmap with splitter threshold set very low
hannesw
parents:
19095
diff
changeset
|
123 |
final int len = statements.length; |
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
124 |
final int terminalFlags = len > 0 && statements[len - 1].hasTerminalFlags() ? IS_TERMINAL : 0; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
125 |
this.flags = terminalFlags | flags; |
24751 | 126 |
this.conversion = null; |
16147 | 127 |
} |
128 |
||
129 |
/** |
|
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
130 |
* Constructs a new block |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
131 |
* |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
132 |
* @param token The first token of the block |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
133 |
* @param finish The index of the last character |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
134 |
* @param statements All statements in the block |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
135 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
136 |
public Block(final long token, final int finish, final Statement...statements){ |
29407 | 137 |
this(token, finish, IS_SYNTHETIC, statements); |
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
138 |
} |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
139 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
140 |
/** |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
141 |
* Constructs a new block |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
142 |
* |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
143 |
* @param token The first token of the block |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
144 |
* @param finish The index of the last character |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
145 |
* @param statements All statements in the block |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
146 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
147 |
public Block(final long token, final int finish, final List<Statement> statements){ |
29407 | 148 |
this(token, finish, IS_SYNTHETIC, statements); |
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
149 |
} |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
150 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
151 |
/** |
17233 | 152 |
* Constructor |
16147 | 153 |
* |
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
154 |
* @param token The first token of the block |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
155 |
* @param finish The index of the last character |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
156 |
* @param flags The flags of the block |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
157 |
* @param statements All statements in the block |
16147 | 158 |
*/ |
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
159 |
public Block(final long token, final int finish, final int flags, final List<Statement> statements) { |
35407
204abe4d8cbc
8147591: Revisit Collection.toArray(new T[size]) calls in nashorn and dynalink code
mhaupt
parents:
32435
diff
changeset
|
160 |
this(token, finish, flags, statements.toArray(new Statement[0])); |
17233 | 161 |
} |
16147 | 162 |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
163 |
private Block(final Block block, final int finish, final List<Statement> statements, final int flags, final Map<String, Symbol> symbols, final LocalVariableConversion conversion) { |
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
26503
diff
changeset
|
164 |
super(block, finish); |
17233 | 165 |
this.statements = statements; |
166 |
this.flags = flags; |
|
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:
17233
diff
changeset
|
167 |
this.symbols = new LinkedHashMap<>(symbols); //todo - symbols have no dependencies on any IR node and can as far as we understand it be shallow copied now |
16240
e1468b33e201
8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents:
16234
diff
changeset
|
168 |
this.entryLabel = new Label(block.entryLabel); |
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
169 |
this.breakLabel = new Label(block.breakLabel); |
24751 | 170 |
this.conversion = conversion; |
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:
17233
diff
changeset
|
171 |
} |
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:
17233
diff
changeset
|
172 |
|
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:
17233
diff
changeset
|
173 |
/** |
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:
24719
diff
changeset
|
174 |
* Is this block the outermost eager global scope - i.e. the primordial program? |
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:
24719
diff
changeset
|
175 |
* Used for global anchor point for scope depth computation for recompilation code |
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:
24719
diff
changeset
|
176 |
* @return true if outermost eager global scope |
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:
24719
diff
changeset
|
177 |
*/ |
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:
24719
diff
changeset
|
178 |
public boolean isGlobalScope() { |
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:
24719
diff
changeset
|
179 |
return getFlag(IS_GLOBAL_SCOPE); |
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:
24719
diff
changeset
|
180 |
} |
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:
24719
diff
changeset
|
181 |
|
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:
24719
diff
changeset
|
182 |
/** |
32435
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
183 |
* Returns true if this block defines any symbols. |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
184 |
* @return true if this block defines any symbols. |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
185 |
*/ |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
186 |
public boolean hasSymbols() { |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
187 |
return !symbols.isEmpty(); |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
188 |
} |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
189 |
|
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
190 |
/** |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
191 |
* Replaces symbols defined in this block with different symbols. Used to ensure symbol tables are |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
192 |
* immutable upon construction and have copy-on-write semantics. Note that this method only replaces the |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
193 |
* symbols in the symbol table, it does not act on any contained AST nodes that might reference the symbols. |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
194 |
* Those should be updated separately as this method is meant to be used as part of such an update pass. |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
195 |
* @param lc the current lexical context |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
196 |
* @param replacements the map of symbol replacements |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
197 |
* @return a new block with replaced symbols, or this block if none of the replacements modified the symbol |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
198 |
* table. |
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:
17233
diff
changeset
|
199 |
*/ |
32435
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
200 |
public Block replaceSymbols(final LexicalContext lc, final Map<Symbol, Symbol> replacements) { |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
201 |
if (symbols.isEmpty()) { |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
202 |
return this; |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
203 |
} |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
204 |
final LinkedHashMap<String, Symbol> newSymbols = new LinkedHashMap<>(symbols); |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
205 |
for (final Map.Entry<String, Symbol> entry: newSymbols.entrySet()) { |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
206 |
final Symbol newSymbol = replacements.get(entry.getValue()); |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
207 |
assert newSymbol != null : "Missing replacement for " + entry.getKey(); |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
208 |
entry.setValue(newSymbol); |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
209 |
} |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
210 |
return Node.replaceInLexicalContext(lc, this, new Block(this, finish, statements, flags, newSymbols, conversion)); |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
211 |
} |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
212 |
|
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
213 |
/** |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
214 |
* Returns a copy of this block with a shallow copy of the symbol table. |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
215 |
* @return a copy of this block with a shallow copy of the symbol table. |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
216 |
*/ |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
217 |
public Block copyWithNewSymbols() { |
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
218 |
return new Block(this, finish, statements, flags, new LinkedHashMap<>(symbols), conversion); |
16147 | 219 |
} |
220 |
||
221 |
@Override |
|
17233 | 222 |
public Node ensureUniqueLabels(final LexicalContext lc) { |
24751 | 223 |
return Node.replaceInLexicalContext(lc, this, new Block(this, finish, statements, flags, symbols, conversion)); |
16147 | 224 |
} |
225 |
||
226 |
/** |
|
227 |
* Assist in IR navigation. |
|
228 |
* |
|
229 |
* @param visitor IR navigating visitor. |
|
230 |
* @return new or same node |
|
231 |
*/ |
|
232 |
@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:
17524
diff
changeset
|
233 |
public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) { |
17233 | 234 |
if (visitor.enterBlock(this)) { |
25821
fbb51e67d2a7
8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents:
25244
diff
changeset
|
235 |
return visitor.leaveBlock(setStatements(lc, Node.accept(visitor, statements))); |
16147 | 236 |
} |
237 |
||
238 |
return this; |
|
239 |
} |
|
240 |
||
241 |
/** |
|
24751 | 242 |
* Get a copy of the list for all the symbols defined in this block |
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:
16240
diff
changeset
|
243 |
* @return symbol iterator |
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:
16240
diff
changeset
|
244 |
*/ |
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:
17233
diff
changeset
|
245 |
public List<Symbol> getSymbols() { |
32435
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
246 |
return symbols.isEmpty() ? Collections.emptyList() : Collections.unmodifiableList(new ArrayList<>(symbols.values())); |
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:
16240
diff
changeset
|
247 |
} |
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:
16240
diff
changeset
|
248 |
|
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:
16240
diff
changeset
|
249 |
/** |
16530
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16523
diff
changeset
|
250 |
* Retrieves an existing symbol defined in the current block. |
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16523
diff
changeset
|
251 |
* @param name the name of the symbol |
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16523
diff
changeset
|
252 |
* @return an existing symbol with the specified name defined in the current block, or null if this block doesn't |
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:
17233
diff
changeset
|
253 |
* define a symbol with this name.T |
16147 | 254 |
*/ |
16530
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16523
diff
changeset
|
255 |
public Symbol getExistingSymbol(final String name) { |
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16523
diff
changeset
|
256 |
return symbols.get(name); |
16147 | 257 |
} |
258 |
||
259 |
/** |
|
49145
2854589fd853
8199236: Nashorn uses deprecated HTML tags in Javadoc
hannesw
parents:
47216
diff
changeset
|
260 |
* Test if this block represents a <code>catch</code> block in a <code>try</code> statement. |
16147 | 261 |
* This is used by the Splitter as catch blocks are not be subject to splitting. |
262 |
* |
|
263 |
* @return true if this block represents a catch block in a try statement. |
|
264 |
*/ |
|
265 |
public boolean isCatchBlock() { |
|
266 |
return statements.size() == 1 && statements.get(0) instanceof CatchNode; |
|
267 |
} |
|
268 |
||
269 |
@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
|
270 |
public void toString(final StringBuilder sb, final boolean printType) { |
16147 | 271 |
for (final Node statement : statements) { |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
272 |
statement.toString(sb, printType); |
16147 | 273 |
sb.append(';'); |
274 |
} |
|
275 |
} |
|
276 |
||
277 |
/** |
|
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16168
diff
changeset
|
278 |
* Print symbols in block in alphabetical order, sorted on name |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16168
diff
changeset
|
279 |
* Used for debugging, see the --print-symbols flag |
16147 | 280 |
* |
281 |
* @param stream print writer to output symbols to |
|
282 |
* |
|
283 |
* @return true if symbols were found |
|
284 |
*/ |
|
285 |
public boolean printSymbols(final PrintWriter stream) { |
|
16201
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16168
diff
changeset
|
286 |
final List<Symbol> values = new ArrayList<>(symbols.values()); |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16168
diff
changeset
|
287 |
|
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16168
diff
changeset
|
288 |
Collections.sort(values, new Comparator<Symbol>() { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16168
diff
changeset
|
289 |
@Override |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16168
diff
changeset
|
290 |
public int compare(final Symbol s0, final Symbol s1) { |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16168
diff
changeset
|
291 |
return s0.getName().compareTo(s1.getName()); |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16168
diff
changeset
|
292 |
} |
889ddb179cdf
8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
16168
diff
changeset
|
293 |
}); |
16147 | 294 |
|
295 |
for (final Symbol symbol : values) { |
|
296 |
symbol.print(stream); |
|
297 |
} |
|
298 |
||
299 |
return !values.isEmpty(); |
|
300 |
} |
|
301 |
||
302 |
/** |
|
17233 | 303 |
* Tag block as terminal or non terminal |
304 |
* @param lc lexical context |
|
305 |
* @param isTerminal is block terminal |
|
306 |
* @return same block, or new if flag changed |
|
16147 | 307 |
*/ |
17233 | 308 |
public Block setIsTerminal(final LexicalContext lc, final boolean isTerminal) { |
309 |
return isTerminal ? setFlag(lc, IS_TERMINAL) : clearFlag(lc, IS_TERMINAL); |
|
310 |
} |
|
311 |
||
312 |
@Override |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24725
diff
changeset
|
313 |
public int getFlags() { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24725
diff
changeset
|
314 |
return flags; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24725
diff
changeset
|
315 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24725
diff
changeset
|
316 |
|
25244
627d7e86f3b5
8047357: More precise synthetic return + unreachable throw
attila
parents:
24759
diff
changeset
|
317 |
/** |
627d7e86f3b5
8047357: More precise synthetic return + unreachable throw
attila
parents:
24759
diff
changeset
|
318 |
* Is this a terminal block, i.e. does it end control flow like ending with a throw or return? |
627d7e86f3b5
8047357: More precise synthetic return + unreachable throw
attila
parents:
24759
diff
changeset
|
319 |
* |
627d7e86f3b5
8047357: More precise synthetic return + unreachable throw
attila
parents:
24759
diff
changeset
|
320 |
* @return true if this node statement is terminal |
627d7e86f3b5
8047357: More precise synthetic return + unreachable throw
attila
parents:
24759
diff
changeset
|
321 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24725
diff
changeset
|
322 |
@Override |
17233 | 323 |
public boolean isTerminal() { |
47038
f57fa7f112a0
8177691: Labeled break in catch and finally works wrongly, when invoked through nashorn
sdama
parents:
37732
diff
changeset
|
324 |
return getFlag(IS_TERMINAL) && !getFlag(IS_BREAKABLE); |
16147 | 325 |
} |
326 |
||
327 |
/** |
|
328 |
* Get the entry label for this block |
|
329 |
* @return the entry label |
|
330 |
*/ |
|
331 |
public Label getEntryLabel() { |
|
332 |
return entryLabel; |
|
333 |
} |
|
334 |
||
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
335 |
@Override |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
336 |
public Label getBreakLabel() { |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
337 |
return breakLabel; |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
338 |
} |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
339 |
|
24751 | 340 |
@Override |
341 |
public Block setLocalVariableConversion(final LexicalContext lc, final LocalVariableConversion conversion) { |
|
342 |
if(this.conversion == conversion) { |
|
343 |
return this; |
|
344 |
} |
|
345 |
return Node.replaceInLexicalContext(lc, this, new Block(this, finish, statements, flags, symbols, conversion)); |
|
346 |
} |
|
347 |
||
348 |
@Override |
|
349 |
public LocalVariableConversion getLocalVariableConversion() { |
|
350 |
return conversion; |
|
351 |
} |
|
352 |
||
16147 | 353 |
/** |
354 |
* Get the list of statements in this block |
|
355 |
* |
|
356 |
* @return a list of statements |
|
357 |
*/ |
|
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
|
358 |
public List<Statement> getStatements() { |
16147 | 359 |
return Collections.unmodifiableList(statements); |
360 |
} |
|
361 |
||
362 |
/** |
|
26503 | 363 |
* Returns the number of statements in the block. |
364 |
* @return the number of statements in the block. |
|
365 |
*/ |
|
366 |
public int getStatementCount() { |
|
367 |
return statements.size(); |
|
368 |
} |
|
369 |
||
370 |
/** |
|
24751 | 371 |
* Returns the line number of the first statement in the block. |
372 |
* @return the line number of the first statement in the block, or -1 if the block has no statements. |
|
373 |
*/ |
|
374 |
public int getFirstStatementLineNumber() { |
|
375 |
if(statements == null || statements.isEmpty()) { |
|
376 |
return -1; |
|
377 |
} |
|
378 |
return statements.get(0).getLineNumber(); |
|
379 |
} |
|
380 |
||
381 |
/** |
|
28690 | 382 |
* Returns the last statement in the block. |
383 |
* @return the last statement in the block, or null if the block has no statements. |
|
384 |
*/ |
|
385 |
public Statement getLastStatement() { |
|
386 |
return statements.isEmpty() ? null : statements.get(statements.size() - 1); |
|
387 |
} |
|
388 |
||
389 |
/** |
|
16147 | 390 |
* Reset the statement list for this block |
391 |
* |
|
17233 | 392 |
* @param lc lexical context |
393 |
* @param statements new statement list |
|
394 |
* @return new block if statements changed, identity of statements == block.statements |
|
16147 | 395 |
*/ |
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
|
396 |
public Block setStatements(final LexicalContext lc, final List<Statement> statements) { |
17233 | 397 |
if (this.statements == statements) { |
398 |
return this; |
|
399 |
} |
|
400 |
int lastFinish = 0; |
|
401 |
if (!statements.isEmpty()) { |
|
402 |
lastFinish = statements.get(statements.size() - 1).getFinish(); |
|
403 |
} |
|
24751 | 404 |
return Node.replaceInLexicalContext(lc, this, new Block(this, Math.max(finish, lastFinish), statements, flags, symbols, conversion)); |
16147 | 405 |
} |
406 |
||
407 |
/** |
|
408 |
* Add or overwrite an existing symbol in the block |
|
409 |
* |
|
410 |
* @param symbol symbol |
|
411 |
*/ |
|
32435
cfd619ef23a6
8133300: Ensure symbol table immutability in Nashorn AST
attila
parents:
29407
diff
changeset
|
412 |
public void putSymbol(final Symbol symbol) { |
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:
17233
diff
changeset
|
413 |
symbols.put(symbol.getName(), symbol); |
16147 | 414 |
} |
415 |
||
416 |
/** |
|
417 |
* Check whether scope is necessary for this Block |
|
418 |
* |
|
419 |
* @return true if this function needs a scope |
|
420 |
*/ |
|
421 |
public boolean needsScope() { |
|
17233 | 422 |
return (flags & NEEDS_SCOPE) == NEEDS_SCOPE; |
423 |
} |
|
424 |
||
29407 | 425 |
/** |
426 |
* Check whether this block is synthetic or not. |
|
427 |
* |
|
428 |
* @return true if this is a synthetic block |
|
429 |
*/ |
|
430 |
public boolean isSynthetic() { |
|
431 |
return (flags & IS_SYNTHETIC) == IS_SYNTHETIC; |
|
432 |
} |
|
433 |
||
17233 | 434 |
@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:
24719
diff
changeset
|
435 |
public Block setFlags(final LexicalContext lc, final int flags) { |
17233 | 436 |
if (this.flags == flags) { |
437 |
return this; |
|
438 |
} |
|
24751 | 439 |
return Node.replaceInLexicalContext(lc, this, new Block(this, finish, statements, flags, symbols, conversion)); |
17233 | 440 |
} |
441 |
||
442 |
@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:
24719
diff
changeset
|
443 |
public Block clearFlag(final LexicalContext lc, final int flag) { |
17233 | 444 |
return setFlags(lc, flags & ~flag); |
445 |
} |
|
446 |
||
447 |
@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:
24719
diff
changeset
|
448 |
public Block setFlag(final LexicalContext lc, final int flag) { |
17233 | 449 |
return setFlags(lc, flags | flag); |
450 |
} |
|
451 |
||
452 |
@Override |
|
453 |
public boolean getFlag(final int flag) { |
|
454 |
return (flags & flag) == flag; |
|
16147 | 455 |
} |
456 |
||
457 |
/** |
|
16168
f0c208287983
8005976: Break out AccessSpecializer into one pass before CodeGenerator instead of iterative applications from CodeGenerator
lagergren
parents:
16160
diff
changeset
|
458 |
* Set the needs scope flag. |
17233 | 459 |
* @param lc lexicalContext |
460 |
* @return new block if state changed, otherwise this |
|
16147 | 461 |
*/ |
17233 | 462 |
public Block setNeedsScope(final LexicalContext lc) { |
463 |
if (needsScope()) { |
|
464 |
return this; |
|
465 |
} |
|
466 |
||
24751 | 467 |
return Node.replaceInLexicalContext(lc, this, new Block(this, finish, statements, flags | NEEDS_SCOPE, symbols, conversion)); |
16147 | 468 |
} |
469 |
||
16530
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16523
diff
changeset
|
470 |
/** |
17233 | 471 |
* Computationally determine the next slot for this block, |
472 |
* indexed from 0. Use this as a relative base when computing |
|
473 |
* frames |
|
474 |
* @return next slot |
|
16530
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16523
diff
changeset
|
475 |
*/ |
17233 | 476 |
public int nextSlot() { |
477 |
int next = 0; |
|
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:
17233
diff
changeset
|
478 |
for (final Symbol symbol : getSymbols()) { |
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:
17233
diff
changeset
|
479 |
if (symbol.hasSlot()) { |
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:
17233
diff
changeset
|
480 |
next += symbol.slotCount(); |
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:
17233
diff
changeset
|
481 |
} |
17233 | 482 |
} |
483 |
return next; |
|
16530
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16523
diff
changeset
|
484 |
} |
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16523
diff
changeset
|
485 |
|
36690
06b714373aa4
8151810: for-in iteration does not provide per-iteration scope
hannesw
parents:
35407
diff
changeset
|
486 |
/** |
06b714373aa4
8151810: for-in iteration does not provide per-iteration scope
hannesw
parents:
35407
diff
changeset
|
487 |
* Determine whether this block needs to provide its scope object creator for use by its child nodes. |
06b714373aa4
8151810: for-in iteration does not provide per-iteration scope
hannesw
parents:
35407
diff
changeset
|
488 |
* This is only necessary for synthetic parent blocks of for-in loops with lexical declarations. |
06b714373aa4
8151810: for-in iteration does not provide per-iteration scope
hannesw
parents:
35407
diff
changeset
|
489 |
* |
06b714373aa4
8151810: for-in iteration does not provide per-iteration scope
hannesw
parents:
35407
diff
changeset
|
490 |
* @see ForNode#needsScopeCreator() |
06b714373aa4
8151810: for-in iteration does not provide per-iteration scope
hannesw
parents:
35407
diff
changeset
|
491 |
* @return true if child nodes need access to this block's scope creator |
06b714373aa4
8151810: for-in iteration does not provide per-iteration scope
hannesw
parents:
35407
diff
changeset
|
492 |
*/ |
06b714373aa4
8151810: for-in iteration does not provide per-iteration scope
hannesw
parents:
35407
diff
changeset
|
493 |
public boolean providesScopeCreator() { |
06b714373aa4
8151810: for-in iteration does not provide per-iteration scope
hannesw
parents:
35407
diff
changeset
|
494 |
return needsScope() && isSynthetic() |
06b714373aa4
8151810: for-in iteration does not provide per-iteration scope
hannesw
parents:
35407
diff
changeset
|
495 |
&& (getLastStatement() instanceof ForNode) |
06b714373aa4
8151810: for-in iteration does not provide per-iteration scope
hannesw
parents:
35407
diff
changeset
|
496 |
&& ((ForNode) getLastStatement()).needsScopeCreator(); |
06b714373aa4
8151810: for-in iteration does not provide per-iteration scope
hannesw
parents:
35407
diff
changeset
|
497 |
} |
06b714373aa4
8151810: for-in iteration does not provide per-iteration scope
hannesw
parents:
35407
diff
changeset
|
498 |
|
17233 | 499 |
@Override |
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
500 |
public boolean isBreakableWithoutLabel() { |
17233 | 501 |
return false; |
16530
201d682e75f4
8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents:
16523
diff
changeset
|
502 |
} |
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
503 |
|
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
504 |
@Override |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
505 |
public List<Label> getLabels() { |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
506 |
return Collections.unmodifiableList(Arrays.asList(entryLabel, breakLabel)); |
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
507 |
} |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
508 |
|
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
509 |
@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:
24719
diff
changeset
|
510 |
public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { |
18867
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
511 |
return Acceptor.accept(this, visitor); |
bc91e3fcc5ba
8013925: Remove symbol fields from nodes that don't need them
attila
parents:
17769
diff
changeset
|
512 |
} |
37732 | 513 |
|
514 |
/** |
|
515 |
* Checks if this is a function body. |
|
516 |
* |
|
517 |
* @return true if the function body flag is set |
|
518 |
*/ |
|
519 |
public boolean isFunctionBody() { |
|
520 |
return getFlag(IS_BODY); |
|
521 |
} |
|
522 |
||
523 |
/** |
|
524 |
* Checks if this is a parameter block. |
|
525 |
* |
|
526 |
* @return true if the parameter block flag is set |
|
527 |
*/ |
|
528 |
public boolean isParameterBlock() { |
|
529 |
return getFlag(IS_PARAMETER_BLOCK); |
|
530 |
} |
|
531 |
||
532 |
/** |
|
533 |
* Checks whether this is a switch block. |
|
534 |
* |
|
535 |
* @return true if this is a switch block |
|
536 |
*/ |
|
537 |
public boolean isSwitchBlock() { |
|
538 |
return getFlag(IS_SWITCH_BLOCK); |
|
539 |
} |
|
16147 | 540 |
} |