當前位置: 首頁>>代碼示例>>Java>>正文


Java MethodVisitor.visitTryCatchBlock方法代碼示例

本文整理匯總了Java中org.objectweb.asm.MethodVisitor.visitTryCatchBlock方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodVisitor.visitTryCatchBlock方法的具體用法?Java MethodVisitor.visitTryCatchBlock怎麽用?Java MethodVisitor.visitTryCatchBlock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.objectweb.asm.MethodVisitor的用法示例。


在下文中一共展示了MethodVisitor.visitTryCatchBlock方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeNonAbstractMethodWrapper

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private void writeNonAbstractMethodWrapper(ClassVisitor visitor, Type generatedType, Class<?> managedTypeClass, Method method) {
    Label start = new Label();
    Label end = new Label();
    Label handler = new Label();

    MethodVisitor methodVisitor = declareMethod(visitor, method);

    methodVisitor.visitTryCatchBlock(start, end, handler, null);

    setCanCallSettersField(methodVisitor, generatedType, false);

    methodVisitor.visitLabel(start);
    invokeSuperMethod(methodVisitor, managedTypeClass, method);
    methodVisitor.visitLabel(end);

    setCanCallSettersField(methodVisitor, generatedType, true);
    methodVisitor.visitInsn(ARETURN);

    methodVisitor.visitLabel(handler);
    setCanCallSettersField(methodVisitor, generatedType, true);
    methodVisitor.visitInsn(ATHROW);

    methodVisitor.visitMaxs(0, 0);
    methodVisitor.visitEnd();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:26,代碼來源:ManagedProxyClassGenerator.java

示例2: visitBlockStructured

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private static void visitBlockStructured(ClassWriter cw, boolean normalReturnError, boolean tooMany) {
    String name = (tooMany ? "tooMany" : "tooFew") + "Exits" + (normalReturnError ? "" : "Exceptional");
    // Generate too many or too few exits down the either the normal or exceptional return
    // paths
    int exceptionalExitCount = normalReturnError ? 1 : (tooMany ? 2 : 0);
    int normalExitCount = normalReturnError ? (tooMany ? 2 : 0) : 1;
    MethodVisitor mv;
    mv = cw.visitMethod(ACC_PUBLIC, name, "(Ljava/lang/Object;Ljava/lang/Object;)Z", null, null);
    mv.visitCode();
    Label l0 = new Label();
    Label l1 = new Label();
    Label l2 = new Label();
    mv.visitTryCatchBlock(l0, l1, l2, null);
    Label l3 = new Label();
    mv.visitTryCatchBlock(l2, l3, l2, null);
    Label l4 = new Label();
    Label l5 = new Label();
    Label l6 = new Label();
    mv.visitTryCatchBlock(l4, l5, l6, null);
    Label l7 = new Label();
    mv.visitTryCatchBlock(l2, l7, l6, null);
    Label l8 = new Label();
    mv.visitLabel(l8);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ASTORE, 3);
    mv.visitInsn(MONITORENTER);
    mv.visitLabel(l4);
    mv.visitVarInsn(ALOAD, 2);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ASTORE, 4);
    mv.visitInsn(MONITORENTER);
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 2);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z", false);
    mv.visitVarInsn(ALOAD, 4);
    mv.visitInsn(MONITOREXIT);
    mv.visitLabel(l1);
    for (int i = 0; i < normalExitCount; i++) {
        mv.visitVarInsn(ALOAD, 3);
        mv.visitInsn(MONITOREXIT);
    }
    mv.visitLabel(l5);
    mv.visitInsn(IRETURN);
    mv.visitLabel(l2);
    mv.visitFrame(Opcodes.F_FULL, 5, new Object[]{INNER_CLASS_NAME_INTERNAL, "java/lang/Object", "java/lang/Object", "java/lang/Object",
                    "java/lang/Object"}, 1, new Object[]{"java/lang/Throwable"});
    mv.visitVarInsn(ALOAD, 4);
    mv.visitInsn(MONITOREXIT);
    mv.visitLabel(l3);
    mv.visitInsn(ATHROW);
    mv.visitLabel(l6);
    mv.visitFrame(Opcodes.F_FULL, 4, new Object[]{INNER_CLASS_NAME_INTERNAL, "java/lang/Object", "java/lang/Object", "java/lang/Object"}, 1,
                    new Object[]{"java/lang/Throwable"});
    for (int i = 0; i < exceptionalExitCount; i++) {
        mv.visitVarInsn(ALOAD, 3);
        mv.visitInsn(MONITOREXIT);
    }
    mv.visitLabel(l7);
    mv.visitInsn(ATHROW);
    Label l9 = new Label();
    mv.visitLabel(l9);
    mv.visitMaxs(2, 5);
    mv.visitEnd();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:67,代碼來源:UnbalancedMonitorsTest.java

