Author: ankit
Date: 2006-01-13 08:07:09 -0500 (Fri, 13 Jan 2006)
New Revision: 55502
Modified:
trunk/mcs/ilasm/codegen/BaseTypeRef.cs
trunk/mcs/ilasm/codegen/ChangeLog
trunk/mcs/ilasm/codegen/CodeGen.cs
trunk/mcs/ilasm/codegen/ExternTypeRef.cs
trunk/mcs/ilasm/codegen/GenericParamRef.cs
trunk/mcs/ilasm/codegen/GenericTypeInst.cs
trunk/mcs/ilasm/codegen/MethodPointerTypeRef.cs
trunk/mcs/ilasm/codegen/PrimitiveTypeRef.cs
trunk/mcs/ilasm/codegen/Sentinel.cs
trunk/mcs/ilasm/codegen/TypeRef.cs
trunk/mcs/ilasm/parser/ChangeLog
trunk/mcs/ilasm/parser/ILParser.jay
Log:
In ilasm/codegen:
Move caching of method-refs and field-refs to BaseTypeRef, and use
CreateMethodRef & CreateFieldRef for creating the actual object.
Override these in derived classes to return the right objects.
* BaseTypeRef.cs (BaseTypeRef.CreateMethodRef): New.
(BaseTypeRef.CreateFieldRef): New.
(BaseTypeRef.GetMethodRef): Implement caching.
(BaseTypeRef.GetFieldRef): Likewise.
GenericTypeInst and PrimitiveTypeRef are not cached, so static
hashtables
are used here for caching their MethodRefs n FieldRefs.
* GenericTypeInst.cs (GenericTypeInst.GetMethodRef): Override and use
static hashtable to do caching.
(GenericTypeInst.GetFieldRef): Likewise.
* PrimitiveTypeRef.cs (PrimitiveTypeRef.GetMethodRef): Likewise.
(PrimitiveTypeRef.GetFieldRef): Likewise.
* CodeGen.cs (CodeGen.GetGlobalMethodRef): New. Cache global method
refs.
(CodeGen.GetGlobalFieldRef): New. Cache global field refs.
In ilasm/parser:
* ILParser.jay: Update to use CodeGen.GetGlobalMethodRef &
CodeGen.GetGlobalFieldRef instead of creating objects.
Modified: trunk/mcs/ilasm/codegen/BaseTypeRef.cs
===================================================================
--- trunk/mcs/ilasm/codegen/BaseTypeRef.cs 2006-01-13 13:05:51 UTC (rev
55501)
+++ trunk/mcs/ilasm/codegen/BaseTypeRef.cs 2006-01-13 13:07:09 UTC (rev
55502)
@@ -17,6 +17,8 @@
protected string sig_mod;
protected PEAPI.Type type;
protected bool is_resolved;
+ protected Hashtable method_table;
+ protected Hashtable field_table;
protected BaseTypeRef (string full_name)
: this (full_name, null, null)
@@ -54,17 +56,55 @@
throw new Exception ("Should not be called");
}
- public virtual IMethodRef GetMethodRef (BaseTypeRef ret_type,
+ public virtual IMethodRef CreateMethodRef (BaseTypeRef
ret_type,
PEAPI.CallConv call_conv, string name, BaseTypeRef[]
param, int gen_param_count)
{
throw new Exception ("Should not be called");
}
- public virtual IFieldRef GetFieldRef (BaseTypeRef ret_type,
string name)
+ public virtual IMethodRef GetMethodRef (BaseTypeRef ret_type,
+ PEAPI.CallConv call_conv, string name, BaseTypeRef[]
param, int gen_param_count)
{
+ IMethodRef mr = null;
+
+ /* Note: FullName not reqd as this is cached per
object */
+ string key = MethodDef.CreateSignature (ret_type,
name, param, gen_param_count);
+ if (method_table == null)
+ method_table = new Hashtable ();
+ else
+ mr = (IMethodRef) method_table [key];
+
+ if (mr == null) {
+ mr = CreateMethodRef (ret_type, call_conv,
name, param, gen_param_count);
+ method_table [key] = mr;
+ }
+
+ return mr;
+ }
+
+ public virtual IFieldRef CreateFieldRef (BaseTypeRef ret_type,
string name)
+ {
throw new Exception ("Should not be called");
}
+ public virtual IFieldRef GetFieldRef (BaseTypeRef ret_type,
string name)
+ {
+ IFieldRef fr = null;
+ string key = ret_type.FullName + name;
+
+ if (field_table == null)
+ field_table = new Hashtable ();
+ else
+ fr = (IFieldRef) field_table [key];
+
+ if (fr == null) {
+ fr = CreateFieldRef (ret_type, name);
+ field_table [key] = fr;
+ }
+
+ return fr;
+ }
+
}
}
Modified: trunk/mcs/ilasm/codegen/ChangeLog
===================================================================
--- trunk/mcs/ilasm/codegen/ChangeLog 2006-01-13 13:05:51 UTC (rev 55501)
+++ trunk/mcs/ilasm/codegen/ChangeLog 2006-01-13 13:07:09 UTC (rev 55502)
@@ -1,5 +1,28 @@
2006-01-13 Ankit Jain <[EMAIL PROTECTED]>
+ Move caching of method-refs and field-refs to BaseTypeRef, and use
+ CreateMethodRef & CreateFieldRef for creating the actual object.
+ Override these in derived classes to return the right objects.
+
+ * BaseTypeRef.cs (BaseTypeRef.CreateMethodRef): New.
+ (BaseTypeRef.CreateFieldRef): New.
+ (BaseTypeRef.GetMethodRef): Implement caching.
+ (BaseTypeRef.GetFieldRef): Likewise.
+
+ GenericTypeInst and PrimitiveTypeRef are not cached, so static
hashtables
+ are used here for caching their MethodRefs n FieldRefs.
+
+ * GenericTypeInst.cs (GenericTypeInst.GetMethodRef): Override and use
+ static hashtable to do caching.
+ (GenericTypeInst.GetFieldRef): Likewise.
+ * PrimitiveTypeRef.cs (PrimitiveTypeRef.GetMethodRef): Likewise.
+ (PrimitiveTypeRef.GetFieldRef): Likewise.
+
+ * CodeGen.cs (CodeGen.GetGlobalMethodRef): New. Cache global method
refs.
+ (CodeGen.GetGlobalFieldRef): New. Cache global field refs.
+
+2006-01-13 Ankit Jain <[EMAIL PROTECTED]>
+
Create BaseClassRef, BaseGenericTypeRef from IClassRef & IGenTypeRef.
Replace usage of interfaces ITypeRef, IClassRef & IGenTypeRef with their
corresponding Base* types.
Modified: trunk/mcs/ilasm/codegen/CodeGen.cs
===================================================================
--- trunk/mcs/ilasm/codegen/CodeGen.cs 2006-01-13 13:05:51 UTC (rev 55501)
+++ trunk/mcs/ilasm/codegen/CodeGen.cs 2006-01-13 13:07:09 UTC (rev 55502)
@@ -52,6 +52,8 @@
private ExternTable extern_table;
private Hashtable global_field_table;
private Hashtable global_method_table;
+ private Hashtable global_methodref_table;
+ private Hashtable global_fieldref_table;
private ArrayList data_list;
private FileRef file_ref;
private ArrayList manifestResources;
@@ -190,6 +192,45 @@
return tr;
}
+ public GlobalMethodRef GetGlobalMethodRef (BaseTypeRef
ret_type, PEAPI.CallConv call_conv,
+ string name, BaseTypeRef[] param, int
gen_param_count)
+ {
+ string key = MethodDef.CreateSignature (ret_type,
name, param, gen_param_count);
+
+ GlobalMethodRef methref = null;
+
+ if (global_methodref_table == null)
+ global_methodref_table = new Hashtable ();
+ else
+ methref = (GlobalMethodRef)
global_methodref_table [key];
+
+ if (methref == null) {
+ methref = new GlobalMethodRef (ret_type,
call_conv, name, param, gen_param_count);
+ global_methodref_table [key] = methref;
+ }
+
+ return methref;
+ }
+
+ public GlobalFieldRef GetGlobalFieldRef (BaseTypeRef ret_type,
string name)
+ {
+ string key = ret_type.FullName + name;
+
+ GlobalFieldRef fieldref = null;
+
+ if (global_fieldref_table == null)
+ global_fieldref_table = new Hashtable ();
+ else
+ fieldref = (GlobalFieldRef)
global_fieldref_table [key];
+
+ if (fieldref == null) {
+ fieldref = new GlobalFieldRef (ret_type, name);
+ global_fieldref_table [key] = fieldref;
+ }
+
+ return fieldref;
+ }
+
public void SetSubSystem (int sub_system)
{
this.sub_system = sub_system;
Modified: trunk/mcs/ilasm/codegen/ExternTypeRef.cs
===================================================================
--- trunk/mcs/ilasm/codegen/ExternTypeRef.cs 2006-01-13 13:05:51 UTC (rev
55501)
+++ trunk/mcs/ilasm/codegen/ExternTypeRef.cs 2006-01-13 13:07:09 UTC (rev
55502)
@@ -21,8 +21,6 @@
private IScope extern_ref;
private Hashtable nestedtypes_table;
private Hashtable nestedclass_table;
- private Hashtable method_table;
- private Hashtable field_table;
public ExternTypeRef (IScope extern_ref, string full_name,
bool is_valuetype)
: this (extern_ref, full_name, is_valuetype, null,
null)
@@ -37,8 +35,6 @@
nestedclass_table = new Hashtable ();
nestedtypes_table = new Hashtable ();
- method_table = new Hashtable ();
- field_table = new Hashtable ();
}
public override BaseClassRef Clone ()
@@ -80,30 +76,15 @@
is_resolved = true;
}
- public override IMethodRef GetMethodRef (BaseTypeRef ret_type,
PEAPI.CallConv call_conv,
+ public override IMethodRef CreateMethodRef (BaseTypeRef
ret_type, PEAPI.CallConv call_conv,
string name, BaseTypeRef[] param, int
gen_param_count)
{
- string sig = MethodDef.CreateSignature (ret_type,
name, param, gen_param_count);
- ExternMethodRef mr = method_table [sig] as
ExternMethodRef;
-
- if (mr == null) {
- mr = new ExternMethodRef (this, ret_type,
call_conv, name, param, gen_param_count);
- method_table [sig] = mr;
- }
-
- return mr;
+ return new ExternMethodRef (this, ret_type, call_conv,
name, param, gen_param_count);
}
- public override IFieldRef GetFieldRef (BaseTypeRef ret_type,
string name)
+ public override IFieldRef CreateFieldRef (BaseTypeRef
ret_type, string name)
{
- ExternFieldRef fr = field_table [name] as
ExternFieldRef;
-
- if (fr == null) {
- fr = new ExternFieldRef (this, ret_type, name);
- field_table [name] = fr;
- }
-
- return fr;
+ return new ExternFieldRef (this, ret_type, name);
}
public ExternTypeRef GetTypeRef (string _name, bool
is_valuetype)
Modified: trunk/mcs/ilasm/codegen/GenericParamRef.cs
===================================================================
--- trunk/mcs/ilasm/codegen/GenericParamRef.cs 2006-01-13 13:05:51 UTC (rev
55501)
+++ trunk/mcs/ilasm/codegen/GenericParamRef.cs 2006-01-13 13:07:09 UTC (rev
55502)
@@ -90,13 +90,13 @@
param.Name));
}
- public override IMethodRef GetMethodRef (BaseTypeRef ret_type,
PEAPI.CallConv call_conv,
+ public override IMethodRef CreateMethodRef (BaseTypeRef
ret_type, PEAPI.CallConv call_conv,
string name, BaseTypeRef[] param, int
gen_param_count)
{
return new TypeSpecMethodRef (this, call_conv,
ret_type, name, param, gen_param_count);
}
- public override IFieldRef GetFieldRef (BaseTypeRef ret_type,
string name)
+ public override IFieldRef CreateFieldRef (BaseTypeRef
ret_type, string name)
{
return new TypeSpecFieldRef (this, ret_type, name);
}
Modified: trunk/mcs/ilasm/codegen/GenericTypeInst.cs
===================================================================
--- trunk/mcs/ilasm/codegen/GenericTypeInst.cs 2006-01-13 13:05:51 UTC (rev
55501)
+++ trunk/mcs/ilasm/codegen/GenericTypeInst.cs 2006-01-13 13:07:09 UTC (rev
55502)
@@ -22,7 +22,9 @@
private bool is_valuetypeinst;
private GenericArguments gen_args;
private bool is_added; /* Added to PEFile (to TypeSpec table)
? */
- private static Hashtable method_table = new Hashtable ();
+ /* Note: Using static hashtable here as GenericTypeInsts is
not cached */
+ private static Hashtable s_method_table = new Hashtable ();
+ private static Hashtable s_field_table = new Hashtable ();
public GenericTypeInst (BaseClassRef class_ref,
GenericArguments gen_args, bool is_valuetypeinst)
: this (class_ref, gen_args, is_valuetypeinst, null,
null)
@@ -89,19 +91,30 @@
public override IMethodRef GetMethodRef (BaseTypeRef ret_type,
PEAPI.CallConv call_conv,
string meth_name, BaseTypeRef[] param, int
gen_param_count)
{
+ /* Note: Using FullName here as we are caching in a
static hashtable */
string key = FullName + MethodDef.CreateSignature
(ret_type, meth_name, param, gen_param_count);
- TypeSpecMethodRef mr = method_table [key] as
TypeSpecMethodRef;
+ TypeSpecMethodRef mr = s_method_table [key] as
TypeSpecMethodRef;
if (mr == null) {
mr = new TypeSpecMethodRef (this, call_conv,
ret_type, meth_name, param, gen_param_count);
- method_table [key] = mr;
+ s_method_table [key] = mr;
}
return mr;
}
- public override IFieldRef GetFieldRef (BaseTypeRef ret_type,
string field_name)
+ public override IFieldRef CreateFieldRef (BaseTypeRef
ret_type, string field_name)
{
- return new TypeSpecFieldRef (this, ret_type,
field_name);
+ /* Note: Using FullName here as we are caching in a
static hashtable */
+ string key = FullName + ret_type.FullName + field_name;
+
+ IFieldRef fr = (IFieldRef) s_field_table [key];
+
+ if (fr == null) {
+ fr = new TypeSpecFieldRef (this, ret_type,
field_name);
+ s_field_table [key] = fr;
+ }
+
+ return fr;
}
}
}
Modified: trunk/mcs/ilasm/codegen/MethodPointerTypeRef.cs
===================================================================
--- trunk/mcs/ilasm/codegen/MethodPointerTypeRef.cs 2006-01-13 13:05:51 UTC
(rev 55501)
+++ trunk/mcs/ilasm/codegen/MethodPointerTypeRef.cs 2006-01-13 13:07:09 UTC
(rev 55502)
@@ -78,13 +78,13 @@
is_resolved = true;
}
- public override IMethodRef GetMethodRef (BaseTypeRef ret_type,
PEAPI.CallConv call_conv,
+ public override IMethodRef CreateMethodRef (BaseTypeRef
ret_type, PEAPI.CallConv call_conv,
string name, BaseTypeRef[] param, int
gen_param_count)
{
return new TypeSpecMethodRef (this, call_conv,
ret_type, name, param, gen_param_count);
}
- public override IFieldRef GetFieldRef (BaseTypeRef ret_type,
string name)
+ public override IFieldRef CreateFieldRef (BaseTypeRef
ret_type, string name)
{
return new TypeSpecFieldRef (this, ret_type, name);
}
Modified: trunk/mcs/ilasm/codegen/PrimitiveTypeRef.cs
===================================================================
--- trunk/mcs/ilasm/codegen/PrimitiveTypeRef.cs 2006-01-13 13:05:51 UTC (rev
55501)
+++ trunk/mcs/ilasm/codegen/PrimitiveTypeRef.cs 2006-01-13 13:07:09 UTC (rev
55502)
@@ -18,12 +18,13 @@
/// </summary>
public class PrimitiveTypeRef : BaseTypeRef {
- private static Hashtable method_table = new Hashtable ();
+ private static Hashtable s_method_table = new Hashtable ();
public PrimitiveTypeRef (PEAPI.PrimitiveType type, string
full_name)
: base (full_name)
{
this.type = type;
+ SigMod = String.Empty;
}
public string Name {
@@ -62,20 +63,21 @@
public override IMethodRef GetMethodRef (BaseTypeRef ret_type,
PEAPI.CallConv call_conv,
string name, BaseTypeRef[] param, int
gen_param_count)
{
- string key = full_name + MethodDef.CreateSignature
(ret_type, name, param, gen_param_count) + sig_mod;
- TypeSpecMethodRef mr = method_table [key] as
TypeSpecMethodRef;
+ /* Use FullName also here, as we are caching in a
static hashtable */
+ string key = FullName + MethodDef.CreateSignature
(ret_type, name, param, gen_param_count);
+ TypeSpecMethodRef mr = s_method_table [key] as
TypeSpecMethodRef;
if (mr != null)
return mr;
//FIXME: generic methodref for primitive type?
mr = new TypeSpecMethodRef (this, call_conv, ret_type,
name, param, gen_param_count);
- method_table [key] = mr;
+ s_method_table [key] = mr;
return mr;
}
- public override IFieldRef GetFieldRef (BaseTypeRef ret_type,
string name)
+ public override IFieldRef CreateFieldRef (BaseTypeRef
ret_type, string name)
{
- return new TypeSpecFieldRef (this, ret_type, name);
+ throw new Exception ("PrimitiveType's can't have
fields!");
}
public BaseClassRef AsClassRef (CodeGen code_gen)
Modified: trunk/mcs/ilasm/codegen/Sentinel.cs
===================================================================
--- trunk/mcs/ilasm/codegen/Sentinel.cs 2006-01-13 13:05:51 UTC (rev 55501)
+++ trunk/mcs/ilasm/codegen/Sentinel.cs 2006-01-13 13:07:09 UTC (rev 55502)
@@ -29,13 +29,13 @@
is_resolved = true;
}
- public override IMethodRef GetMethodRef (BaseTypeRef ret_type,
PEAPI.CallConv call_conv,
+ public override IMethodRef CreateMethodRef (BaseTypeRef
ret_type, PEAPI.CallConv call_conv,
string name, BaseTypeRef[] param, int
gen_param_count)
{
return new TypeSpecMethodRef (this, call_conv,
ret_type, name, param, gen_param_count);
}
- public override IFieldRef GetFieldRef (BaseTypeRef ret_type,
string name)
+ public override IFieldRef CreateFieldRef (BaseTypeRef
ret_type, string name)
{
return new TypeSpecFieldRef (this, ret_type, name);
}
Modified: trunk/mcs/ilasm/codegen/TypeRef.cs
===================================================================
--- trunk/mcs/ilasm/codegen/TypeRef.cs 2006-01-13 13:05:51 UTC (rev 55501)
+++ trunk/mcs/ilasm/codegen/TypeRef.cs 2006-01-13 13:07:09 UTC (rev 55502)
@@ -37,13 +37,13 @@
return new TypeRef (full_name, is_valuetype, location,
(ArrayList) ConversionList.Clone (), sig_mod);
}
- public override IMethodRef GetMethodRef (BaseTypeRef ret_type,
+ public override IMethodRef CreateMethodRef (BaseTypeRef
ret_type,
PEAPI.CallConv call_conv, string name, BaseTypeRef[]
param, int gen_param_count)
{
return new MethodRef (this, call_conv, ret_type,
name, param, gen_param_count);
}
- public override IFieldRef GetFieldRef (BaseTypeRef ret_type,
string name)
+ public override IFieldRef CreateFieldRef (BaseTypeRef
ret_type, string name)
{
return new FieldRef (this, ret_type, name);
}
Modified: trunk/mcs/ilasm/parser/ChangeLog
===================================================================
--- trunk/mcs/ilasm/parser/ChangeLog 2006-01-13 13:05:51 UTC (rev 55501)
+++ trunk/mcs/ilasm/parser/ChangeLog 2006-01-13 13:07:09 UTC (rev 55502)
@@ -1,5 +1,10 @@
2006-01-13 Ankit Jain <[EMAIL PROTECTED]>
+ * ILParser.jay: Update to use CodeGen.GetGlobalMethodRef &
+ CodeGen.GetGlobalFieldRef instead of creating objects.
+
+2006-01-13 Ankit Jain <[EMAIL PROTECTED]>
+
* ILParser.jay: Update to use Base* instead of ITypeRef, IClassRef
& IGenTypeRef.
Modified: trunk/mcs/ilasm/parser/ILParser.jay
===================================================================
--- trunk/mcs/ilasm/parser/ILParser.jay 2006-01-13 13:05:51 UTC (rev 55501)
+++ trunk/mcs/ilasm/parser/ILParser.jay 2006-01-13 13:07:09 UTC (rev 55502)
@@ -2347,7 +2347,7 @@
}
| INSTR_FIELD type id
{
- GlobalFieldRef fieldref = new GlobalFieldRef
((BaseTypeRef) $2, (string) $3);
+ GlobalFieldRef fieldref =
codegen.GetGlobalFieldRef ((BaseTypeRef) $2, (string) $3);
codegen.CurrentMethodDef.AddInstr (new
FieldInstr ((FieldOp) $1, fieldref, tokenizer.Location));
}
@@ -2437,7 +2437,7 @@
else
param_list = new BaseTypeRef[0];
- $$ = new GlobalMethodRef ((BaseTypeRef) $2,
(CallConv) $1,
+ $$ = codegen.GetGlobalMethodRef ((BaseTypeRef)
$2, (CallConv) $1,
(string) $3, param_list, 0);
}
| call_conv type method_name typars_clause
@@ -2452,7 +2452,7 @@
else
param_list = new BaseTypeRef[0];
- IMethodRef methref = new GlobalMethodRef
((BaseTypeRef) $2, (CallConv) $1,
+ IMethodRef methref = codegen.GetGlobalMethodRef
((BaseTypeRef) $2, (CallConv) $1,
(string) $3, param_list, (ga != null ?
ga.Count : 0));
if (ga != null)
@@ -2531,7 +2531,7 @@
}
| K_FIELD type id
{
- $$ = new GlobalFieldRef ((BaseTypeRef) $2,
(string) $3);
+ $$ = codegen.GetGlobalFieldRef ((BaseTypeRef)
$2, (string) $3);
}
;
@@ -2698,7 +2698,7 @@
else
param_list = new BaseTypeRef[0];
- $$ = new GlobalMethodRef ((BaseTypeRef) $2,
(CallConv) $1,
+ $$ = codegen.GetGlobalMethodRef ((BaseTypeRef)
$2, (CallConv) $1,
(string) $3, param_list, 0);
}
;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches