PC Review


Reply
Thread Tools Rate Thread

Compiler/JIT optimization causing problems

 
 
Prasad Dabak
Guest
Posts: n/a
 
      7th Jan 2005
Hello,

I am facing some serious problems in my C# application probably due to
compiler/JIT optimization. Let is give an hypothetical example that
demonstrates the problem I am running into


class class1 {
public static string func(string param) {
string processedvalue;
//Process the param and return the value
...
...
...
return processedvalue;
}
}

class class2 {
static string x=class1.func("testparam");

public string func() {
return x;
}


class MainClass {
[STAThread]
static void Main(string[] args) {
class2 x=new class2();
x.func();

class2 y=new class2();
y.func();
}
}


Now, class1.func() function is getting called only once. Although it
is passed same parameter the return value of the function may differ
depending upon some external factors.

I want to ensure, that, class1.func() is always called and not
optimized at all.

Is there any way to tell compiler/JIT not to do any optmization for
call to class1.func at all. I know that removing static for varible
class2.x solves this problem. However, I don't want to do that, as,
there are too many places II would need to do that in my application.

-Prasad
 
Reply With Quote
 
 
 
 
Jon Shemitz
Guest
Posts: n/a
 
      7th Jan 2005
Prasad Dabak wrote:

> I am facing some serious problems in my C# application probably due to
> compiler/JIT optimization. Let is give an hypothetical example that
> demonstrates the problem I am running into


> class class2 {
> static string x=class1.func("testparam");


> Now, class1.func() function is getting called only once. Although it
> is passed same parameter the return value of the function may differ
> depending upon some external factors.
>
> I want to ensure, that, class1.func() is always called and not
> optimized at all.
>
> Is there any way to tell compiler/JIT not to do any optmization for
> call to class1.func at all. I know that removing static for varible
> class2.x solves this problem. However, I don't want to do that, as,
> there are too many places II would need to do that in my application.


This has nothing to do with the jitter. The compiler is doing exactly
what you told it to do; the defined semantics of an initialized static
are that it will be initialized once, before it's first read.

If you want class1.func called every time you call class2.func, you'll
have to make x an instance variable, or explicitly reset it within
every call to class2.func.

--

programmer, author http://www.midnightbeach.com
and father http://www.midnightbeach.com/hs
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiler optimization question Lloyd Dupont Microsoft Dot NET Framework 2 7th Sep 2005 12:26 AM
Negative optimization in C# compiler? Gianluca Microsoft C# .NET 7 24th May 2005 01:01 AM
Compiler optimization? Tomer Microsoft Dot NET Compact Framework 1 23rd Dec 2004 07:19 PM
JIT compiler global optimization ? =?Utf-8?B?Q2FybA==?= Microsoft Dot NET 3 24th Aug 2004 11:47 AM
Re: Compiler optimization of enum... Cody Manix Microsoft C# .NET 0 15th Jul 2003 02:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:01 PM.