42 import jdk.nashorn.internal.ir.IndexNode; |
42 import jdk.nashorn.internal.ir.IndexNode; |
43 import jdk.nashorn.internal.ir.JumpToInlinedFinally; |
43 import jdk.nashorn.internal.ir.JumpToInlinedFinally; |
44 import jdk.nashorn.internal.ir.LexicalContext; |
44 import jdk.nashorn.internal.ir.LexicalContext; |
45 import jdk.nashorn.internal.ir.LiteralNode; |
45 import jdk.nashorn.internal.ir.LiteralNode; |
46 import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode; |
46 import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode; |
47 import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode.ArrayUnit; |
|
48 import jdk.nashorn.internal.ir.Node; |
47 import jdk.nashorn.internal.ir.Node; |
|
48 import jdk.nashorn.internal.ir.ObjectNode; |
49 import jdk.nashorn.internal.ir.PropertyNode; |
49 import jdk.nashorn.internal.ir.PropertyNode; |
50 import jdk.nashorn.internal.ir.ReturnNode; |
50 import jdk.nashorn.internal.ir.ReturnNode; |
51 import jdk.nashorn.internal.ir.RuntimeNode; |
51 import jdk.nashorn.internal.ir.RuntimeNode; |
52 import jdk.nashorn.internal.ir.SplitNode; |
52 import jdk.nashorn.internal.ir.SplitNode; |
|
53 import jdk.nashorn.internal.ir.Splittable; |
53 import jdk.nashorn.internal.ir.SwitchNode; |
54 import jdk.nashorn.internal.ir.SwitchNode; |
54 import jdk.nashorn.internal.ir.ThrowNode; |
55 import jdk.nashorn.internal.ir.ThrowNode; |
55 import jdk.nashorn.internal.ir.TryNode; |
56 import jdk.nashorn.internal.ir.TryNode; |
56 import jdk.nashorn.internal.ir.UnaryNode; |
57 import jdk.nashorn.internal.ir.UnaryNode; |
57 import jdk.nashorn.internal.ir.VarNode; |
58 import jdk.nashorn.internal.ir.VarNode; |
86 static final long SPLIT_WEIGHT = 40; |
87 static final long SPLIT_WEIGHT = 40; |
87 static final long SWITCH_WEIGHT = 8; |
88 static final long SWITCH_WEIGHT = 8; |
88 static final long THROW_WEIGHT = 2; |
89 static final long THROW_WEIGHT = 2; |
89 static final long VAR_WEIGHT = 40; |
90 static final long VAR_WEIGHT = 40; |
90 static final long WITH_WEIGHT = 8; |
91 static final long WITH_WEIGHT = 8; |
|
92 static final long OBJECT_WEIGHT = 16; |
|
93 static final long SETPROP_WEIGHT = 5; |
91 |
94 |
92 /** Accumulated weight. */ |
95 /** Accumulated weight. */ |
93 private long weight; |
96 private long weight; |
94 |
97 |
95 /** Optional cache for weight of block nodes. */ |
98 /** Optional cache for weight of block nodes. */ |
211 |
214 |
212 if (literalNode instanceof ArrayLiteralNode) { |
215 if (literalNode instanceof ArrayLiteralNode) { |
213 final ArrayLiteralNode arrayLiteralNode = (ArrayLiteralNode)literalNode; |
216 final ArrayLiteralNode arrayLiteralNode = (ArrayLiteralNode)literalNode; |
214 final Node[] value = arrayLiteralNode.getValue(); |
217 final Node[] value = arrayLiteralNode.getValue(); |
215 final int[] postsets = arrayLiteralNode.getPostsets(); |
218 final int[] postsets = arrayLiteralNode.getPostsets(); |
216 final List<ArrayUnit> units = arrayLiteralNode.getUnits(); |
219 final List<Splittable.SplitRange> units = arrayLiteralNode.getSplitRanges(); |
217 |
220 |
218 if (units == null) { |
221 if (units == null) { |
219 for (final int postset : postsets) { |
222 for (final int postset : postsets) { |
220 weight += AASTORE_WEIGHT; |
223 weight += AASTORE_WEIGHT; |
221 final Node element = value[postset]; |
224 final Node element = value[postset]; |
231 |
234 |
232 return true; |
235 return true; |
233 } |
236 } |
234 |
237 |
235 @Override |
238 @Override |
|
239 public boolean enterObjectNode(final ObjectNode objectNode) { |
|
240 weight += OBJECT_WEIGHT; |
|
241 final List<PropertyNode> properties = objectNode.getElements(); |
|
242 final boolean isSpillObject = properties.size() > CodeGenerator.OBJECT_SPILL_THRESHOLD; |
|
243 |
|
244 for (final PropertyNode property : properties) { |
|
245 if (!LiteralNode.isConstant(property.getValue())) { |
|
246 weight += SETPROP_WEIGHT; |
|
247 property.getValue().accept(this); |
|
248 } else if (!isSpillObject) { |
|
249 // constants in spill object are set via preset spill array, |
|
250 // but fields objects need to set constants. |
|
251 weight += SETPROP_WEIGHT; |
|
252 } |
|
253 |
|
254 } |
|
255 |
|
256 return false; |
|
257 } |
|
258 |
|
259 @Override |
236 public Node leavePropertyNode(final PropertyNode propertyNode) { |
260 public Node leavePropertyNode(final PropertyNode propertyNode) { |
237 weight += LITERAL_WEIGHT; |
261 weight += LITERAL_WEIGHT; |
238 return propertyNode; |
262 return propertyNode; |
239 } |
263 } |
240 |
264 |