.NETプログラム (のランタイムを実装する) 入門なのです

1fe26e11357f3ba7250b6668ca61309f?s=47 Mayuki Sawatari
September 16, 2015

.NETプログラム (のランタイムを実装する) 入門なのです

1fe26e11357f3ba7250b6668ca61309f?s=128

Mayuki Sawatari

September 16, 2015
Tweet

Transcript

  1. None
  2. http://github.com/mayuki

  3. None
  4. MSIL Java MSIL https://github.com/ojanacek/MsilInterpreter https://github.com/kazuk/SimpleILer

  5. CLR …

  6. None
  7. http://github.com/mayuki/Inazuma FizzBuzz

  8. None
  9. CLR “Lightning”

  10. None
  11. CoreCLR MSIL

  12. None
  13. .NET …

  14. MSIL MethodInfo Mono.Cecil http://github.com/dotnet/corefx

  15. Reference Definition … Reference Resolve Definition

  16. None
  17. None
  18. EEClass MethodTable MethodDesc, FieldDesc

  19. MethodTable MethodTable NumVirtuals EEClass EEClass ParentMethodTable Interfaces MethodSlots StaticFields MethodSlots

    Slot MethodDesc 0 MethodA(0x1) 1 MethodB(0x2) 2 MethodA(0x1) 3 MethodB(0x2) 4 MethodC(0x2)
  20. System.Object Slot MethodDesc 0 ToString (virtual) 1 Equals (virtual) 2

    GetHashCode (virtual) A Slot MethodDesc 0 A.ToString (override) 1 Equals 2 GetHashCode 3 VirtualMethod (virtual) B Slot MethodDesc 0 A.ToString 1 Equals 2 GetHashCode 3 B.VirtualMethod (override) 4 B.VirtualMethod2
  21. CLR ? 0:006> !name2ee *!ConsoleApplication3.B Module: 73281000 Assembly: mscorlib.dll --------------------------------------

    Module: 02dd3fbc Assembly: ConsoleApplication3.exe Token: 02000004 MethodTable: 02dd4dcc EEClass: 02dd1858 Name: ConsoleApplication3.B 0:006> !dumpmt -md 02dd4dcc EEClass: 02dd1858 Module: 02dd3fbc Name: ConsoleApplication3.B mdToken: 02000004 File: C:\Users\Tomoyo\Documents\visual studio 2015\Projects\ConsoleApplication3\ConsoleApplication3\bin\Debug\ConsoleApplication3.exe BaseSize: 0xc ComponentSize: 0x0 Slots in VTable: 7 Number of IFaces in IFaceMap: 0 -------------------------------------- MethodDesc Table Entry MethodDe JIT Name 02e20055 02dd4d44 NONE ConsoleApplication3.A.ToString() 735f5600 7328835c PreJIT System.Object.Equals(System.Object) 735c19b0 7328837c PreJIT System.Object.GetHashCode() 735c16e8 73288390 PreJIT System.Object.Finalize() 02e20075 02dd4db4 NONE ConsoleApplication3.B.VirtualMethod() 02e20079 02dd4dbc NONE ConsoleApplication3.B.VirtualMethod2() 02e204a8 02dd4dc4 JIT ConsoleApplication3.B..ctor() 0:006> !name2ee *!ConsoleApplication3.A Module: 73281000 Assembly: mscorlib.dll -------------------------------------- Module: 02dd3fbc Assembly: ConsoleApplication3.exe Token: 02000003 MethodTable: 02dd4d5c EEClass: 02dd1804 Name: ConsoleApplication3.A 0:006> !dumpmt -md 02dd4d5c EEClass: 02dd1804 Module: 02dd3fbc Name: ConsoleApplication3.A mdToken: 02000003 File: C:\Users\Tomoyo\Documents\visual studio 2015\Projects\ConsoleApplication3\ConsoleApplication3\bin\Debug\ConsoleApplication3.exe BaseSize: 0xc ComponentSize: 0x0 Slots in VTable: 6 Number of IFaces in IFaceMap: 0 -------------------------------------- MethodDesc Table Entry MethodDe JIT Name 02e20055 02dd4d44 NONE ConsoleApplication3.A.ToString() 735f5600 7328835c PreJIT System.Object.Equals(System.Object) 735c19b0 7328837c PreJIT System.Object.GetHashCode() 735c16e8 73288390 PreJIT System.Object.Finalize() 02e20059 02dd4d4c NONE ConsoleApplication3.A.VirtualMethod() 02e204e0 02dd4d54 JIT ConsoleApplication3.A..ctor()
  22. Inazuma MethodTable

  23. MethodTable MethodTable Slot MethodDesc 0 MethodA(0x1) 1 MethodB(0x2) 2 MethodA(0x1)

    3 MethodB(0x2) 4 MethodC(0x2) interface IA { void MethodA(); void MethodB(); } interface IB { void MethodA(); void MethodB(); } class C : IA, IB { public void MethodA() { } public void MethodB() { } public void MethodC() { } } InterfaceVTableMap Interface MTSlot IA 0 IB 2
  24. None
  25. IL opcode MSIL https://msdn.microsoft.com/ja-jp/library/System.Reflection.Emit.OpCodes.aspx

  26. MethodDefinition IL ( )

  27. None
  28. None
  29. mscorlib CoreCLR mscorlib mscorlib /nostdlib

  30. None
  31. opcode MethodTable

  32. Garbage Collection

  33. None
  34. None
  35. Book of the Runtime ( BotR) https://github.com/dotnet/coreclr/tree/master/Documentation#book-of-the-runtime SOS & WinDbg

    & ildasm The Root of .NET Framework OpCodes https://msdn.microsoft.com/ja-jp/library/System.Reflection.Emit.OpCodes.aspx
  36. C# .NET JIT and Run: .NET Framework : CLR https://msdn.microsoft.com/ja-jp/magazine/ee216336.aspx

  37. None
  38. IL CLR feature

  39. CoreCLR https://github.com/dotnet/coreclr/blob/master/Documentation/building/windows-instructions.md git clone coreclr Install Visual Studio 2015 Install

    CMake
  40. Developer Command Prompt for VS2015 bin\Product\Windows_NT.x64.Debug CoreCLR

  41. Interpreter CMakeLists.txt Coreclr/bin ( ) Build

  42. bin\tests\obj\Windows_NT.x64.Debug\CoreCLR.sln VS Cee_wks Warning treats as error fprintf warning CoreCLR

    CoreRun
  43. CoreRun.exe MyProgram.exe ( )

  44. mscorlib.dll mscorlib.dll coreclr.dll

  45. Visual Studio CoreRun Interpreter

  46. CoreCLR CoreRun CoreConsole CoreRun CoreConsole

  47. None
  48. CoreCLR .NET CLR