[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[dotgnu-pnet-commits] pnet ChangeLog engine/cvmc.c engine/engine.h en...
From: |
Klaus Treichel |
Subject: |
[dotgnu-pnet-commits] pnet ChangeLog engine/cvmc.c engine/engine.h en... |
Date: |
Sun, 24 Aug 2008 17:45:34 +0000 |
CVSROOT: /cvsroot/dotgnu-pnet
Module name: pnet
Changes by: Klaus Treichel <ktreichel> 08/08/24 17:45:34
Modified files:
. : ChangeLog
engine : cvmc.c engine.h ilrun.c jitc.c jitc_call.c
jitc_pinvoke.c jitc_profile.c jitc_setup.c
lib_profiling.c null_coder.c verify.c
verify_call.c verify_except.c
include : il_coder.h
Log message:
Add enhanced profiling support for libjit and do some refactoring.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3563&r2=1.3564
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/cvmc.c?cvsroot=dotgnu-pnet&r1=1.60&r2=1.61
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/engine.h?cvsroot=dotgnu-pnet&r1=1.126&r2=1.127
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/ilrun.c?cvsroot=dotgnu-pnet&r1=1.63&r2=1.64
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc.c?cvsroot=dotgnu-pnet&r1=1.84&r2=1.85
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc_call.c?cvsroot=dotgnu-pnet&r1=1.42&r2=1.43
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc_pinvoke.c?cvsroot=dotgnu-pnet&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc_profile.c?cvsroot=dotgnu-pnet&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc_setup.c?cvsroot=dotgnu-pnet&r1=1.28&r2=1.29
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/lib_profiling.c?cvsroot=dotgnu-pnet&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/null_coder.c?cvsroot=dotgnu-pnet&r1=1.32&r2=1.33
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/verify.c?cvsroot=dotgnu-pnet&r1=1.54&r2=1.55
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/verify_call.c?cvsroot=dotgnu-pnet&r1=1.60&r2=1.61
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/verify_except.c?cvsroot=dotgnu-pnet&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/pnet/include/il_coder.h?cvsroot=dotgnu-pnet&r1=1.58&r2=1.59
Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3563
retrieving revision 1.3564
diff -u -b -r1.3563 -r1.3564
--- ChangeLog 21 Aug 2008 12:20:34 -0000 1.3563
+++ ChangeLog 24 Aug 2008 17:45:20 -0000 1.3564
@@ -1,3 +1,62 @@
+2008-08-24 Klaus Treichel <address@hidden>
+
+ * engine/cvmc.c (CVMCoder_SetOptimizationLevel,
+ CVMCoder_GetOptimizationLevel): Add new functions for managing the
+ optimization level.
+ (CVMCoder_Create): Initialize the optimizationLevel.
+
+ * engine/engine.h: Add prototypes for the new profiling functions
+ _ILProfilingDump, _ILProfilingStart and _ILProfilingEnd.
+
+ * engine/ilrun.c (main): Add new option -O to set the optimization level
+ for the coder.
+
+ * engine/jitc.c (ILJitInit): Create the jit types and signatures needed
+ for enhanced profiling.
+ (JITCoder_SetOptimizationLevel, JITCoder_GetOptimizationLevel): Add new
+ coder functions.
+ (_ILJitCallInternal): Add emitting profiling information for the
internal
+ call.
+ (_ILJitCompileInternal): Intitialize members needed in the the jitCoder.
+
+ * engine/jitc_call.c (JITCoder_CallMethod): Remove increasing the call
+ count of the called method.
+
+ * engine/jitc_pinvoke.c (_ILJitCompilePinvoke): Add initialization of
+ more coder members needed by profiling.
+ (_ILJitInlinePinvoke): Add emitting profiling information.
+
+ * engine/jitc_profile.c: Add support for enhanced profiling.
+
+ * engine/jitc_setup.c (JITCoder_Setup): Remove increasing the call count
+ of the current method. Initialize the new members for enhanced
profiling.
+
+ * engine/lib_profiling.c (_ILProfilingStart, _ILProfilingEnd): Add new
+ functions for enhanced profiling support.
+ (_ILProfilingDump): Move the common code for dumping profiling
information
+ from the coders to here.
+
+ * engine/null_coder.c (Coder_ProfileStart, Coder_ProfileEnd,
+ Coder_SetOptimizationLevel, Coder_GetOptimizationLevel): Add the stubs
+ for the new coder members.
+
+ * engine/verify.c (_ILVerify): Get the optimization level used by the
+ coder. Add call to ILCoderProfileStart after the call to ILCoderSetup.
+ Pass coderFlags to OutputExceptionTable.
+
+ * engine/verify_call.c (IL_OP_CALL): Enable inlining if the optimization
+ level used is > 0 instead of checking the coder flags.
+ (IL_OP_RET): Add call to ILCoderProfileEnd before calling
+ ILCoderReturnInsn.
+
+ * engine/verify_except.c (OutputExceptionTable): Add call to
+ ILCoderProfileEnd before rethowing the exception to the caller.
+ (IL_OP_THROW): likewise.
+
+ * include/il_coder.h: Add some comments to the coder flags.
+ Add the new coder members: profileStart, profileEnd,
setOptimizationLevel
+ and getOptimizationLevel.
+
2008-08-21 Klaus Treichel <address@hidden>
* engine/cvm.h: Add opcodes for inlining array copy and clear for
vectors
Index: engine/cvmc.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvmc.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -b -r1.60 -r1.61
--- engine/cvmc.c 6 Aug 2008 13:31:47 -0000 1.60
+++ engine/cvmc.c 24 Aug 2008 17:45:25 -0000 1.61
@@ -84,6 +84,7 @@
int labelOutOfMemory;
unsigned char *switchStart;
int debugEnabled;
+ ILUInt32 optimizationLevel;
#ifdef IL_DEBUGGER
/* Flag if current method can be debugged */
int markBreakpoints;
@@ -192,6 +193,7 @@
coder->switchStart = 0;
coder->debugEnabled = 0;
coder->flags = 0;
+ coder->optimizationLevel = 1;
coder->nativeArgPosn = 0;
coder->nativeArgHeight = 0;
coder->process = process;
@@ -324,6 +326,35 @@
}
/*
+ * Start profiling of the current method.
+ */
+static void CVMCoder_ProfilingStart(ILCoder *_coder)
+{
+ /* TODO */
+}
+
+/*
+ * End profiling of the current method.
+ */
+static void CVMCoder_ProfilingEnd(ILCoder *_coder)
+{
+ /* TODO */
+}
+
+static void CVMCoder_SetOptimizationLevel(ILCoder *_coder,
+
ILUInt32 optimizationLevel)
+{
+ ILCVMCoder *coder = (ILCVMCoder *)_coder;
+ coder->optimizationLevel = optimizationLevel;
+}
+
+static ILUInt32 CVMCoder_GetOptimizationLevel(ILCoder *_coder)
+{
+ ILCVMCoder *coder = (ILCVMCoder *)_coder;
+ return coder->optimizationLevel;
+}
+
+/*
* Get a block of method cache memory for use in code unrolling.
*/
int _ILCVMStartUnrollBlock(ILCoder *_coder, int align, ILCachePosn *posn)
@@ -428,8 +459,6 @@
{
ILCache *cache = ((ILCVMCoder *)(process->coder))->cache;
ILMethod **list;
- ILMethod **temp;
- ILMethod *method;
int haveCounts;
/* Get the list of all translated methods from the cache */
@@ -439,49 +468,8 @@
return 0;
}
- /* Sort the method list into decreasing order of count */
- if(list[0] != 0 && list[1] != 0)
- {
- ILMethod **outer;
- ILMethod **inner;
- for(outer = list; outer[1] != 0; ++outer)
- {
- for(inner = outer + 1; inner[0] != 0; ++inner)
- {
- if(outer[0]->count < inner[0]->count)
- {
- method = outer[0];
- outer[0] = inner[0];
- inner[0] = method;
- }
- }
- }
- }
-
- /* Print the method information */
- haveCounts = 0;
- temp = list;
-#ifdef ENHANCED_PROFILER
- printf ("Count\tTotal time\tAverage time\tMethod\n");
-#endif
- while((method = *temp++) != 0)
- {
- if(!(method->count))
- {
- continue;
- }
-#ifdef ENHANCED_PROFILER
- printf("%lu\t%lu\t%lu\t", (unsigned long)(method->count),
- (unsigned long)(method->time), (unsigned
long)(method->time) / (unsigned long)(method->count));
-#else
- printf("%lu\t", (unsigned long)(method->count));
-#endif
- ILDumpMethodType(stdout, ILProgramItem_Image(method),
- ILMethod_Signature(method), 0,
- ILMethod_Owner(method),
ILMethod_Name(method), 0);
- putc('\n', stdout);
- haveCounts = 1;
- }
+ /* Dump the profiling information */
+ haveCounts = _ILProfilingDump(stream, list);
/* Clean up and exit */
ILFree(list);
@@ -624,6 +612,10 @@
CVMCoder_RunCCtors,
CVMCoder_RunCCtor,
CVMCoder_HandleLockedMethod,
+ CVMCoder_ProfilingStart,
+ CVMCoder_ProfilingEnd,
+ CVMCoder_SetOptimizationLevel,
+ CVMCoder_GetOptimizationLevel,
"sentinel"
};
Index: engine/engine.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/engine.h,v
retrieving revision 1.126
retrieving revision 1.127
diff -u -b -r1.126 -r1.127
--- engine/engine.h 12 Aug 2008 18:19:51 -0000 1.126
+++ engine/engine.h 24 Aug 2008 17:45:29 -0000 1.127
@@ -902,6 +902,30 @@
*/
ILInt32 _ILStringToBuffer(ILExecThread *thread, ILString *str, ILUInt16 **buf);
+#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
+/*
+ * Dump the profiling information for the given methods.
+ * A NULL method marks the end of the list.
+ * Returns 1 if profiling information was dumped otherwise 0.
+ */
+int _ILProfilingDump(FILE *stream, ILMethod **methods);
+#ifdef ENHANCED_PROFILER
+/*
+ * Get the start profiling timestamp.
+ */
+void _ILProfilingStart(ILCurrTime *timestamp);
+
+/*
+ * End profiling for the method given and add the difference between the
+ * timestamp given and the current time to the total execution time of
+ * the method.
+ * Increase the execution counter here too so that the number of executions
+ * and spent time in the method matches.
+ */
+void _ILProfilingEnd(ILMethod *method, ILCurrTime *startTimestamp);
+#endif /* ENHANCED_PROFILER */
+#endif /* !IL_CONFIG_REDUCE_CODE && !IL_WITHOUT_TOOLS */
+
#ifndef REDUCED_STDIO
/*
Index: engine/ilrun.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/ilrun.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -b -r1.63 -r1.64
--- engine/ilrun.c 10 Aug 2008 16:16:13 -0000 1.63
+++ engine/ilrun.c 24 Aug 2008 17:45:31 -0000 1.64
@@ -85,6 +85,10 @@
{"--ignore-load-errors", 'i', 0,
"--ignore-load-errors or -i",
"Ignore metadata errors when loading (discouraged)."},
+ {"-O", 'O', 1, 0, 0},
+ {"--optimization-level", 'O', 1,
+ "--optimization-level level or -O level",
+ "Set optimization level (0 = no optimizations)."},
#if defined(linux) || defined(__linux) || defined(__linux__)
{"--register", 'r', 0,
"--register [fullpath]",
@@ -175,6 +179,8 @@
int ilprogramLen;
int flags=0;
int loadFlags = 0;
+ int optimizationLeve = 0;
+ int setOptimizationLevel = 0;
#ifndef IL_CONFIG_REDUCE_CODE
int dumpInsnProfile = 0;
int dumpVarProfile = 0;
@@ -267,6 +273,16 @@
}
break;
+ case 'O':
+ {
+ if(param && *param >= '0' && *param <= '9')
+ {
+ optimizationLeve = (*param - '0');
+ setOptimizationLevel = 1;
+ }
+ }
+ break;
+
#ifndef IL_CONFIG_REDUCE_CODE
case 'I':
{
@@ -436,6 +452,10 @@
ILExecProcessSetCoderFlags(process,flags);
ILExecProcessSetLoadFlags(process, loadFlags, loadFlags);
+ if(setOptimizationLevel)
+ {
+ ILCoderSetOptimizationLevel(process->coder, optimizationLeve);
+ }
/* Set the list of directories to use for path searching */
if(numLibraryDirs > 0)
Index: engine/jitc.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/jitc.c,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -b -r1.84 -r1.85
--- engine/jitc.c 21 Aug 2008 12:20:37 -0000 1.84
+++ engine/jitc.c 24 Aug 2008 17:45:31 -0000 1.85
@@ -153,6 +153,15 @@
static ILObject *_ILJitAllocTyped(ILClass *classInfo);
#endif /* IL_USE_TYPED_ALLOCATION */
+#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
+#ifdef ENHANCED_PROFILER
+/*
+ * Type for the ILCurrTime used by profiling.
+ */
+static ILJitType _ILJitTypeCurrTime = 0;
+#endif /* ENHANCED_PROFILER */
+#endif /* !IL_CONFIG_REDUCE_CODE && !IL_WITHOUT_TOOLS */
+
/*
* Definition of signatures of internal functions used by jitted code.
* They have to be kept in sync with the corresponding engine funcions.
@@ -347,6 +356,20 @@
*/
static ILJitType _ILJitSignature_ILSArrayClear_AI4I4 = 0;
+#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
+#ifdef ENHANCED_PROFILER
+/*
+ * void _ILProfilingStart(ILCurrTime *timestamp)
+ */
+static ILJitType _ILJitSignature_ILProfilingStart = 0;
+
+/*
+ * void _ILProfilingEnd(ILMethod *method, ILCurrTime *startTimestamp)
+ */
+static ILJitType _ILJitSignature_ILProfilingEnd = 0;
+#endif /* ENHANCED_PROFILER */
+#endif /* !IL_CONFIG_REDUCE_CODE && !IL_WITHOUT_TOOLS */
+
/*
* void ILJitTraceIn(ILExecThread *thread, ILMethod *method)
* void ILJitTraceOut(ILExecThread *thread, ILMethod *method)
@@ -384,6 +407,7 @@
#include "jitc_call.c"
#include "jitc_delegate.c"
#include "jitc_math.c"
+#include "jitc_profile.c"
#undef IL_JITC_DECLARATIONS
/*
@@ -461,6 +485,7 @@
#include "jitc_locals.c"
#include "jitc_stack.c"
#include "jitc_labels.c"
+#include "jitc_profile.c"
#undef IL_JITC_CODER_INSTANCE
/* The current jitted function. */
@@ -474,6 +499,9 @@
/* The manager for running the required cctors. */
ILCCtorMgr cctorMgr;
+ /* The optimization level used by the coder */
+ ILUInt32 optimizationLevel;
+
#ifndef IL_JIT_THREAD_IN_SIGNATURE
/* cache for the current thread. */
ILJitValue thread;
@@ -2285,6 +2313,18 @@
_IL_ALIGN_FOR_TYPE(void_p));
_ILJitTypesInitBase(&_ILJitType_TYPEDREF, _ILJitTypedRef);
+#ifndef IL_CONFIG_REDUCE_CODE
+#ifdef ENHANCED_PROFILER
+ if(!(_ILJitTypeCurrTime = jit_type_create_struct(0, 0, 0)))
+ {
+ return 0;
+ }
+ jit_type_set_size_and_alignment(_ILJitTypeCurrTime,
+
sizeof(ILCurrTime),
+
_IL_ALIGN_FOR_TYPE(void_p));
+#endif /* ENHANCED_PROFILER */
+#endif /* !IL_CONFIG_REDUCE_CODE */
+
/* Initialize the native method signatures. */
returnType = _IL_JIT_TYPE_VPTR;
if(!(_ILJitSignature_ILExecThreadCurrent =
@@ -2593,6 +2633,27 @@
}
#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
+#ifdef ENHANCED_PROFILER
+ args[0] = _IL_JIT_TYPE_VPTR;
+ returnType = _IL_JIT_TYPE_VOID;
+ if(!(_ILJitSignature_ILProfilingStart =
+ jit_type_create_signature(IL_JIT_CALLCONV_CDECL, returnType,
args, 1, 1)))
+ {
+ return 0;
+ }
+
+ args[0] = _IL_JIT_TYPE_VPTR;
+ args[1] = _IL_JIT_TYPE_VPTR;
+ returnType = _IL_JIT_TYPE_VOID;
+ if(!(_ILJitSignature_ILProfilingEnd =
+ jit_type_create_signature(IL_JIT_CALLCONV_CDECL, returnType,
args, 2, 1)))
+ {
+ return 0;
+ }
+#endif /* ENHANCED_PROFILER */
+#endif /* !IL_CONFIG_REDUCE_CODE && !IL_WITHOUT_TOOLS */
+
+#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
args[0] = _IL_JIT_TYPE_VPTR;
args[1] = _IL_JIT_TYPE_VPTR;
returnType = _IL_JIT_TYPE_VOID;
@@ -2626,6 +2687,7 @@
}
coder->debugEnabled = 0;
coder->flags = 0;
+ coder->optimizationLevel = 1;
/* Intialize the pool for the method infos. */
ILMemPoolInit(&(coder->methodPool), sizeof(ILJitMethodInfo), 100);
@@ -2649,10 +2711,11 @@
#endif
#define IL_JITC_CODER_INIT
- #include "jitc_inline.c"
- #include "jitc_locals.c"
- #include "jitc_stack.c"
- #include "jitc_labels.c"
+#include "jitc_inline.c"
+#include "jitc_locals.c"
+#include "jitc_stack.c"
+#include "jitc_labels.c"
+#include "jitc_profile.c"
#undef IL_JITC_CODER_INIT
/* Ready to go */
@@ -2881,6 +2944,7 @@
#include "jitc_locals.c"
#include "jitc_stack.c"
#include "jitc_labels.c"
+#include "jitc_profile.c"
#undef IL_JITC_CODER_DESTROY
if(coder->context)
@@ -2973,6 +3037,21 @@
return ILCCtorMgr_HandleLockedMethod(&(jitCoder->cctorMgr), method);
}
+static void JITCoder_SetOptimizationLevel(ILCoder *coder,
+
ILUInt32 optimizationLevel)
+{
+ ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
+
+ jitCoder->optimizationLevel = optimizationLevel;
+}
+
+static ILUInt32 JITCoder_GetOptimizationLevel(ILCoder *coder)
+{
+ ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
+
+ return jitCoder->optimizationLevel;
+}
+
#ifdef IL_CONFIG_PINVOKE
/*
@@ -3128,7 +3207,7 @@
/*
* Generate the code to call an internal function.
*/
-static ILJitValue _ILJitCallInternal(ILJitFunction func,
+static ILJitValue _ILJitCallInternal(ILJITCoder *jitCoder,
ILJitValue thread,
ILMethod *method,
void
*nativeFunction,
@@ -3203,8 +3282,9 @@
{
++totalParams;
jitParamTypes[1] = _IL_JIT_TYPE_VPTR;
- returnValue = jit_value_create(func, returnType);
- jitParams[1] = jit_insn_address_of(func, returnValue);
+ returnValue = jit_value_create(jitCoder->jitFunction,
returnType);
+ jitParams[1] =
jit_insn_address_of(jitCoder->jitFunction,
+
returnValue);
returnType = _IL_JIT_TYPE_VOID;
hasStructReturn = 1;
++param;
@@ -3222,22 +3302,24 @@
{
jitParamTypes[param] = _IL_JIT_TYPE_VPTR;
#ifdef IL_JIT_THREAD_IN_SIGNATURE
- jitParams[param] = jit_insn_address_of(func,
args[current - 1]);
+ jitParams[param] =
jit_insn_address_of(jitCoder->jitFunction,
+
args[current - 1]);
#else
- jitParams[param] = jit_insn_address_of(func,
args[current]);
+ jitParams[param] =
jit_insn_address_of(jitCoder->jitFunction,
+
args[current]);
#endif
}
else
{
jitParamTypes[param] = paramType;
#ifdef IL_JIT_THREAD_IN_SIGNATURE
- args[current - 1] =
_ILJitValueConvertImplicit(func,
+ args[current - 1] =
_ILJitValueConvertImplicit(jitCoder->jitFunction,
args[current - 1],
paramType);
jitParams[param] = args[current - 1];
#else
- args[current] = _ILJitValueConvertImplicit(func,
+ args[current] =
_ILJitValueConvertImplicit(jitCoder->jitFunction,
args[current],
paramType);
jitParams[param] = args[current];
@@ -3250,23 +3332,44 @@
jitParamTypes,
totalParams, 1);
- _ILJitSetMethodInThread(func, thread, method);
- _ILJitBeginNativeCall(func, thread);
+ _ILJitSetMethodInThread(jitCoder->jitFunction, thread, method);
+ _ILJitBeginNativeCall(jitCoder->jitFunction, thread);
+#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
+ /*
+ * Emit the code to start profiling of the method if profiling
+ * is enabled
+ */
+ if(jitCoder->flags & IL_CODER_FLAG_METHOD_PROFILE)
+ {
+ _ILJitProfileStart(jitCoder, method);
+ }
+#endif /* !IL_CONFIG_REDUCE_CODE && !IL_WITHOUT_TOOLS */
if(!hasStructReturn)
{
- returnValue = jit_insn_call_native(func, methodName,
nativeFunction,
+ returnValue =
jit_insn_call_native(jitCoder->jitFunction,
+
methodName, nativeFunction,
callSignature,
jitParams, totalParams, 0);
}
else
{
- jit_insn_call_native(func, methodName, nativeFunction,
- callSignature,
+ jit_insn_call_native(jitCoder->jitFunction, methodName,
+
nativeFunction, callSignature,
jitParams,
totalParams, 0);
}
jit_type_free(callSignature);
+#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
+ /*
+ * Emit the code to end profiling of the method if profiling
+ * is enabled
+ */
+ if(jitCoder->flags & IL_CODER_FLAG_METHOD_PROFILE)
+ {
+ _ILJitProfileEnd(jitCoder, method);
+ }
+#endif /* !IL_CONFIG_REDUCE_CODE && !IL_WITHOUT_TOOLS */
}
- _ILJitEndNativeCall(func, thread);
+ _ILJitEndNativeCall(jitCoder->jitFunction, thread);
return returnValue;
}
@@ -3277,10 +3380,8 @@
static int _ILJitCompileInternal(ILJitFunction func)
{
ILMethod *method = (ILMethod *)jit_function_get_meta(func,
IL_JIT_META_METHOD);
-#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS) &&
defined(_IL_JIT_ENABLE_DEBUG)
ILClassPrivate *classPrivate = (ILClassPrivate
*)(ILMethod_Owner(method)->userData);
ILJITCoder *jitCoder = (ILJITCoder *)(classPrivate->process->coder);
-#endif
ILJitMethodInfo *jitMethodInfo = (ILJitMethodInfo *)(method->userData);
ILJitType signature = jit_function_get_signature(func);
unsigned int numParams = jit_type_num_params(signature);
@@ -3295,6 +3396,20 @@
ILJitValue jitParams[numParams];
#endif
+ /* Set the current function in the coder */
+ jitCoder->jitFunction = func;
+
+#ifndef IL_JIT_THREAD_IN_SIGNATURE
+ /* Reset the cached thread. */
+ jitCoder->thread = 0;
+#endif
+
+#ifdef ENHANCED_PROFILER
+ /* Reset the timestamps */
+ jitCoder->profileTimestamp = 0;
+ jitCoder->inlineTimestamp = 0;
+#endif /* ENHANCED_PROFILER */
+
#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS) &&
defined(_IL_JIT_ENABLE_DEBUG)
methodName = _ILJitFunctionGetMethodName(func);
if(jitCoder->flags & IL_CODER_FLAG_STATS)
@@ -3308,29 +3423,29 @@
#ifdef IL_JIT_THREAD_IN_SIGNATURE
for(current = 1; current < numParams; ++current)
{
- if(!(paramValue = jit_value_get_param(func, current)))
+ if(!(paramValue = jit_value_get_param(jitCoder->jitFunction,
current)))
{
return JIT_RESULT_OUT_OF_MEMORY;
}
jitParams[current - 1] = paramValue;
}
- returnValue = _ILJitCallInternal(func, thread, method,
+ returnValue = _ILJitCallInternal(jitCoder, thread, method,
jitMethodInfo->fnInfo.func, methodName,
jitParams, numParams - 1);
#else
for(current = 0; current < numParams; ++current)
{
- if(!(paramValue = jit_value_get_param(func, current)))
+ if(!(paramValue = jit_value_get_param(jitCoder->jitFunction,
current)))
{
return JIT_RESULT_OUT_OF_MEMORY;
}
jitParams[current] = paramValue;
}
- returnValue = _ILJitCallInternal(func, thread, method,
+ returnValue = _ILJitCallInternal(jitCoder, thread, method,
jitMethodInfo->fnInfo.func, methodName,
jitParams, numParams);
#endif
- jit_insn_return(func, returnValue);
+ jit_insn_return(jitCoder->jitFunction, returnValue);
return JIT_RESULT_OK;
}
@@ -3374,7 +3489,6 @@
return 0;
}
-#include "jitc_profile.c"
#include "jitc_pinvoke.c"
/*
@@ -4614,7 +4728,6 @@
int haveCounts = 0;
ILMethod *method;
ILMethod **methods;
- ILMethod **temp;
/* Get the number of created and called functions */
function = jit_function_next(coder->context, 0);
@@ -4655,56 +4768,41 @@
/* Mark the end of the list. */
methods[current] = 0;
- /* Sort the method list into decreasing order of count */
- if(methods[0] != 0 && methods[1] != 0)
- {
- ILMethod **outer;
- ILMethod **inner;
- for(outer = methods; outer[1] != 0; ++outer)
- {
- for(inner = outer + 1; inner[0] != 0; ++inner)
- {
- if(outer[0]->count < inner[0]->count)
- {
- method = outer[0];
- outer[0] = inner[0];
- inner[0] = method;
- }
- }
- }
- }
-
- /* Print the method information */
- temp = methods;
-#ifdef ENHANCED_PROFILER
- printf ("Count\tTotal time\tAverage time\tMethod\n");
-#endif
- while((method = *temp++) != 0)
- {
- if(!(method->count))
- {
- continue;
- }
-#ifdef ENHANCED_PROFILER
- printf("%lu\t%lu\t%lu\t", (unsigned long)(method->count),
- (unsigned long)(method->time), (unsigned
long)(method->time) / (unsigned long)(method->count));
-#else
- printf("%lu\t", (unsigned long)(method->count));
-#endif
- ILDumpMethodType(stdout, ILProgramItem_Image(method),
- ILMethod_Signature(method), 0,
- ILMethod_Owner(method),
ILMethod_Name(method), 0);
- putc('\n', stdout);
- haveCounts = 1;
- }
+ /* Dump the profiling information */
+ haveCounts = _ILProfilingDump(stream, methods);
/* Clean up and exit */
-
ILFree(methods);
return haveCounts;
}
-#endif /* !IL_CONFIG_REDUCE_CODE */
+static void ILJitTraceIn(ILExecThread *thread, ILMethod *method)
+{
+ /* TODO: nesting level */
+ ILMutexLock(globalTraceMutex);
+ fputs("Entering ", stdout);
+ ILDumpMethodType(stdout, ILProgramItem_Image(method),
+ ILMethod_Signature(method), 0,
+ ILMethod_Owner(method),
+ ILMethod_Name(method), method);
+ putc('\n',stdout);
+ fflush(stdout);
+ ILMutexUnlock(globalTraceMutex);
+}
+
+static void ILJitTraceOut(ILExecThread *thread, ILMethod *method)
+{
+ /* TODO: nesting level */
+ ILMutexLock(globalTraceMutex);
+ fputs("Leaving ", stdout);
+ ILDumpMethodType(stdout, ILProgramItem_Image(method),
+ ILMethod_Signature(method), 0,
+ ILMethod_Owner(method),
+ ILMethod_Name(method), method);
+ putc('\n',stdout);
+ fflush(stdout);
+ ILMutexUnlock(globalTraceMutex);
+}
#ifdef _IL_JIT_ENABLE_DEBUG
@@ -4744,8 +4842,8 @@
jit_function_t fn;
void *handler = 0;
ILMethod *method;
- char *methodName;
- char *className;
+ const char *methodName;
+ const char *className;
char *result;
thread = ILExecThreadCurrent();
@@ -4928,37 +5026,7 @@
#endif /* _IL_JIT_ENABLE_DEBUG */
-#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
-
-static void ILJitTraceIn(ILExecThread *thread, ILMethod *method)
-{
- /* TODO: nesting level */
- ILMutexLock(globalTraceMutex);
- fputs("Entering ", stdout);
- ILDumpMethodType(stdout, ILProgramItem_Image(method),
- ILMethod_Signature(method), 0,
- ILMethod_Owner(method),
- ILMethod_Name(method), method);
- putc('\n',stdout);
- fflush(stdout);
- ILMutexUnlock(globalTraceMutex);
-}
-
-static void ILJitTraceOut(ILExecThread *thread, ILMethod *method)
-{
- /* TODO: nesting level */
- ILMutexLock(globalTraceMutex);
- fputs("Leaving ", stdout);
- ILDumpMethodType(stdout, ILProgramItem_Image(method),
- ILMethod_Signature(method), 0,
- ILMethod_Owner(method),
- ILMethod_Name(method), method);
- putc('\n',stdout);
- fflush(stdout);
- ILMutexUnlock(globalTraceMutex);
-}
-
-#endif
+#endif /* !IL_CONFIG_REDUCE_CODE && !IL_WITHOUT_TOOLS */
#define IL_JITC_FUNCTIONS
#include "jitc_arith.c"
@@ -4973,6 +5041,7 @@
#include "jitc_call.c"
#include "jitc_delegate.c"
#include "jitc_math.c"
+#include "jitc_profile.c"
#undef IL_JITC_FUNCTIONS
/*
@@ -4992,6 +5061,7 @@
#include "jitc_conv.c"
#include "jitc_obj.c"
#include "jitc_call.c"
+#include "jitc_profile.c"
#undef IL_JITC_CODE
/*
@@ -5110,6 +5180,10 @@
JITCoder_RunCCtors,
JITCoder_RunCCtor,
JITCoder_HandleLockedMethod,
+ JITCoder_ProfilingStart,
+ JITCoder_ProfilingEnd,
+ JITCoder_SetOptimizationLevel,
+ JITCoder_GetOptimizationLevel,
"sentinel"
};
#ifdef __cplusplus
Index: engine/jitc_call.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/jitc_call.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -b -r1.42 -r1.43
--- engine/jitc_call.c 21 Aug 2008 12:20:38 -0000 1.42
+++ engine/jitc_call.c 24 Aug 2008 17:45:31 -0000 1.43
@@ -512,14 +512,6 @@
{
ILJitValue thread = _ILJitCoderGetThread(jitCoder);
- #ifndef IL_CONFIG_REDUCE_CODE
- /* Emit the code to increase the call count of the method if
profiling is enabled. */
- if(jitCoder->flags & IL_CODER_FLAG_METHOD_PROFILE)
- {
- _ILJitProfileIncreaseMethodCallCount(jitCoder,
methodInfo);
- }
- #endif
-
/* Call the engine function directly with the supplied args. */
/* Queue the cctor to run. */
ILCCtorMgr_OnCallMethod(&(jitCoder->cctorMgr), methodInfo);
@@ -538,7 +530,7 @@
0,
&callSignature);
#endif
- returnValue = _ILJitCallInternal(jitCoder->jitFunction, thread,
+ returnValue = _ILJitCallInternal(jitCoder, thread,
methodInfo,
fnInfo.func, methodName,
jitParams,
@@ -595,13 +587,6 @@
ILPInvoke *pinv = ILPInvokeFind(methodInfo);
if(pinv &&
((ILJitMethodInfo*)(methodInfo->userData))->fnInfo.func)
{
- #ifndef IL_CONFIG_REDUCE_CODE
- /* Emit the code to increase the call count of the
method if profiling is enabled. */
- if(jitCoder->flags & IL_CODER_FLAG_METHOD_PROFILE)
- {
- _ILJitProfileIncreaseMethodCallCount(jitCoder,
methodInfo);
- }
- #endif
returnValue = _ILJitInlinePinvoke(jitCoder, methodInfo,
jitParams);
}
else
@@ -858,7 +843,7 @@
0,
&callSignature);
#endif
- returnValue = _ILJitCallInternal(jitCoder->jitFunction,
thread,
+ returnValue = _ILJitCallInternal(jitCoder, thread,
methodInfo,
fnInfo.func, methodName,
jitParams,
@@ -876,7 +861,7 @@
1,
&callSignature);
- returnValue = _ILJitCallInternal(jitCoder->jitFunction,
thread,
+ returnValue = _ILJitCallInternal(jitCoder, thread,
methodInfo,
fnInfo.func, methodName,
jitParams, argCount + 1);
Index: engine/jitc_pinvoke.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/jitc_pinvoke.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- engine/jitc_pinvoke.c 6 Jan 2008 21:40:06 -0000 1.9
+++ engine/jitc_pinvoke.c 24 Aug 2008 17:45:31 -0000 1.10
@@ -112,6 +112,17 @@
/* Setup the needed stuff in the jitCoder. */
jitCoder->jitFunction = func;
+#ifndef IL_JIT_THREAD_IN_SIGNATURE
+ /* Reset the cached thread. */
+ jitCoder->thread = 0;
+#endif
+
+#ifdef ENHANCED_PROFILER
+ /* Reset the timestamps */
+ jitCoder->profileTimestamp = 0;
+ jitCoder->inlineTimestamp = 0;
+#endif /* ENHANCED_PROFILER */
+
/* Check if the method to invoke was found on this system. */
if(_ILJitPinvokeError(jitMethodInfo->fnInfo))
{
@@ -470,6 +481,18 @@
ILJitType jitParamTypes[numParams + 1];
ILJitValue jitParams[numParams + 1];
ILUInt32 param = 0;
+
+#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
+ /*
+ * Emit the code to start profiling of the method if profiling
+ * is enabled
+ */
+ if(jitCoder->flags & IL_CODER_FLAG_METHOD_PROFILE)
+ {
+ _ILJitProfileStart(jitCoder, method);
+ }
+#endif /* !IL_CONFIG_REDUCE_CODE && !IL_WITHOUT_TOOLS */
+
#ifdef IL_JIT_THREAD_IN_SIGNATURE
for(current = 1; current < numParams; ++current)
#else
@@ -501,7 +524,7 @@
else if(ILTypeIsStringClass(valueType))
{
ILJitValue args[2];
- args[0] = _ILJitFunctionGetThread(func);
+ args[0] = _ILJitCoderGetThread(jitCoder);
args[1] = tempParams[current];
switch(marshalType)
{
@@ -682,6 +705,16 @@
}
++param;
}
+#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
+ /*
+ * Emit the code to start profiling of the method if profiling
+ * is enabled
+ */
+ if(jitCoder->flags & IL_CODER_FLAG_METHOD_PROFILE)
+ {
+ _ILJitProfileEnd(jitCoder, method);
+ }
+#endif /* !IL_CONFIG_REDUCE_CODE && !IL_WITHOUT_TOOLS */
#endif
if(returnType==jit_type_void)return 0;
else return(returnValue);
Index: engine/jitc_profile.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/jitc_profile.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- engine/jitc_profile.c 1 Oct 2006 17:11:24 -0000 1.1
+++ engine/jitc_profile.c 24 Aug 2008 17:45:32 -0000 1.2
@@ -18,6 +18,52 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifdef IL_JITC_CODER_INSTANCE
+
+#ifndef IL_CONFIG_REDUCE_CODE
+#ifdef ENHANCED_PROFILER
+ /* profile timestamp for the current function */
+ ILJitValue profileTimestamp;
+
+ /* profile timestamp for inlined functions */
+ ILJitValue inlineTimestamp;
+#endif /* ENHANCED_PROFILER */
+#endif /* !IL_CONFIG_REDUCE_CODE */
+
+#endif /* IL_JITC_CODER_INSTANCE */
+
+#ifdef IL_JITC_CODER_INIT
+
+#ifndef IL_CONFIG_REDUCE_CODE
+#ifdef ENHANCED_PROFILER
+ /* initialize the timestamps */
+ coder->profileTimestamp = 0;
+ coder->inlineTimestamp = 0;
+#endif /* ENHANCED_PROFILER */
+#endif /* !IL_CONFIG_REDUCE_CODE */
+
+#endif /* IL_JITC_CODER_INIT */
+
+#ifdef IL_JITC_DECLARATIONS
+
+#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
+/*
+ * Emit the code for start profiling an internal call or inlined method.
+ */
+static void _ILJitProfileStart(ILJITCoder *jitCoder, ILMethod *method);
+
+/*
+ * Emit the code for end profiling an internal call or inlined method.
+ */
+static void _ILJitProfileEnd(ILJITCoder *jitCoder, ILMethod *method);
+#endif /* !IL_CONFIG_REDUCE_CODE && !IL_WITHOUT_TOOLS */
+
+#endif /* IL_JITC_DECLARATIONS */
+
+#ifdef IL_JITC_FUNCTIONS
+
+#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
+#ifndef ENHANCED_PROFILER
/*
* Emit the code to increase the call count of a method.
*/
@@ -26,28 +72,193 @@
ILJitValue callCounter =
jit_value_create_nint_constant(jitCoder->jitFunction,
_IL_JIT_TYPE_VPTR,
(jit_nint)(&(method->count)));
+
+ jit_insn_call_native(jitCoder->jitFunction,
+ "ILInterlockedIncrement",
+ ILInterlockedIncrement,
+
_ILJitSignature_ILInterlockedIncrement,
+ &callCounter, 1,
JIT_CALL_NOTHROW);
+}
+#endif /* !ENHANCED_PROFILER */
+
+/*
+ * Emit the code for start profiling an internal call or inlined method.
+ */
+static void _ILJitProfileStart(ILJITCoder *jitCoder, ILMethod *method)
+{
#ifdef ENHANCED_PROFILER
- /* If the enhanced profiler is selected then don't count when
- * profiling is disabled
- * (e.g. via DotGNU.Misc.Profiling.StopProfiling())
+ ILJitValue timestampAddress;
+
+ if(!jitCoder->inlineTimestamp)
+ {
+ if(!(jitCoder->inlineTimestamp =
jit_value_create(jitCoder->jitFunction,
+
_ILJitTypeCurrTime)))
+ {
+ return;
+ }
+ }
+ if(!(timestampAddress = jit_insn_address_of(jitCoder->jitFunction,
+
jitCoder->inlineTimestamp)))
+ {
+ return;
+ }
+ jit_insn_call_native(jitCoder->jitFunction, "_ILProfilingStart",
+ _ILProfilingStart,
_ILJitSignature_ILProfilingStart,
+ ×tampAddress, 1,
JIT_CALL_NOTHROW);
+#else /* !ENHANCED_PROFILER */
+ if(method)
+ {
+ /* Emit the code to increase the call count of the method*/
+ _ILJitProfileIncreaseMethodCallCount(jitCoder, method);
+ }
+#endif /* !ENHANCED_PROFILER */
+}
+
+/*
+ * Emit the code for end profiling an internal call or inlined method.
*/
- jit_label_t label = jit_label_undefined;
+static void _ILJitProfileEnd(ILJITCoder *jitCoder, ILMethod *method)
+{
+#ifdef ENHANCED_PROFILER
ILJitValue thread = _ILJitCoderGetThread(jitCoder);
- ILJitValue profilingEnabled =
jit_insn_load_relative(jitCoder->jitFunction,
+ jit_label_t label = jit_label_undefined;
+ ILJitValue profilingEnabled;
+ ILJitValue args[2];
+
+ if(!jitCoder->inlineTimestamp)
+ {
+ return;
+ }
+
+ /*
+ * If the enhanced profiler is selected then don't count if profiling
+ * is disabled (e.g. via DotGNU.Misc.Profiling.StopProfiling())
+ */
+ profilingEnabled = jit_insn_load_relative(jitCoder->jitFunction,
thread,
offsetof(ILExecThread, profilingEnabled),
jit_type_sys_int);
jit_insn_branch_if_not(jitCoder->jitFunction, profilingEnabled, &label);
-#endif
+ if(!(args[0] = jit_value_create_nint_constant(jitCoder->jitFunction,
+
_IL_JIT_TYPE_VPTR,
+
(jit_nint)method)))
+ {
+ return;
+ }
+ if(!(args[1] = jit_insn_address_of(jitCoder->jitFunction,
+
jitCoder->inlineTimestamp)))
+ {
+ return;
+ }
+ jit_insn_call_native(jitCoder->jitFunction, "_ILProfilingEnd",
+ _ILProfilingEnd,
_ILJitSignature_ILProfilingEnd,
+ args, 2, JIT_CALL_NOTHROW);
+ jit_insn_label(jitCoder->jitFunction, &label);
+#endif /* ENHANCED_PROFILER */
+}
+#endif /* !IL_CONFIG_REDUCE_CODE && !IL_WITHOUT_TOOLS */
+
+#endif /* IL_JITC_FUNCTIONS */
+
+#ifdef IL_JITC_CODE
+
+/*
+ * Start profiling of the current method.
+ */
+static void JITCoder_ProfilingStart(ILCoder *coder)
+{
+#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
+ ILJITCoder *jitCoder = ((ILJITCoder *)coder);
- jit_insn_call_native(jitCoder->jitFunction,
- "ILInterlockedIncrement",
- ILInterlockedIncrement,
-
_ILJitSignature_ILInterlockedIncrement,
- &callCounter, 1,
JIT_CALL_NOTHROW);
#ifdef ENHANCED_PROFILER
+ jit_label_t startLabel = jit_label_undefined;
+ jit_label_t endLabel = jit_label_undefined;
+ ILJitValue timestampAddress;
+
+ if(!jitCoder->profileTimestamp)
+ {
+ if(!(jitCoder->profileTimestamp =
jit_value_create(jitCoder->jitFunction,
+
_ILJitTypeCurrTime)))
+ {
+ return;
+ }
+ }
+ jit_insn_label(jitCoder->jitFunction, &startLabel);
+ if(!(timestampAddress = jit_insn_address_of(jitCoder->jitFunction,
+
jitCoder->profileTimestamp)))
+ {
+ return;
+ }
+ jit_insn_call_native(jitCoder->jitFunction, "_ILProfilingStart",
+ _ILProfilingStart,
_ILJitSignature_ILProfilingStart,
+ ×tampAddress, 1,
JIT_CALL_NOTHROW);
+ jit_insn_label(jitCoder->jitFunction, &endLabel);
+ jit_insn_move_blocks_to_start(jitCoder->jitFunction, startLabel,
endLabel);
+#else /* !ENHANCED_PROFILER */
+ ILMethod *method;
+
+ method = ILCCtorMgr_GetCurrentMethod(&(jitCoder->cctorMgr));
+ if(method)
+ {
+ /* Emit the code to increase the call count of the method*/
+ _ILJitProfileIncreaseMethodCallCount(jitCoder, method);
+ }
+#endif /* !ENHANCED_PROFILER */
+#endif /* !IL_CONFIG_REDUCE_CODE && !IL_WITHOUT_TOOLS */
+}
+
+/*
+ * End profiling of the current method.
+ */
+static void JITCoder_ProfilingEnd(ILCoder *coder)
+{
+#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
+#if defined(ENHANCED_PROFILER)
+ ILJITCoder *jitCoder = ((ILJITCoder *)coder);
+ ILJitValue thread = _ILJitCoderGetThread(jitCoder);
+ jit_label_t label = jit_label_undefined;
+ ILJitValue profilingEnabled;
+ ILMethod *method;
+ ILJitValue args[2];
+
+ method = ILCCtorMgr_GetCurrentMethod(&(jitCoder->cctorMgr));
+ if(!method)
+ {
+ return;
+ }
+
+ if(!jitCoder->profileTimestamp)
+ {
+ return;
+ }
+
+ /*
+ * If the enhanced profiler is selected then don't count if profiling
+ * is disabled (e.g. via DotGNU.Misc.Profiling.StopProfiling())
+ */
+ profilingEnabled = jit_insn_load_relative(jitCoder->jitFunction,
+
thread,
+
offsetof(ILExecThread, profilingEnabled),
+
jit_type_sys_int);
+ jit_insn_branch_if_not(jitCoder->jitFunction, profilingEnabled, &label);
+ if(!(args[0] = jit_value_create_nint_constant(jitCoder->jitFunction,
+
_IL_JIT_TYPE_VPTR,
+
(jit_nint)method)))
+ {
+ return;
+ }
+ if(!(args[1] = jit_insn_address_of(jitCoder->jitFunction,
+
jitCoder->profileTimestamp)))
+ {
+ return;
+ }
+ jit_insn_call_native(jitCoder->jitFunction, "_ILProfilingEnd",
+ _ILProfilingEnd,
_ILJitSignature_ILProfilingEnd,
+ args, 2, JIT_CALL_NOTHROW);
jit_insn_label(jitCoder->jitFunction, &label);
-#endif
+#endif /* !ENHANCED_PROFILER */
+#endif /* !IL_CONFIG_REDUCE_CODE && !IL_WITHOUT_TOOLS */
}
+#endif /* IL_JITC_CODE */
Index: engine/jitc_setup.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/jitc_setup.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- engine/jitc_setup.c 21 Apr 2008 19:05:56 -0000 1.28
+++ engine/jitc_setup.c 24 Aug 2008 17:45:32 -0000 1.29
@@ -62,14 +62,6 @@
}
#endif
-#ifndef IL_CONFIG_REDUCE_CODE
- /* Emit the code to increase the call count of the method if profiling
is enabled. */
- if(coder->flags & IL_CODER_FLAG_METHOD_PROFILE)
- {
- _ILJitProfileIncreaseMethodCallCount(coder, method);
- }
-#endif
-
#ifdef IL_DEBUGGER
/* Check if this method can be debugged */
debugger = ILDebuggerFromProcess(coder->process);
@@ -108,6 +100,12 @@
coder->thread = 0;
#endif
+#ifdef ENHANCED_PROFILER
+ /* Reset the timestamps */
+ coder->profileTimestamp = 0;
+ coder->inlineTimestamp = 0;
+#endif /* ENHANCED_PROFILER */
+
/* Ensure that the evaluation stack can hold at least the methods
maxStack */
/* items. */
/* We need two additional slots for the ValueCtorArgs. */
Index: engine/lib_profiling.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/lib_profiling.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- engine/lib_profiling.c 23 Apr 2005 10:38:16 -0000 1.2
+++ engine/lib_profiling.c 24 Aug 2008 17:45:32 -0000 1.3
@@ -18,10 +18,13 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "engine.h"
+#include "engine_private.h"
#include "lib_defs.h"
#include "il_utils.h"
#include "il_sysio.h"
+#ifndef IL_WITHOUT_TOOLS
+#include "il_dumpasm.h"
+#endif
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
@@ -36,6 +39,123 @@
extern "C" {
#endif
+#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
+
+/*
+ * Dump the profiling information for the given methods.
+ * A NULL method marks the end of the list.
+ * Returns 1 if profiling information was dumped otherwise 0.
+ */
+int _ILProfilingDump(FILE *stream, ILMethod **methods)
+{
+ ILMethod *method;
+ ILMethod **temp;
+ int haveCounts = 0;
+
+ if(!methods)
+ {
+ return 0;
+ }
+
+ /* Sort the method list into decreasing order of count */
+ if(methods[0] != 0 && methods[1] != 0)
+ {
+ ILMethod **outer;
+ ILMethod **inner;
+ for(outer = methods; outer[1] != 0; ++outer)
+ {
+ for(inner = outer + 1; inner[0] != 0; ++inner)
+ {
+ if(outer[0]->count < inner[0]->count)
+ {
+ method = outer[0];
+ outer[0] = inner[0];
+ inner[0] = method;
+ }
+ }
+ }
+ }
+
+ /* Print the method information */
+ temp = methods;
+#ifdef ENHANCED_PROFILER
+ printf ("Count Total time Average time Method\n");
+#else
+ printf ("Count Method\n");
+#endif
+ while((method = *temp++) != 0)
+ {
+ if(!(method->count))
+ {
+ continue;
+ }
+#ifdef ENHANCED_PROFILER
+ printf("%-11lu%-11lu%-13lu", (unsigned long)(method->count),
+ (unsigned long)(method->time), (unsigned
long)(method->time) / (unsigned long)(method->count));
+#else
+ printf("%-11lu", (unsigned long)(method->count));
+#endif
+ ILDumpMethodType(stdout, ILProgramItem_Image(method),
+ ILMethod_Signature(method), 0,
+ ILMethod_Owner(method),
ILMethod_Name(method), 0);
+ putc('\n', stdout);
+ haveCounts = 1;
+ }
+
+ return haveCounts;
+}
+
+#ifdef ENHANCED_PROFILER
+/*
+ * Get the start profiling timestamp.
+ */
+void _ILProfilingStart(ILCurrTime *timestamp)
+{
+ ILGetSinceRebootTime(timestamp);
+}
+
+/*
+ * End profiling for the method given and add the difference between the
+ * timestamp given and the current time to the total execution time of
+ * the method.
+ * Increase the execution counter here too so that the number of executions
+ * and spent time in the method matches.
+ */
+void _ILProfilingEnd(ILMethod *method, ILCurrTime *startTimestamp)
+{
+ ILCurrTime timestamp;
+ ILInt64 seconds;
+ ILUInt32 nanoSeconds;
+ ILUInt32 timeDiff;
+
+ if(!method || !startTimestamp)
+ {
+ return;
+ }
+
+ ILGetSinceRebootTime(×tamp);
+
+ if(timestamp.nsecs < startTimestamp->nsecs)
+ {
+ seconds = timestamp.secs - startTimestamp->secs - 1;
+ nanoSeconds = (timestamp.nsecs + 1000000000) -
startTimestamp->nsecs;
+ }
+ else
+ {
+ seconds = timestamp.secs - startTimestamp->secs;
+ nanoSeconds = timestamp.nsecs - startTimestamp->nsecs;
+ }
+
+ /* calculate the timedifference in microseconds */
+ timeDiff = (seconds * 1000000) + (nanoSeconds / 1000);
+
+ method->time += timeDiff;
+ ++method->count;
+}
+#endif /* ENHANCED_PROFILER */
+
+#endif /* !IL_CONFIG_REDUCE_CODE && !IL_WITHOUT_TOOLS */
+
/*
* public static void StartProfiling();
*/
Index: engine/null_coder.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/null_coder.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -b -r1.32 -r1.33
--- engine/null_coder.c 21 Aug 2008 12:20:39 -0000 1.32
+++ engine/null_coder.c 24 Aug 2008 17:45:32 -0000 1.33
@@ -440,7 +440,20 @@
{
return 0;
}
-
+static void Coder_ProfileStart(ILCoder *coder)
+{
+}
+static void Coder_ProfileEnd(ILCoder *coder)
+{
+}
+static void Coder_SetOptimizationLevel(ILCoder *coder,
+
ILUInt32 optimizationLevel)
+{
+}
+static ILUInt32 Coder_GetOptimizationLevel(ILCoder *coder)
+{
+ return 0;
+}
/*
* Null coder class and instance.
*/
@@ -556,6 +569,10 @@
Coder_RunCCtors,
Coder_RunCCtor,
Coder_HandleLockedMethod,
+ Coder_ProfileStart,
+ Coder_ProfileEnd,
+ Coder_SetOptimizationLevel,
+ Coder_GetOptimizationLevel,
"sentinel"
};
ILCoder _ILNullCoder = {&_ILNullCoderClass};
Index: engine/verify.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/verify.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -b -r1.54 -r1.55
--- engine/verify.c 21 Aug 2008 12:20:40 -0000 1.54
+++ engine/verify.c 24 Aug 2008 17:45:32 -0000 1.55
@@ -670,6 +670,7 @@
unsigned int tryInlineOpcode;
unsigned char *tryInlinePc;
ILType *constraintType;
+ ILUInt32 optimizationLevel;
#ifdef IL_CONFIG_DEBUG_LINES
int haveDebug = ILDebugPresent(ILProgramItem_Image(method));
#else
@@ -698,6 +699,7 @@
}
coderFlags = ILCoderGetFlags(coder);
+ optimizationLevel = ILCoderGetOptimizationLevel(coder);
isStatic = ILMethod_IsStatic(method);
isSynchronized = ILMethod_IsSynchronized(method);
@@ -720,6 +722,11 @@
VERIFY_MEMORY_ERROR();
}
+ if((coderFlags & IL_CODER_FLAG_METHOD_PROFILE) != 0)
+ {
+ ILCoderProfileStart(coder);
+ }
+
/* Allocate the jump target mask */
jumpMask = (unsigned long *)TempAllocate
(&allocator,
BYTES_FOR_MASK(code->codeLen));
@@ -1166,7 +1173,7 @@
/* Output the exception handler table, if necessary */
if(exceptions != 0 || isSynchronized)
{
- OutputExceptionTable(coder, method, exceptions, hasRethrow);
+ OutputExceptionTable(coder, method, exceptions, hasRethrow,
coderFlags);
}
/* Finish processing using the coder */
Index: engine/verify_call.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/verify_call.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -b -r1.60 -r1.61
--- engine/verify_call.c 21 Aug 2008 12:20:40 -0000 1.60
+++ engine/verify_call.c 24 Aug 2008 17:45:33 -0000 1.61
@@ -1671,9 +1671,7 @@
callNonvirtualFromVirtual:
- if((coderFlags & (IL_CODER_FLAG_IR_DUMP
- |
IL_CODER_FLAG_METHOD_PROFILE
- |
IL_CODER_FLAG_METHOD_TRACE)) == 0)
+ if(optimizationLevel > 0)
{
ILInt32 elementSize = 0;
@@ -2252,6 +2250,12 @@
ILCoderCallInlineable(coder,
IL_INLINEMETHOD_MONITOR_EXIT, 0, 0);
}
+ /* Notify the coder to emit profiling for method end */
+ if((coderFlags & IL_CODER_FLAG_METHOD_PROFILE) != 0)
+ {
+ ILCoderProfileEnd(coder);
+ }
+
/* Notify the coder of the return instruction */
ILCoderReturnInsn(coder, stack[stackSize - 1].engineType,
returnType);
@@ -2266,6 +2270,12 @@
ILCoderCallInlineable(coder,
IL_INLINEMETHOD_MONITOR_EXIT, 0, 0);
}
+ /* Notify the coder to emit profiling for method end */
+ if((coderFlags & IL_CODER_FLAG_METHOD_PROFILE) != 0)
+ {
+ ILCoderProfileEnd(coder);
+ }
+
/* Notify the coder of a non-value return instruction */
ILCoderReturnInsn(coder, ILEngineType_Invalid, ILType_Void);
}
Index: engine/verify_except.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/verify_except.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- engine/verify_except.c 21 Aug 2008 12:20:41 -0000 1.16
+++ engine/verify_except.c 24 Aug 2008 17:45:33 -0000 1.17
@@ -30,7 +30,8 @@
* attempt to match the exception against the rules.
*/
static void OutputExceptionTable(ILCoder *coder, ILMethod *method,
- ILException
*exceptions, int hasRethrow)
+ ILException
*exceptions, int hasRethrow,
+ int coderFlags)
{
ILUInt32 offset;
ILUInt32 end;
@@ -127,6 +128,12 @@
ILCoderCallInlineable(coder, IL_INLINEMETHOD_MONITOR_EXIT, 0,
0);
}
+ /* Notify the coder to emit profiling for method end */
+ if((coderFlags & IL_CODER_FLAG_METHOD_PROFILE) != 0)
+ {
+ ILCoderProfileEnd(coder);
+ }
+
ILCoderThrow(coder, 0);
ILCoderTryHandlerEnd(coder);
}
@@ -241,6 +248,12 @@
ILCoderCallInlineable(coder,
IL_INLINEMETHOD_MONITOR_EXIT, 0, 0);
}
+ /* Notify the coder to emit profiling for method end */
+ if((coderFlags & IL_CODER_FLAG_METHOD_PROFILE) != 0)
+ {
+ ILCoderProfileEnd(coder);
+ }
+
ILCoderThrow(coder, 0);
}
stackSize = 0;
Index: include/il_coder.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/include/il_coder.h,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -b -r1.58 -r1.59
--- include/il_coder.h 21 Aug 2008 12:20:41 -0000 1.58
+++ include/il_coder.h 24 Aug 2008 17:45:33 -0000 1.59
@@ -161,11 +161,11 @@
/*
* Profiling flags
*/
-
#define IL_CODER_FLAG_IR_DUMP 1
-#define IL_CODER_FLAG_METHOD_PROFILE 2
-#define IL_CODER_FLAG_METHOD_TRACE 4
-#define IL_CODER_FLAG_STATS 8
+#define IL_CODER_FLAG_METHOD_PROFILE 2 /* emit profiling code */
+#define IL_CODER_FLAG_METHOD_TRACE 4 /* emit trace code */
+#define IL_CODER_FLAG_STATS 8 /* print code
generation informaton */
+
/*
* Coder class definition.
*/
@@ -857,6 +857,26 @@
void *(*handleLockedMethod)(ILCoder *coder, ILMethod *method);
/*
+ * Start profiling of the current method.
+ */
+ void (*profileStart)(ILCoder *coder);
+
+ /*
+ * End profiling of the current method.
+ */
+ void (*profileEnd)(ILCoder *coder);
+
+ /*
+ * Set the optimization level to be used by the coder.
+ */
+ void (*setOptimizationLevel)(ILCoder *coder, ILUInt32
optimizationLevel);
+
+ /*
+ * Get the optimization level to be used by the coder.
+ */
+ ILUInt32 (*getOptimizationLevel)(ILCoder *coder);
+
+ /*
* Sentinel string to catch missing methods in class tables.
*/
const char *sentinel;
@@ -1150,6 +1170,14 @@
((*((coder)->classInfo->runCCtor))((coder),
(classInfo)))
#define ILCoderHandleLockedMethod(coder,method) \
(*((coder)->classInfo->handleLockedMethod))((coder),
(method))
+#define ILCoderProfileStart(coder) \
+ (*((coder)->classInfo->profileStart))((coder))
+#define ILCoderProfileEnd(coder) \
+ (*((coder)->classInfo->profileEnd))((coder))
+#define ILCoderSetOptimizationLevel(coder, optimizationLevel) \
+ (*((coder)->classInfo->setOptimizationLevel))((coder),
(optimizationLevel))
+#define ILCoderGetOptimizationLevel(coder) \
+ (*((coder)->classInfo->getOptimizationLevel))((coder))
#ifdef __cplusplus
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [dotgnu-pnet-commits] pnet ChangeLog engine/cvmc.c engine/engine.h en...,
Klaus Treichel <=