public void processCase(Object key, Label end) { e.getfield((String)sigMap.get(key)); e.return_value(); } public void processDefault() {
public void processCase(int key, Label end) { e.getfield(getCallbackField(key)); e.goTo(end); } public void processDefault() {
public void processCase(int key, Label end) throws Exception { Type type = (Type)fields.get(names[key]); e.getfield(names[key]); e.box(type); e.return_value(); } public void processDefault() throws Exception {
public void processCase(Object key, Label end) { Type type = (Type)fields.get(key); e.getfield((String)key); e.box(type); e.return_value(); } public void processDefault() {
private void addDelegate(Method m) { Method delegate; try { delegate = delegateImpl.getMethod(m.getName(), m.getParameterTypes()); if (!delegate.getReturnType().getName().equals(m.getReturnType().getName())){ throw new IllegalArgumentException("Invalid delegate signature " + delegate); } } catch (NoSuchMethodException e) { throw new CodeGenerationException(e); } final Signature sig = ReflectUtils.getSignature(m); Type[] exceptions = TypeUtils.getTypes(m.getExceptionTypes()); CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, sig, exceptions); e.load_this(); e.getfield(DELEGATE); e.load_args(); e.invoke_virtual(delegateType, sig); e.return_value(); e.end_method(); } }
private void emitSetThreadCallbacks(ClassEmitter ce) { CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC | Constants.ACC_STATIC, SET_THREAD_CALLBACKS, null); e.getfield(THREAD_CALLBACKS_FIELD); e.load_arg(0); e.invoke_virtual(THREAD_LOCAL, THREAD_LOCAL_SET); e.return_value(); e.end_method(); }
private void emitCurrentCallback(CodeEmitter e, int index) { e.load_this(); e.getfield(getCallbackField(index)); e.dup(); Label end = e.make_label(); e.ifnonnull(end); e.pop(); // stack height e.load_this(); e.invoke_static_this(BIND_CALLBACKS); e.load_this(); e.getfield(getCallbackField(index)); e.mark(end); }
public void generate(ClassEmitter ce, Context context, List methods) { for (Iterator it = methods.iterator(); it.hasNext();) { MethodInfo method = (MethodInfo)it.next(); Signature impl = context.getImplSignature(method); ce.declare_field(Constants.PRIVATE_FINAL_STATIC, impl.getName(), METHOD, null); CodeEmitter e = context.beginMethod(ce, method); Block handler = e.begin_block(); context.emitCallback(e, context.getIndex(method)); e.load_this(); e.getfield(impl.getName()); e.create_arg_array(); e.invoke_interface(INVOCATION_HANDLER, INVOKE); e.unbox(method.getSignature().getReturnType()); e.return_value(); handler.end(); EmitUtils.wrap_undeclared_throwable(e, handler, method.getExceptionTypes(), UNDECLARED_THROWABLE_EXCEPTION); e.end_method(); } }
public CodeEmitter beginMethod(ClassEmitter ce, MethodInfo method) { CodeEmitter e = EmitUtils.begin_method(ce, method); if (!interceptDuringConstruction && !TypeUtils.isAbstract(method.getModifiers())) { Label constructed = e.make_label(); e.load_this(); e.getfield(CONSTRUCTED_FIELD); e.if_jump(e.NE, constructed); e.load_this(); e.load_args(); e.super_invoke(); e.return_value(); e.mark(constructed); } return e; } };
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(); }
private void generateKeySet(String[] allNames) { // static initializer declare_field(Constants.ACC_STATIC | Constants.ACC_PRIVATE, "keys", FIXED_KEY_SET, null); CodeEmitter e = begin_static(); e.new_instance(FIXED_KEY_SET); e.dup(); EmitUtils.push_array(e, allNames); e.invoke_constructor(FIXED_KEY_SET, CSTRUCT_STRING_ARRAY); e.putfield("keys"); e.return_value(); e.end_method(); // keySet e = begin_method(Constants.ACC_PUBLIC, KEY_SET, null); e.load_this(); e.getfield("keys"); e.return_value(); e.end_method(); }
private static void load_class_helper(CodeEmitter e, final Type type) { if (e.isStaticHook()) { // have to fall back on non-optimized load e.push(TypeUtils.emulateClassGetName(type)); e.invoke_static(Constants.TYPE_CLASS, FOR_NAME); } else { ClassEmitter ce = e.getClassEmitter(); String typeName = TypeUtils.emulateClassGetName(type); // TODO: can end up with duplicated field names when using chained transformers; incorporate static hook # somehow String fieldName = "CGLIB$load_class$" + TypeUtils.escapeType(typeName); if (!ce.isFieldDeclared(fieldName)) { ce.declare_field(Constants.PRIVATE_FINAL_STATIC, fieldName, Constants.TYPE_CLASS, null); CodeEmitter hook = ce.getStaticHook(); hook.push(typeName); hook.invoke_static(Constants.TYPE_CLASS, FOR_NAME); hook.putstatic(ce.getClassType(), fieldName, Constants.TYPE_CLASS); } e.getfield(fieldName); } }
public static void add_property(ClassEmitter ce, String name, Type type, String fieldName) { String property = TypeUtils.upperFirst(name); CodeEmitter e; e = ce.begin_method(Constants.ACC_PUBLIC, new Signature("get" + property, type, Constants.TYPES_EMPTY), null); e.load_this(); e.getfield(fieldName); e.return_value(); e.end_method(); e = ce.begin_method(Constants.ACC_PUBLIC, new Signature("set" + property, Type.VOID_TYPE, new Type[]{ type }), null); e.load_this(); e.load_arg(0); e.putfield(fieldName); e.return_value(); e.end_method(); }
public void begin_class(int version, int access, String className, Type superType, Type[] interfaces, String sourceFile) { if (!TypeUtils.isInterface(access)) { super.begin_class(version, access, className, superType, TypeUtils.add(interfaces, ENABLED), sourceFile); super.declare_field(Constants.ACC_PRIVATE | Constants.ACC_TRANSIENT, CALLBACK_FIELD, CALLBACK, null); CodeEmitter e; e = super.begin_method(Constants.ACC_PUBLIC, ENABLED_GET, null); e.load_this(); e.getfield(CALLBACK_FIELD); e.return_value(); e.end_method(); e = super.begin_method(Constants.ACC_PUBLIC, ENABLED_SET, null); e.load_this(); e.load_arg(0); e.putfield(CALLBACK_FIELD); e.return_value(); e.end_method(); } else { super.begin_class(version, access, className, superType, interfaces, sourceFile); } }
e.getfield(getFieldName(i)); e.store_local(T);
public void declare_field(int access, final String name, Type type, Object value) { super.declare_field(access, name, type, value); String property = TypeUtils.upperFirst(callback.getPropertyName(getClassType(), name)); if (property != null) { CodeEmitter e; e = begin_method(Constants.ACC_PUBLIC, new Signature("get" + property, type, Constants.TYPES_EMPTY), null); e.load_this(); e.getfield(name); e.return_value(); e.end_method(); e = begin_method(Constants.ACC_PUBLIC, new Signature("set" + property, Type.VOID_TYPE, new Type[]{ type }), null); e.load_this(); e.load_arg(0); e.putfield(name); e.return_value(); e.end_method(); } } }
e = EmitUtils.begin_method(this, method, Constants.ACC_PUBLIC); e.load_this(); e.getfield(FIELD_NAME); e.aaload((route != null) ? route[i] : i); e.checkcast(method.getClassInfo().getType());
private void addReadMethod(String name, Type type) { CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, readMethodSig(name, type.getDescriptor()), null); e.load_this(); e.getfield(name); e.load_this(); e.invoke_interface(ENABLED,ENABLED_GET); Label intercept = e.make_label(); e.ifnonnull(intercept); e.return_value(); e.mark(intercept); Local result = e.make_local(type); e.store_local(result); e.load_this(); e.invoke_interface(ENABLED,ENABLED_GET); e.load_this(); e.push(name); e.load_local(result); e.invoke_interface(CALLBACK, readCallbackSig(type)); if (!TypeUtils.isPrimitive(type)) { e.checkcast(type); } e.return_value(); e.end_method(); }
private void addWriteMethod(String name, Type type) { CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, writeMethodSig(name, type.getDescriptor()), null); e.load_this(); e.dup(); e.invoke_interface(ENABLED,ENABLED_GET); Label skip = e.make_label(); e.ifnull(skip); e.load_this(); e.invoke_interface(ENABLED,ENABLED_GET); e.load_this(); e.push(name); e.load_this(); e.getfield(name); e.load_arg(0); e.invoke_interface(CALLBACK, writeCallbackSig(type)); if (!TypeUtils.isPrimitive(type)) { e.checkcast(type); } Label go = e.make_label(); e.goTo(go); e.mark(skip); e.load_arg(0); e.mark(go); e.putfield(name); e.return_value(); e.end_method(); }
e = EmitUtils.begin_method(ce, getter, Constants.ACC_PUBLIC); e.load_this(); e.getfield(FIELD_NAME); e.invoke(getter); e.return_value();