Path: blob/master/jcl/src/java.base/share/classes/java/lang/invoke/CatchHandle.java
12520 views
/*[INCLUDE-IF Sidecar17 & !OPENJDK_METHODHANDLES]*/1/*******************************************************************************2* Copyright (c) 2011, 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 CatchHandle extends PassThroughHandle {25private final MethodHandle tryTarget;26private final Class<? extends Throwable> exceptionClass;27private final MethodHandle catchTarget;2829protected CatchHandle(MethodHandle tryTarget, Class<? extends Throwable> exceptionClass, MethodHandle catchTarget, MethodHandle equivalent) {30super(equivalent, infoAffectingThunks(catchTarget.type().parameterCount())); //$NON-NLS-1$31this.tryTarget = tryTarget;32this.exceptionClass = exceptionClass;33this.catchTarget = catchTarget;34}3536CatchHandle(CatchHandle catchHandle, MethodType newType) {37super(catchHandle, newType);38this.tryTarget = catchHandle.tryTarget;39this.exceptionClass = catchHandle.exceptionClass;40this.catchTarget = catchHandle.catchTarget;41}4243MethodHandle cloneWithNewType(MethodType newType) {44return new CatchHandle(this, newType);45}4647public static CatchHandle get(MethodHandle tryTarget, Class<? extends Throwable> exceptionClass, MethodHandle catchTarget, MethodHandle equivalent) {48return new CatchHandle(tryTarget, exceptionClass, catchTarget, equivalent);49}5051// {{{ JIT support52private static final ThunkTable _thunkTable = new ThunkTable();53protected final ThunkTable thunkTable(){ return _thunkTable; }5455private static native int numCatchTargetArgsToPassThrough();5657private static Object infoAffectingThunks(int numCatchTargetArgs) {58// The number of arguments passed to the catch target affects the code generated in the thunks59return numCatchTargetArgs;60}6162protected final ThunkTuple computeThunks(Object arg) {63int numCatchTargetArgs = (Integer)arg;64return thunkTable().get(new ThunkKeyWithInt(ThunkKey.computeThunkableType(type()), numCatchTargetArgs));65}6667@FrameIteratorSkip68private final int invokeExact_thunkArchetype_X(int argPlaceholder) {69if (ILGenMacros.isShareableThunk()) {70undoCustomizationLogic(tryTarget, catchTarget);71}72if (!ILGenMacros.isCustomThunk()) {73doCustomizationLogic();74}75try {76return ILGenMacros.invokeExact_X(tryTarget, argPlaceholder);77} catch (Throwable t) {78if (exceptionClass.isInstance(t)) {79return ILGenMacros.invokeExact_X(catchTarget, ILGenMacros.placeholder(t, ILGenMacros.firstN(numCatchTargetArgsToPassThrough(), argPlaceholder)));80} else {81throw t;82}83}84}8586// }}} JIT support8788final void compareWith(MethodHandle right, Comparator c) {89if (right instanceof CatchHandle) {90((CatchHandle)right).compareWithCatch(this, c);91} else {92c.fail();93}94}9596final void compareWithCatch(CatchHandle left, Comparator c) {97c.compareStructuralParameter(left.exceptionClass, this.exceptionClass);98c.compareChildHandle(left.tryTarget, this.tryTarget);99c.compareChildHandle(left.catchTarget, this.catchTarget);100}101}102103104105