ifnull(fail); load_arg(1); invoke(PROXY_NEW_INSTANCE); checkcast_this();
load_arg(0); constructor_switch((Constructor[])constructors.toArray(new Constructor[0]), new ObjectSwitchCallback() { public void processCase(Object key, Label end) throws Exception { Constructor constructor = (Constructor)key; Class types[] = constructor.getParameterTypes(); for (int i = 0; i < types.length; i++) { load_arg(1); push(i); aaload(); unbox(types[i]); } invoke_constructor_this(types); goTo(end); } public void processDefault() { throw_exception(IllegalArgumentException.class, "Constructor not found"); } });
    private void generateFactory() throws Exception {        int[] keys = getCallbackKeys();        // Factory.getCallback(int)        begin_method(GET_CALLBACK);        load_this();        load_arg(0);        process_switch(keys, new ProcessSwitchCallback() {                public void processCase(int key, Label end) throws Exception {                    getfield(getCallbackField(key));                    goTo(end);                }                public void processDefault() throws Exception {                    pop(); // stack height                    aconst_null();                }            });        return_value();        end_method();        // Factory.setCallback(int, Callback)        begin_method(SET_CALLBACK);        load_this();        load_arg(1);        load_arg(0);        process_switch(keys, new ProcessSwitchCallback() {                public void processCase(int key, Label end) throws Exception {                    checkcast(Callbacks.getType(key));                    putfield(getCallbackField(key));                    goTo(end);                }                public void processDefault() {                    pop2(); // stack height                }            });        return_value();        end_method();                // Factory.setCallbacks(Callbacks);        begin_method(SET_CALLBACKS);        load_this();        load_arg(0);        generateSetCallbacks();        return_value();        end_method();        // Factory.newInstance(Callbacks)        begin_method(NEW_INSTANCE);        load_arg(0);        invoke_static_this(SET_THREAD_CALLBACKS, Void.TYPE, new Class[]{ Callbacks.class });        new_instance_this();        dup();        invoke_constructor_this();        dup();        load_arg(0);        generateSetCallbacks();        return_value();        end_method();        // Factory.newInstance(Callback)        begin_method(SINGLE_NEW_INSTANCE);        if (usedCallbacks.length() == 1) {            int type = usedCallbacks.nextSetBit(0);            getfield(getThreadLocal(type));            load_arg(0);            invoke(MethodConstants.THREADLOCAL_SET);            new_instance_this();            dup();            invoke_constructor_this();            dup();            push(type);            load_arg(0);            invoke(SET_CALLBACK);        } else if (usedCallbacks.length() == 0) {            // TODO: make sure Callback is null?            new_instance_this();            dup();            invoke_constructor_this();        } else {            throw_exception(IllegalStateException.class, "More than one callback object required");        }        return_value();        end_method();                // Factory.newInstance(Class[], Object[], Callbacks)        Label skipSetCallbacks = make_label();        Label fail = make_label();        begin_method(MULTIARG_NEW_INSTANCE);        load_arg(2);        invoke_static_this(SET_THREAD_CALLBACKS, Void.TYPE, new Class[]{ Callbacks.class });        getfield(CONSTRUCTOR_PROXY_MAP);        load_arg(0); // Class[] types        invoke(NEW_CLASS_KEY); // key        invoke(MethodConstants.MAP_GET); // PROXY_MAP.get(key(types))        checkcast(ConstructorProxy.class);        dup();        ifnull(fail);        load_arg(1);        invoke(PROXY_NEW_INSTANCE);        checkcast_this();        load_arg(2);        ifnull(skipSetCallbacks);        dup();        load_arg(2);        generateSetCallbacks();                mark(skipSetCallbacks);        return_value();        mark(fail);        throw_exception(IllegalArgumentException.class, "Constructor not found");        end_method();    }