示例3: visit

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
@Override
public Object visit(ASTCatch node, Object data) throws CompileException {

  dump_context_stack();
  TContext context = popContext();
  Debug.assertion(context != null, "Context should not be null");

  LangUnitNode stream_node = (LangUnitNode) node.jjtGetParent();
  Debug.assertion(stream_node != null, "stream_node should be valid");
  Debug.assertion(stream_node.isNodeId(JJTSTREAM), "stream_node should be stream node");

  int streamblock_idx = stream_node.getChildIdxWithId(JJTSTREAMBLOCK, 0);
  LangUnitNode streamblock_node = (LangUnitNode) stream_node.getChildren(streamblock_idx);
  Debug.assertion(streamblock_node != null, "streamblock_node should be valid");
  Debug.assertion(streamblock_node.isNodeId(JJTSTREAMBLOCK), "streamblock_node should be streamblock node");

  Label stream_end_label = stream_node.getStreamEndLabel();
  Debug.assertion(stream_end_label != null, "stream_end_label should be valid");

  Label streamblock_start_label = streamblock_node.getStreamBlockStartLabel();
  Debug.assertion(streamblock_start_label != null, "streamblock_start_label should be valid");

  Label streamblock_end_label = streamblock_node.getStreamBlockEndLabel();
  Debug.assertion(streamblock_end_label != null, "streamblock_end_label should be valid");

  Label catch_label = node.getCatchLabel();
  Debug.assertion(catch_label != null, "catch_label should be valid");

  TContextFunc func_ctx = (TContextFunc) getTopContext().getClosestAncestor(AbsType.FORM_FUNC);
  Debug.assertion(func_ctx != null, "catch should be used in function context");

  MethodVisitor mv = func_ctx.getMethodVisitor();

  /*
   * public void visitCode() { super.visitCode(); visitTryCatchBlock(start,
   * end, handler, "java/lang/Exception"); visitLabel(start); }
   * mv.visitTryCatchBlock(arg0, arg1, arg2, arg3);
   */

  AbsTypeList excptype_list = node.getCatchExceptionList();
  Debug.assertion(excptype_list != null, "excptype_list should be valid");

  AbsType excptype = null;

  int size = excptype_list.size();
  for (int i = 0; i < size; i++) {
    excptype = excptype_list.get(i);
    LOG.debug("trycatch block for exception " + excptype);
    mv.visitTryCatchBlock(streamblock_start_label, streamblock_end_label, catch_label, excptype.getName());
  }

  LOG.info("GOTO stream_end_label({})", stream_end_label);
  mv.visitJumpInsn(GOTO, stream_end_label);

  return null;
}
 
開發者ID:Samsung,項目名稱:MeziLang,代碼行數:57,代碼來源:ASTCompileVisitor.java

