Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/SpecializationNode.java @ 19764:e8d2f3f95dcd
Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 10 Mar 2015 19:28:26 +0100 |
parents | f4792a544170 |
children | f682b9e6ca07 |
comparison
equal
deleted
inserted
replaced
19763:d03352ba2efb | 19764:e8d2f3f95dcd |
---|---|
28 import java.util.*; | 28 import java.util.*; |
29 import java.util.concurrent.*; | 29 import java.util.concurrent.*; |
30 | 30 |
31 import com.oracle.truffle.api.*; | 31 import com.oracle.truffle.api.*; |
32 import com.oracle.truffle.api.dsl.*; | 32 import com.oracle.truffle.api.dsl.*; |
33 import com.oracle.truffle.api.dsl.internal.RewriteEvent.RewriteEvent0; | 33 import com.oracle.truffle.api.dsl.internal.SlowPathEvent.SlowPathEvent0; |
34 import com.oracle.truffle.api.dsl.internal.RewriteEvent.RewriteEvent1; | 34 import com.oracle.truffle.api.dsl.internal.SlowPathEvent.SlowPathEvent1; |
35 import com.oracle.truffle.api.dsl.internal.RewriteEvent.RewriteEvent2; | 35 import com.oracle.truffle.api.dsl.internal.SlowPathEvent.SlowPathEvent2; |
36 import com.oracle.truffle.api.dsl.internal.RewriteEvent.RewriteEvent3; | 36 import com.oracle.truffle.api.dsl.internal.SlowPathEvent.SlowPathEvent3; |
37 import com.oracle.truffle.api.dsl.internal.RewriteEvent.RewriteEvent4; | 37 import com.oracle.truffle.api.dsl.internal.SlowPathEvent.SlowPathEvent4; |
38 import com.oracle.truffle.api.dsl.internal.RewriteEvent.RewriteEventN; | 38 import com.oracle.truffle.api.dsl.internal.SlowPathEvent.SlowPathEvent5; |
39 import com.oracle.truffle.api.dsl.internal.SlowPathEvent.SlowPathEventN; | |
39 import com.oracle.truffle.api.frame.*; | 40 import com.oracle.truffle.api.frame.*; |
40 import com.oracle.truffle.api.nodes.*; | 41 import com.oracle.truffle.api.nodes.*; |
41 import com.oracle.truffle.api.nodes.NodeUtil.NodeClass; | 42 import com.oracle.truffle.api.nodes.NodeUtil.NodeClass; |
42 import com.oracle.truffle.api.nodes.NodeUtil.NodeField; | 43 import com.oracle.truffle.api.nodes.NodeUtil.NodeField; |
43 | 44 |
44 /** | 45 /** |
45 * Internal implementation dependent base class for generated specialized nodes. | 46 * Internal implementation dependent base class for generated specialized nodes. |
46 */ | 47 */ |
48 @NodeInfo(cost = NodeCost.NONE) | |
47 @SuppressWarnings("unused") | 49 @SuppressWarnings("unused") |
48 @NodeInfo(cost = NodeCost.NONE) | |
49 public abstract class SpecializationNode extends Node { | 50 public abstract class SpecializationNode extends Node { |
50 | 51 |
51 @Child protected SpecializationNode next; | 52 @Child protected SpecializationNode next; |
52 | 53 |
53 private final int index; | 54 final int index; |
54 | 55 |
55 public SpecializationNode() { | 56 public SpecializationNode() { |
56 this(-1); | 57 this(-1); |
57 } | 58 } |
58 | 59 |
90 if (start.next != null) { | 91 if (start.next != null) { |
91 updateRootImpl(start.next, node); | 92 updateRootImpl(start.next, node); |
92 } | 93 } |
93 } | 94 } |
94 | 95 |
95 protected final SpecializationNode polymorphicMerge(SpecializationNode newNode) { | 96 protected final SpecializationNode polymorphicMerge(SpecializationNode newNode, SpecializationNode merged) { |
96 SpecializationNode merged = next.merge(newNode); | 97 if (merged == newNode && count() <= 2) { |
97 if (merged == newNode && !isSame(newNode) && count() <= 2) { | 98 return removeSame(new SlowPathEvent0(this, "merged polymorphic to monomorphic", null)); |
98 return removeSame(new RewriteEvent0(findRoot(), "merged polymorphic to monomorphic")); | |
99 } | 99 } |
100 return merged; | 100 return merged; |
101 } | 101 } |
102 | 102 |
103 public final NodeCost getNodeCost() { | 103 public final NodeCost getNodeCost() { |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 protected abstract Node[] getSuppliedChildren(); | 115 protected abstract Node[] getSuppliedChildren(); |
116 | 116 |
117 protected SpecializationNode merge(SpecializationNode newNode) { | 117 protected SpecializationNode merge(SpecializationNode newNode, Frame frame) { |
118 if (this.isSame(newNode)) { | 118 if (isIdentical(newNode, frame)) { |
119 return this; | 119 return this; |
120 } | 120 } |
121 return next != null ? next.merge(newNode) : newNode; | 121 return next != null ? next.merge(newNode, frame) : newNode; |
122 } | 122 } |
123 | 123 |
124 protected SpecializationNode mergeNoSame(SpecializationNode newNode) { | 124 protected SpecializationNode merge(SpecializationNode newNode, Frame frame, Object o1) { |
125 return next != null ? next.merge(newNode) : newNode; | 125 if (isIdentical(newNode, frame, o1)) { |
126 return this; | |
127 } | |
128 return next != null ? next.merge(newNode, frame, o1) : newNode; | |
129 } | |
130 | |
131 protected SpecializationNode merge(SpecializationNode newNode, Frame frame, Object o1, Object o2) { | |
132 if (isIdentical(newNode, frame, o1, o2)) { | |
133 return this; | |
134 } | |
135 return next != null ? next.merge(newNode, frame, o1, o2) : newNode; | |
136 } | |
137 | |
138 protected SpecializationNode merge(SpecializationNode newNode, Frame frame, Object o1, Object o2, Object o3) { | |
139 if (isIdentical(newNode, frame, o1, o2, o3)) { | |
140 return this; | |
141 } | |
142 return next != null ? next.merge(newNode, frame, o1, o2, o3) : newNode; | |
143 } | |
144 | |
145 protected SpecializationNode merge(SpecializationNode newNode, Frame frame, Object o1, Object o2, Object o3, Object o4) { | |
146 if (isIdentical(newNode, frame, o1, o2, o3, o4)) { | |
147 return this; | |
148 } | |
149 return next != null ? next.merge(newNode, frame, o1, o2, o3, o4) : newNode; | |
150 } | |
151 | |
152 protected SpecializationNode merge(SpecializationNode newNode, Frame frame, Object o1, Object o2, Object o3, Object o4, Object o5) { | |
153 if (isIdentical(newNode, frame, o1, o2, o3, o4, o5)) { | |
154 return this; | |
155 } | |
156 return next != null ? next.merge(newNode, frame, o1, o2, o3, o4, o5) : newNode; | |
157 } | |
158 | |
159 protected SpecializationNode merge(SpecializationNode newNode, Frame frame, Object... args) { | |
160 if (isIdentical(newNode, frame, args)) { | |
161 return this; | |
162 } | |
163 return next != null ? next.merge(newNode, frame, args) : newNode; | |
164 } | |
165 | |
166 protected boolean isSame(SpecializationNode other) { | |
167 return getClass() == other.getClass(); | |
168 } | |
169 | |
170 protected boolean isIdentical(SpecializationNode newNode, Frame frame) { | |
171 return isSame(newNode); | |
172 } | |
173 | |
174 protected boolean isIdentical(SpecializationNode newNode, Frame frame, Object o1) { | |
175 return isSame(newNode); | |
176 } | |
177 | |
178 protected boolean isIdentical(SpecializationNode newNode, Frame frame, Object o1, Object o2) { | |
179 return isSame(newNode); | |
180 } | |
181 | |
182 protected boolean isIdentical(SpecializationNode newNode, Frame frame, Object o1, Object o2, Object o3) { | |
183 return isSame(newNode); | |
184 } | |
185 | |
186 protected boolean isIdentical(SpecializationNode newNode, Frame frame, Object o1, Object o2, Object o3, Object o4) { | |
187 return isSame(newNode); | |
188 } | |
189 | |
190 protected boolean isIdentical(SpecializationNode newNode, Frame frame, Object o1, Object o2, Object o3, Object o4, Object o5) { | |
191 return isSame(newNode); | |
192 } | |
193 | |
194 protected boolean isIdentical(SpecializationNode newNode, Frame frame, Object... args) { | |
195 return isSame(newNode); | |
126 } | 196 } |
127 | 197 |
128 protected final int countSame(SpecializationNode node) { | 198 protected final int countSame(SpecializationNode node) { |
129 return findStart().countSameImpl(node); | 199 return findStart().countSameImpl(node); |
130 } | 200 } |
146 } | 216 } |
147 | 217 |
148 @Override | 218 @Override |
149 public final int hashCode() { | 219 public final int hashCode() { |
150 return index; | 220 return index; |
151 } | |
152 | |
153 protected boolean isSame(SpecializationNode other) { | |
154 return getClass() == other.getClass(); | |
155 } | 221 } |
156 | 222 |
157 private int count() { | 223 private int count() { |
158 return next != null ? next.count() + 1 : 1; | 224 return next != null ? next.count() + 1 : 1; |
159 } | 225 } |
224 | 290 |
225 private Node findRoot() { | 291 private Node findRoot() { |
226 return findStart().getParent(); | 292 return findStart().getParent(); |
227 } | 293 } |
228 | 294 |
229 private SpecializationNode removeSameImpl(SpecializationNode toRemove, CharSequence reason) { | 295 private SpecializedNode findSpecializedNode() { |
230 SpecializationNode start = findStart(); | 296 return (SpecializedNode) findEnd().findStart().getParent(); |
297 } | |
298 | |
299 private static SpecializationNode removeSameImpl(SpecializationNode toRemove, CharSequence reason) { | |
300 SpecializationNode start = toRemove.findStart(); | |
231 SpecializationNode current = start; | 301 SpecializationNode current = start; |
232 while (current != null) { | 302 while (current != null) { |
233 if (current.isSame(toRemove)) { | 303 if (current.isSame(toRemove)) { |
234 current.replace(current.next, reason); | 304 current.replace(current.next, reason); |
235 if (current == start) { | 305 if (current == start) { |
236 start = start.next; | 306 start = start.next; |
237 } | 307 } |
238 } | 308 } |
239 current = current.next; | 309 current = current.next; |
240 } | 310 } |
241 return findEnd().findStart(); | 311 return toRemove.findEnd().findStart(); |
242 } | 312 } |
243 | 313 |
244 public Object acceptAndExecute(Frame frame) { | 314 public Object acceptAndExecute(Frame frame) { |
245 throw new UnsupportedOperationException(); | 315 throw new UnsupportedOperationException(); |
246 } | 316 } |
312 nextSpecialization = createFallback(); | 382 nextSpecialization = createFallback(); |
313 } | 383 } |
314 if (nextSpecialization == null) { | 384 if (nextSpecialization == null) { |
315 return unsupported(frame); | 385 return unsupported(frame); |
316 } | 386 } |
317 return insertSpecialization(nextSpecialization, new RewriteEvent0(findRoot(), "inserted new specialization")).acceptAndExecute(frame); | 387 return atomic(new InsertionEvent0(this, "insert new specialization", frame, nextSpecialization)).acceptAndExecute(frame); |
318 } | 388 } |
319 | 389 |
320 protected final Object uninitialized(Frame frame, Object o1) { | 390 protected final Object uninitialized(Frame frame, Object o1) { |
321 CompilerDirectives.transferToInterpreterAndInvalidate(); | 391 CompilerDirectives.transferToInterpreterAndInvalidate(); |
322 SpecializationNode nextSpecialization = createNext(frame, o1); | 392 SpecializationNode nextSpecialization = createNext(frame, o1); |
324 nextSpecialization = createFallback(); | 394 nextSpecialization = createFallback(); |
325 } | 395 } |
326 if (nextSpecialization == null) { | 396 if (nextSpecialization == null) { |
327 return unsupported(frame, o1); | 397 return unsupported(frame, o1); |
328 } | 398 } |
329 return insertSpecialization(nextSpecialization, new RewriteEvent1(findRoot(), "inserted new specialization", o1)).acceptAndExecute(frame, o1); | 399 return atomic(new InsertionEvent1(this, "insert new specialization", frame, o1, nextSpecialization)).acceptAndExecute(frame, o1); |
330 } | 400 } |
331 | 401 |
332 protected final Object uninitialized(Frame frame, Object o1, Object o2) { | 402 protected final Object uninitialized(Frame frame, Object o1, Object o2) { |
333 CompilerDirectives.transferToInterpreterAndInvalidate(); | 403 CompilerDirectives.transferToInterpreterAndInvalidate(); |
334 SpecializationNode nextSpecialization = createNext(frame, o1, o2); | 404 SpecializationNode nextSpecialization = createNext(frame, o1, o2); |
336 nextSpecialization = createFallback(); | 406 nextSpecialization = createFallback(); |
337 } | 407 } |
338 if (nextSpecialization == null) { | 408 if (nextSpecialization == null) { |
339 return unsupported(frame, o1, o2); | 409 return unsupported(frame, o1, o2); |
340 } | 410 } |
341 return insertSpecialization(nextSpecialization, new RewriteEvent2(findRoot(), "inserted new specialization", o1, o2)).acceptAndExecute(frame, o1, o2); | 411 return atomic(new InsertionEvent2(this, "insert new specialization", frame, o1, o2, nextSpecialization)).acceptAndExecute(frame, o1, o2); |
342 } | 412 } |
343 | 413 |
344 protected final Object uninitialized(Frame frame, Object o1, Object o2, Object o3) { | 414 protected final Object uninitialized(Frame frame, Object o1, Object o2, Object o3) { |
345 CompilerDirectives.transferToInterpreterAndInvalidate(); | 415 CompilerDirectives.transferToInterpreterAndInvalidate(); |
346 SpecializationNode nextSpecialization = createNext(frame, o1, o2, o3); | 416 SpecializationNode nextSpecialization = createNext(frame, o1, o2, o3); |
348 nextSpecialization = createFallback(); | 418 nextSpecialization = createFallback(); |
349 } | 419 } |
350 if (nextSpecialization == null) { | 420 if (nextSpecialization == null) { |
351 return unsupported(frame, o1, o2, o3); | 421 return unsupported(frame, o1, o2, o3); |
352 } | 422 } |
353 return insertSpecialization(nextSpecialization, new RewriteEvent3(findRoot(), "inserted new specialization", o1, o2, o3)).acceptAndExecute(frame, o1, o2, o3); | 423 return atomic(new InsertionEvent3(this, "insert new specialization", frame, o1, o2, o3, nextSpecialization)).acceptAndExecute(frame, o1, o2, o3); |
354 } | 424 } |
355 | 425 |
356 protected final Object uninitialized(Frame frame, Object o1, Object o2, Object o3, Object o4) { | 426 protected final Object uninitialized(Frame frame, Object o1, Object o2, Object o3, Object o4) { |
357 CompilerDirectives.transferToInterpreterAndInvalidate(); | 427 CompilerDirectives.transferToInterpreterAndInvalidate(); |
358 SpecializationNode nextSpecialization = createNext(frame, o1, o2, o3, o4); | 428 SpecializationNode nextSpecialization = createNext(frame, o1, o2, o3, o4); |
360 nextSpecialization = createFallback(); | 430 nextSpecialization = createFallback(); |
361 } | 431 } |
362 if (nextSpecialization == null) { | 432 if (nextSpecialization == null) { |
363 return unsupported(frame, o1, o2, o3, o4); | 433 return unsupported(frame, o1, o2, o3, o4); |
364 } | 434 } |
365 return insertSpecialization(nextSpecialization, new RewriteEvent4(findRoot(), "inserts new specialization", o1, o2, o3, o4)).acceptAndExecute(frame, o1, o2, o3, o4); | 435 return atomic(new InsertionEvent4(this, "insert new specialization", frame, o1, o2, o3, o4, nextSpecialization)).acceptAndExecute(frame, o1, o2, o3, o4); |
366 } | 436 } |
367 | 437 |
368 protected final Object uninitialized(Frame frame, Object o1, Object o2, Object o3, Object o4, Object o5) { | 438 protected final Object uninitialized(Frame frame, Object o1, Object o2, Object o3, Object o4, Object o5) { |
369 CompilerDirectives.transferToInterpreterAndInvalidate(); | 439 CompilerDirectives.transferToInterpreterAndInvalidate(); |
370 SpecializationNode nextSpecialization = createNext(frame, o1, o2, o3, o4, o5); | 440 SpecializationNode nextSpecialization = createNext(frame, o1, o2, o3, o4, o5); |
372 nextSpecialization = createFallback(); | 442 nextSpecialization = createFallback(); |
373 } | 443 } |
374 if (nextSpecialization == null) { | 444 if (nextSpecialization == null) { |
375 unsupported(frame, o1, o2, o3, o4, o5); | 445 unsupported(frame, o1, o2, o3, o4, o5); |
376 } | 446 } |
377 return insertSpecialization(nextSpecialization, new RewriteEventN(findRoot(), "inserts new specialization", o1, o2, o3, o4, o5)).acceptAndExecute(frame, o1, o2, o3, o4, o5); | 447 return atomic(new InsertionEvent5(this, "insert new specialization", frame, o1, o2, o3, o4, o5, nextSpecialization)).acceptAndExecute(frame, o1, o2, o3, o4, o5); |
378 } | 448 } |
379 | 449 |
380 protected final Object uninitialized(Frame frame, Object... args) { | 450 protected final Object uninitialized(Frame frame, Object... args) { |
381 CompilerDirectives.transferToInterpreterAndInvalidate(); | 451 CompilerDirectives.transferToInterpreterAndInvalidate(); |
382 SpecializationNode nextSpecialization = createNext(frame, args); | 452 SpecializationNode nextSpecialization = createNext(frame, args); |
384 nextSpecialization = createFallback(); | 454 nextSpecialization = createFallback(); |
385 } | 455 } |
386 if (nextSpecialization == null) { | 456 if (nextSpecialization == null) { |
387 unsupported(frame, args); | 457 unsupported(frame, args); |
388 } | 458 } |
389 return insertSpecialization(nextSpecialization, new RewriteEventN(findRoot(), "inserts new specialization", args)).acceptAndExecute(frame, args); | 459 return atomic(new InsertionEventN(this, "insert new specialization", frame, args, nextSpecialization)).acceptAndExecute(frame, args); |
390 } | |
391 | |
392 private boolean needsPolymorphic() { | |
393 return findStart().count() == 2; | |
394 } | 460 } |
395 | 461 |
396 protected final Object remove(String reason, Frame frame) { | 462 protected final Object remove(String reason, Frame frame) { |
397 return removeSame(new RewriteEvent0(findRoot(), reason)).acceptAndExecute(frame); | 463 return atomic(new RemoveEvent0(this, reason, frame)).acceptAndExecute(frame); |
398 } | 464 } |
399 | 465 |
400 protected final Object remove(String reason, Frame frame, Object o1) { | 466 protected final Object remove(String reason, Frame frame, Object o1) { |
401 return removeSame(new RewriteEvent1(findRoot(), reason, o1)).acceptAndExecute(frame, o1); | 467 return atomic(new RemoveEvent1(this, reason, frame, o1)).acceptAndExecute(frame, o1); |
402 } | 468 } |
403 | 469 |
404 protected final Object remove(String reason, Frame frame, Object o1, Object o2) { | 470 protected final Object remove(String reason, Frame frame, Object o1, Object o2) { |
405 return removeSame(new RewriteEvent2(findRoot(), reason, o1, o2)).acceptAndExecute(frame, o1, o2); | 471 return atomic(new RemoveEvent2(this, reason, frame, o1, o2)).acceptAndExecute(frame, o1, o2); |
406 } | 472 } |
407 | 473 |
408 protected final Object remove(String reason, Frame frame, Object o1, Object o2, Object o3) { | 474 protected final Object remove(String reason, Frame frame, Object o1, Object o2, Object o3) { |
409 return removeSame(new RewriteEvent3(findRoot(), reason, o1, o2, o3)).acceptAndExecute(frame, o1, o2, o3); | 475 return atomic(new RemoveEvent3(this, reason, frame, o1, o2, o3)).acceptAndExecute(frame, o1, o2, o3); |
410 } | 476 } |
411 | 477 |
412 protected final Object remove(String reason, Frame frame, Object o1, Object o2, Object o3, Object o4) { | 478 protected final Object remove(String reason, Frame frame, Object o1, Object o2, Object o3, Object o4) { |
413 return removeSame(new RewriteEvent4(findRoot(), reason, o1, o2, o3, o4)).acceptAndExecute(frame, o1, o2, o3, o4); | 479 return atomic(new RemoveEvent4(this, reason, frame, o1, o2, o3, o4)).acceptAndExecute(frame, o1, o2, o3, o4); |
414 } | 480 } |
415 | 481 |
416 protected final Object remove(String reason, Frame frame, Object o1, Object o2, Object o3, Object o4, Object o5) { | 482 protected final Object remove(String reason, Frame frame, Object o1, Object o2, Object o3, Object o4, Object o5) { |
417 return removeSame(new RewriteEventN(findRoot(), reason, o1, o2, o3, o4, o5)).acceptAndExecute(frame, o1, o2, o3, o4, o5); | 483 return atomic(new RemoveEvent5(this, reason, frame, o1, o2, o3, o4, o5)).acceptAndExecute(frame, o1, o2, o3, o4, o5); |
418 } | 484 } |
419 | 485 |
420 protected final Object remove(String reason, Frame frame, Object... args) { | 486 protected final Object remove(String reason, Frame frame, Object... args) { |
421 return removeSame(new RewriteEventN(findRoot(), reason, args)).acceptAndExecute(frame, args); | 487 return atomic(new RemoveEventN(this, reason, frame, args)).acceptAndExecute(frame, args); |
422 } | 488 } |
423 | 489 |
424 protected Object unsupported(Frame frame) { | 490 protected Object unsupported(Frame frame) { |
425 throw new UnsupportedSpecializationException(findRoot(), getSuppliedChildren()); | 491 throw new UnsupportedSpecializationException(findRoot(), getSuppliedChildren()); |
426 } | 492 } |
447 | 513 |
448 protected Object unsupported(Frame frame, Object... args) { | 514 protected Object unsupported(Frame frame, Object... args) { |
449 throw new UnsupportedSpecializationException(findRoot(), getSuppliedChildren(), args); | 515 throw new UnsupportedSpecializationException(findRoot(), getSuppliedChildren(), args); |
450 } | 516 } |
451 | 517 |
452 private SpecializationNode insertSpecialization(final SpecializationNode generated, final CharSequence message) { | 518 static SpecializationNode insertSorted(SpecializationNode start, final SpecializationNode generated, final CharSequence message, final SpecializationNode merged) { |
453 return atomic(new Callable<SpecializationNode>() { | |
454 public SpecializationNode call() { | |
455 return insert(generated, message); | |
456 } | |
457 }); | |
458 } | |
459 | |
460 private SpecializationNode insert(final SpecializationNode generated, CharSequence message) { | |
461 SpecializationNode start = findStart(); | |
462 if (start == this) { | |
463 // fast path for first insert | |
464 return insertBefore(this, generated, message); | |
465 } else { | |
466 return slowSortedInsert(start, generated, message); | |
467 } | |
468 } | |
469 | |
470 private static <T> SpecializationNode slowSortedInsert(SpecializationNode start, final SpecializationNode generated, final CharSequence message) { | |
471 final SpecializationNode merged = start.merge(generated); | |
472 if (merged == generated) { | 519 if (merged == generated) { |
473 // new node | 520 // new node |
474 if (start.count() == 2) { | 521 if (start.count() == 2) { |
475 insertBefore(start, start.createPolymorphic(), "insert polymorphic"); | 522 insertAt(start, start.createPolymorphic(), "insert polymorphic"); |
476 } | 523 } |
477 SpecializationNode insertBefore = findInsertBeforeNode(generated.index, start); | 524 SpecializationNode current = start; |
478 return insertBefore(insertBefore, generated, message); | 525 while (current != null && current.index < generated.index) { |
526 current = current.next; | |
527 } | |
528 return insertAt(current, generated, message); | |
479 } else { | 529 } else { |
480 // existing node | 530 // existing node |
481 merged.replace(merged, new RewriteEvent0(merged.findRoot(), "merged specialization")); | |
482 return start; | 531 return start; |
483 } | 532 } |
484 } | 533 } |
485 | 534 |
486 private static SpecializationNode findInsertBeforeNode(int generatedIndex, SpecializationNode start) { | 535 static <T> SpecializationNode insertAt(SpecializationNode node, SpecializationNode insertBefore, CharSequence message) { |
487 SpecializationNode current = start; | |
488 while (current != null && current.index < generatedIndex) { | |
489 current = current.next; | |
490 } | |
491 return current; | |
492 } | |
493 | |
494 private static <T> SpecializationNode insertBefore(SpecializationNode node, SpecializationNode insertBefore, CharSequence message) { | |
495 insertBefore.next = node; | 536 insertBefore.next = node; |
496 return node.replace(insertBefore, message); | 537 return node.replace(insertBefore, message); |
497 } | 538 } |
498 | 539 |
499 @Override | 540 @Override |
543 sep = ", "; | 584 sep = ", "; |
544 } | 585 } |
545 b.append(")"); | 586 b.append(")"); |
546 } | 587 } |
547 | 588 |
548 // utilities for generated code | |
549 protected static void check(Assumption assumption) throws InvalidAssumptionException { | 589 protected static void check(Assumption assumption) throws InvalidAssumptionException { |
550 if (assumption != null) { | 590 if (assumption != null) { |
551 assumption.check(); | 591 assumption.check(); |
552 } | 592 } |
553 } | 593 } |
578 } | 618 } |
579 } | 619 } |
580 return true; | 620 return true; |
581 } | 621 } |
582 | 622 |
623 private static final class InsertionEvent0 extends SlowPathEvent0 implements Callable<SpecializationNode> { | |
624 | |
625 private final SpecializationNode next; | |
626 | |
627 public InsertionEvent0(SpecializationNode source, String reason, Frame frame, SpecializationNode next) { | |
628 super(source, reason, frame); | |
629 this.next = next; | |
630 } | |
631 | |
632 public SpecializationNode call() throws Exception { | |
633 SpecializationNode start = source.findStart(); | |
634 if (start.index == Integer.MAX_VALUE) { | |
635 return insertAt(start, next, this); | |
636 } else { | |
637 return insertSorted(start, next, this, start.merge(next, frame)); | |
638 } | |
639 } | |
640 | |
641 } | |
642 | |
643 private static final class InsertionEvent1 extends SlowPathEvent1 implements Callable<SpecializationNode> { | |
644 | |
645 private final SpecializationNode next; | |
646 | |
647 public InsertionEvent1(SpecializationNode source, String reason, Frame frame, Object o1, SpecializationNode next) { | |
648 super(source, reason, frame, o1); | |
649 this.next = next; | |
650 } | |
651 | |
652 public SpecializationNode call() throws Exception { | |
653 SpecializationNode start = source.findStart(); | |
654 if (start.index == Integer.MAX_VALUE) { | |
655 return insertAt(start, next, this); | |
656 } else { | |
657 return insertSorted(start, next, this, start.merge(next, frame, o1)); | |
658 } | |
659 } | |
660 | |
661 } | |
662 | |
663 private static final class InsertionEvent2 extends SlowPathEvent2 implements Callable<SpecializationNode> { | |
664 | |
665 private final SpecializationNode next; | |
666 | |
667 public InsertionEvent2(SpecializationNode source, String reason, Frame frame, Object o1, Object o2, SpecializationNode next) { | |
668 super(source, reason, frame, o1, o2); | |
669 this.next = next; | |
670 } | |
671 | |
672 public SpecializationNode call() throws Exception { | |
673 SpecializationNode start = source.findStart(); | |
674 if (start.index == Integer.MAX_VALUE) { | |
675 return insertAt(start, next, this); | |
676 } else { | |
677 return insertSorted(start, next, this, start.merge(next, frame, o1, o2)); | |
678 } | |
679 } | |
680 | |
681 } | |
682 | |
683 private static final class InsertionEvent3 extends SlowPathEvent3 implements Callable<SpecializationNode> { | |
684 | |
685 private final SpecializationNode next; | |
686 | |
687 public InsertionEvent3(SpecializationNode source, String reason, Frame frame, Object o1, Object o2, Object o3, SpecializationNode next) { | |
688 super(source, reason, frame, o1, o2, o3); | |
689 this.next = next; | |
690 } | |
691 | |
692 public SpecializationNode call() throws Exception { | |
693 SpecializationNode start = source.findStart(); | |
694 if (start.index == Integer.MAX_VALUE) { | |
695 return insertAt(start, next, this); | |
696 } else { | |
697 return insertSorted(start, next, this, start.merge(next, frame, o1, o2, o3)); | |
698 } | |
699 } | |
700 | |
701 } | |
702 | |
703 private static final class InsertionEvent4 extends SlowPathEvent4 implements Callable<SpecializationNode> { | |
704 | |
705 private final SpecializationNode next; | |
706 | |
707 public InsertionEvent4(SpecializationNode source, String reason, Frame frame, Object o1, Object o2, Object o3, Object o4, SpecializationNode next) { | |
708 super(source, reason, frame, o1, o2, o3, o4); | |
709 this.next = next; | |
710 } | |
711 | |
712 public SpecializationNode call() throws Exception { | |
713 SpecializationNode start = source.findStart(); | |
714 if (start.index == Integer.MAX_VALUE) { | |
715 return insertAt(start, next, this); | |
716 } else { | |
717 return insertSorted(start, next, this, start.merge(next, frame, o1, o2, o3, o4)); | |
718 } | |
719 } | |
720 | |
721 } | |
722 | |
723 private static final class InsertionEvent5 extends SlowPathEvent5 implements Callable<SpecializationNode> { | |
724 | |
725 private final SpecializationNode next; | |
726 | |
727 public InsertionEvent5(SpecializationNode source, String reason, Frame frame, Object o1, Object o2, Object o3, Object o4, Object o5, SpecializationNode next) { | |
728 super(source, reason, frame, o1, o2, o3, o4, o5); | |
729 this.next = next; | |
730 } | |
731 | |
732 public SpecializationNode call() throws Exception { | |
733 SpecializationNode start = source.findStart(); | |
734 if (start.index == Integer.MAX_VALUE) { | |
735 return insertAt(start, next, this); | |
736 } else { | |
737 return insertSorted(start, next, this, start.merge(next, frame, o1, o2, o3, o4, o5)); | |
738 } | |
739 } | |
740 | |
741 } | |
742 | |
743 private static final class InsertionEventN extends SlowPathEventN implements Callable<SpecializationNode> { | |
744 | |
745 private final SpecializationNode next; | |
746 | |
747 public InsertionEventN(SpecializationNode source, String reason, Frame frame, Object[] args, SpecializationNode next) { | |
748 super(source, reason, frame, args); | |
749 this.next = next; | |
750 } | |
751 | |
752 public SpecializationNode call() throws Exception { | |
753 SpecializationNode start = source.findStart(); | |
754 if (start.index == Integer.MAX_VALUE) { | |
755 return insertAt(start, next, this); | |
756 } else { | |
757 return insertSorted(start, next, this, start.merge(next, frame, args)); | |
758 } | |
759 } | |
760 } | |
761 | |
762 private static final class RemoveEvent0 extends SlowPathEvent0 implements Callable<SpecializationNode> { | |
763 | |
764 public RemoveEvent0(SpecializationNode source, String reason, Frame frame) { | |
765 super(source, reason, frame); | |
766 } | |
767 | |
768 public SpecializationNode call() throws Exception { | |
769 return removeSameImpl(source, this); | |
770 } | |
771 | |
772 } | |
773 | |
774 private static final class RemoveEvent1 extends SlowPathEvent1 implements Callable<SpecializationNode> { | |
775 | |
776 public RemoveEvent1(SpecializationNode source, String reason, Frame frame, Object o1) { | |
777 super(source, reason, frame, o1); | |
778 } | |
779 | |
780 public SpecializationNode call() throws Exception { | |
781 return removeSameImpl(source, this); | |
782 } | |
783 | |
784 } | |
785 | |
786 private static final class RemoveEvent2 extends SlowPathEvent2 implements Callable<SpecializationNode> { | |
787 | |
788 public RemoveEvent2(SpecializationNode source, String reason, Frame frame, Object o1, Object o2) { | |
789 super(source, reason, frame, o1, o2); | |
790 } | |
791 | |
792 public SpecializationNode call() throws Exception { | |
793 return removeSameImpl(source, this); | |
794 } | |
795 | |
796 } | |
797 | |
798 private static final class RemoveEvent3 extends SlowPathEvent3 implements Callable<SpecializationNode> { | |
799 | |
800 public RemoveEvent3(SpecializationNode source, String reason, Frame frame, Object o1, Object o2, Object o3) { | |
801 super(source, reason, frame, o1, o2, o3); | |
802 } | |
803 | |
804 public SpecializationNode call() throws Exception { | |
805 return removeSameImpl(source, this); | |
806 } | |
807 | |
808 } | |
809 | |
810 private static final class RemoveEvent4 extends SlowPathEvent4 implements Callable<SpecializationNode> { | |
811 | |
812 public RemoveEvent4(SpecializationNode source, String reason, Frame frame, Object o1, Object o2, Object o3, Object o4) { | |
813 super(source, reason, frame, o1, o2, o3, o4); | |
814 } | |
815 | |
816 public SpecializationNode call() throws Exception { | |
817 return removeSameImpl(source, this); | |
818 } | |
819 | |
820 } | |
821 | |
822 private static final class RemoveEvent5 extends SlowPathEvent5 implements Callable<SpecializationNode> { | |
823 | |
824 public RemoveEvent5(SpecializationNode source, String reason, Frame frame, Object o1, Object o2, Object o3, Object o4, Object o5) { | |
825 super(source, reason, frame, o1, o2, o3, o4, o5); | |
826 } | |
827 | |
828 public SpecializationNode call() throws Exception { | |
829 return removeSameImpl(source, this); | |
830 } | |
831 | |
832 } | |
833 | |
834 private static final class RemoveEventN extends SlowPathEventN implements Callable<SpecializationNode> { | |
835 | |
836 public RemoveEventN(SpecializationNode source, String reason, Frame frame, Object[] args) { | |
837 super(source, reason, frame, args); | |
838 } | |
839 | |
840 public SpecializationNode call() throws Exception { | |
841 return removeSameImpl(source, this); | |
842 } | |
843 } | |
844 | |
583 } | 845 } |