clr

Does the CLR perform “lock elision” optimization? If not why not?

梦想与她 提交于 2019-12-03 06:30:21
The JVM performs a neat trick called lock elision to avoid the cost of locking on objects that are only visible to one thread. There's a good description of the trick here: http://www.ibm.com/developerworks/java/library/j-jtp10185/ Does the .Net CLR do something similar? If not then why not? It's neat, but is it useful? I have a hard time coming up with an example where the compiler can prove that a lock is thread local. Almost all classes don't use locking by default, and when you choose one that locks, then in most cases it will be referenced from some kind of static variable foiling the

CLR class memory layout

允我心安 提交于 2019-12-03 06:06:31
What is the memory layout of a CLR class? Coming from a C++ background, the memory layout of a C++ class with virtual functions starts with a v-table pointer, and then the data members of the class follow in memory. Do CLR classes with virtual functions have a v-table pointer? Is this pointer the first field in the class memory layout? Are there any extra fields in a CLR class memory layout in addition to programmers' defined data members? And what do these extra fields represent? Jon Skeet It's implementation specific, but this article gives a description of what was present in the Microsoft

Returning table with CLR

↘锁芯ラ 提交于 2019-12-03 05:54:57
问题 I want to write an CLR procedure which takes a text and returns a table with all the words in this text. But I can't figure out how to return a table. Could you please tell me it? [Microsoft.SqlServer.Server.SqlFunction] public static WhatTypeShouldIWriteHere Function1(SqlString str) { string[] words = Regex.Split(str, @"\W+").Distinct().ToArray(); //how to return a table with one column of words? } Thank you for your help. UPDATED: I need to do it for sql-2005 回答1: You can return any list

how are C# object references represented in memory / at runtime (in the CLR)?

落花浮王杯 提交于 2019-12-03 05:53:35
I'm curious to know how C# object references are represented in memory at runtime (in the .NET CLR). Some questions that come to mind are: How much memory does an object reference occupy? Does it differ when defined in the scope of a class vs the scope of a method? Does where it live differ based on this scope (stack vs heap)? What is the actual data maintained within an object reference? Is it simply a memory address that points to the object it refers to or is there more to it? Does this differ based on whether it is defined within the scope of a class or method? Same questions as above, but

Why CLR Exception FatalExecutionEngineError happens?

落爺英雄遲暮 提交于 2019-12-03 05:49:27
We are using a struct that encapsulates numeric values and I found out when the nullable version of this struct is used in an expression, a FatalExecutionEngineError happens: Additional information: The runtime has encountered a fatal error. The address of the error was at 0x729c1e04, on thread 0x52d8. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack. I am using Visual Studio Premium 2013 Update 3 Here is the

Is Richter mistaken when describing the internals of a non-virtual method call?

前提是你 提交于 2019-12-03 05:47:44
I would write this question directly to Jeffrey Richter, but last time he didn't answer me :) so I will try to get an answer with your help here, guys :) In the book "CLR via C#", 3rd edition, on p.108, Jeffrey writes: void M3() { Employee e; e = new Manager(); year = e.GetYearsEmployed(); ... } The next line of code in M3 calls Employee’s nonvirtual instance GetYearsEmployed method. When calling a nonvirtual instance method, the JIT compiler locates the type object that corresponds to the type of the variable being used to make the call. In this case, the variable e is defined as an Employee.

The uncatchable exception, pt 2

风流意气都作罢 提交于 2019-12-03 05:38:11
Update: I've filed a bug report on Microsoft Connect: https://connect.microsoft.com/VisualStudio/feedback/details/568271/debugger-halting-on-exception-thrown-inside-methodinfo-invoke#details If you can reproduce this problem on your machine, please upvote the bug so it can be fixed! Ok I've done some testing and I've reduced the problem to something very simple: i. Create a method in a new class that throws an exception: public class Class1 { public void CallMe() { string blah = null; blah.ToLower(); } } ii. Create a MethodInfo that points to this method somewhere else: Type class1 = typeof(

hosting clr and catching threading exceptions

人盡茶涼 提交于 2019-12-03 05:35:49
I am trying to write an plugin system that can load managed plugins. The host should be able to unload the plugins if there are any exceptions. for my poc I have a sample code library in C# that throws an exception like this ... public static int StartUp(string arguments) { Console.WriteLine("Started exception thrower with args {0}", arguments); Thread workerThread = new Thread(() => { Console.WriteLine("Starting a thread, doing some important work"); Thread.Sleep(1000); throw new ApplicationException(); } ); workerThread.Start(); workerThread.Join(); Console.WriteLine("this should never print

Is there any way to change the .NET JIT compiler to favor performance over compile time?

两盒软妹~` 提交于 2019-12-03 05:32:48
I was wondering if there's any way to change the behavior of the .NET JIT compiler, by specifying a preference for more in-depth optimizations. Failing that, it would be nice if it could do some kind of profile-guided optimization, if it doesn't already. This is set when you compile your assembly. There are two types of optimizations: IL optimization JIT Native Code quality. The default setting is this /optimize- /debug- This means unoptimized IL, and optimized native code. /optimize /debug(+/full/pdbonly) This means unoptimized IL, and unoptimized native code (best debug settings). Finally,

What kind of data is stored in 'Type Object pointer' and 'Sync Block Index'?

人走茶凉 提交于 2019-12-03 05:21:41
问题 In CLR, each instance have 2 additional fields to store some data to manage object: Type Object Pointer Sync Block Index Can you explain basically what do they store inside and briefly how are they used by CLR? Thanks! 回答1: The type object pointer is a pointer to a type description of the object. This is used to find out what the actual type of an object is, for example needed to do virtual calls. The sync block index is an index into a table of synchronisation blocks. Each object can have a