1 /*
2 * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
1089
1090 /**
1091 * @param type
1092 */
1093 protected void handleUnresolvedExceptionType(JavaType type) {
1094 assert !graphBuilderConfig.unresolvedIsError();
1095 DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
1096 deopt.updateNodeSourcePosition(() -> createBytecodePosition());
1097 }
1098
1099 /**
1100 * @param javaMethod
1101 * @param invokeKind
1102 */
1103 protected void handleUnresolvedInvoke(JavaMethod javaMethod, InvokeKind invokeKind) {
1104 assert !graphBuilderConfig.unresolvedIsError();
1105 DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
1106 deopt.updateNodeSourcePosition(() -> createBytecodePosition());
1107 }
1108
1109 private AbstractBeginNode handleException(ValueNode exceptionObject, int bci, boolean deoptimizeOnly) {
1110 assert bci == BytecodeFrame.BEFORE_BCI || bci == bci() : "invalid bci";
1111 debug.log("Creating exception dispatch edges at %d, exception object=%s, exception seen=%s", bci, exceptionObject, (profilingInfo == null ? "" : profilingInfo.getExceptionSeen(bci)));
1112
1113 FrameStateBuilder dispatchState = frameState.copy();
1114 dispatchState.clearStack();
1115
1116 AbstractBeginNode dispatchBegin;
1117 if (exceptionObject == null) {
1118 ExceptionObjectNode newExceptionObject = graph.add(new ExceptionObjectNode(metaAccess));
1119 dispatchBegin = newExceptionObject;
1120 dispatchState.push(JavaKind.Object, dispatchBegin);
1121 dispatchState.setRethrowException(true);
1122 newExceptionObject.setStateAfter(dispatchState.create(bci, newExceptionObject));
1123 } else {
1124 dispatchBegin = graph.add(new BeginNode());
1125 dispatchState.push(JavaKind.Object, exceptionObject);
1126 dispatchState.setRethrowException(true);
1127 }
1128 this.controlFlowSplit = true;
1129 FixedWithNextNode finishedDispatch = finishInstruction(dispatchBegin, dispatchState);
1130
1131 if (deoptimizeOnly) {
1132 DeoptimizeNode deoptimizeNode = graph.add(new DeoptimizeNode(DeoptimizationAction.None, DeoptimizationReason.TransferToInterpreter));
1133 dispatchBegin.setNext(BeginNode.begin(deoptimizeNode));
1134 } else {
1135 createHandleExceptionTarget(finishedDispatch, bci, dispatchState);
1136 }
1137 return dispatchBegin;
1138 }
1139
1140 protected void createHandleExceptionTarget(FixedWithNextNode finishedDispatch, int bci, FrameStateBuilder dispatchState) {
1141 BciBlock dispatchBlock = currentBlock.exceptionDispatchBlock();
1142 /*
1143 * The exception dispatch block is always for the last bytecode of a block, so if we are not
1144 * at the endBci yet, there is no exception handler for this bci and we can unwind
1145 * immediately.
1146 */
1147 if (bci != currentBlock.endBci || dispatchBlock == null) {
1148 dispatchBlock = blockMap.getUnwindBlock();
1149 }
1150
1151 FixedNode target = createTarget(dispatchBlock, dispatchState);
1152 finishedDispatch.setNext(target);
1153 }
1154
1155 protected ValueNode genLoadIndexed(ValueNode array, ValueNode index, GuardingNode boundsCheck, JavaKind kind) {
1156 return LoadIndexedNode.create(graph.getAssumptions(), array, index, boundsCheck, kind, metaAccess, constantReflection);
1157 }
1158
1159 protected void genStoreIndexed(ValueNode array, ValueNode index, GuardingNode boundsCheck, GuardingNode storeCheck, JavaKind kind, ValueNode value) {
1160 add(new StoreIndexedNode(array, index, boundsCheck, storeCheck, kind, value));
1161 }
1162
1163 protected ValueNode genIntegerAdd(ValueNode x, ValueNode y) {
1164 return AddNode.create(x, y, NodeView.DEFAULT);
1165 }
1166
1167 protected ValueNode genIntegerSub(ValueNode x, ValueNode y) {
1168 return SubNode.create(x, y, NodeView.DEFAULT);
1169 }
1170
1171 protected ValueNode genIntegerMul(ValueNode x, ValueNode y) {
1172 return MulNode.create(x, y, NodeView.DEFAULT);
|
1 /*
2 * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
1089
1090 /**
1091 * @param type
1092 */
1093 protected void handleUnresolvedExceptionType(JavaType type) {
1094 assert !graphBuilderConfig.unresolvedIsError();
1095 DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
1096 deopt.updateNodeSourcePosition(() -> createBytecodePosition());
1097 }
1098
1099 /**
1100 * @param javaMethod
1101 * @param invokeKind
1102 */
1103 protected void handleUnresolvedInvoke(JavaMethod javaMethod, InvokeKind invokeKind) {
1104 assert !graphBuilderConfig.unresolvedIsError();
1105 DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
1106 deopt.updateNodeSourcePosition(() -> createBytecodePosition());
1107 }
1108
1109 /**
1110 * @return the entry point to exception dispatch
1111 */
1112 private AbstractBeginNode handleException(ValueNode exceptionObject, int bci, boolean deoptimizeOnly) {
1113 FixedWithNextNode currentLastInstr = lastInstr;
1114 assert bci == BytecodeFrame.BEFORE_BCI || bci == bci() : "invalid bci";
1115 debug.log("Creating exception dispatch edges at %d, exception object=%s, exception seen=%s", bci, exceptionObject, (profilingInfo == null ? "" : profilingInfo.getExceptionSeen(bci)));
1116
1117 FrameStateBuilder dispatchState = frameState.copy();
1118 dispatchState.clearStack();
1119
1120 AbstractBeginNode dispatchBegin;
1121 if (exceptionObject == null) {
1122 ExceptionObjectNode newExceptionObject = graph.add(new ExceptionObjectNode(metaAccess));
1123 dispatchBegin = newExceptionObject;
1124 dispatchState.push(JavaKind.Object, dispatchBegin);
1125 dispatchState.setRethrowException(true);
1126 newExceptionObject.setStateAfter(dispatchState.create(bci, newExceptionObject));
1127 } else {
1128 dispatchBegin = graph.add(new BeginNode());
1129 dispatchState.push(JavaKind.Object, exceptionObject);
1130 dispatchState.setRethrowException(true);
1131 }
1132 this.controlFlowSplit = true;
1133 FixedWithNextNode afterExceptionLoaded = finishInstruction(dispatchBegin, dispatchState);
1134
1135 if (deoptimizeOnly) {
1136 DeoptimizeNode deoptimizeNode = graph.add(new DeoptimizeNode(DeoptimizationAction.None, DeoptimizationReason.TransferToInterpreter));
1137 afterExceptionLoaded.setNext(BeginNode.begin(deoptimizeNode));
1138 } else {
1139 createHandleExceptionTarget(afterExceptionLoaded, bci, dispatchState);
1140 }
1141 assert currentLastInstr == lastInstr;
1142 return dispatchBegin;
1143 }
1144
1145 protected void createHandleExceptionTarget(FixedWithNextNode afterExceptionLoaded, int bci, FrameStateBuilder dispatchState) {
1146 FixedWithNextNode afterInstrumentation = afterExceptionLoaded;
1147 for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
1148 afterInstrumentation = plugin.instrumentExceptionDispatch(graph, afterInstrumentation);
1149 assert afterInstrumentation.next() == null : "exception dispatch instrumentation will be linked to dispatch block";
1150 }
1151
1152 BciBlock dispatchBlock = currentBlock.exceptionDispatchBlock();
1153 /*
1154 * The exception dispatch block is always for the last bytecode of a block, so if we are not
1155 * at the endBci yet, there is no exception handler for this bci and we can unwind
1156 * immediately.
1157 */
1158 if (bci != currentBlock.endBci || dispatchBlock == null) {
1159 dispatchBlock = blockMap.getUnwindBlock();
1160 }
1161
1162 FixedNode target = createTarget(dispatchBlock, dispatchState);
1163 afterInstrumentation.setNext(target);
1164 }
1165
1166 protected ValueNode genLoadIndexed(ValueNode array, ValueNode index, GuardingNode boundsCheck, JavaKind kind) {
1167 return LoadIndexedNode.create(graph.getAssumptions(), array, index, boundsCheck, kind, metaAccess, constantReflection);
1168 }
1169
1170 protected void genStoreIndexed(ValueNode array, ValueNode index, GuardingNode boundsCheck, GuardingNode storeCheck, JavaKind kind, ValueNode value) {
1171 add(new StoreIndexedNode(array, index, boundsCheck, storeCheck, kind, value));
1172 }
1173
1174 protected ValueNode genIntegerAdd(ValueNode x, ValueNode y) {
1175 return AddNode.create(x, y, NodeView.DEFAULT);
1176 }
1177
1178 protected ValueNode genIntegerSub(ValueNode x, ValueNode y) {
1179 return SubNode.create(x, y, NodeView.DEFAULT);
1180 }
1181
1182 protected ValueNode genIntegerMul(ValueNode x, ValueNode y) {
1183 return MulNode.create(x, y, NodeView.DEFAULT);
|