Skip to content

Instantly share code, notes, and snippets.

View schani's full-sized avatar
⌨️
I just sit at my computer and curse a bit.

Mark Probst schani

⌨️
I just sit at my computer and curse a bit.
View GitHub Profile
if !CROSS_COMPILING
if !HOST_WIN32
if SUPPORT_BOEHM
test_mono_linked_list_set_SOURCES = test-mono-linked-list-set.c
test_mono_linked_list_set_CFLAGS = $(SGEN_DEFINES) $(GLIB_CFLAGS)
test_mono_linked_list_set_LDADD = $(sgen_static_libraries) $(GLIB_LIBS) -lm $(LIBICONV)
if PLATFORM_DARWIN
test_mono_linked_list_set_LDFLAGS=-framework CoreFoundation -framework Foundation
endif
#include <assert.h>
#include <pthread.h>
#include <config.h>
#include <mono/metadata/metadata.h>
#include <mono/utils/mono-threads.h>
#include <mono/utils/hazard-pointer.h>
#include <mono/utils/mono-linked-list-set.h>
#include <mono/utils/atomic.h>
func iterate<S : Sequence, T where T == S.GeneratorType.Element> (seq : S, f : T -> ()) {
for x in seq {
f (x)
}
}
func toArray<S : Sequence, T where T == S.GeneratorType.Element> (seq : S) -> T[] {
var arr = T[] ()
iterate (seq, {x in arr.append (x)})
return arr

In my first post on Swift I expressed mild bewilderment at Apple's decision to make protocols generic not by giving them generic type arguments, like C# does, but via what they call "associated types". To reiterate the example, the Sequence protocol in Swift is defined as

protocol Sequence {
    typealias GeneratorType : Generator

func generate() -> GeneratorType

λ ~/Work/mono/roslyn/ master ~/Work/mono/installation/bin/xbuild Src/Compilers/CSharp/csc/csc.csproj
XBuild Engine Version 12.0
Mono, Version 3.10.1.0
Copyright (C) 2005-2013 Various Mono authors
Build started 9/26/2014 11:35:41 AM.
__________________________________________________
Project "/Users/schani/Work/mono/roslyn/Src/Compilers/CSharp/csc/csc.csproj" (default target(s)):
Target RestorePackages:
Executing: mono --runtime=v4.0.30319 ../../../.nuget/NuGet.exe install "packages.config" -source "" -RequireConsent -solutionDir "../../../"
This file has been truncated, but you can view the full file.
λ ~/Work/mono/roslyn/ master ~/Work/mono/installation/bin/xbuild Src/Compilers/CSharp/csc/csc.csproj
XBuild Engine Version 12.0
Mono, Version 3.10.1.0
Copyright (C) 2005-2013 Various Mono authors
Build started 9/29/2014 9:27:21 AM.
__________________________________________________
Project "/Users/schani/Work/mono/roslyn/Src/Compilers/CSharp/csc/csc.csproj" (default target(s)):
Target RestorePackages:
Executing: mono --runtime=v4.0.30319 ../../../.nuget/NuGet.exe install "packages.config" -source "" -RequireConsent -solutionDir "../../../"
mscorlib/InternalApis/NDP_Common/inc/PinnableBufferCache.cs:350: // Hit a ----, try again later.
mscorlib/microsoft/win32/registrykey.cs:249: // NOTE: since HKEY_PERFORMANCE_DATA is process wide, there is inherent ---- in closing
mscorlib/microsoft/win32/registrykey.cs:251: // in this situation the down level OSes are not. We have a small window of ---- between
mscorlib/system/_localdatastore.cs:139: // This is necesary to avoid resurection ----s.
mscorlib/system/_localdatastore.cs:169: // This is necesary to avoid resurection ----s.
mscorlib/system/appdomain.cs:3268: // ---- handler exceptions to allow other handlers to proceed
mscorlib/system/collections/Concurrent/ConcurrentDictionary.cs:1626: /// table as a result of ----s, the Tables instance that holds the table of buckets deemed too
mscorlib/system/collections/Concurrent/PartitionerStatic.cs:375: // elements actually got ----gined

Vlad has been working on thin locks, and hit a fundamental performance problem.

Thin Lock Overview

First a quick overview of how thin locks work: The second word in the object header, the synchronization word, is used for two purposes, namely locking and storing the object's hash code. It cannot do both, so in the case both are required for a particular object, we "inflate" that object's lock. The inflated lock structure contains the actual lock as well as the hash code. Possible values for the synchronization word are therefore:

  • NULL - no lock, no hash code
  • hash - a hash code but no lock
  • thin lock (owner, recursion count) - a lock but no hash code
  • pointer to fat lock - lock as well as hash code, or a lock that's blocked on
/Users/schani/Work/mono/mono/mono/mini/mini-arm.c:180: define 'ADD_LR_PC_4' not used
/Users/schani/Work/mono/mono/mono/metadata/verify.c:1188: define 'ADD_WARN' not used
/Users/schani/Work/mono/mono/mono/metadata/sgen-alloc.c:54: define 'ALLOC_ALIGN_BITS' not used
/Users/schani/Work/mono/mono/mono/mini/mini-arm.c:185: define 'ARM_LDR_IMM_GENERAL' not used
/Users/schani/Work/mono/mono/mono/mini/mini-arm.h:261: define 'ARM_NUM_REG_ARGS' not used
/Users/schani/Work/mono/mono/mono/mini/mini-arm.h:262: define 'ARM_NUM_REG_FPARGS' not used
/Users/schani/Work/mono/mono/mono/mini/mini-arm.c:195: define 'ARM_STR_IMM_GENERAL' not used
/Users/schani/Work/mono/mono/mono/metadata/tabledefs.h:262: define 'ASSEMBLYREF_DISABLEJITCOMPILE_OPTIMIZER_FLAG' not used
/Users/schani/Work/mono/mono/mono/metadata/tabledefs.h:261: define 'ASSEMBLYREF_ENABLEJITCOMPILE_TRACKING_FLAG' not used
/Users/schani/Work/mono/mono/mono/mini/image-writer.c:106: define 'AS_GLOBAL_PREFIX' not used
~/W/m/m/m/mini (master)$ ./mono-sgen -v --regression basic.exe
converting method System.OutOfMemoryException:.ctor (string)
Method System.OutOfMemoryException:.ctor (string) emitted at 0x100fb5b40 to 0x100fb5b85 (code length 69) [basic.exe]
converting method (wrapper runtime-invoke) <Module>:runtime_invoke_void__this___object (object,intptr,intptr,intptr)
Method (wrapper runtime-invoke) <Module>:runtime_invoke_void__this___object (object,intptr,intptr,intptr) emitted at 0x100fb5bb0 to 0x100fb5cb8 (code length 264) [basic.exe]
converting method System.SystemException:.ctor (string)
Method System.SystemException:.ctor (string) emitted at 0x100fb5cc0 to 0x100fb5d05 (code length 69) [basic.exe]
converting method System.Exception:.ctor (string)
Method System.Exception:.ctor (string) emitted at 0x100fb5d20 to 0x100fb5d90 (code length 112) [basic.exe]
converting method System.NullReferenceException:.ctor (string)