none
Problem with the .NET 3.5SP1 JIT-Compiler RRS feed

  • Question

  • Hello,

    Beginning with the .NET CRL 2.0.50727.3053 (.NET 3.5 SP1) a NullReferenceException is thrown in our application (only "Release" version, not "Debug" version).
    It is a mixed managed/unmanaged C++ CLI VS2008 Project.

    The problem occurs on different Windows versions (XP,Vista, english and german versions, clean installation) as soon as 3.5SP1 was installed.

    It has shown that all 2.0 CLR versions before 3.5SP1 can run this code without an exception.

    When running with an attached VS2008 .NET Debugger (not the native debugger) the problem only occurs when
    the Debugging Option "Suppress JIT optimization on module load" is disabled(!).

    Emitting the Debuggable attribute (linker option /ASSEMBLYDEBUG) resolves the problem (by disabling the JIT-Optimizations)

    I tried the Hotfix at http://support.microsoft.com/? (updates to CLR Version 2.0.50727.3068) without any effect.

    I made a simplified test project where the problem also occurs.

    The source code is in two C++ files and two header files with this content:

    File: "ChildClass.cpp"

    #include "stdafx.h"
    #include "ParentClass.h"

    class CChildClass :public CParentClass
    {
    public:

    void ExtractCommonData( )
    {
    for(int i = 0; i <= 1; i++ )
    {
    /*************HERE is the Problem: a NullReferenceException is thrown.*****/
        
    SetInfo( 1, 0, TRUE );
    }
    }

    };

    int ExtractInt()
    {
    double value = atoi("0");
    return (int)(value);
    }

    void TestProc()
    {
    CChildClass object;
    int nDefaultID = ExtractInt();
    object.ExtractCommonData( );
    }


    int _tmain(int argc, _TCHAR* argv[])
    {
    System::Console::WriteLine(
    "Test running with CLR Version: "+System::Environment::Version->ToString());
    try
    {//TestProc must be called twice to show the error.
        
    TestProc();
        TestProc();
        System::Console::WriteLine(
    "The test worked without an error.");
    }
    catch (System::Exception^)
    {
        System::Console::ForegroundColor=System::ConsoleColor::Red;
        System::Console::WriteLine(
    "A problem occured!");
    }
    System::Console::ReadKey();
    return 0;
    }




    File: "ParentClass.h"

    #pragma once

    class
    CParentClass
    {
    public:

    void SetInfo(int nConf, int nBit, BOOL bSet);
    void setbit(unsigned char nr, BYTE *xconf);
    BYTE conf[3][3];
    };




    File: "ParentClass.cpp"

    void
    CParentClass::setbit(unsigned char nr, BYTE *xconf)
    {
        int xx;
        unsigned char kx,lx;
        kx = nr % 8; 
        lx = nr / 8; 
        xx = 0x01;
        while (kx-- > 0) xx = xx << 1;
        xconf[lx] = xconf[lx] | xx;
    }

    void CParentClass::SetInfo(int nConf, int nBit, BOOL bSet)
    {
        setbit(nBit, conf[nConf]);
    }


    File: "stdafx.h"

    #pragma once
    #ifndef
    WINVER
    #define WINVER 0x0500
    #endif

    #include <stdio.h>
    #include <tchar.h>
    #include <windows.h>



    Looking at the generated x86 assembler code it seems that the new JIT-Compiler of .NET 3.5SP1 does more inlining at the SetInfo() Method. Maybe the problem is releated with this.

    I have prepeared a VS2008 solution to demonstrate this problem. I can upload or email it if required.


    Thank you for any help,

    Marco Scholz



    Saturday, December 13, 2008 6:02 PM

Answers

  • I couldn't repro the problem with the provided code.  Exact same tools as yours.  I don't doubt there's a problem, smells like inlining (as enabled by turning the debugger option off) is causing your problem.  The generated machine code looked oddly inefficient.

    Not much we can do about JIT problems in a forum.  Post your issue, including any code that demonstrates it, at connect.microsoft.com.  If your problem is urgent, contact Microsoft CSS.
    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Friday, December 19, 2008 11:23 AM
    Saturday, December 13, 2008 7:11 PM
    Moderator

All replies

  • I couldn't repro the problem with the provided code.  Exact same tools as yours.  I don't doubt there's a problem, smells like inlining (as enabled by turning the debugger option off) is causing your problem.  The generated machine code looked oddly inefficient.

    Not much we can do about JIT problems in a forum.  Post your issue, including any code that demonstrates it, at connect.microsoft.com.  If your problem is urgent, contact Microsoft CSS.
    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Friday, December 19, 2008 11:23 AM
    Saturday, December 13, 2008 7:11 PM
    Moderator
  • Hello,

    First, thank you for your quick response!

    I made an forum entry to ensure that this is not a well known problem and I just haven't found the right hotfix or KB entry.
    I also made a Feedback at microsoft's connect webside (ID 387958).
    http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=387958

    I uploaded the sample VS2008 solution there.

    By the way, what is CSS ("Cascading Style Sheets" ??) ?


    Marco Scholz

    Sunday, December 14, 2008 11:25 AM
  • CSS = Customer Support Services
    Hans Passant.
    Sunday, December 14, 2008 1:27 PM
    Moderator