invokedynamic

grails 2 / groovy 2 / JDK7: how to reap the benefits?

可紊 提交于 2019-12-03 07:40:20
问题 I really love Grails but I was wondering how to get the performance benefits of Groovy 2. The question is how to configure the development and production environments in order to get that "close to Java" performance boost. So, if I setup: * JDK 7 * Groovy 2 (indie JAR to use invokedynamic) * Grails 2.2 are there any guidelines in order to really speed my webapp out-of-the-box ? And do I need to do any re-factoring in my Grails webapp codebase? I mean that dependency injection stuff like

Dynamic Type of InvokeDynamic Arguments

﹥>﹥吖頭↗ 提交于 2019-12-01 11:35:19
To support dynamic types and method dispatch, my programming language introduces a type called dynamic . When calling a method on a callee whose type is dynamic , the compiler first pushes the callee and all arguments on the stack, and then generates an invokedynamic instruction instead of a normal invoke* instruction. The instruction points to a special bootstrap method in a class called DynamicLinker , but only static types are available when it is called. My Problem : How do I get the runtime type of the arguments that were passed to the invokedynamic instruction? The "dynamic" part of

Dynamic Type of InvokeDynamic Arguments

我们两清 提交于 2019-12-01 09:44:00
问题 To support dynamic types and method dispatch, my programming language introduces a type called dynamic . When calling a method on a callee whose type is dynamic , the compiler first pushes the callee and all arguments on the stack, and then generates an invokedynamic instruction instead of a normal invoke* instruction. The instruction points to a special bootstrap method in a class called DynamicLinker , but only static types are available when it is called. My Problem : How do I get the

Convert MethodHandle to method reference (here Function)

十年热恋 提交于 2019-11-30 18:03:37
MethodType methodType = MethodType.methodType(void.class, ByteBuffer.class); MethodHandle handle = MethodHandles.publicLookup().findConstructor(type, methodType); Function<ByteBuffer, Object> = handle; // ??? Is it possible to get the last assignment work? The inverted way does not work: Is it possible to convert method reference to MethodHandle? Here another and copy-pastable example: new Integer("123"); MethodType methodType = MethodType.methodType(void.class, String.class); MethodHandle handle = MethodHandles.publicLookup().findConstructor(Integer.class, methodType); Function<String,

Invoke private method with java.lang.invoke.MethodHandle

一个人想着一个人 提交于 2019-11-30 13:55:03
How can I invoke private method using method handles ? As far as I can see there are only two kinds of publicly accessible Lookup instances: MethodHandles.lookup() MethodHandles.publicLookup() and neither allows unrestricted private access. There is the non-public Lookup.IMPL_LOOKUP that does what I want. Is there some public way to obtain it (assuming that SecurityManager allows it) ? Turns out it's possible with Lookup#unreflect(Method) and temporarily making method accessible (potentially introducing small security issue unless done during program initialization). Here is modified main

InvokeDynamic from source code in JDK7

跟風遠走 提交于 2019-11-30 09:51:43
问题 Prerelease versions of JDK 7 contained a class java.dyn.InvokeDynamic that allowed creating invokedynamic instructions from source code. See here: http://fwierzbicki.blogspot.com/2009/08/invokedynamic-and-jython-part-i.html In the official JDK 7 release this class seems to have disappeared. Does anyone know if this source-code option is still supported? 回答1: java.dyn package has been renamed to java.lang.invoke. Though I don't think you can create the 'invokedynamic' instruction from Java,

Convert MethodHandle to method reference (here Function)

妖精的绣舞 提交于 2019-11-30 01:44:36
问题 MethodType methodType = MethodType.methodType(void.class, ByteBuffer.class); MethodHandle handle = MethodHandles.publicLookup().findConstructor(type, methodType); Function<ByteBuffer, Object> = handle; // ??? Is it possible to get the last assignment work? The inverted way does not work: Is it possible to convert method reference to MethodHandle? Here another and copy-pastable example: new Integer("123"); MethodType methodType = MethodType.methodType(void.class, String.class); MethodHandle

解析JDK 7的动态类型语言支持

99封情书 提交于 2019-11-29 21:18:38
Java虚拟机的字节码指令集的数量自从Sun公司的第一款Java虚拟机问世至JDK 7来临之前的十余年时间里,一直没有发生任何变化[1]。随着JDK 7的发布,字节码指令集终于迎来了第一位新成员—— invokedynamic指令 。这条新增加的指令是JDK 7实现“动态类型语言(Dynamically Typed Language)”支持而进行的改进之一,也是为JDK 8可以顺利实现Lambda表达式做技术准备。在这篇文章中,我们将去了解JDK 7这项新特性的出现前因后果和它的意义。 动态类型语言 在介绍JDK 7提供的动态类型语言支持之前,我们要先弄明白动态类型语言是什么?它与Java语言、Java虚拟机有什么关系?了解JDK 7提供动态类型语言支持的技术背景,对理解这个语言特性是很必要的。 什么是动态类型语言[2]?动态类型语言的关键特征是它的类型检查的主体过程是在运行期而不是编译期进行的,满足这个特征的语言有很多,常用的包括:APL、Clojure、Erlang、Groovy、JavaScript、Jython、Lisp、Lua、PHP、Prolog、Python、Ruby、Smalltalk和Tcl等等。那相对地,在编译期就进行类型检查过程的语言,如C++和Java等就是最常用的静态类型语言。 觉得上面定义过于概念化?那我们不妨通过两个例子以最浅显的方式来说明什么是

Invoke private method with java.lang.invoke.MethodHandle

大憨熊 提交于 2019-11-29 19:09:32
问题 How can I invoke private method using method handles ? As far as I can see there are only two kinds of publicly accessible Lookup instances: MethodHandles.lookup() MethodHandles.publicLookup() and neither allows unrestricted private access. There is the non-public Lookup.IMPL_LOOKUP that does what I want. Is there some public way to obtain it (assuming that SecurityManager allows it) ? 回答1: Turns out it's possible with Lookup#unreflect(Method) and temporarily making method accessible

MethodHandle - What is it all about?

谁说胖子不能爱 提交于 2019-11-28 04:38:48
I am studying new features of JDK 1.7 and I just can't get it what MethodHandle is designed for? I understand (direct) invocation of the static method (and use of Core Reflection API that is straightforward in this case). I understand also (direct) invocation of the virtual method (non-static, non-final) (and use of Core Reflection API that requires going through Class's hierarchy obj.getClass().getSuperclass() ). Invocation of non-virtual method can be treated as special case of the former one. Yes, I aware that there is an issue with overloading. If you want to invoke method you have to