84 import java.util.HashSet; |
84 import java.util.HashSet; |
85 import java.util.Iterator; |
85 import java.util.Iterator; |
86 import java.util.List; |
86 import java.util.List; |
87 import java.util.TreeSet; |
87 import java.util.TreeSet; |
88 |
88 |
|
89 import org.graalvm.collections.EconomicMap; |
|
90 import org.graalvm.collections.Equivalence; |
89 import org.graalvm.compiler.bytecode.Bytecode; |
91 import org.graalvm.compiler.bytecode.Bytecode; |
90 import org.graalvm.compiler.bytecode.BytecodeLookupSwitch; |
92 import org.graalvm.compiler.bytecode.BytecodeLookupSwitch; |
91 import org.graalvm.compiler.bytecode.BytecodeStream; |
93 import org.graalvm.compiler.bytecode.BytecodeStream; |
92 import org.graalvm.compiler.bytecode.BytecodeSwitch; |
94 import org.graalvm.compiler.bytecode.BytecodeSwitch; |
93 import org.graalvm.compiler.bytecode.BytecodeTableSwitch; |
95 import org.graalvm.compiler.bytecode.BytecodeTableSwitch; |
94 import org.graalvm.compiler.bytecode.Bytecodes; |
96 import org.graalvm.compiler.bytecode.Bytecodes; |
95 import org.graalvm.compiler.core.common.PermanentBailoutException; |
97 import org.graalvm.compiler.core.common.PermanentBailoutException; |
96 import org.graalvm.compiler.debug.DebugContext; |
98 import org.graalvm.compiler.debug.DebugContext; |
97 import org.graalvm.compiler.options.OptionValues; |
99 import org.graalvm.compiler.options.OptionValues; |
98 import org.graalvm.util.EconomicMap; |
|
99 import org.graalvm.util.Equivalence; |
|
100 |
100 |
101 import jdk.vm.ci.code.BytecodeFrame; |
101 import jdk.vm.ci.code.BytecodeFrame; |
102 import jdk.vm.ci.meta.ExceptionHandler; |
102 import jdk.vm.ci.meta.ExceptionHandler; |
103 |
103 |
104 /** |
104 /** |
746 createJsrAlternatives(blockMap, successor); |
743 createJsrAlternatives(blockMap, successor); |
747 } |
744 } |
748 } |
745 } |
749 } |
746 } |
750 |
747 |
751 private EconomicMap<ExceptionHandler, ExceptionDispatchBlock> initialExceptionDispatch; |
|
752 |
|
753 private EconomicMap<ExceptionHandler, ExceptionDispatchBlock> getInitialExceptionDispatch() { |
|
754 if (initialExceptionDispatch == null) { |
|
755 initialExceptionDispatch = EconomicMap.create(Equivalence.DEFAULT); |
|
756 } |
|
757 return initialExceptionDispatch; |
|
758 } |
|
759 |
|
760 private ExceptionDispatchBlock handleExceptions(BciBlock[] blockMap, int bci) { |
748 private ExceptionDispatchBlock handleExceptions(BciBlock[] blockMap, int bci) { |
761 ExceptionDispatchBlock lastHandler = null; |
749 ExceptionDispatchBlock lastHandler = null; |
762 |
750 |
763 for (int i = exceptionHandlers.length - 1; i >= 0; i--) { |
751 for (int i = exceptionHandlers.length - 1; i >= 0; i--) { |
764 ExceptionHandler h = exceptionHandlers[i]; |
752 ExceptionHandler h = exceptionHandlers[i]; |
767 // Discard all information about succeeding exception handlers, since they can |
755 // Discard all information about succeeding exception handlers, since they can |
768 // never be reached. |
756 // never be reached. |
769 lastHandler = null; |
757 lastHandler = null; |
770 } |
758 } |
771 |
759 |
772 EconomicMap<ExceptionHandler, ExceptionDispatchBlock> exceptionDispatch = lastHandler != null ? lastHandler.exceptionDispatch : getInitialExceptionDispatch(); |
760 // We do not reuse exception dispatch blocks, because nested exception handlers |
773 ExceptionDispatchBlock curHandler = exceptionDispatch.get(h); |
761 // might have problems reasoning about the correct frame state. |
774 if (curHandler == null) { |
762 ExceptionDispatchBlock curHandler = new ExceptionDispatchBlock(); |
775 curHandler = new ExceptionDispatchBlock(); |
763 blocksNotYetAssignedId++; |
776 blocksNotYetAssignedId++; |
764 curHandler.startBci = -1; |
777 curHandler.startBci = -1; |
765 curHandler.endBci = -1; |
778 curHandler.endBci = -1; |
766 curHandler.deoptBci = bci; |
779 curHandler.deoptBci = bci; |
767 curHandler.handler = h; |
780 curHandler.handler = h; |
768 curHandler.addSuccessor(blockMap[h.getHandlerBCI()]); |
781 curHandler.addSuccessor(blockMap[h.getHandlerBCI()]); |
769 if (lastHandler != null) { |
782 if (lastHandler != null) { |
770 curHandler.addSuccessor(lastHandler); |
783 curHandler.addSuccessor(lastHandler); |
|
784 } |
|
785 exceptionDispatch.put(h, curHandler); |
|
786 } |
771 } |
787 lastHandler = curHandler; |
772 lastHandler = curHandler; |
788 } |
773 } |
789 } |
774 } |
790 return lastHandler; |
775 return lastHandler; |