java JVM字节码表示法,注释语法.动态调用 [英] java JVM bytecode notation, comment grammar. InvokeDynamic

查看:73
本文介绍了java JVM字节码表示法,注释语法.动态调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:第14行是什么意思?

Question: What does line 14 means?

使用javap -v -c分解以下代码:

Use javap -v -c to disassembly the following code:

 public class test {
     static int i = 2;
     public static void main(String[] args) {
         test x = new test();
         System.out.println("text + String: " + i);
     } 
 }

在主函数中,我们得到以下信息:

in the main function we get the following:

14: invokedynamic #20,  0             // InvokeDynamic #0:makeConcatWithConstants:(I)Ljava/lang/String;
19: invokevirtual #24                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
...
BootstrapMethods:
  0: #38 REF_invokeStatic java/lang/invoke/StringConcatFactory.makeConcatWithConstants:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;
    Method arguments:
      #44 text + String: \u0001

因此,例如,第19行表示运行时常量池中#24项的invokevirtual函数.调用的方法是来自类java/io/PrintStreamprintln(),其输入是来自类Ljava/lang/String的返回值是Void.

So, for example, line 19 means that invokevirtual function from the #24 item in the runtime constant pool. The method invoked is println() from the class java/io/PrintStream, its input is from the class Ljava/lang/String, its return value is Void.

关于第14行,#0保留对BootstrapMethod的引用,并返回其类为CallSite的Object吗? 然后:

As for line 14, #0 holds the reference to the BootstrapMethod and returns an Object whose class is CallSite right? Then:

  1. #20指向什么?
  2. 注释#0:makeConcatWithConstants:(I)Ljava/lang/String;是什么意思?
  1. what is #20 pointing to?
  2. What does the comment #0:makeConcatWithConstants:(I)Ljava/lang/String; means?

此外,在哪里可以找到有关Javap反汇编代码语法的更多信息?或正确的关键字是什么? Oracle关于the JVM instruction set的文档似乎没有清楚地描述注释的含义.

Also, where could I find more about the Javap disassembly code's grammar? or what is the right keyword? Oracle's document about the JVM instruction set does not seems to describe clearly about the meaning of the comment.

推荐答案

简短版本:Java从Java 9开始就使用invokedynamic来连接字符串.

The short version: Java uses invokedynamic to concatenate strings since Java 9.

让我们细分一下:

Invokedynamic有两个步骤:

Invokedynamic has two steps:

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