本文介绍了如何在Jasmin中使用invokedynamic?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处:

Since 2.1 :
[..]
added the invokedynamic instruction

因此,我想可以用jasmin编写包含invokedynamics的指令代码.但是我找不到有关jasmin语法的任何文档,我只是想出了如何使用invokedynamic与Jasmin一起获取VerifyErrors,而不是如何创建有效的示例.

Thus I suppose that it is possible to write instruction code containing invokedynamics with jasmin. However I could not find any documentation on the jasmin syntax and I just figured out how to use invokedynamic to get VerifyErrors with Jasmin, but not how to create a working example.

在Jasmin中如何正确使用此说明?

How is this instruction correctly used in Jasmin?

推荐答案

每个invokedynamic字节码应引用相应的呼叫站点说明符(JVMS 6.5)实际上是CONSTANT_InvokeDynamic类型(JVMS 4.4.10).

Each invokedynamic bytecode should refer to a corresponding call site specifier (JVMS 6.5) which is actually a constant pool entry of CONSTANT_InvokeDynamic type (JVMS 4.4.10).

Jasmin( http://jasmin.sourceforge.net )不支持CONSTANT_InvokeDynamic,但Sable/茉莉花尽管在手写汇编中使用invokedynamic是一件令人不快的工作.

Jasmin (http://jasmin.sourceforge.net) does not support CONSTANT_InvokeDynamic, but Sable/jasmin does. Though using invokedynamic in hand-written assembly is ungrateful job.

这里是一个动态方法的示例,该方法返回对System.out的引用:

Here is an example of dynamic method that returns a reference to System.out:

.class public HelloWorld
.super java/lang/Object

.method public <init>()V
   aload_0
   invokespecial java/lang/Object/<init>()V
   return
.end method

.method public static main([Ljava/lang/String;)V
   .limit stack 2
   .limit locals 1

   invokedynamic "getPrintStream" ()Ljava/io/PrintStream; HelloWorld/bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;()
   ldc "Hello, world"
   invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V

   return
.end method

.method private static bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
   .limit stack 6
   .limit locals 3

   new java/lang/invoke/ConstantCallSite
   dup

   aload_0
   ldc java/lang/System
   ldc "out"
   ldc java/io/PrintStream
   invokevirtual java/lang/invoke/MethodHandles$Lookup/findStaticGetter(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/invoke/MethodHandle;

   invokespecial java/lang/invoke/ConstantCallSite/<init>(Ljava/lang/invoke/MethodHandle;)V

   areturn
.end method

这篇关于如何在Jasmin中使用invokedynamic?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 23:24