Java字节码DUP [英] Java Bytecode DUP

查看:132
本文介绍了Java字节码DUP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么以下字节码中的异常(用于抛出异常)是重复的。

I am wondering why the Exception in the following bytecode (used to throw an Exception) is duplicated.

NEW java/lang/IllegalArgumentException
DUP
INVOKESPECIAL java/lang/IllegalArgumentException <init> ()V
ATHROW


推荐答案

我会在使用该操作之后,逐行分析[] =新堆栈:

I'll analyze this line by line where [] = new stack after that op is used:


  1. NEW放置一个新的 IllegalArgumentException 到堆栈 [SomeIllegalArgumentException]

  2. DUP重复它 [SomeIllegalArgumentException,SomeIllegalArgumentException]

  3. INVOKESPECIAL弹出顶部并通过调用它的< init>来初始化它。方法 [SomeIllegalArgumentException] (init方法不会返回要放回堆栈的对象,因此必须首先复制对象以便将其保留在堆栈中)

  4. ATHROW抛出另一个(与我们初始化的一个重复) []

  1. NEW puts a new IllegalArgumentException onto the stack [SomeIllegalArgumentException]
  2. DUP duplicates it [SomeIllegalArgumentException, SomeIllegalArgumentException]
  3. INVOKESPECIAL pops off the top one and initializes it by calling it's <init> method [SomeIllegalArgumentException] (The init method will not return the object to put back onto the stack, so the object must first be duplicated so as to keep it on the stack)
  4. ATHROW Throws the other (a duplicate off the one we initialized) []

这篇关于Java字节码DUP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