Path: blob/master/jcl/src/java.base/share/classes/java/lang/invoke/FinallyHandle.java
12520 views
/*[INCLUDE-IF Sidecar19-SE & !OPENJDK_METHODHANDLES]*/1/*******************************************************************************2* Copyright (c) 2016, 2020 IBM Corp. and others3*4* This program and the accompanying materials are made available under5* the terms of the Eclipse Public License 2.0 which accompanies this6* distribution and is available at https://www.eclipse.org/legal/epl-2.0/7* or the Apache License, Version 2.0 which accompanies this distribution and8* is available at https://www.apache.org/licenses/LICENSE-2.0.9*10* This Source Code may also be made available under the following11* Secondary Licenses when the conditions for such availability set12* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU13* General Public License, version 2 with the GNU Classpath14* Exception [1] and GNU General Public License, version 2 with the15* OpenJDK Assembly Exception [2].16*17* [1] https://www.gnu.org/software/classpath/license.html18* [2] http://openjdk.java.net/legal/assembly-exception.html19*20* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception21*******************************************************************************/22package java.lang.invoke;2324final class FinallyHandle extends PassThroughHandle {25private final MethodHandle tryTarget;26private final MethodHandle finallyTarget;2728protected FinallyHandle(MethodHandle tryTarget, MethodHandle finallyTarget, MethodHandle equivalent) {29super(equivalent, infoAffectingThunks(finallyTarget.type().parameterCount())); //$NON-NLS-1$30this.tryTarget = tryTarget;31this.finallyTarget = finallyTarget;32}3334FinallyHandle(FinallyHandle finallyHandle, MethodType newType) {35super(finallyHandle, newType);36this.tryTarget = finallyHandle.tryTarget;37this.finallyTarget = finallyHandle.finallyTarget;38}3940public static FinallyHandle get(MethodHandle tryTarget, MethodHandle finallyTarget, MethodHandle equivalent) {41return new FinallyHandle(tryTarget, finallyTarget, equivalent);42}4344// {{{ JIT support45private static final ThunkTable _thunkTable = new ThunkTable();46protected final ThunkTable thunkTable(){ return _thunkTable; }4748private static native int numFinallyTargetArgsToPassThrough();4950private static Object infoAffectingThunks(int numFinallyTargetArgs) {51// The number of arguments passed to the finally target affects the code generated in the thunks52return numFinallyTargetArgs;53}5455protected final ThunkTuple computeThunks(Object arg) {56int numFinallyTargetArgs = (Integer)arg;57return thunkTable().get(new ThunkKeyWithInt(ThunkKey.computeThunkableType(type()), numFinallyTargetArgs));58}59// }}} JIT support6061final void compareWith(MethodHandle right, Comparator c) {62if (right instanceof FinallyHandle) {63((FinallyHandle)right).compareWithFinally(this, c);64} else {65c.fail();66}67}6869final void compareWithFinally(FinallyHandle left, Comparator c) {70c.compareChildHandle(left.tryTarget, this.tryTarget);71c.compareChildHandle(left.finallyTarget, this.finallyTarget);72}7374MethodHandle cloneWithNewType(MethodType newType) {75return new FinallyHandle(this, newType);76}7778@FrameIteratorSkip79private final void invokeExact_thunkArchetype_V(int argPlaceholder) throws Throwable {80if (ILGenMacros.isShareableThunk()) {81undoCustomizationLogic(tryTarget, finallyTarget);82}83if (!ILGenMacros.isCustomThunk()) {84doCustomizationLogic();85}8687Throwable finallyThrowable = null;88try {89ILGenMacros.invokeExact_V(tryTarget, argPlaceholder);90} catch (Throwable tryThrowable) {91finallyThrowable = tryThrowable;92throw tryThrowable;93} finally {94ILGenMacros.invokeExact_V(finallyTarget,95ILGenMacros.placeholder(finallyThrowable,96ILGenMacros.firstN(numFinallyTargetArgsToPassThrough(),97argPlaceholder)));98}99}100101@FrameIteratorSkip102@SuppressWarnings("finally")103private final boolean invokeExact_thunkArchetype_Z(int argPlaceholder) throws Throwable {104if (ILGenMacros.isShareableThunk()) {105undoCustomizationLogic(tryTarget, finallyTarget);106}107if (!ILGenMacros.isCustomThunk()) {108doCustomizationLogic();109}110111Throwable finallyThrowable = null;112boolean result = false;113try {114result = ILGenMacros.invokeExact_Z(tryTarget, argPlaceholder);115} catch (Throwable tryThrowable) {116finallyThrowable = tryThrowable;117throw tryThrowable;118} finally {119return ILGenMacros.invokeExact_Z(finallyTarget,120ILGenMacros.placeholder(finallyThrowable, result,121ILGenMacros.firstN(numFinallyTargetArgsToPassThrough(),122argPlaceholder)));123}124}125126@FrameIteratorSkip127@SuppressWarnings("finally")128private final byte invokeExact_thunkArchetype_B(int argPlaceholder) throws Throwable {129if (ILGenMacros.isShareableThunk()) {130undoCustomizationLogic(tryTarget, finallyTarget);131}132if (!ILGenMacros.isCustomThunk()) {133doCustomizationLogic();134}135136Throwable finallyThrowable = null;137byte result = 0x0;138try {139result = ILGenMacros.invokeExact_B(tryTarget, argPlaceholder);140} catch (Throwable tryThrowable) {141finallyThrowable = tryThrowable;142throw tryThrowable;143} finally {144return ILGenMacros.invokeExact_B(finallyTarget,145ILGenMacros.placeholder(finallyThrowable, result,146ILGenMacros.firstN(numFinallyTargetArgsToPassThrough(),147argPlaceholder)));148}149}150151@FrameIteratorSkip152@SuppressWarnings("finally")153private final short invokeExact_thunkArchetype_S(int argPlaceholder) throws Throwable {154if (ILGenMacros.isShareableThunk()) {155undoCustomizationLogic(tryTarget, finallyTarget);156}157if (!ILGenMacros.isCustomThunk()) {158doCustomizationLogic();159}160161Throwable finallyThrowable = null;162short result = 0;163try {164result = ILGenMacros.invokeExact_S(tryTarget, argPlaceholder);165} catch (Throwable tryThrowable) {166finallyThrowable = tryThrowable;167throw tryThrowable;168} finally {169return ILGenMacros.invokeExact_S(finallyTarget,170ILGenMacros.placeholder(finallyThrowable, result,171ILGenMacros.firstN(numFinallyTargetArgsToPassThrough(),172argPlaceholder)));173}174}175176@FrameIteratorSkip177@SuppressWarnings("finally")178private final int invokeExact_thunkArchetype_X(int argPlaceholder) throws Throwable {179if (ILGenMacros.isShareableThunk()) {180undoCustomizationLogic(tryTarget, finallyTarget);181}182if (!ILGenMacros.isCustomThunk()) {183doCustomizationLogic();184}185186Throwable finallyThrowable = null;187int result = 0;188try {189result = ILGenMacros.invokeExact_X(tryTarget, argPlaceholder);190} catch (Throwable tryThrowable) {191finallyThrowable = tryThrowable;192throw tryThrowable;193} finally {194return ILGenMacros.invokeExact_X(finallyTarget,195ILGenMacros.placeholder(finallyThrowable, result,196ILGenMacros.firstN(numFinallyTargetArgsToPassThrough(),197argPlaceholder)));198}199}200201@FrameIteratorSkip202@SuppressWarnings("finally")203private final long invokeExact_thunkArchetype_J(int argPlaceholder) throws Throwable {204if (ILGenMacros.isShareableThunk()) {205undoCustomizationLogic(tryTarget, finallyTarget);206}207if (!ILGenMacros.isCustomThunk()) {208doCustomizationLogic();209}210211Throwable finallyThrowable = null;212long result = 0L;213try {214result = ILGenMacros.invokeExact_J(tryTarget, argPlaceholder);215} catch (Throwable tryThrowable) {216finallyThrowable = tryThrowable;217throw tryThrowable;218} finally {219return ILGenMacros.invokeExact_J(finallyTarget,220ILGenMacros.placeholder(finallyThrowable, result,221ILGenMacros.firstN(numFinallyTargetArgsToPassThrough(),222argPlaceholder)));223}224}225226@FrameIteratorSkip227@SuppressWarnings("finally")228private final float invokeExact_thunkArchetype_F(int argPlaceholder) throws Throwable {229if (ILGenMacros.isShareableThunk()) {230undoCustomizationLogic(tryTarget, finallyTarget);231}232if (!ILGenMacros.isCustomThunk()) {233doCustomizationLogic();234}235236Throwable finallyThrowable = null;237float result = 0.0F;238try {239result = ILGenMacros.invokeExact_F(tryTarget, argPlaceholder);240} catch (Throwable tryThrowable) {241finallyThrowable = tryThrowable;242throw tryThrowable;243} finally {244return ILGenMacros.invokeExact_F(finallyTarget,245ILGenMacros.placeholder(finallyThrowable, result,246ILGenMacros.firstN(numFinallyTargetArgsToPassThrough(),247argPlaceholder)));248}249}250251@FrameIteratorSkip252@SuppressWarnings("finally")253private final double invokeExact_thunkArchetype_D(int argPlaceholder) throws Throwable {254if (ILGenMacros.isShareableThunk()) {255undoCustomizationLogic(tryTarget, finallyTarget);256}257if (!ILGenMacros.isCustomThunk()) {258doCustomizationLogic();259}260261Throwable finallyThrowable = null;262double result = 0.0D;263try {264result = ILGenMacros.invokeExact_D(tryTarget, argPlaceholder);265} catch (Throwable tryThrowable) {266finallyThrowable = tryThrowable;267throw tryThrowable;268} finally {269return ILGenMacros.invokeExact_D(finallyTarget,270ILGenMacros.placeholder(finallyThrowable, result,271ILGenMacros.firstN(numFinallyTargetArgsToPassThrough(),272argPlaceholder)));273}274}275276@FrameIteratorSkip277@SuppressWarnings("finally")278private final Object invokeExact_thunkArchetype_L(int argPlaceholder) throws Throwable {279if (ILGenMacros.isShareableThunk()) {280undoCustomizationLogic(tryTarget, finallyTarget);281}282if (!ILGenMacros.isCustomThunk()) {283doCustomizationLogic();284}285286Throwable finallyThrowable = null;287Object result = null;288try {289result = ILGenMacros.invokeExact_L(tryTarget, argPlaceholder);290} catch (Throwable tryThrowable) {291finallyThrowable = tryThrowable;292throw tryThrowable;293} finally {294return ILGenMacros.invokeExact_L(finallyTarget,295ILGenMacros.placeholder(finallyThrowable, result,296ILGenMacros.firstN(numFinallyTargetArgsToPassThrough(),297argPlaceholder)));298}299}300}301302303