Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/SpecializationNode.java @ 19786:7108d2319169
Truffle-DSL: make the whole specialization block atomic to avoid unnecessary node allocations.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Wed, 11 Mar 2015 11:32:13 +0100 |
parents | 8caabd6cf363 |
children | 5b7db8941fd7 |
comparison
equal
deleted
inserted
replaced
19785:e773cc48d3e8 | 19786:7108d2319169 |
---|---|
382 throw new UnsupportedOperationException(); | 382 throw new UnsupportedOperationException(); |
383 } | 383 } |
384 | 384 |
385 protected final Object uninitialized(Frame frame) { | 385 protected final Object uninitialized(Frame frame) { |
386 CompilerDirectives.transferToInterpreterAndInvalidate(); | 386 CompilerDirectives.transferToInterpreterAndInvalidate(); |
387 SpecializationNode nextSpecialization = createNext(frame); | 387 SpecializationNode newNode = atomic(new InsertionEvent0(this, "insert new specialization", frame)); |
388 if (nextSpecialization == null) { | 388 if (newNode == null) { |
389 nextSpecialization = createFallback(); | |
390 } | |
391 if (nextSpecialization == null) { | |
392 return unsupported(frame); | 389 return unsupported(frame); |
393 } | 390 } |
394 return atomic(new InsertionEvent0(this, "insert new specialization", frame, nextSpecialization)).acceptAndExecute(frame); | 391 return newNode.acceptAndExecute(frame); |
395 } | 392 } |
396 | 393 |
397 protected final Object uninitialized(Frame frame, Object o1) { | 394 protected final Object uninitialized(Frame frame, Object o1) { |
398 CompilerDirectives.transferToInterpreterAndInvalidate(); | 395 CompilerDirectives.transferToInterpreterAndInvalidate(); |
399 SpecializationNode nextSpecialization = createNext(frame, o1); | 396 SpecializationNode newNode = atomic(new InsertionEvent1(this, "insert new specialization", frame, o1)); |
400 if (nextSpecialization == null) { | 397 if (newNode == null) { |
401 nextSpecialization = createFallback(); | |
402 } | |
403 if (nextSpecialization == null) { | |
404 return unsupported(frame, o1); | 398 return unsupported(frame, o1); |
405 } | 399 } |
406 return atomic(new InsertionEvent1(this, "insert new specialization", frame, o1, nextSpecialization)).acceptAndExecute(frame, o1); | 400 return newNode.acceptAndExecute(frame, o1); |
407 } | 401 } |
408 | 402 |
409 protected final Object uninitialized(Frame frame, Object o1, Object o2) { | 403 protected final Object uninitialized(Frame frame, Object o1, Object o2) { |
410 CompilerDirectives.transferToInterpreterAndInvalidate(); | 404 CompilerDirectives.transferToInterpreterAndInvalidate(); |
411 SpecializationNode nextSpecialization = createNext(frame, o1, o2); | 405 SpecializationNode newNode = atomic(new InsertionEvent2(this, "insert new specialization", frame, o1, o2)); |
412 if (nextSpecialization == null) { | 406 if (newNode == null) { |
413 nextSpecialization = createFallback(); | |
414 } | |
415 if (nextSpecialization == null) { | |
416 return unsupported(frame, o1, o2); | 407 return unsupported(frame, o1, o2); |
417 } | 408 } |
418 return atomic(new InsertionEvent2(this, "insert new specialization", frame, o1, o2, nextSpecialization)).acceptAndExecute(frame, o1, o2); | 409 return newNode.acceptAndExecute(frame, o1, o2); |
419 } | 410 } |
420 | 411 |
421 protected final Object uninitialized(Frame frame, Object o1, Object o2, Object o3) { | 412 protected final Object uninitialized(Frame frame, Object o1, Object o2, Object o3) { |
422 CompilerDirectives.transferToInterpreterAndInvalidate(); | 413 CompilerDirectives.transferToInterpreterAndInvalidate(); |
423 SpecializationNode nextSpecialization = createNext(frame, o1, o2, o3); | 414 SpecializationNode newNode = atomic(new InsertionEvent3(this, "insert new specialization", frame, o1, o2, o3)); |
424 if (nextSpecialization == null) { | 415 if (newNode == null) { |
425 nextSpecialization = createFallback(); | |
426 } | |
427 if (nextSpecialization == null) { | |
428 return unsupported(frame, o1, o2, o3); | 416 return unsupported(frame, o1, o2, o3); |
429 } | 417 } |
430 return atomic(new InsertionEvent3(this, "insert new specialization", frame, o1, o2, o3, nextSpecialization)).acceptAndExecute(frame, o1, o2, o3); | 418 return newNode.acceptAndExecute(frame, o1, o2, o3); |
431 } | 419 } |
432 | 420 |
433 protected final Object uninitialized(Frame frame, Object o1, Object o2, Object o3, Object o4) { | 421 protected final Object uninitialized(Frame frame, Object o1, Object o2, Object o3, Object o4) { |
434 CompilerDirectives.transferToInterpreterAndInvalidate(); | 422 CompilerDirectives.transferToInterpreterAndInvalidate(); |
435 SpecializationNode nextSpecialization = createNext(frame, o1, o2, o3, o4); | 423 SpecializationNode newNode = atomic(new InsertionEvent4(this, "insert new specialization", frame, o1, o2, o3, o4)); |
436 if (nextSpecialization == null) { | 424 if (newNode == null) { |
437 nextSpecialization = createFallback(); | |
438 } | |
439 if (nextSpecialization == null) { | |
440 return unsupported(frame, o1, o2, o3, o4); | 425 return unsupported(frame, o1, o2, o3, o4); |
441 } | 426 } |
442 return atomic(new InsertionEvent4(this, "insert new specialization", frame, o1, o2, o3, o4, nextSpecialization)).acceptAndExecute(frame, o1, o2, o3, o4); | 427 return newNode.acceptAndExecute(frame, o1, o2, o3, o4); |
443 } | 428 } |
444 | 429 |
445 protected final Object uninitialized(Frame frame, Object o1, Object o2, Object o3, Object o4, Object o5) { | 430 protected final Object uninitialized(Frame frame, Object o1, Object o2, Object o3, Object o4, Object o5) { |
446 CompilerDirectives.transferToInterpreterAndInvalidate(); | 431 CompilerDirectives.transferToInterpreterAndInvalidate(); |
447 SpecializationNode nextSpecialization = createNext(frame, o1, o2, o3, o4, o5); | 432 SpecializationNode newNode = atomic(new InsertionEvent5(this, "insert new specialization", frame, o1, o2, o3, o4, o5)); |
448 if (nextSpecialization == null) { | 433 if (newNode == null) { |
449 nextSpecialization = createFallback(); | 434 return unsupported(frame, o1, o2, o3, o4, o5); |
450 } | 435 } |
451 if (nextSpecialization == null) { | 436 return newNode.acceptAndExecute(frame, o1, o2, o3, o4, o5); |
452 unsupported(frame, o1, o2, o3, o4, o5); | |
453 } | |
454 return atomic(new InsertionEvent5(this, "insert new specialization", frame, o1, o2, o3, o4, o5, nextSpecialization)).acceptAndExecute(frame, o1, o2, o3, o4, o5); | |
455 } | 437 } |
456 | 438 |
457 protected final Object uninitialized(Frame frame, Object... args) { | 439 protected final Object uninitialized(Frame frame, Object... args) { |
458 CompilerDirectives.transferToInterpreterAndInvalidate(); | 440 CompilerDirectives.transferToInterpreterAndInvalidate(); |
459 SpecializationNode nextSpecialization = createNext(frame, args); | 441 SpecializationNode newNode = atomic(new InsertionEventN(this, "insert new specialization", frame, args)); |
460 if (nextSpecialization == null) { | 442 if (newNode == null) { |
461 nextSpecialization = createFallback(); | 443 return unsupported(frame, args); |
462 } | 444 } |
463 if (nextSpecialization == null) { | 445 return newNode.acceptAndExecute(frame, args); |
464 unsupported(frame, args); | |
465 } | |
466 return atomic(new InsertionEventN(this, "insert new specialization", frame, args, nextSpecialization)).acceptAndExecute(frame, args); | |
467 } | 446 } |
468 | 447 |
469 protected final Object remove(String reason, Frame frame) { | 448 protected final Object remove(String reason, Frame frame) { |
470 return atomic(new RemoveEvent0(this, reason, frame)).acceptAndExecute(frame); | 449 return atomic(new RemoveEvent0(this, reason, frame)).acceptAndExecute(frame); |
471 } | 450 } |
628 return true; | 607 return true; |
629 } | 608 } |
630 | 609 |
631 private static final class InsertionEvent0 extends SlowPathEvent0 implements Callable<SpecializationNode> { | 610 private static final class InsertionEvent0 extends SlowPathEvent0 implements Callable<SpecializationNode> { |
632 | 611 |
633 private final SpecializationNode next; | 612 public InsertionEvent0(SpecializationNode source, String reason, Frame frame) { |
634 | |
635 public InsertionEvent0(SpecializationNode source, String reason, Frame frame, SpecializationNode next) { | |
636 super(source, reason, frame); | 613 super(source, reason, frame); |
637 this.next = next; | 614 } |
638 } | 615 |
639 | 616 public SpecializationNode call() throws Exception { |
640 public SpecializationNode call() throws Exception { | 617 SpecializationNode next = source.createNext(frame); |
618 if (next == null) { | |
619 next = source.createFallback(); | |
620 } | |
621 if (next == null) { | |
622 return null; | |
623 } | |
641 SpecializationNode start = source.findStart(); | 624 SpecializationNode start = source.findStart(); |
642 if (start.index == Integer.MAX_VALUE) { | 625 if (start.index == Integer.MAX_VALUE) { |
643 return insertAt(start, next, this); | 626 return insertAt(start, next, this); |
644 } else { | 627 } else { |
645 return insertSorted(start, next, this, start.merge(next, frame)); | 628 return insertSorted(start, next, this, start.merge(next, frame)); |
648 | 631 |
649 } | 632 } |
650 | 633 |
651 private static final class InsertionEvent1 extends SlowPathEvent1 implements Callable<SpecializationNode> { | 634 private static final class InsertionEvent1 extends SlowPathEvent1 implements Callable<SpecializationNode> { |
652 | 635 |
653 private final SpecializationNode next; | 636 public InsertionEvent1(SpecializationNode source, String reason, Frame frame, Object o1) { |
654 | |
655 public InsertionEvent1(SpecializationNode source, String reason, Frame frame, Object o1, SpecializationNode next) { | |
656 super(source, reason, frame, o1); | 637 super(source, reason, frame, o1); |
657 this.next = next; | 638 } |
658 } | 639 |
659 | 640 public SpecializationNode call() throws Exception { |
660 public SpecializationNode call() throws Exception { | 641 SpecializationNode next = source.createNext(frame, o1); |
642 if (next == null) { | |
643 next = source.createFallback(); | |
644 } | |
645 if (next == null) { | |
646 return null; | |
647 } | |
661 SpecializationNode start = source.findStart(); | 648 SpecializationNode start = source.findStart(); |
662 if (start.index == Integer.MAX_VALUE) { | 649 if (start.index == Integer.MAX_VALUE) { |
663 return insertAt(start, next, this); | 650 return insertAt(start, next, this); |
664 } else { | 651 } else { |
665 return insertSorted(start, next, this, start.merge(next, frame, o1)); | 652 return insertSorted(start, next, this, start.merge(next, frame, o1)); |
668 | 655 |
669 } | 656 } |
670 | 657 |
671 private static final class InsertionEvent2 extends SlowPathEvent2 implements Callable<SpecializationNode> { | 658 private static final class InsertionEvent2 extends SlowPathEvent2 implements Callable<SpecializationNode> { |
672 | 659 |
673 private final SpecializationNode next; | 660 public InsertionEvent2(SpecializationNode source, String reason, Frame frame, Object o1, Object o2) { |
674 | |
675 public InsertionEvent2(SpecializationNode source, String reason, Frame frame, Object o1, Object o2, SpecializationNode next) { | |
676 super(source, reason, frame, o1, o2); | 661 super(source, reason, frame, o1, o2); |
677 this.next = next; | 662 } |
678 } | 663 |
679 | 664 public SpecializationNode call() throws Exception { |
680 public SpecializationNode call() throws Exception { | 665 SpecializationNode next = source.createNext(frame, o1, o2); |
666 if (next == null) { | |
667 next = source.createFallback(); | |
668 } | |
669 if (next == null) { | |
670 return null; | |
671 } | |
681 SpecializationNode start = source.findStart(); | 672 SpecializationNode start = source.findStart(); |
682 if (start.index == Integer.MAX_VALUE) { | 673 if (start.index == Integer.MAX_VALUE) { |
683 return insertAt(start, next, this); | 674 return insertAt(start, next, this); |
684 } else { | 675 } else { |
685 return insertSorted(start, next, this, start.merge(next, frame, o1, o2)); | 676 return insertSorted(start, next, this, start.merge(next, frame, o1, o2)); |
688 | 679 |
689 } | 680 } |
690 | 681 |
691 private static final class InsertionEvent3 extends SlowPathEvent3 implements Callable<SpecializationNode> { | 682 private static final class InsertionEvent3 extends SlowPathEvent3 implements Callable<SpecializationNode> { |
692 | 683 |
693 private final SpecializationNode next; | 684 public InsertionEvent3(SpecializationNode source, String reason, Frame frame, Object o1, Object o2, Object o3) { |
694 | |
695 public InsertionEvent3(SpecializationNode source, String reason, Frame frame, Object o1, Object o2, Object o3, SpecializationNode next) { | |
696 super(source, reason, frame, o1, o2, o3); | 685 super(source, reason, frame, o1, o2, o3); |
697 this.next = next; | 686 } |
698 } | 687 |
699 | 688 public SpecializationNode call() throws Exception { |
700 public SpecializationNode call() throws Exception { | 689 SpecializationNode next = source.createNext(frame, o1, o2, o3); |
690 if (next == null) { | |
691 next = source.createFallback(); | |
692 } | |
693 if (next == null) { | |
694 return null; | |
695 } | |
701 SpecializationNode start = source.findStart(); | 696 SpecializationNode start = source.findStart(); |
702 if (start.index == Integer.MAX_VALUE) { | 697 if (start.index == Integer.MAX_VALUE) { |
703 return insertAt(start, next, this); | 698 return insertAt(start, next, this); |
704 } else { | 699 } else { |
705 return insertSorted(start, next, this, start.merge(next, frame, o1, o2, o3)); | 700 return insertSorted(start, next, this, start.merge(next, frame, o1, o2, o3)); |
708 | 703 |
709 } | 704 } |
710 | 705 |
711 private static final class InsertionEvent4 extends SlowPathEvent4 implements Callable<SpecializationNode> { | 706 private static final class InsertionEvent4 extends SlowPathEvent4 implements Callable<SpecializationNode> { |
712 | 707 |
713 private final SpecializationNode next; | 708 public InsertionEvent4(SpecializationNode source, String reason, Frame frame, Object o1, Object o2, Object o3, Object o4) { |
714 | |
715 public InsertionEvent4(SpecializationNode source, String reason, Frame frame, Object o1, Object o2, Object o3, Object o4, SpecializationNode next) { | |
716 super(source, reason, frame, o1, o2, o3, o4); | 709 super(source, reason, frame, o1, o2, o3, o4); |
717 this.next = next; | 710 } |
718 } | 711 |
719 | 712 public SpecializationNode call() throws Exception { |
720 public SpecializationNode call() throws Exception { | 713 SpecializationNode next = source.createNext(frame, o1, o2, o3, o4); |
714 if (next == null) { | |
715 next = source.createFallback(); | |
716 } | |
717 if (next == null) { | |
718 return null; | |
719 } | |
721 SpecializationNode start = source.findStart(); | 720 SpecializationNode start = source.findStart(); |
722 if (start.index == Integer.MAX_VALUE) { | 721 if (start.index == Integer.MAX_VALUE) { |
723 return insertAt(start, next, this); | 722 return insertAt(start, next, this); |
724 } else { | 723 } else { |
725 return insertSorted(start, next, this, start.merge(next, frame, o1, o2, o3, o4)); | 724 return insertSorted(start, next, this, start.merge(next, frame, o1, o2, o3, o4)); |
728 | 727 |
729 } | 728 } |
730 | 729 |
731 private static final class InsertionEvent5 extends SlowPathEvent5 implements Callable<SpecializationNode> { | 730 private static final class InsertionEvent5 extends SlowPathEvent5 implements Callable<SpecializationNode> { |
732 | 731 |
733 private final SpecializationNode next; | 732 public InsertionEvent5(SpecializationNode source, String reason, Frame frame, Object o1, Object o2, Object o3, Object o4, Object o5) { |
734 | |
735 public InsertionEvent5(SpecializationNode source, String reason, Frame frame, Object o1, Object o2, Object o3, Object o4, Object o5, SpecializationNode next) { | |
736 super(source, reason, frame, o1, o2, o3, o4, o5); | 733 super(source, reason, frame, o1, o2, o3, o4, o5); |
737 this.next = next; | 734 } |
738 } | 735 |
739 | 736 public SpecializationNode call() throws Exception { |
740 public SpecializationNode call() throws Exception { | 737 SpecializationNode next = source.createNext(frame, o1, o2, o3, o4, o5); |
738 if (next == null) { | |
739 next = source.createFallback(); | |
740 } | |
741 if (next == null) { | |
742 return null; | |
743 } | |
741 SpecializationNode start = source.findStart(); | 744 SpecializationNode start = source.findStart(); |
742 if (start.index == Integer.MAX_VALUE) { | 745 if (start.index == Integer.MAX_VALUE) { |
743 return insertAt(start, next, this); | 746 return insertAt(start, next, this); |
744 } else { | 747 } else { |
745 return insertSorted(start, next, this, start.merge(next, frame, o1, o2, o3, o4, o5)); | 748 return insertSorted(start, next, this, start.merge(next, frame, o1, o2, o3, o4, o5)); |
748 | 751 |
749 } | 752 } |
750 | 753 |
751 private static final class InsertionEventN extends SlowPathEventN implements Callable<SpecializationNode> { | 754 private static final class InsertionEventN extends SlowPathEventN implements Callable<SpecializationNode> { |
752 | 755 |
753 private final SpecializationNode next; | 756 public InsertionEventN(SpecializationNode source, String reason, Frame frame, Object[] args) { |
754 | |
755 public InsertionEventN(SpecializationNode source, String reason, Frame frame, Object[] args, SpecializationNode next) { | |
756 super(source, reason, frame, args); | 757 super(source, reason, frame, args); |
757 this.next = next; | 758 } |
758 } | 759 |
759 | 760 public SpecializationNode call() throws Exception { |
760 public SpecializationNode call() throws Exception { | 761 SpecializationNode next = source.createNext(frame, args); |
762 if (next == null) { | |
763 next = source.createFallback(); | |
764 } | |
765 if (next == null) { | |
766 return null; | |
767 } | |
761 SpecializationNode start = source.findStart(); | 768 SpecializationNode start = source.findStart(); |
762 if (start.index == Integer.MAX_VALUE) { | 769 if (start.index == Integer.MAX_VALUE) { |
763 return insertAt(start, next, this); | 770 return insertAt(start, next, this); |
764 } else { | 771 } else { |
765 return insertSorted(start, next, this, start.merge(next, frame, args)); | 772 return insertSorted(start, next, this, start.merge(next, frame, args)); |