示例4: writeTypeConvertingSetter

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private void writeTypeConvertingSetter(ClassVisitor visitor, Type generatedType, Class<?> viewClass, ModelProperty<?> property) {
    WeaklyTypeReferencingMethod<?, ?> weakSetter = property.getAccessor(SETTER);
    // There is no setter for this property
    if (weakSetter == null) {
        return;
    }
    if (!(property.getSchema() instanceof ScalarValueSchema)) {
        return;
    }

    Class<?> propertyClass = property.getType().getConcreteClass();
    Type propertyType = Type.getType(propertyClass);
    Class<?> boxedClass = propertyClass.isPrimitive() ? BOXED_TYPES.get(propertyClass) : propertyClass;
    Type boxedType = Type.getType(boxedClass);

    Method setter = weakSetter.getMethod();
    MethodVisitor methodVisitor = declareMethod(visitor, setter.getName(), SET_OBJECT_PROPERTY_DESCRIPTOR, SET_OBJECT_PROPERTY_DESCRIPTOR);

    putThisOnStack(methodVisitor);
    putTypeConverterFieldValueOnStack(methodVisitor, generatedType);

    // Object converted = $typeConverter.convert(foo, Float.class, false);
    methodVisitor.visitVarInsn(ALOAD, 1); // put var #1 ('foo') on the stack
    methodVisitor.visitLdcInsn(boxedType); // push the constant Class onto the stack
    methodVisitor.visitInsn(propertyClass.isPrimitive() ? ICONST_1 : ICONST_0); // push int 1 or 0 (interpreted as true or false) onto the stack
    Label startTry = new Label();
    methodVisitor.visitLabel(startTry);
    methodVisitor.visitMethodInsn(INVOKEINTERFACE, TYPE_CONVERTER_TYPE.getInternalName(), "convert", COERCE_TO_SCALAR_DESCRIPTOR, true);
    Label endTry = new Label();
    methodVisitor.visitLabel(endTry);
    methodVisitor.visitTypeInsn(CHECKCAST, boxedType.getInternalName());

    if (propertyClass.isPrimitive()) {
        unboxType(methodVisitor, propertyClass);
    }

    // invoke the typed setter
    methodVisitor.visitMethodInsn(INVOKEVIRTUAL, generatedType.getInternalName(), setter.getName(), Type.getMethodDescriptor(Type.VOID_TYPE, propertyType), false);
    methodVisitor.visitInsn(RETURN);

    // catch(TypeConversionException e) { throw ... }
    Label startCatch = new Label();
    methodVisitor.visitLabel(startCatch);
    methodVisitor.visitTryCatchBlock(startTry, endTry, startCatch, TYPE_CONVERSION_EXCEPTION_TYPE.getInternalName());
    methodVisitor.visitVarInsn(ASTORE, 2); // store thrown exception
    putClassOnStack(methodVisitor, viewClass);
    methodVisitor.visitLdcInsn(property.getName());
    putFirstMethodArgumentOnStack(methodVisitor);
    methodVisitor.visitVarInsn(ALOAD, 2);
    methodVisitor.visitMethodInsn(INVOKESTATIC, Type.getInternalName(ManagedProxyClassGenerator.class), "propertyValueConvertFailure",
            Type.getMethodDescriptor(Type.VOID_TYPE, CLASS_TYPE, STRING_TYPE, OBJECT_TYPE, TYPE_CONVERSION_EXCEPTION_TYPE), false);
    finishVisitingMethod(methodVisitor);
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:54,代碼來源:ManagedProxyClassGenerator.java

示例5: visitWrongOrder

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private static void visitWrongOrder(ClassWriter cw) {
    MethodVisitor mv;
    mv = cw.visitMethod(ACC_PUBLIC, "wrongOrder", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", null, null);
    mv.visitCode();
    Label l0 = new Label();
    Label l1 = new Label();
    Label l2 = new Label();
    mv.visitTryCatchBlock(l0, l1, l2, null);
    Label l3 = new Label();
    mv.visitTryCatchBlock(l2, l3, l2, null);
    Label l4 = new Label();
    Label l5 = new Label();
    Label l6 = new Label();
    mv.visitTryCatchBlock(l4, l5, l6, null);
    Label l7 = new Label();
    mv.visitTryCatchBlock(l2, l7, l6, null);
    Label l8 = new Label();
    mv.visitLabel(l8);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ASTORE, 3);
    mv.visitInsn(MONITORENTER);
    mv.visitLabel(l4);
    mv.visitVarInsn(ALOAD, 2);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ASTORE, 4);
    mv.visitInsn(MONITORENTER);
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 2);
    mv.visitVarInsn(ALOAD, 3);
    mv.visitInsn(MONITOREXIT);
    mv.visitLabel(l1);
    // Swapped exit order with exit above
    mv.visitVarInsn(ALOAD, 4);
    mv.visitInsn(MONITOREXIT);
    mv.visitLabel(l5);
    mv.visitInsn(ARETURN);
    mv.visitLabel(l2);
    mv.visitFrame(Opcodes.F_FULL, 5, new Object[]{INNER_CLASS_NAME_INTERNAL, "java/lang/Object", "java/lang/Object", "java/lang/Object",
                    "java/lang/Object"}, 1, new Object[]{"java/lang/Throwable"});
    mv.visitVarInsn(ALOAD, 4);
    mv.visitInsn(MONITOREXIT);
    mv.visitLabel(l3);
    mv.visitInsn(ATHROW);
    mv.visitLabel(l6);
    mv.visitFrame(Opcodes.F_FULL, 4, new Object[]{INNER_CLASS_NAME_INTERNAL, "java/lang/Object", "java/lang/Object", "java/lang/Object"}, 1,
                    new Object[]{"java/lang/Throwable"});
    mv.visitVarInsn(ALOAD, 3);
    mv.visitInsn(MONITOREXIT);
    mv.visitLabel(l7);
    mv.visitInsn(ATHROW);
    Label l9 = new Label();
    mv.visitLabel(l9);
    mv.visitMaxs(2, 5);
    mv.visitEnd();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:57,代碼來源:UnbalancedMonitorsTest.java


注:本文中的org.objectweb.asm.MethodVisitor.visitTryCatchBlock方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。