public void invoke_static_this(Signature sig) { invoke_static(ce.getClassType(), sig); }
public void invoke_static_this(Signature sig) { invoke_static(ce.getClassType(), sig); }
private static void hash_primitive(CodeEmitter e, Type type) { switch (type.getSort()) { case Type.BOOLEAN: // f ? 0 : 1 e.push(1); e.math(e.XOR, Type.INT_TYPE); break; case Type.FLOAT: // Float.floatToIntBits(f) e.invoke_static(Constants.TYPE_FLOAT, FLOAT_TO_INT_BITS); break; case Type.DOUBLE: // Double.doubleToLongBits(f), hash_code(Long.TYPE) e.invoke_static(Constants.TYPE_DOUBLE, DOUBLE_TO_LONG_BITS); // fall through case Type.LONG: hash_long(e); } }
private static void hash_primitive(CodeEmitter e, Type type) { switch (type.getSort()) { case Type.BOOLEAN: // f ? 0 : 1 e.push(1); e.math(e.XOR, Type.INT_TYPE); break; case Type.FLOAT: // Float.floatToIntBits(f) e.invoke_static(Constants.TYPE_FLOAT, FLOAT_TO_INT_BITS); break; case Type.DOUBLE: // Double.doubleToLongBits(f), hash_code(Long.TYPE) e.invoke_static(Constants.TYPE_DOUBLE, DOUBLE_TO_LONG_BITS); // fall through case Type.LONG: hash_long(e); } }
private void emitNewInstanceCallbacks(ClassEmitter ce) { CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, NEW_INSTANCE, null); Type thisType = getThisType(e); e.load_arg(0); e.invoke_static(thisType, SET_THREAD_CALLBACKS); emitCommonNewInstance(e); }
private void emitNewInstanceCallbacks(ClassEmitter ce) { CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, NEW_INSTANCE, null); Type thisType = getThisType(e); e.load_arg(0); e.invoke_static(thisType, SET_THREAD_CALLBACKS); emitCommonNewInstance(e); }
private void emitCommonNewInstance(CodeEmitter e) { Type thisType = getThisType(e); e.new_instance(thisType); e.dup(); e.invoke_constructor(thisType); e.aconst_null(); e.invoke_static(thisType, SET_THREAD_CALLBACKS); 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); } }
private void emitCommonNewInstance(CodeEmitter e) { Type thisType = getThisType(e); e.new_instance(thisType); e.dup(); e.invoke_constructor(thisType); e.aconst_null(); e.invoke_static(thisType, SET_THREAD_CALLBACKS); e.return_value(); e.end_method(); }
private void emitNewInstanceMultiarg(ClassEmitter ce, List constructors) { final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, MULTIARG_NEW_INSTANCE, null); final Type thisType = getThisType(e); e.load_arg(2); e.invoke_static(thisType, SET_THREAD_CALLBACKS); e.new_instance(thisType); e.dup(); e.load_arg(0); EmitUtils.constructor_switch(e, constructors, new ObjectSwitchCallback() { public void processCase(Object key, Label end) { MethodInfo constructor = (MethodInfo)key; Type types[] = constructor.getSignature().getArgumentTypes(); for (int i = 0; i < types.length; i++) { e.load_arg(1); e.push(i); e.aaload(); e.unbox(types[i]); } e.invoke_constructor(thisType, constructor.getSignature()); e.goTo(end); } public void processDefault() { e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Constructor not found"); } }); e.aconst_null(); e.invoke_static(thisType, SET_THREAD_CALLBACKS); e.return_value(); e.end_method(); }
public void invoke(MethodInfo method, Type virtualType) { ClassInfo classInfo = method.getClassInfo(); Type type = classInfo.getType(); Signature sig = method.getSignature(); if (sig.getName().equals(Constants.CONSTRUCTOR_NAME)) { invoke_constructor(type, sig); } else if (TypeUtils.isInterface(classInfo.getModifiers())) { invoke_interface(type, sig); } else if (TypeUtils.isStatic(method.getModifiers())) { invoke_static(type, sig); } else { invoke_virtual(virtualType, sig); } }
private void emitNewInstanceMultiarg(ClassEmitter ce, List constructors) { final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, MULTIARG_NEW_INSTANCE, null); final Type thisType = getThisType(e); e.load_arg(2); e.invoke_static(thisType, SET_THREAD_CALLBACKS); e.new_instance(thisType); e.dup(); e.load_arg(0); EmitUtils.constructor_switch(e, constructors, new ObjectSwitchCallback() { public void processCase(Object key, Label end) { MethodInfo constructor = (MethodInfo)key; Type types[] = constructor.getSignature().getArgumentTypes(); for (int i = 0; i < types.length; i++) { e.load_arg(1); e.push(i); e.aaload(); e.unbox(types[i]); } e.invoke_constructor(thisType, constructor.getSignature()); e.goTo(end); } public void processDefault() { e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Constructor not found"); } }); e.aconst_null(); e.invoke_static(thisType, SET_THREAD_CALLBACKS); e.return_value(); e.end_method(); }
public void invoke(MethodInfo method, Type virtualType) { ClassInfo classInfo = method.getClassInfo(); Type type = classInfo.getType(); Signature sig = method.getSignature(); if (sig.getName().equals(Constants.CONSTRUCTOR_NAME)) { invoke_constructor(type, sig); } else if (TypeUtils.isInterface(classInfo.getModifiers())) { invoke_interface(type, sig); } else if (TypeUtils.isStatic(method.getModifiers())) { invoke_static(type, sig); } else { invoke_virtual(virtualType, sig); } }
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); } }
private void emitIndexByClassArray(List methods) { CodeEmitter e = begin_method(Constants.ACC_PUBLIC, METHOD_GET_INDEX, null); if (methods.size() > TOO_MANY_METHODS) { // hack for big classes List signatures = CollectionUtils.transform(methods, new Transformer() { public Object transform(Object obj) { String s = ReflectUtils.getSignature((Method)obj).toString(); return s.substring(0, s.lastIndexOf(')') + 1); } }); e.load_args(); e.invoke_static(FAST_CLASS, GET_SIGNATURE_WITHOUT_RETURN_TYPE); signatureSwitchHelper(e, signatures); } else { e.load_args(); List info = CollectionUtils.transform(methods, MethodInfoTransformer.getInstance()); EmitUtils.method_switch(e, info, new GetIndexCallback(e, info)); } e.end_method(); }
private void emitIndexByClassArray(List methods) { CodeEmitter e = begin_method(Constants.ACC_PUBLIC, METHOD_GET_INDEX, null); if (methods.size() > TOO_MANY_METHODS) { // hack for big classes List signatures = CollectionUtils.transform(methods, new Transformer() { public Object transform(Object obj) { String s = ReflectUtils.getSignature((Method)obj).toString(); return s.substring(0, s.lastIndexOf(')') + 1); } }); e.load_args(); e.invoke_static(FAST_CLASS, GET_SIGNATURE_WITHOUT_RETURN_TYPE); signatureSwitchHelper(e, signatures); } else { e.load_args(); List info = CollectionUtils.transform(methods, MethodInfoTransformer.getInstance()); EmitUtils.method_switch(e, info, new GetIndexCallback(e, info)); } e.end_method(); }
private void emitNewInstanceCallback(ClassEmitter ce) { CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, SINGLE_NEW_INSTANCE, null); switch (callbackTypes.length) { case 0: // TODO: make sure Callback is null break; case 1: // for now just make a new array; TODO: optimize e.push(1); e.newarray(CALLBACK); e.dup(); e.push(0); e.load_arg(0); e.aastore(); e.invoke_static(getThisType(e), SET_THREAD_CALLBACKS); break; default: e.throw_exception(ILLEGAL_STATE_EXCEPTION, "More than one callback object required"); } emitCommonNewInstance(e); }
e.store_local(declaringclass); e.invoke_virtual(Constants.TYPE_CLASS, GET_DECLARED_METHODS); e.invoke_static(REFLECT_UTILS, FIND_METHODS); e.push(sig.getName()); e.push(impl.getName()); e.invoke_static(METHOD_PROXY, MAKE_PROXY); e.putfield(getMethodProxyField(impl));
private void emitNewInstanceCallback(ClassEmitter ce) { CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, SINGLE_NEW_INSTANCE, null); switch (callbackTypes.length) { case 0: // TODO: make sure Callback is null break; case 1: // for now just make a new array; TODO: optimize e.push(1); e.newarray(CALLBACK); e.dup(); e.push(0); e.load_arg(0); e.aastore(); e.invoke_static(getThisType(e), SET_THREAD_CALLBACKS); break; default: e.throw_exception(ILLEGAL_STATE_EXCEPTION, "More than one callback object required"); } emitCommonNewInstance(e); }
e.store_local(declaringclass); e.invoke_virtual(Constants.TYPE_CLASS, GET_DECLARED_METHODS); e.invoke_static(REFLECT_UTILS, FIND_METHODS); e.push(sig.getName()); e.push(impl.getName()); e.invoke_static(METHOD_PROXY, MAKE_PROXY); e.putfield(getMethodProxyField(impl));