473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Compiler/JIT optimization causing problems

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
Nov 16 '05 #1
1 1689
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
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nick L. | last post by:
All, This is a general question regarding how, and if, compiler optimization techniques affect the general concept of being able to update a component of an application without requiring a...
8
by: jon morgan | last post by:
OK, I'm going to be brave. There is a bug in VS.Net 1.1 that causes random compiler errors. I have raised this issue in posts at least three time in the past couple of months without attracting...
4
by: Neil | last post by:
I just resolved a strange situation I was having with an ODBC linked SQL 7 view in an Access 2000 MDB file, and I'm trying to get some understanding as to what happened. The linked view was...
14
by: joshc | last post by:
I'm writing some C to be used in an embedded environment and the code needs to be optimized. I have a question about optimizing compilers in general. I'm using GCC for the workstation and Diab...
19
by: Jerry | last post by:
I managed to narrow this down to a very simple expression. try this: private void Bug() { bool b = false; Test(3, (b || b) && b && !b); } private void Works() {
3
by: Binary | last post by:
VC++ .NET 2003: Access violation with /O2 compiler switch; no AV with /O Hi I'm in the process of narrowing down a problem, and I have reduced the code involved to the following If someone could...
5
by: wkaras | last post by:
I've compiled this code: const int x0 = 10; const int x1 = 20; const int x2 = 30; int x = { x2, x0, x1 }; struct Y {
41
by: Miroslaw Makowiecki | last post by:
Where can I download Comeau compiler as a trial version? Thanks in advice.
29
by: sammy | last post by:
Word up! If there are any gcc users here, maybe you could help me out. I have a program and I've tried compiling it with -O2 and -O3 optimization settings. The wired thing is that it actually...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.