[Ikvm-commit] ikvm/runtime LambdaMetafactory.cs, 1.2, 1.3 compiler.cs, 1.251, 1.252
Brought to you by:
jfrijters
|
From: Jeroen F. <jfr...@us...> - 2014-07-08 08:44:10
|
Update of /cvsroot/ikvm/ikvm/runtime In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv10390 Modified Files: LambdaMetafactory.cs compiler.cs Log Message: Use the same nested type for lambdas that are created with an invokedynamic to the same constant pool item (so that deserialization uses the same class as the original). Index: LambdaMetafactory.cs =================================================================== RCS file: /cvsroot/ikvm/ikvm/runtime/LambdaMetafactory.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** LambdaMetafactory.cs 8 Jul 2014 08:23:41 -0000 1.2 --- LambdaMetafactory.cs 8 Jul 2014 08:44:08 -0000 1.3 *************** *** 36,42 **** namespace IKVM.Internal { ! static class LambdaMetafactory { ! internal static bool Emit(DynamicTypeWrapper.FinishContext context, ClassFile classFile, ClassFile.ConstantPoolItemInvokeDynamic cpi, CodeEmitter ilgen) { ClassFile.BootstrapMethod bsm = classFile.GetBootstrapMethod(cpi.BootstrapMethod); --- 36,44 ---- namespace IKVM.Internal { ! sealed class LambdaMetafactory { ! private MethodBuilder ctor; ! ! internal static bool Emit(DynamicTypeWrapper.FinishContext context, ClassFile classFile, int constantPoolIndex, ClassFile.ConstantPoolItemInvokeDynamic cpi, CodeEmitter ilgen) { ClassFile.BootstrapMethod bsm = classFile.GetBootstrapMethod(cpi.BootstrapMethod); *************** *** 45,49 **** return false; } ! if (!EmitImpl(context, classFile, cpi, bsm, ilgen)) { #if STATIC_COMPILER --- 47,52 ---- return false; } ! LambdaMetafactory lmf = context.GetValue<LambdaMetafactory>(constantPoolIndex); ! if (lmf.ctor == null && !lmf.EmitImpl(context, classFile, cpi, bsm, ilgen)) { #if STATIC_COMPILER *************** *** 55,62 **** return false; } return true; } ! private static bool EmitImpl(DynamicTypeWrapper.FinishContext context, ClassFile classFile, ClassFile.ConstantPoolItemInvokeDynamic cpi, ClassFile.BootstrapMethod bsm, CodeEmitter ilgen) { if (HasUnloadable(cpi)) --- 58,68 ---- return false; } + ilgen.Emit(OpCodes.Newobj, lmf.ctor); + // the CLR verification rules about type merging mean we have to explicitly cast to the interface type here + ilgen.Emit(OpCodes.Castclass, cpi.GetRetType().TypeAsBaseType); return true; } ! private bool EmitImpl(DynamicTypeWrapper.FinishContext context, ClassFile classFile, ClassFile.ConstantPoolItemInvokeDynamic cpi, ClassFile.BootstrapMethod bsm, CodeEmitter ilgen) { if (HasUnloadable(cpi)) *************** *** 179,187 **** tb.AddInterfaceImplementation(CoreClasses.java.io.Serializable.Wrapper.TypeAsBaseType); } ! MethodBuilder ctor = CreateConstructorAndDispatch(context, cpi.GetArgTypes(), tb, interfaceMethod, implParameters, samMethodType, implMethod, instantiatedMethodType, serializable); AddDefaultInterfaceMethods(context, methodList, tb); - ilgen.Emit(OpCodes.Newobj, ctor); - // the CLR verification rules about type merging mean we have to explicitly cast to the interface type here - ilgen.Emit(OpCodes.Castclass, interfaceType.TypeAsBaseType); return true; } --- 185,190 ---- tb.AddInterfaceImplementation(CoreClasses.java.io.Serializable.Wrapper.TypeAsBaseType); } ! ctor = CreateConstructorAndDispatch(context, cpi.GetArgTypes(), tb, interfaceMethod, implParameters, samMethodType, implMethod, instantiatedMethodType, serializable); AddDefaultInterfaceMethods(context, methodList, tb); return true; } Index: compiler.cs =================================================================== RCS file: /cvsroot/ikvm/ikvm/runtime/compiler.cs,v retrieving revision 1.251 retrieving revision 1.252 diff -C2 -d -r1.251 -r1.252 *** compiler.cs 1 Jul 2014 15:12:34 -0000 1.251 --- compiler.cs 8 Jul 2014 08:44:08 -0000 1.252 *************** *** 1435,1440 **** ClassFile.ConstantPoolItemInvokeDynamic cpi = classFile.GetInvokeDynamic(instr.Arg1); CastInterfaceArgs(null, cpi.GetArgTypes(), i, false); ! EmitInvokeDynamic(cpi); ! EmitReturnTypeConversion(cpi.GetRetType()); nonleaf = true; break; --- 1435,1443 ---- ClassFile.ConstantPoolItemInvokeDynamic cpi = classFile.GetInvokeDynamic(instr.Arg1); CastInterfaceArgs(null, cpi.GetArgTypes(), i, false); ! if (!LambdaMetafactory.Emit(context, classFile, instr.Arg1, cpi, ilGenerator)) ! { ! EmitInvokeDynamic(cpi); ! EmitReturnTypeConversion(cpi.GetRetType()); ! } nonleaf = true; break; *************** *** 3209,3217 **** private void EmitInvokeDynamic(ClassFile.ConstantPoolItemInvokeDynamic cpi) { - if (LambdaMetafactory.Emit(context, classFile, cpi, ilGenerator)) - { - // we intrinsified the lambda factory - return; - } CodeEmitter ilgen = ilGenerator; TypeWrapper[] args = cpi.GetArgTypes(); --- 3212,3215 ---- |