Search in sources :

Example 6 with InterfaceHelperClassNode

use of org.codehaus.groovy.ast.InterfaceHelperClassNode in project groovy by apache.

the class CallSiteWriter method generateGetCallSiteArray.

private void generateGetCallSiteArray() {
    int visibility = (controller.getClassNode() instanceof InterfaceHelperClassNode) ? MOD_PUBSS : MOD_PRIVSS;
    MethodVisitor mv = controller.getClassVisitor().visitMethod(visibility, GET_CALLSITE_METHOD, GET_CALLSITE_DESC, null, null);
    controller.setMethodVisitor(mv);
    mv.visitCode();
    mv.visitFieldInsn(GETSTATIC, controller.getInternalClassName(), "$callSiteArray", "Ljava/lang/ref/SoftReference;");
    Label l0 = new Label();
    mv.visitJumpInsn(IFNULL, l0);
    mv.visitFieldInsn(GETSTATIC, controller.getInternalClassName(), "$callSiteArray", "Ljava/lang/ref/SoftReference;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/ref/SoftReference", "get", "()Ljava/lang/Object;", false);
    mv.visitTypeInsn(CHECKCAST, "org/codehaus/groovy/runtime/callsite/CallSiteArray");
    mv.visitInsn(DUP);
    mv.visitVarInsn(ASTORE, 0);
    Label l1 = new Label();
    mv.visitJumpInsn(IFNONNULL, l1);
    mv.visitLabel(l0);
    mv.visitMethodInsn(INVOKESTATIC, controller.getInternalClassName(), "$createCallSiteArray", "()Lorg/codehaus/groovy/runtime/callsite/CallSiteArray;", false);
    mv.visitVarInsn(ASTORE, 0);
    mv.visitTypeInsn(NEW, "java/lang/ref/SoftReference");
    mv.visitInsn(DUP);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/ref/SoftReference", "<init>", "(Ljava/lang/Object;)V", false);
    mv.visitFieldInsn(PUTSTATIC, controller.getInternalClassName(), "$callSiteArray", "Ljava/lang/ref/SoftReference;");
    mv.visitLabel(l1);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, "org/codehaus/groovy/runtime/callsite/CallSiteArray", "array", "[Lorg/codehaus/groovy/runtime/callsite/CallSite;");
    mv.visitInsn(ARETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
Also used : InterfaceHelperClassNode(org.codehaus.groovy.ast.InterfaceHelperClassNode) Label(org.objectweb.asm.Label) MethodVisitor(org.objectweb.asm.MethodVisitor)

Aggregations

InterfaceHelperClassNode (org.codehaus.groovy.ast.InterfaceHelperClassNode)6 ClassNode (org.codehaus.groovy.ast.ClassNode)4 InnerClassNode (org.codehaus.groovy.ast.InnerClassNode)4 MethodVisitor (org.objectweb.asm.MethodVisitor)4 GroovyRuntimeException (groovy.lang.GroovyRuntimeException)2 AnnotationNode (org.codehaus.groovy.ast.AnnotationNode)2 MethodNode (org.codehaus.groovy.ast.MethodNode)2 PackageNode (org.codehaus.groovy.ast.PackageNode)2 MopWriter (org.codehaus.groovy.classgen.asm.MopWriter)2 WriterController (org.codehaus.groovy.classgen.asm.WriterController)2 WriterControllerFactory (org.codehaus.groovy.classgen.asm.WriterControllerFactory)2 AnnotationVisitor (org.objectweb.asm.AnnotationVisitor)2 Label (org.objectweb.asm.Label)2