[Ikvm-commit] ikvm/runtime BigEndianBinaryReader.cs, 1.8, 1.9 ClassFile.cs, 1.128, 1.129 DynamicTyp
Brought to you by:
jfrijters
|
From: Jeroen F. <jfr...@us...> - 2014-06-05 11:09:00
|
Update of /cvsroot/ikvm/ikvm/runtime In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv11169 Modified Files: BigEndianBinaryReader.cs ClassFile.cs DynamicTypeWrapper.cs TypeWrapper.cs Log Message: Implemented type annotation reflection for dynamically loaded classes. Index: TypeWrapper.cs =================================================================== RCS file: /cvsroot/ikvm/ikvm/runtime/TypeWrapper.cs,v retrieving revision 1.468 retrieving revision 1.469 diff -C2 -d -r1.468 -r1.469 *** TypeWrapper.cs 3 Jun 2014 12:04:42 -0000 1.468 --- TypeWrapper.cs 5 Jun 2014 11:08:57 -0000 1.469 *************** *** 3350,3353 **** --- 3350,3373 ---- #endif } + + internal virtual object[] GetConstantPool() + { + return null; + } + + internal virtual byte[] GetRawTypeAnnotations() + { + return null; + } + + internal virtual byte[] GetMethodRawTypeAnnotations(MethodWrapper mw) + { + return null; + } + + internal virtual byte[] GetFieldRawTypeAnnotations(FieldWrapper fw) + { + return null; + } } Index: DynamicTypeWrapper.cs =================================================================== RCS file: /cvsroot/ikvm/ikvm/runtime/DynamicTypeWrapper.cs,v retrieving revision 1.246 retrieving revision 1.247 diff -C2 -d -r1.246 -r1.247 *** DynamicTypeWrapper.cs 3 Jun 2014 14:28:37 -0000 1.246 --- DynamicTypeWrapper.cs 5 Jun 2014 11:08:57 -0000 1.247 *************** *** 444,447 **** --- 444,451 ---- internal abstract object[] GetFieldAnnotations(int index); internal abstract MethodInfo GetFinalizeMethod(); + internal abstract object[] GetConstantPool(); + internal abstract byte[] GetRawTypeAnnotations(); + internal abstract byte[] GetMethodRawTypeAnnotations(int index); + internal abstract byte[] GetFieldRawTypeAnnotations(int index); } *************** *** 3440,3443 **** --- 3444,3471 ---- return finalizeMethod; } + + internal override object[] GetConstantPool() + { + Debug.Fail("Unreachable code"); + return null; + } + + internal override byte[] GetRawTypeAnnotations() + { + Debug.Fail("Unreachable code"); + return null; + } + + internal override byte[] GetMethodRawTypeAnnotations(int index) + { + Debug.Fail("Unreachable code"); + return null; + } + + internal override byte[] GetFieldRawTypeAnnotations(int index) + { + Debug.Fail("Unreachable code"); + return null; + } } *************** *** 3447,3456 **** private readonly object[][] annotations; private readonly MethodParametersEntry[][] methodParameters; ! private Metadata(string[][] genericMetaData, object[][] annotations, MethodParametersEntry[][] methodParameters) { this.genericMetaData = genericMetaData; this.annotations = annotations; this.methodParameters = methodParameters; } --- 3475,3489 ---- private readonly object[][] annotations; private readonly MethodParametersEntry[][] methodParameters; + private readonly byte[][][] runtimeVisibleTypeAnnotations; + private readonly object[] constantPool; ! private Metadata(string[][] genericMetaData, object[][] annotations, MethodParametersEntry[][] methodParameters, ! byte[][][] runtimeVisibleTypeAnnotations, object[] constantPool) { this.genericMetaData = genericMetaData; this.annotations = annotations; this.methodParameters = methodParameters; + this.runtimeVisibleTypeAnnotations = runtimeVisibleTypeAnnotations; + this.constantPool = constantPool; } *************** *** 3464,3467 **** --- 3497,3501 ---- object[][] annotations = null; MethodParametersEntry[][] methodParameters = null; + byte[][][] runtimeVisibleTypeAnnotations = null; for (int i = 0; i < classFile.Methods.Length; i++) { *************** *** 3522,3525 **** --- 3556,3571 ---- methodParameters[i] = classFile.Methods[i].MethodParameters; } + if (classFile.Methods[i].RuntimeVisibleTypeAnnotations != null) + { + if (runtimeVisibleTypeAnnotations == null) + { + runtimeVisibleTypeAnnotations = new byte[3][][]; + } + if (runtimeVisibleTypeAnnotations[1] == null) + { + runtimeVisibleTypeAnnotations[1] = new byte[classFile.Methods.Length][]; + } + runtimeVisibleTypeAnnotations[1][i] = classFile.Methods[i].RuntimeVisibleTypeAnnotations; + } } for (int i = 0; i < classFile.Fields.Length; i++) *************** *** 3549,3552 **** --- 3595,3610 ---- annotations[4][i] = classFile.Fields[i].Annotations; } + if (classFile.Fields[i].RuntimeVisibleTypeAnnotations != null) + { + if (runtimeVisibleTypeAnnotations == null) + { + runtimeVisibleTypeAnnotations = new byte[3][][]; + } + if (runtimeVisibleTypeAnnotations[2] == null) + { + runtimeVisibleTypeAnnotations[2] = new byte[classFile.Fields.Length][]; + } + runtimeVisibleTypeAnnotations[2][i] = classFile.Fields[i].RuntimeVisibleTypeAnnotations; + } } if (classFile.EnclosingMethod != null) *************** *** 3574,3580 **** annotations[0] = classFile.Annotations; } ! if (genericMetaData != null || annotations != null || methodParameters != null) { ! return new Metadata(genericMetaData, annotations, methodParameters); } return null; --- 3632,3647 ---- annotations[0] = classFile.Annotations; } ! if (classFile.RuntimeVisibleTypeAnnotations != null) { ! if (runtimeVisibleTypeAnnotations == null) ! { ! runtimeVisibleTypeAnnotations = new byte[3][][]; ! } ! runtimeVisibleTypeAnnotations[0] = new byte[1][] { classFile.RuntimeVisibleTypeAnnotations }; ! } ! if (genericMetaData != null || annotations != null || methodParameters != null || runtimeVisibleTypeAnnotations != null) ! { ! object[] constantPool = runtimeVisibleTypeAnnotations == null ? null : classFile.GetConstantPool(); ! return new Metadata(genericMetaData, annotations, methodParameters, runtimeVisibleTypeAnnotations, constantPool); } return null; *************** *** 3671,3674 **** --- 3738,3773 ---- return null; } + + internal static object[] GetConstantPool(Metadata m) + { + return m.constantPool; + } + + internal static byte[] GetRawTypeAnnotations(Metadata m) + { + if (m != null && m.runtimeVisibleTypeAnnotations != null && m.runtimeVisibleTypeAnnotations[0] != null) + { + return m.runtimeVisibleTypeAnnotations[0][0]; + } + return null; + } + + internal static byte[] GetMethodRawTypeAnnotations(Metadata m, int index) + { + if (m != null && m.runtimeVisibleTypeAnnotations != null && m.runtimeVisibleTypeAnnotations[1] != null) + { + return m.runtimeVisibleTypeAnnotations[1][index]; + } + return null; + } + + internal static byte[] GetFieldRawTypeAnnotations(Metadata m, int index) + { + if (m != null && m.runtimeVisibleTypeAnnotations != null && m.runtimeVisibleTypeAnnotations[2] != null) + { + return m.runtimeVisibleTypeAnnotations[2][index]; + } + return null; + } } *************** *** 3809,3812 **** --- 3908,3931 ---- return finalizeMethod; } + + internal override object[] GetConstantPool() + { + return Metadata.GetConstantPool(metadata); + } + + internal override byte[] GetRawTypeAnnotations() + { + return Metadata.GetRawTypeAnnotations(metadata); + } + + internal override byte[] GetMethodRawTypeAnnotations(int index) + { + return Metadata.GetMethodRawTypeAnnotations(metadata, index); + } + + internal override byte[] GetFieldRawTypeAnnotations(int index) + { + return Metadata.GetFieldRawTypeAnnotations(metadata, index); + } } *************** *** 6667,6671 **** return null; } - private Type GetBaseTypeForDefineType() { --- 6786,6789 ---- *************** *** 6759,6762 **** --- 6877,6901 ---- ; } + + + internal override object[] GetConstantPool() + { + return impl.GetConstantPool(); + } + + internal override byte[] GetRawTypeAnnotations() + { + return impl.GetRawTypeAnnotations(); + } + + internal override byte[] GetMethodRawTypeAnnotations(MethodWrapper mw) + { + return impl.GetMethodRawTypeAnnotations(Array.IndexOf(GetMethods(), mw)); + } + + internal override byte[] GetFieldRawTypeAnnotations(FieldWrapper fw) + { + return impl.GetFieldRawTypeAnnotations(Array.IndexOf(GetFields(), fw)); + } } Index: ClassFile.cs =================================================================== RCS file: /cvsroot/ikvm/ikvm/runtime/ClassFile.cs,v retrieving revision 1.128 retrieving revision 1.129 diff -C2 -d -r1.128 -r1.129 *** ClassFile.cs 3 Jun 2014 14:28:37 -0000 1.128 --- ClassFile.cs 5 Jun 2014 11:08:57 -0000 1.129 *************** *** 84,87 **** --- 84,88 ---- private string[] enclosingMethod; private BootstrapMethod[] bootstrapMethods; + private byte[] runtimeVisibleTypeAnnotations; private static class SupportedVersions *************** *** 488,491 **** --- 489,500 ---- bootstrapMethods = ReadBootstrapMethods(br, this); break; + case "RuntimeVisibleTypeAnnotations": + if(majorVersion < 52) + { + goto default; + } + CreateUtf8ConstantPoolItems(utf8_cp); + runtimeVisibleTypeAnnotations = br.Section(br.ReadUInt32()).ToArray(); + break; case "IKVM.NET.Assembly": if(br.ReadUInt32() != 2) *************** *** 537,540 **** --- 546,560 ---- } + private void CreateUtf8ConstantPoolItems(string[] utf8_cp) + { + for (int i = 0; i < constantpool.Length; i++) + { + if (constantpool[i] == null && utf8_cp[i] != null) + { + constantpool[i] = new ConstantPoolItemUtf8(utf8_cp[i]); + } + } + } + private void CheckDuplicates<T>(T[] members, string msg) where T : IEquatable<T> *************** *** 1260,1263 **** --- 1280,1304 ---- } + internal byte[] RuntimeVisibleTypeAnnotations + { + get + { + return runtimeVisibleTypeAnnotations; + } + } + + internal object[] GetConstantPool() + { + object[] cp = new object[constantpool.Length]; + for (int i = 1; i < cp.Length; i++) + { + if (constantpool[i] != null) + { + cp[i] = constantpool[i].GetRuntimeValue(); + } + } + return cp; + } + internal string IKVMAssemblyAttribute { *************** *** 1398,1401 **** --- 1439,1449 ---- { } + + // this is used for sun.reflect.ConstantPool + // it returns a boxed System.Int32, System.Int64, System.Float, System.Double or a string + internal virtual object GetRuntimeValue() + { + return null; + } } *************** *** 1584,1587 **** --- 1632,1640 ---- } } + + internal override object GetRuntimeValue() + { + return d; + } } *************** *** 1914,1917 **** --- 1967,1975 ---- } } + + internal override object GetRuntimeValue() + { + return v; + } } *************** *** 1937,1940 **** --- 1995,2003 ---- } } + + internal override object GetRuntimeValue() + { + return v; + } } *************** *** 1960,1963 **** --- 2023,2031 ---- } } + + internal override object GetRuntimeValue() + { + return l; + } } *************** *** 2242,2245 **** --- 2310,2330 ---- } + // this is only used to copy strings into "constantpool" when we see a RuntimeVisibleTypeAnnotations attribute, + // because we need a consistent way of exposing constant pool items to the runtime and that case + private sealed class ConstantPoolItemUtf8 : ConstantPoolItem + { + private readonly string str; + + internal ConstantPoolItemUtf8(string str) + { + this.str = str; + } + + internal override object GetRuntimeValue() + { + return str; + } + } + private sealed class ConstantPoolItemLiveObject : ConstantPoolItem { *************** *** 2284,2287 **** --- 2369,2373 ---- protected string signature; protected object[] annotations; + protected byte[] runtimeVisibleTypeAnnotations; internal FieldOrMethod(ClassFile classFile, string[] utf8_cp, BigEndianBinaryReader br) *************** *** 2440,2443 **** --- 2526,2537 ---- } + internal byte[] RuntimeVisibleTypeAnnotations + { + get + { + return runtimeVisibleTypeAnnotations; + } + } + public sealed override int GetHashCode() { *************** *** 2574,2577 **** --- 2668,2679 ---- } break; + case "RuntimeVisibleTypeAnnotations": + if (classFile.MajorVersion < 52) + { + goto default; + } + classFile.CreateUtf8ConstantPoolItems(utf8_cp); + runtimeVisibleTypeAnnotations = br.Section(br.ReadUInt32()).ToArray(); + break; default: br.Skip(br.ReadUInt32()); *************** *** 2924,2927 **** --- 3026,3037 ---- break; } + case "RuntimeVisibleTypeAnnotations": + if (classFile.MajorVersion < 52) + { + goto default; + } + classFile.CreateUtf8ConstantPoolItems(utf8_cp); + runtimeVisibleTypeAnnotations = br.Section(br.ReadUInt32()).ToArray(); + break; default: br.Skip(br.ReadUInt32()); Index: BigEndianBinaryReader.cs =================================================================== RCS file: /cvsroot/ikvm/ikvm/runtime/BigEndianBinaryReader.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** BigEndianBinaryReader.cs 1 May 2012 07:20:51 -0000 1.8 --- BigEndianBinaryReader.cs 5 Jun 2014 11:08:57 -0000 1.9 *************** *** 1,4 **** /* ! Copyright (C) 2002-2012 Jeroen Frijters This software is provided 'as-is', without any express or implied --- 1,4 ---- /* ! Copyright (C) 2002-2014 Jeroen Frijters This software is provided 'as-is', without any express or implied *************** *** 225,227 **** --- 225,234 ---- return i; } + + internal byte[] ToArray() + { + byte[] res = new byte[end - pos]; + Buffer.BlockCopy(buf, pos, res, 0, res.Length); + return res; + } } |