Search in sources :

Example 6 with CodeEmitter

use of org.springframework.cglib.core.CodeEmitter in project spring-framework by spring-projects.

the class Enhancer method emitSetCallbacks.

private void emitSetCallbacks(ClassEmitter ce) {
    CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, SET_CALLBACKS, null);
    e.load_this();
    e.load_arg(0);
    for (int i = 0; i < callbackTypes.length; i++) {
        e.dup2();
        e.aaload(i);
        e.checkcast(callbackTypes[i]);
        e.putfield(getCallbackField(i));
    }
    e.return_value();
    e.end_method();
}
Also used : CodeEmitter(org.springframework.cglib.core.CodeEmitter)

Example 7 with CodeEmitter

use of org.springframework.cglib.core.CodeEmitter in project spring-framework by spring-projects.

the class Enhancer method emitBindCallbacks.

private void emitBindCallbacks(ClassEmitter ce) {
    CodeEmitter e = ce.begin_method(Constants.PRIVATE_FINAL_STATIC, BIND_CALLBACKS, null);
    Local me = e.make_local();
    e.load_arg(0);
    e.checkcast_this();
    e.store_local(me);
    Label end = e.make_label();
    e.load_local(me);
    e.getfield(BOUND_FIELD);
    e.if_jump(CodeEmitter.NE, end);
    e.load_local(me);
    e.push(1);
    e.putfield(BOUND_FIELD);
    e.getfield(THREAD_CALLBACKS_FIELD);
    e.invoke_virtual(THREAD_LOCAL, THREAD_LOCAL_GET);
    e.dup();
    Label found_callback = e.make_label();
    e.ifnonnull(found_callback);
    e.pop();
    e.getfield(STATIC_CALLBACKS_FIELD);
    e.dup();
    e.ifnonnull(found_callback);
    e.pop();
    e.goTo(end);
    e.mark(found_callback);
    e.checkcast(CALLBACK_ARRAY);
    e.load_local(me);
    e.swap();
    for (int i = callbackTypes.length - 1; i >= 0; i--) {
        if (i != 0) {
            e.dup2();
        }
        e.aaload(i);
        e.checkcast(callbackTypes[i]);
        e.putfield(getCallbackField(i));
    }
    e.mark(end);
    e.return_value();
    e.end_method();
}
Also used : CodeEmitter(org.springframework.cglib.core.CodeEmitter) Label(org.springframework.asm.Label) Local(org.springframework.cglib.core.Local)

Example 8 with CodeEmitter

use of org.springframework.cglib.core.CodeEmitter in project spring-framework by spring-projects.

the class Enhancer method emitSetCallback.

private void emitSetCallback(ClassEmitter ce, int[] keys) {
    final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, SET_CALLBACK, null);
    e.load_arg(0);
    e.process_switch(keys, new ProcessSwitchCallback() {

        public void processCase(int key, Label end) {
            e.load_this();
            e.load_arg(1);
            e.checkcast(callbackTypes[key]);
            e.putfield(getCallbackField(key));
            e.goTo(end);
        }

        public void processDefault() {
        // TODO: error?
        }
    });
    e.return_value();
    e.end_method();
}
Also used : CodeEmitter(org.springframework.cglib.core.CodeEmitter) ProcessSwitchCallback(org.springframework.cglib.core.ProcessSwitchCallback) Label(org.springframework.asm.Label)

Example 9 with CodeEmitter

use of org.springframework.cglib.core.CodeEmitter in project spring-framework by spring-projects.

the class Enhancer method emitGetCallback.

private void emitGetCallback(ClassEmitter ce, int[] keys) {
    final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, GET_CALLBACK, null);
    e.load_this();
    e.invoke_static_this(BIND_CALLBACKS);
    e.load_this();
    e.load_arg(0);
    e.process_switch(keys, new ProcessSwitchCallback() {

        public void processCase(int key, Label end) {
            e.getfield(getCallbackField(key));
            e.goTo(end);
        }

        public void processDefault() {
            // stack height
            e.pop();
            e.aconst_null();
        }
    });
    e.return_value();
    e.end_method();
}
Also used : CodeEmitter(org.springframework.cglib.core.CodeEmitter) ProcessSwitchCallback(org.springframework.cglib.core.ProcessSwitchCallback) Label(org.springframework.asm.Label)

Example 10 with CodeEmitter

use of org.springframework.cglib.core.CodeEmitter in project spring-framework by spring-projects.

the class Enhancer method emitGetCallbacks.

private void emitGetCallbacks(ClassEmitter ce) {
    CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, GET_CALLBACKS, null);
    e.load_this();
    e.invoke_static_this(BIND_CALLBACKS);
    e.load_this();
    e.push(callbackTypes.length);
    e.newarray(CALLBACK);
    for (int i = 0; i < callbackTypes.length; i++) {
        e.dup();
        e.push(i);
        e.load_this();
        e.getfield(getCallbackField(i));
        e.aastore();
    }
    e.return_value();
    e.end_method();
}
Also used : CodeEmitter(org.springframework.cglib.core.CodeEmitter)

Aggregations

CodeEmitter (org.springframework.cglib.core.CodeEmitter)13 Label (org.springframework.asm.Label)5 MethodInfo (org.springframework.cglib.core.MethodInfo)4 Type (org.springframework.asm.Type)3 Signature (org.springframework.cglib.core.Signature)3 Iterator (java.util.Iterator)2 ProcessSwitchCallback (org.springframework.cglib.core.ProcessSwitchCallback)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ClassEmitter (org.springframework.cglib.core.ClassEmitter)1 CodeGenerationException (org.springframework.cglib.core.CodeGenerationException)1 Local (org.springframework.cglib.core.Local)1 ObjectSwitchCallback (org.springframework.cglib.core.ObjectSwitchCallback)1