Mercurial > hg > graal-jvmci-8
comparison jvmci/jdk.vm.ci.code/src/jdk/vm/ci/code/CompilationResult.java @ 22740:22110ef74a40
8144083 [JVMCI] CompilationResult should be finalized by JVMCI compiler and made effectively final
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 26 Nov 2015 00:47:01 +0100 |
parents | f41ed1d87d68 |
children |
comparison
equal
deleted
inserted
replaced
22739:f41ed1d87d68 | 22740:22110ef74a40 |
---|---|
496 } | 496 } |
497 return false; | 497 return false; |
498 } | 498 } |
499 } | 499 } |
500 | 500 |
501 private boolean closed; | |
502 | |
501 private int entryBCI = -1; | 503 private int entryBCI = -1; |
502 | 504 |
503 private final DataSection dataSection = new DataSection(); | 505 private final DataSection dataSection = new DataSection(); |
504 | 506 |
505 private final List<Infopoint> infopoints = new ArrayList<>(); | 507 private final List<Infopoint> infopoints = new ArrayList<>(); |
596 | 598 |
597 /** | 599 /** |
598 * @param entryBCI the entryBCI to set | 600 * @param entryBCI the entryBCI to set |
599 */ | 601 */ |
600 public void setEntryBCI(int entryBCI) { | 602 public void setEntryBCI(int entryBCI) { |
603 checkOpen(); | |
601 this.entryBCI = entryBCI; | 604 this.entryBCI = entryBCI; |
602 } | 605 } |
603 | 606 |
604 /** | 607 /** |
605 * Sets the assumptions made during compilation. | 608 * Sets the assumptions made during compilation. |
606 */ | 609 */ |
607 public void setAssumptions(Assumption[] assumptions) { | 610 public void setAssumptions(Assumption[] assumptions) { |
611 checkOpen(); | |
608 this.assumptions = assumptions; | 612 this.assumptions = assumptions; |
609 } | 613 } |
610 | 614 |
611 /** | 615 /** |
612 * Gets the assumptions made during compilation. | 616 * Gets the assumptions made during compilation. |
617 * | |
618 * The caller must not modify the contents of the returned array. | |
613 */ | 619 */ |
614 public Assumption[] getAssumptions() { | 620 public Assumption[] getAssumptions() { |
615 return assumptions; | 621 return assumptions; |
616 } | 622 } |
617 | 623 |
620 * | 626 * |
621 * @param rootMethod the root method of the compilation | 627 * @param rootMethod the root method of the compilation |
622 * @param inlinedMethods the methods inlined during compilation | 628 * @param inlinedMethods the methods inlined during compilation |
623 */ | 629 */ |
624 public void setMethods(ResolvedJavaMethod rootMethod, Collection<ResolvedJavaMethod> inlinedMethods) { | 630 public void setMethods(ResolvedJavaMethod rootMethod, Collection<ResolvedJavaMethod> inlinedMethods) { |
631 checkOpen(); | |
625 assert rootMethod != null; | 632 assert rootMethod != null; |
626 assert inlinedMethods != null; | 633 assert inlinedMethods != null; |
627 if (inlinedMethods.contains(rootMethod)) { | 634 if (inlinedMethods.contains(rootMethod)) { |
628 methods = inlinedMethods.toArray(new ResolvedJavaMethod[inlinedMethods.size()]); | 635 methods = inlinedMethods.toArray(new ResolvedJavaMethod[inlinedMethods.size()]); |
629 for (int i = 0; i < methods.length; i++) { | 636 for (int i = 0; i < methods.length; i++) { |
647 } | 654 } |
648 | 655 |
649 /** | 656 /** |
650 * Gets the methods whose bytecodes were used as input to the compilation. | 657 * Gets the methods whose bytecodes were used as input to the compilation. |
651 * | 658 * |
659 * The caller must not modify the contents of the returned array. | |
660 * | |
652 * @return {@code null} if the compilation did not record method dependencies otherwise the | 661 * @return {@code null} if the compilation did not record method dependencies otherwise the |
653 * methods whose bytecodes were used as input to the compilation with the first element | 662 * methods whose bytecodes were used as input to the compilation with the first element |
654 * being the root method of the compilation | 663 * being the root method of the compilation |
655 */ | 664 */ |
656 public ResolvedJavaMethod[] getMethods() { | 665 public ResolvedJavaMethod[] getMethods() { |
657 return methods; | 666 return methods; |
658 } | 667 } |
659 | 668 |
660 public void setBytecodeSize(int bytecodeSize) { | 669 public void setBytecodeSize(int bytecodeSize) { |
670 checkOpen(); | |
661 this.bytecodeSize = bytecodeSize; | 671 this.bytecodeSize = bytecodeSize; |
662 } | 672 } |
663 | 673 |
664 public int getBytecodeSize() { | 674 public int getBytecodeSize() { |
665 return bytecodeSize; | 675 return bytecodeSize; |
685 * if any. | 695 * if any. |
686 * | 696 * |
687 * @param size the size of the frame in bytes | 697 * @param size the size of the frame in bytes |
688 */ | 698 */ |
689 public void setTotalFrameSize(int size) { | 699 public void setTotalFrameSize(int size) { |
700 checkOpen(); | |
690 totalFrameSize = size; | 701 totalFrameSize = size; |
691 } | 702 } |
692 | 703 |
693 /** | 704 /** |
694 * Sets the machine that has been generated by the compiler. | 705 * Sets the machine that has been generated by the compiler. |
695 * | 706 * |
696 * @param code the machine code generated | 707 * @param code the machine code generated |
697 * @param size the size of the machine code | 708 * @param size the size of the machine code |
698 */ | 709 */ |
699 public void setTargetCode(byte[] code, int size) { | 710 public void setTargetCode(byte[] code, int size) { |
711 checkOpen(); | |
700 targetCode = code; | 712 targetCode = code; |
701 targetCodeSize = size; | 713 targetCodeSize = size; |
702 } | 714 } |
703 | 715 |
704 /** | 716 /** |
708 * | 720 * |
709 * @param codePos The position in the code that needs to be patched. | 721 * @param codePos The position in the code that needs to be patched. |
710 * @param ref The reference that should be inserted in the code. | 722 * @param ref The reference that should be inserted in the code. |
711 */ | 723 */ |
712 public void recordDataPatch(int codePos, Reference ref) { | 724 public void recordDataPatch(int codePos, Reference ref) { |
725 checkOpen(); | |
713 assert codePos >= 0 && ref != null; | 726 assert codePos >= 0 && ref != null; |
714 dataPatches.add(new DataPatch(codePos, ref)); | 727 dataPatches.add(new DataPatch(codePos, ref)); |
715 } | 728 } |
716 | 729 |
717 /** | 730 /** |
722 * @param target the being called | 735 * @param target the being called |
723 * @param debugInfo the debug info for the call | 736 * @param debugInfo the debug info for the call |
724 * @param direct specifies if this is a {@linkplain Call#direct direct} call | 737 * @param direct specifies if this is a {@linkplain Call#direct direct} call |
725 */ | 738 */ |
726 public void recordCall(int codePos, int size, InvokeTarget target, DebugInfo debugInfo, boolean direct) { | 739 public void recordCall(int codePos, int size, InvokeTarget target, DebugInfo debugInfo, boolean direct) { |
740 checkOpen(); | |
727 final Call call = new Call(target, codePos, size, direct, debugInfo); | 741 final Call call = new Call(target, codePos, size, direct, debugInfo); |
728 addInfopoint(call); | 742 addInfopoint(call); |
729 } | 743 } |
730 | 744 |
731 /** | 745 /** |
733 * | 747 * |
734 * @param codePos the position in the code that is covered by the handler | 748 * @param codePos the position in the code that is covered by the handler |
735 * @param handlerPos the position of the handler | 749 * @param handlerPos the position of the handler |
736 */ | 750 */ |
737 public void recordExceptionHandler(int codePos, int handlerPos) { | 751 public void recordExceptionHandler(int codePos, int handlerPos) { |
752 checkOpen(); | |
738 assert validateExceptionHandlerAdd(codePos, handlerPos) : String.format("Duplicate exception handler for pc 0x%x handlerPos 0x%x", codePos, handlerPos); | 753 assert validateExceptionHandlerAdd(codePos, handlerPos) : String.format("Duplicate exception handler for pc 0x%x handlerPos 0x%x", codePos, handlerPos); |
739 exceptionHandlers.add(new ExceptionHandler(codePos, handlerPos)); | 754 exceptionHandlers.add(new ExceptionHandler(codePos, handlerPos)); |
740 } | 755 } |
741 | 756 |
742 /** | 757 /** |
783 * handled by dedicated methods like {@link #recordCall}. | 798 * handled by dedicated methods like {@link #recordCall}. |
784 * | 799 * |
785 * @param infopoint the infopoint to record, usually a derived class from {@link Infopoint} | 800 * @param infopoint the infopoint to record, usually a derived class from {@link Infopoint} |
786 */ | 801 */ |
787 public void addInfopoint(Infopoint infopoint) { | 802 public void addInfopoint(Infopoint infopoint) { |
803 checkOpen(); | |
788 infopoints.add(infopoint); | 804 infopoints.add(infopoint); |
789 } | 805 } |
790 | 806 |
791 /** | 807 /** |
792 * Records an instruction mark within this method. | 808 * Records an instruction mark within this method. |
793 * | 809 * |
794 * @param codePos the position in the code that is covered by the handler | 810 * @param codePos the position in the code that is covered by the handler |
795 * @param markId the identifier for this mark | 811 * @param markId the identifier for this mark |
796 */ | 812 */ |
797 public Mark recordMark(int codePos, Object markId) { | 813 public Mark recordMark(int codePos, Object markId) { |
814 checkOpen(); | |
798 Mark mark = new Mark(codePos, markId); | 815 Mark mark = new Mark(codePos, markId); |
799 marks.add(mark); | 816 marks.add(mark); |
800 return mark; | 817 return mark; |
801 } | 818 } |
802 | 819 |
812 /** | 829 /** |
813 * @see #getCustomStackAreaOffset() | 830 * @see #getCustomStackAreaOffset() |
814 * @param offset | 831 * @param offset |
815 */ | 832 */ |
816 public void setCustomStackAreaOffset(int offset) { | 833 public void setCustomStackAreaOffset(int offset) { |
834 checkOpen(); | |
817 customStackAreaOffset = offset; | 835 customStackAreaOffset = offset; |
818 } | 836 } |
819 | 837 |
820 /** | 838 /** |
821 * @return the machine code generated for this method | 839 * @return the machine code generated for this method |
840 } | 858 } |
841 return annotations; | 859 return annotations; |
842 } | 860 } |
843 | 861 |
844 public void addAnnotation(CodeAnnotation annotation) { | 862 public void addAnnotation(CodeAnnotation annotation) { |
863 checkOpen(); | |
845 assert annotation != null; | 864 assert annotation != null; |
846 if (annotations == null) { | 865 if (annotations == null) { |
847 annotations = new ArrayList<>(); | 866 annotations = new ArrayList<>(); |
848 } | 867 } |
849 annotations.add(annotation); | 868 annotations.add(annotation); |
922 public String getName() { | 941 public String getName() { |
923 return name; | 942 return name; |
924 } | 943 } |
925 | 944 |
926 public void setHasUnsafeAccess(boolean hasUnsafeAccess) { | 945 public void setHasUnsafeAccess(boolean hasUnsafeAccess) { |
946 checkOpen(); | |
927 this.hasUnsafeAccess = hasUnsafeAccess; | 947 this.hasUnsafeAccess = hasUnsafeAccess; |
928 } | 948 } |
929 | 949 |
930 public boolean hasUnsafeAccess() { | 950 public boolean hasUnsafeAccess() { |
931 return hasUnsafeAccess; | 951 return hasUnsafeAccess; |
932 } | 952 } |
953 | |
954 /** | |
955 * Clears the information in this object pertaining to generating code. That is, the | |
956 * {@linkplain #getMarks() marks}, {@linkplain #getInfopoints() infopoints}, | |
957 * {@linkplain #getExceptionHandlers() exception handlers}, {@linkplain #getDataPatches() data | |
958 * patches} and {@linkplain #getAnnotations() annotations} recorded in this object are cleared. | |
959 */ | |
960 public void resetForEmittingCode() { | |
961 checkOpen(); | |
962 infopoints.clear(); | |
963 dataPatches.clear(); | |
964 exceptionHandlers.clear(); | |
965 marks.clear(); | |
966 dataSection.clear(); | |
967 if (annotations != null) { | |
968 annotations.clear(); | |
969 } | |
970 } | |
971 | |
972 private void checkOpen() { | |
973 if (closed) { | |
974 throw new IllegalStateException(); | |
975 } | |
976 } | |
977 | |
978 /** | |
979 * Closes this compilation result to future updates. | |
980 */ | |
981 public void close() { | |
982 if (closed) { | |
983 throw new IllegalStateException("Cannot re-close compilation result " + this); | |
984 } | |
985 dataSection.close(); | |
986 closed = true; | |
987 } | |
933 } | 988 } |