为支持Groovy、JRuby等新的动态类型语言,JDK1.7在Java虚拟机上特意引入了新的动态调用指令。文章提出将其应用于Java程序,在生成的Java类文件中用它替换某些成员访问指令,由此可以突破Java原本固有的运行模式,引入满足应用需要的新运行机制,使程序更简单、灵活,提高开发效率。同时分析了原有成员访问指令的局限,讨论了新的动态调用指令的优势,给出了指令替换的实现方法。%Since JDK1.7, the invokedynamic instruction has been introduced to JVM to support dynamically typed languages such as Groovy, JRuby. This paper proposes replacing some appropriate member access instructions with it in a Java class file, which may break Java inherent operation mode, introduce a new mechanism that meets the application needs, make the program more simple and flexible, and improve development efficiency. At the same time, the limitations of the original member access instruction and the advantages of the invokedynamic instruction is analyzed, and the method to realize the instruction replacement is given.
展开▼