author | hannesw |
Tue, 12 Dec 2017 15:38:18 +0100 | |
changeset 48247 | fa5a47cad0c9 |
parent 47216 | 71c04702a3d5 |
child 48380 | 597f69e5f1e3 |
permissions | -rw-r--r-- |
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:
diff
changeset
|
1 |
/* |
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:
diff
changeset
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
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:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
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:
diff
changeset
|
4 |
* |
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:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
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:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
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:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
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:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
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:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
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:
diff
changeset
|
10 |
* |
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:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
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:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
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:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
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:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
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:
diff
changeset
|
15 |
* accompanied this code). |
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:
diff
changeset
|
16 |
* |
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:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
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:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
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:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
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:
diff
changeset
|
20 |
* |
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:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
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:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
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:
diff
changeset
|
23 |
* questions. |
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:
diff
changeset
|
24 |
*/ |
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:
diff
changeset
|
25 |
|
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:
diff
changeset
|
26 |
package jdk.nashorn.internal.codegen; |
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:
diff
changeset
|
27 |
|
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:
diff
changeset
|
28 |
import java.util.ArrayDeque; |
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:
diff
changeset
|
29 |
import java.util.Collection; |
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:
diff
changeset
|
30 |
import java.util.Collections; |
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:
diff
changeset
|
31 |
import java.util.Deque; |
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:
diff
changeset
|
32 |
import java.util.HashMap; |
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:
diff
changeset
|
33 |
import java.util.Map; |
24719 | 34 |
import jdk.nashorn.internal.IntDeque; |
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:
diff
changeset
|
35 |
import jdk.nashorn.internal.codegen.types.Type; |
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:
diff
changeset
|
36 |
import jdk.nashorn.internal.ir.Block; |
29410 | 37 |
import jdk.nashorn.internal.ir.Expression; |
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:
diff
changeset
|
38 |
import jdk.nashorn.internal.ir.FunctionNode; |
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:
diff
changeset
|
39 |
import jdk.nashorn.internal.ir.LexicalContext; |
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:
diff
changeset
|
40 |
import jdk.nashorn.internal.ir.LexicalContextNode; |
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:
diff
changeset
|
41 |
import jdk.nashorn.internal.ir.Node; |
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:
diff
changeset
|
42 |
import jdk.nashorn.internal.ir.Symbol; |
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:
diff
changeset
|
43 |
import jdk.nashorn.internal.ir.WithNode; |
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:
diff
changeset
|
44 |
|
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:
diff
changeset
|
45 |
/** |
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:
diff
changeset
|
46 |
* A lexical context that also tracks if we have any dynamic scopes in the context. Such scopes can have new |
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:
diff
changeset
|
47 |
* variables introduced into them at run time - a with block or a function directly containing an eval call. |
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:
diff
changeset
|
48 |
* Furthermore, this class keeps track of current discard state, which the current method emitter being used is, |
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:
diff
changeset
|
49 |
* the current compile unit, and local variable indexes |
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:
diff
changeset
|
50 |
*/ |
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:
diff
changeset
|
51 |
final class CodeGeneratorLexicalContext extends LexicalContext { |
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:
diff
changeset
|
52 |
private int dynamicScopeCount; |
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:
diff
changeset
|
53 |
|
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:
diff
changeset
|
54 |
/** Map of shared scope call sites */ |
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:
diff
changeset
|
55 |
private final Map<SharedScopeCall, SharedScopeCall> scopeCalls = new HashMap<>(); |
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:
diff
changeset
|
56 |
|
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:
diff
changeset
|
57 |
/** Compile unit stack - every time we start a sub method (e.g. a split) we push one */ |
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:
diff
changeset
|
58 |
private final Deque<CompileUnit> compileUnits = new ArrayDeque<>(); |
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:
diff
changeset
|
59 |
|
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:
diff
changeset
|
60 |
/** Method emitter stack - every time we start a sub method (e.g. a split) we push one */ |
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:
diff
changeset
|
61 |
private final Deque<MethodEmitter> methodEmitters = new ArrayDeque<>(); |
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:
diff
changeset
|
62 |
|
29410 | 63 |
/** The discard stack - whenever we evaluate an expression that will be discarded, we push it on this stack. Various |
64 |
* implementations of expression code emitter can choose to emit code that'll discard the expression themselves, or |
|
65 |
* ignore it in which case CodeGenerator.loadAndDiscard() will explicitly emit a pop instruction. */ |
|
66 |
private final Deque<Expression> discard = new ArrayDeque<>(); |
|
67 |
||
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:
diff
changeset
|
68 |
|
24719 | 69 |
private final Deque<Map<String, Collection<Label>>> unwarrantedOptimismHandlers = new ArrayDeque<>(); |
70 |
private final Deque<StringBuilder> slotTypesDescriptors = new ArrayDeque<>(); |
|
71 |
private final IntDeque splitNodes = new IntDeque(); |
|
72 |
||
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:
diff
changeset
|
73 |
/** A stack tracking the next free local variable slot in the blocks. There's one entry for every block |
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:
diff
changeset
|
74 |
* currently on the lexical context stack. */ |
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:
diff
changeset
|
75 |
private int[] nextFreeSlots = new int[16]; |
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:
diff
changeset
|
76 |
|
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:
diff
changeset
|
77 |
/** size of next free slot vector */ |
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:
diff
changeset
|
78 |
private int nextFreeSlotsSize; |
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:
diff
changeset
|
79 |
|
28690 | 80 |
private boolean isWithBoundary(final Object node) { |
24749
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24719
diff
changeset
|
81 |
return node instanceof Block && !isEmpty() && peek() instanceof WithNode; |
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24719
diff
changeset
|
82 |
} |
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24719
diff
changeset
|
83 |
|
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:
diff
changeset
|
84 |
@Override |
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:
diff
changeset
|
85 |
public <T extends LexicalContextNode> T push(final T node) { |
24749
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24719
diff
changeset
|
86 |
if (isWithBoundary(node)) { |
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24719
diff
changeset
|
87 |
dynamicScopeCount++; |
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24719
diff
changeset
|
88 |
} else if (node instanceof FunctionNode) { |
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24719
diff
changeset
|
89 |
if (((FunctionNode)node).inDynamicContext()) { |
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24719
diff
changeset
|
90 |
dynamicScopeCount++; |
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24719
diff
changeset
|
91 |
} |
24719 | 92 |
splitNodes.push(0); |
93 |
} |
|
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:
diff
changeset
|
94 |
return super.push(node); |
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:
diff
changeset
|
95 |
} |
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:
diff
changeset
|
96 |
|
24719 | 97 |
void enterSplitNode() { |
98 |
splitNodes.getAndIncrement(); |
|
24751 | 99 |
pushFreeSlots(methodEmitters.peek().getUsedSlotsWithLiveTemporaries()); |
24719 | 100 |
} |
101 |
||
102 |
void exitSplitNode() { |
|
24751 | 103 |
final int count = splitNodes.decrementAndGet(); |
104 |
assert count >= 0; |
|
24719 | 105 |
} |
106 |
||
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:
diff
changeset
|
107 |
@Override |
28690 | 108 |
public <T extends Node> T pop(final T node) { |
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:
diff
changeset
|
109 |
final T popped = super.pop(node); |
24749
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24719
diff
changeset
|
110 |
if (isWithBoundary(node)) { |
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24719
diff
changeset
|
111 |
dynamicScopeCount--; |
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24719
diff
changeset
|
112 |
assert dynamicScopeCount >= 0; |
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24719
diff
changeset
|
113 |
} else if (node instanceof FunctionNode) { |
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24719
diff
changeset
|
114 |
if (((FunctionNode)node).inDynamicContext()) { |
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24719
diff
changeset
|
115 |
dynamicScopeCount--; |
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24719
diff
changeset
|
116 |
assert dynamicScopeCount >= 0; |
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24719
diff
changeset
|
117 |
} |
24719 | 118 |
assert splitNodes.peek() == 0; |
119 |
splitNodes.pop(); |
|
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:
diff
changeset
|
120 |
} |
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:
diff
changeset
|
121 |
return popped; |
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:
diff
changeset
|
122 |
} |
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:
diff
changeset
|
123 |
|
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:
diff
changeset
|
124 |
boolean inDynamicScope() { |
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:
diff
changeset
|
125 |
return dynamicScopeCount > 0; |
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:
diff
changeset
|
126 |
} |
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:
diff
changeset
|
127 |
|
24719 | 128 |
boolean inSplitNode() { |
129 |
return !splitNodes.isEmpty() && splitNodes.peek() > 0; |
|
130 |
} |
|
131 |
||
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:
diff
changeset
|
132 |
MethodEmitter pushMethodEmitter(final MethodEmitter newMethod) { |
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:
diff
changeset
|
133 |
methodEmitters.push(newMethod); |
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:
diff
changeset
|
134 |
return newMethod; |
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:
diff
changeset
|
135 |
} |
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:
diff
changeset
|
136 |
|
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:
diff
changeset
|
137 |
MethodEmitter popMethodEmitter(final MethodEmitter oldMethod) { |
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:
diff
changeset
|
138 |
assert methodEmitters.peek() == oldMethod; |
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:
diff
changeset
|
139 |
methodEmitters.pop(); |
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:
diff
changeset
|
140 |
return methodEmitters.isEmpty() ? null : methodEmitters.peek(); |
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:
diff
changeset
|
141 |
} |
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:
diff
changeset
|
142 |
|
24719 | 143 |
void pushUnwarrantedOptimismHandlers() { |
144 |
unwarrantedOptimismHandlers.push(new HashMap<String, Collection<Label>>()); |
|
145 |
slotTypesDescriptors.push(new StringBuilder()); |
|
146 |
} |
|
147 |
||
148 |
Map<String, Collection<Label>> getUnwarrantedOptimismHandlers() { |
|
149 |
return unwarrantedOptimismHandlers.peek(); |
|
150 |
} |
|
151 |
||
152 |
Map<String, Collection<Label>> popUnwarrantedOptimismHandlers() { |
|
153 |
slotTypesDescriptors.pop(); |
|
154 |
return unwarrantedOptimismHandlers.pop(); |
|
155 |
} |
|
156 |
||
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:
diff
changeset
|
157 |
CompileUnit pushCompileUnit(final CompileUnit newUnit) { |
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:
diff
changeset
|
158 |
compileUnits.push(newUnit); |
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:
diff
changeset
|
159 |
return newUnit; |
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:
diff
changeset
|
160 |
} |
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:
diff
changeset
|
161 |
|
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:
diff
changeset
|
162 |
CompileUnit popCompileUnit(final CompileUnit oldUnit) { |
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:
diff
changeset
|
163 |
assert compileUnits.peek() == oldUnit; |
26506
7d55cc7fc301
8057703: More empty classes generated by Nashorn
lagergren
parents:
25865
diff
changeset
|
164 |
final CompileUnit unit = compileUnits.pop(); |
7d55cc7fc301
8057703: More empty classes generated by Nashorn
lagergren
parents:
25865
diff
changeset
|
165 |
assert unit.hasCode() : "compile unit popped without code"; |
7d55cc7fc301
8057703: More empty classes generated by Nashorn
lagergren
parents:
25865
diff
changeset
|
166 |
unit.setUsed(); |
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:
diff
changeset
|
167 |
return compileUnits.isEmpty() ? null : compileUnits.peek(); |
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:
diff
changeset
|
168 |
} |
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:
diff
changeset
|
169 |
|
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:
diff
changeset
|
170 |
boolean hasCompileUnits() { |
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:
diff
changeset
|
171 |
return !compileUnits.isEmpty(); |
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:
diff
changeset
|
172 |
} |
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:
diff
changeset
|
173 |
|
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:
diff
changeset
|
174 |
Collection<SharedScopeCall> getScopeCalls() { |
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:
diff
changeset
|
175 |
return Collections.unmodifiableCollection(scopeCalls.values()); |
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:
diff
changeset
|
176 |
} |
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:
diff
changeset
|
177 |
|
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:
diff
changeset
|
178 |
/** |
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:
diff
changeset
|
179 |
* Get a shared static method representing a dynamic scope callsite. |
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:
diff
changeset
|
180 |
* |
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:
diff
changeset
|
181 |
* @param unit current compile unit |
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:
diff
changeset
|
182 |
* @param symbol the symbol |
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:
diff
changeset
|
183 |
* @param valueType the value type of the symbol |
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:
diff
changeset
|
184 |
* @param returnType the return type |
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:
diff
changeset
|
185 |
* @param paramTypes the parameter types |
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:
diff
changeset
|
186 |
* @param flags the callsite flags |
48247
fa5a47cad0c9
8069338: Implement sharedScopeCall for optimistic types
hannesw
parents:
47216
diff
changeset
|
187 |
* @param isOptimistic is this an optimistic call |
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:
diff
changeset
|
188 |
* @return an object representing a shared scope call |
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:
diff
changeset
|
189 |
*/ |
48247
fa5a47cad0c9
8069338: Implement sharedScopeCall for optimistic types
hannesw
parents:
47216
diff
changeset
|
190 |
SharedScopeCall getScopeCall(final CompileUnit unit, final Symbol symbol, final Type valueType, |
fa5a47cad0c9
8069338: Implement sharedScopeCall for optimistic types
hannesw
parents:
47216
diff
changeset
|
191 |
final Type returnType, final Type[] paramTypes, final int flags, |
fa5a47cad0c9
8069338: Implement sharedScopeCall for optimistic types
hannesw
parents:
47216
diff
changeset
|
192 |
final boolean isOptimistic) { |
fa5a47cad0c9
8069338: Implement sharedScopeCall for optimistic types
hannesw
parents:
47216
diff
changeset
|
193 |
final SharedScopeCall scopeCall = new SharedScopeCall(symbol, valueType, returnType, paramTypes, flags, |
fa5a47cad0c9
8069338: Implement sharedScopeCall for optimistic types
hannesw
parents:
47216
diff
changeset
|
194 |
isOptimistic); |
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:
diff
changeset
|
195 |
if (scopeCalls.containsKey(scopeCall)) { |
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:
diff
changeset
|
196 |
return scopeCalls.get(scopeCall); |
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:
diff
changeset
|
197 |
} |
22373 | 198 |
scopeCall.setClassAndName(unit, getCurrentFunction().uniqueName(":scopeCall")); |
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:
diff
changeset
|
199 |
scopeCalls.put(scopeCall, scopeCall); |
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:
diff
changeset
|
200 |
return scopeCall; |
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:
diff
changeset
|
201 |
} |
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:
diff
changeset
|
202 |
|
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:
diff
changeset
|
203 |
/** |
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:
diff
changeset
|
204 |
* Get a shared static method representing a dynamic scope get access. |
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:
diff
changeset
|
205 |
* |
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:
diff
changeset
|
206 |
* @param unit current compile unit |
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:
diff
changeset
|
207 |
* @param symbol the symbol |
24719 | 208 |
* @param valueType the type of the variable |
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:
diff
changeset
|
209 |
* @param flags the callsite flags |
48247
fa5a47cad0c9
8069338: Implement sharedScopeCall for optimistic types
hannesw
parents:
47216
diff
changeset
|
210 |
* @param isOptimistic is this an optimistic get |
fa5a47cad0c9
8069338: Implement sharedScopeCall for optimistic types
hannesw
parents:
47216
diff
changeset
|
211 |
* @return an object representing a shared scope get |
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:
diff
changeset
|
212 |
*/ |
48247
fa5a47cad0c9
8069338: Implement sharedScopeCall for optimistic types
hannesw
parents:
47216
diff
changeset
|
213 |
SharedScopeCall getScopeGet(final CompileUnit unit, final Symbol symbol, final Type valueType, final int flags, |
fa5a47cad0c9
8069338: Implement sharedScopeCall for optimistic types
hannesw
parents:
47216
diff
changeset
|
214 |
final boolean isOptimistic) { |
fa5a47cad0c9
8069338: Implement sharedScopeCall for optimistic types
hannesw
parents:
47216
diff
changeset
|
215 |
return getScopeCall(unit, symbol, valueType, valueType, null, flags, isOptimistic); |
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:
diff
changeset
|
216 |
} |
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:
diff
changeset
|
217 |
|
24751 | 218 |
void onEnterBlock(final Block block) { |
219 |
pushFreeSlots(assignSlots(block, isFunctionBody() ? 0 : getUsedSlotCount())); |
|
220 |
} |
|
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:
diff
changeset
|
221 |
|
24751 | 222 |
private void pushFreeSlots(final int freeSlots) { |
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:
diff
changeset
|
223 |
if (nextFreeSlotsSize == nextFreeSlots.length) { |
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:
diff
changeset
|
224 |
final int[] newNextFreeSlots = new int[nextFreeSlotsSize * 2]; |
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:
diff
changeset
|
225 |
System.arraycopy(nextFreeSlots, 0, newNextFreeSlots, 0, nextFreeSlotsSize); |
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:
diff
changeset
|
226 |
nextFreeSlots = newNextFreeSlots; |
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:
diff
changeset
|
227 |
} |
24751 | 228 |
nextFreeSlots[nextFreeSlotsSize++] = freeSlots; |
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:
diff
changeset
|
229 |
} |
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:
diff
changeset
|
230 |
|
24719 | 231 |
int getUsedSlotCount() { |
232 |
return nextFreeSlots[nextFreeSlotsSize - 1]; |
|
233 |
} |
|
234 |
||
24751 | 235 |
void releaseSlots() { |
24719 | 236 |
--nextFreeSlotsSize; |
24751 | 237 |
final int undefinedFromSlot = nextFreeSlotsSize == 0 ? 0 : nextFreeSlots[nextFreeSlotsSize - 1]; |
238 |
if(!slotTypesDescriptors.isEmpty()) { |
|
239 |
slotTypesDescriptors.peek().setLength(undefinedFromSlot); |
|
24719 | 240 |
} |
24751 | 241 |
methodEmitters.peek().undefineLocalVariables(undefinedFromSlot, false); |
24719 | 242 |
} |
243 |
||
244 |
private int assignSlots(final Block block, final int firstSlot) { |
|
24751 | 245 |
int fromSlot = firstSlot; |
246 |
final MethodEmitter method = methodEmitters.peek(); |
|
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:
diff
changeset
|
247 |
for (final Symbol symbol : block.getSymbols()) { |
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:
diff
changeset
|
248 |
if (symbol.hasSlot()) { |
24751 | 249 |
symbol.setFirstSlot(fromSlot); |
250 |
final int toSlot = fromSlot + symbol.slotCount(); |
|
251 |
method.defineBlockLocalVariable(fromSlot, toSlot); |
|
252 |
fromSlot = toSlot; |
|
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:
diff
changeset
|
253 |
} |
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:
diff
changeset
|
254 |
} |
24751 | 255 |
return fromSlot; |
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:
diff
changeset
|
256 |
} |
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:
diff
changeset
|
257 |
|
24719 | 258 |
static Type getTypeForSlotDescriptor(final char typeDesc) { |
24751 | 259 |
// Recognizing both lowercase and uppercase as we're using both to signify symbol boundaries; see |
260 |
// MethodEmitter.markSymbolBoundariesInLvarTypesDescriptor(). |
|
27361 | 261 |
switch (typeDesc) { |
24751 | 262 |
case 'I': |
263 |
case 'i': |
|
24719 | 264 |
return Type.INT; |
24751 | 265 |
case 'J': |
266 |
case 'j': |
|
24719 | 267 |
return Type.LONG; |
24751 | 268 |
case 'D': |
269 |
case 'd': |
|
24719 | 270 |
return Type.NUMBER; |
24751 | 271 |
case 'A': |
272 |
case 'a': |
|
24719 | 273 |
return Type.OBJECT; |
24751 | 274 |
case 'U': |
275 |
case 'u': |
|
24719 | 276 |
return Type.UNKNOWN; |
24751 | 277 |
default: |
24719 | 278 |
throw new AssertionError(); |
279 |
} |
|
280 |
} |
|
281 |
||
29410 | 282 |
void pushDiscard(final Expression expr) { |
283 |
discard.push(expr); |
|
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:
diff
changeset
|
284 |
} |
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:
diff
changeset
|
285 |
|
29410 | 286 |
boolean popDiscardIfCurrent(final Expression expr) { |
287 |
if (isCurrentDiscard(expr)) { |
|
288 |
discard.pop(); |
|
289 |
return true; |
|
290 |
} |
|
291 |
return false; |
|
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:
diff
changeset
|
292 |
} |
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:
diff
changeset
|
293 |
|
29410 | 294 |
boolean isCurrentDiscard(final Expression expr) { |
295 |
return discard.peek() == expr; |
|
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:
diff
changeset
|
296 |
} |
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:
diff
changeset
|
297 |
|
24751 | 298 |
int quickSlot(final Type type) { |
299 |
return methodEmitters.peek().defineTemporaryLocalVariable(type.getSlots()); |
|
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:
diff
changeset
|
300 |
} |
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:
diff
changeset
|
301 |
} |
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:
diff
changeset
|
302 |