dev332.net framework: 64-bit development today and tomorrow kang su gatlin visual c++ program...
TRANSCRIPT
DEV332DEV332.NET Framework: 64-Bit .NET Framework: 64-Bit Development Today Development Today And TomorrowAnd Tomorrow
DEV332DEV332.NET Framework: 64-Bit .NET Framework: 64-Bit Development Today Development Today And TomorrowAnd TomorrowKang Su GatlinKang Su GatlinVisual C++ Program ManagerVisual C++ Program ManagerMicrosoft CorporationMicrosoft Corporation
Geralyn MillerGeralyn Miller.NET Solutions Architect.NET Solutions ArchitectMicrosoft CorporationMicrosoft Corporation
AgendaAgenda
A bit of motivation... and a state of playA bit of motivation... and a state of play
Today: 64-bit Native C++ Today: 64-bit Native C++ State of Tools, Porting Code, Problem State of Tools, Porting Code, Problem areas, Performance areas, Performance
Future: 64-bit .NET Framework and Future: 64-bit .NET Framework and versus 2005versus 2005
State of Tools, Porting Code, COM Interop, State of Tools, Porting Code, COM Interop, Language SpecificsLanguage Specifics
Why 64-Bit Architecture?Why 64-Bit Architecture?Larger Address SpaceLarger Address Space
Address SpaceAddress Space Win64Win64
Total Virtual Address SpaceTotal Virtual Address Space 16 TB16 TB
Virtual Address Space per 64bit ProcessVirtual Address Space per 64bit Process 8 TB8 TB
Virtual Address Space per 32bit ProcessVirtual Address Space per 32bit Process 4GB if compiled with 4GB if compiled with /LARGEADDRESSAWARE 2GB otherwise/LARGEADDRESSAWARE 2GB otherwise
Windows XP ProfessionalWindows XP Professional 32 GB / 1-2 cpus32 GB / 1-2 cpus
Windows Server 2003 StandardWindows Server 2003 Standard 32 GB / 1-4 cpus32 GB / 1-4 cpus
Windows Server 2003 EnterpriseWindows Server 2003 Enterprise 1 TB / 1-8 cpus1 TB / 1-8 cpus
Windows Server 2003 DataCenterWindows Server 2003 DataCenter 1 TB / 1-64 cpus1 TB / 1-64 cpus
Larger values supported by primitive types Larger values supported by primitive types 2^64 >> 2 ^322^64 >> 2 ^32
18,446,744,073,709,551,616 >> 4,294,967,29618,446,744,073,709,551,616 >> 4,294,967,296
Performance?Performance?Possibly, but code size will increasePossibly, but code size will increase
Where Are The Application Spaces?Where Are The Application Spaces?
… … with data?with data?
… … with high performance computing with high performance computing workloads?workloads?
… … with 32-bit primitive types?with 32-bit primitive types?
These are all problem spaces where These are all problem spaces where 64-bit solutions can make sense64-bit solutions can make sense
State Of PlayState Of Play
Two mainstream 64bit architectures Two mainstream 64bit architectures supported by Windowssupported by Windows
Itanium Processor FamilyItanium Processor Family
x64 – a.k.a. AMD64, EM64Tx64 – a.k.a. AMD64, EM64T
Windows versions available (Itanium) Windows versions available (Itanium) and in beta (x64) todayand in beta (x64) today
State Of Play: ItaniumState Of Play: Itanium
““in-order” processorin-order” processor
VLIWVLIW
Bundling and templatesBundling and templates
Support for predicationSupport for predication
Support for control/data Support for control/data speculationspeculation
Rotating register Rotating register support for SWPsupport for SWP
Branch predictionBranch prediction
Functional Units galoreFunctional Units galore
LOTS of registersLOTS of registers128 floating point128 floating point
128 integer128 integer
+ predicate, branch, + predicate, branch, control registers… whew!control registers… whew!
Tough on assembly Tough on assembly folksfolks
No addressing modesNo addressing modes
State Of Play: x64State Of Play: x64
Stretch x86 architectureStretch x86 architecture
Runs legacy x86 at machine speedsRuns legacy x86 at machine speeds
Increased register width of x86 Increased register width of x86 registers to 64-bitregisters to 64-bit
8 additional general purpose registers8 additional general purpose registersREX instruction prefix addresses the REX instruction prefix addresses the new registersnew registers
8 additional 128 bit XMM registers8 additional 128 bit XMM registersVC++ does not generate x87 nor VC++ does not generate x87 nor MMX codeMMX code
“OK, How Do I Get Started With 64-bit Development?”“OK, How Do I Get Started With 64-bit Development?”
Do you remember Win16 to Win32?Do you remember Win16 to Win32?32 to 64-bit much easier32 to 64-bit much easier
The memory model has stayed the sameThe memory model has stayed the samesizeof_x86(long) == sizeof_amd64(long)sizeof_x86(long) == sizeof_amd64(long)
Win64 is simply WindowsWin64 is simply WindowsEssentially simple pointer stretch Essentially simple pointer stretch of Win32 APIof Win32 API
AgendaAgenda
A bit of motivation... and a state of playA bit of motivation... and a state of play
Today: 64-bit Native C++ Today: 64-bit Native C++ State of Tools, Porting Code, Problem State of Tools, Porting Code, Problem areas, Performance areas, Performance
Future: 64-bit .NET Framework and Future: 64-bit .NET Framework and versus 2005versus 2005
State of Tools, Porting Code, COM Interop, State of Tools, Porting Code, COM Interop, Language SpecificsLanguage Specifics
WoW… It Works!WoW… It Works!Windows on Windows 64 (WOW64)Windows on Windows 64 (WOW64)
Isolates 32-bit ApplicationsIsolates 32-bit ApplicationsNotably file and registry isolationNotably file and registry isolation
ConsoleConsole
GUIGUI
ServicesServices
Separate DLLsSeparate DLLs
Performance hit?Performance hit?Substantial on ItaniumSubstantial on Itanium
Little to none on x64Little to none on x64
Wow64 Process LayoutWow64 Process Layout
64-bit ntdll.dll64-bit ntdll.dll
Wow64.dllWow64.dll Wow64win.dllWow64win.dll
Wow64cpu.dllWow64cpu.dll
Win32k.sysWin32k.sys
NT ExecutiveNT Executive
Kernel ModeKernel Mode
User ModeUser Mode
32-bit ntdll.dll32-bit ntdll.dll
32-bit modules32-bit modules
Reserved Address SpaceReserved Address Space0x00000000`7FFEFFFF or 0x00000000`7FFEFFFF or 0x00000000`FFFEFFFF0x00000000`FFFEFFFF
Current Development Modelx86-based Computer (or using WoW)x86-based Computer (or using WoW)
64-bit Computer64-bit Computer
Develop and test 32bit code Develop and test 32bit code herehere
Cross compile for 64-bitCross compile for 64-bit Send executable to 64-bit Send executable to 64-bit
computercomputer
Execute code hereExecute code here Debug remaining bugs hereDebug remaining bugs here
State Of The 64bit VC Dev State Of The 64bit VC Dev Tools World Tools World
ToolsTools ItaniumItanium AMD64/EM64TAMD64/EM64T
Current Supported Current Supported ToolsetToolset
(uses 6.0 version of (uses 6.0 version of libs)libs)
PSDK toolsetPSDK toolset
Less conformant FELess conformant FE
Cross compilerCross compiler
Only unmanaged codegenOnly unmanaged codegen
WinDbg and VS mini-WinDbg and VS mini-debugger debugger
PSDK toolset (available PSDK toolset (available only through Betaplace)only through Betaplace)
VS2005 basedVS2005 based
Cross compilerCross compiler
Only unmanaged codegenOnly unmanaged codegen
WinDbg debuggingWinDbg debugging
7.1 Libs compiler 7.1 Libs compiler [email protected]
New complier for 7.1 libsNew complier for 7.1 libs
Only unmanaged codegenOnly unmanaged codegen
7.1 libs7.1 libs
Only unmanaged codegenOnly unmanaged codegen
Whidbey Beta 1Whidbey Beta 1 Both 64bit hosted and cross compilers, VS can install on Both 64bit hosted and cross compilers, VS can install on Win64, managed codegen support, VS2005 libs for all Win64, managed codegen support, VS2005 libs for all platforms. Remote debugging.platforms. Remote debugging.
Porting Your App To 64-bitPorting Your App To 64-bit
Use compiler switch (-Wp64)Use compiler switch (-Wp64)64-bit brings differences – LLP6464-bit brings differences – LLP64T *, size_t: 64 bit T *, size_t: 64 bit int, long: built-in integers are ALL 32 bitint, long: built-in integers are ALL 32 bitlong long: 64bit alwayslong long: 64bit always
Alignment changesAlignment changesMisalignment can be fatal on ItaniumMisalignment can be fatal on Itanium
32 and 64bit code can NOT be in same process32 and 64bit code can NOT be in same process
APIAPI Data Data ModelModel intint longlong pointerpointer
Win32Win32 ILP32ILP32 3232 3232 3232
Win64Win64 LLP64LLP64 3232 3232 64
UNIXesUNIXes LP64LP64 3232 64 64
Porting Issues FromPorting Issues From32 To 64bit32 To 64bit
Profile Guided Profile Guided Optimization?Optimization?
Compiler can’t answer everything…Compiler can’t answer everything…
if(a < b) foo(); else baz();
if(a < b) foo(); else baz();
for(i = 0; i < count; ++i) bar();for(i = 0; i < count; ++i) bar();
How often is a < b?How often is a < b? What is the typical value of count?What is the typical value of count?
CompileCompile with /GL with /GLSourceSource Object filesObject files
Profile Guided OptimizationProfile Guided Optimization
InstrumentedInstrumentedImageImage
ScenariosScenarios OutputOutput Profile dataProfile data
Object filesObject files Link with /LTCG:PGILink with /LTCG:PGI InstrumentedInstrumentedImageImage
Profile dataProfile data
Object filesObject files
Link with /LTCG:PGOLink with /LTCG:PGOOptimizedOptimized
ImageImage
How Much Performance How Much Performance Does PGO Buy You?Does PGO Buy You?
Performance increase is architecture Performance increase is architecture and application specificand application specific
Itanium tends to benefit the mostItanium tends to benefit the most
Large applications tend to benefit more Large applications tend to benefit more than smallthan small
If you understand your real-world If you understand your real-world scenarios then PGO is almost always scenarios then PGO is almost always a wina win
PGO Improvement Over LTCGPGO Improvement Over LTCG
0
5
10
15
Intel Itanium2 AMD AMD64 Intel x86
% I
mp
rove
men
t O
ver
LT
CG
SPECInt SPECfp
AgendaAgenda
A bit of motivation... and a state of playA bit of motivation... and a state of play
Today: 64-bit Native C++ Today: 64-bit Native C++ State of Tools, Porting Code, Problem State of Tools, Porting Code, Problem areas, Performance areas, Performance
Future: 64-bit .NET Framework and Future: 64-bit .NET Framework and versus 2005versus 2005
State of Tools, Porting Code, COM Interop, State of Tools, Porting Code, COM Interop, Language SpecificsLanguage Specifics
Developer RoadmapDeveloper Roadmap
• Windows “Longhorn” Windows “Longhorn” integrationintegration
• New UI tools and New UI tools and designers designers
• Extensive managed Extensive managed interfaces (WinFX)interfaces (WinFX)
Visual Studio Visual Studio “Orcas”“Orcas”
Visual StudioVisual Studio.NET 2003.NET 2003
• “ “Everett Release”Everett Release”
• Windows Server 2003 Windows Server 2003 integrationintegration
• Support for .NET Support for .NET Compact Framework Compact Framework and device and device development development
• Improved performanceImproved performance
Visual Studio Visual Studio 20052005
• “ “Whidbey” releaseWhidbey” release
• SQL Server 2005 SQL Server 2005 integrationintegration
• 64 bit Framework64 bit Framework
• Improved IDE Improved IDE productivity and productivity and community supportcommunity support
• Extended support for Extended support for XML Web servicesXML Web services
• Office Office programmabilityprogrammability
Availability Of 64-bit Availability Of 64-bit .NET Framework.NET Framework
Visual Studio 2005 timeframeVisual Studio 2005 timeframe
Servers and workstationsServers and workstationsX64 and IA64 supportX64 and IA64 support
OS DependencyOS Dependency>= Windows Server 2003 SP1>= Windows Server 2003 SP1
No Windows 2000 Server 64 bit EditionNo Windows 2000 Server 64 bit Edition
Future Windows 64 bit client releasesFuture Windows 64 bit client releasesLonghorn, Windows XPLonghorn, Windows XP
64-bit .NET Framework And 64-bit .NET Framework And Tools SupportTools Support
Parity w/ 32-bit productParity w/ 32-bit productCommon Language RuntimeCommon Language Runtime.NET Framework Class Libraries .NET Framework Class Libraries (including ASP .NET, Windows Forms, (including ASP .NET, Windows Forms, ADO .NET)ADO .NET)SDK ToolsSDK Tools
Visual Studio .NET supported on Visual Studio .NET supported on WOW64WOW64New JIT, GC, exception handling, and New JIT, GC, exception handling, and debugging servicesdebugging services
Moving 32-bit Moving 32-bit .NET Framework .NET Framework applications To 64-bitapplications To 64-bit
Managed Code on 64 BitManaged Code on 64 Bit
Verifiable code just runsVerifiable code just runs32 bit Whidbey runs on WoW32 bit Whidbey runs on WoW64 bit Whidbey runs native64 bit Whidbey runs nativeAssemblies marked for ‘bitness‘ (32 bit, 64 bit, Assemblies marked for ‘bitness‘ (32 bit, 64 bit, neutral)neutral)
COM Interop, P/Invoke, Floating Point may COM Interop, P/Invoke, Floating Point may require changesrequire changesImages containing native code treated as native Images containing native code treated as native (Managed C++)(Managed C++)Nearly all cost is in test runsNearly all cost is in test runs
““The last automated test pass we did on 64 bit before the The last automated test pass we did on 64 bit before the holidays produced results similar to those on 32 bit after one holidays produced results similar to those on 32 bit after one bug in a cross domain was fixed for us. Oh the joy of being bug in a cross domain was fixed for us. Oh the joy of being fully managed! “ – Rok Yu, Jscriptfully managed! “ – Rok Yu, Jscript
Porting Cost To 64 bitPorting Cost To 64 bit
0
10
20
30
40
50
60
70
80
90
100
Pure Managed Unsafe Managed COM interop(consuming &
exposing)
P/Invoke MC++ / C++
% C
os
t R
ela
tiv
e t
o U
nm
an
ag
ed
Co
de
Writing Portable Writing Portable Managed CodeManaged Code
VerifiableVerifiableNo native code (IL only)No native code (IL only)
No pointer arithmeticNo pointer arithmetic
Follow Interop RulesFollow Interop Rules
Know Architecture DifferencesKnow Architecture Differences
Beware Floating PointBeware Floating Point
Interop RulesInterop Rules
SignaturesSignaturesDllImport, DeclareDllImport, Declare
‘‘int’ and System.IntPtrint’ and System.IntPtr
API’s must exist on all platformsAPI’s must exist on all platforms
MarshalingMarshalingStructLayoutAttributeStructLayoutAttribute
Marshal.SizeOfMarshal.SizeOf
‘‘Int’ And System.IntPtrInt’ And System.IntPtr
Int and IntPtr in import signaturesInt and IntPtr in import signatures‘‘int’ is System.Int32, 32 bit sizeint’ is System.Int32, 32 bit size
System.IntPtr is size of platform integer System.IntPtr is size of platform integer and pointer, may be 32 or 64, or ?and pointer, may be 32 or 64, or ?
‘‘Int’ And System.IntPtrInt’ And System.IntPtr
[StructLayout(LayoutKind.Sequential)][StructLayout(LayoutKind.Sequential)]internal class SECURITY_ATTRIBUTES {internal class SECURITY_ATTRIBUTES {
internal int nLength = 0;internal int nLength = 0;internal int lpSecurityDescriptor internal int lpSecurityDescriptor
= 0;= 0;internal int bInheritHandle = 0;internal int bInheritHandle = 0;
}}
‘‘Int’ And System.IntPtrInt’ And System.IntPtr
[StructLayout(LayoutKind.Sequential)][StructLayout(LayoutKind.Sequential)]internal class SECURITY_ATTRIBUTES {internal class SECURITY_ATTRIBUTES {
internal int nLength = 0;internal int nLength = 0;internal IntPtr internal IntPtr
lpSecurityDescriptor lpSecurityDescriptor = IntPtr.Zero;= IntPtr.Zero;
internal int bInheritHandle = 0;internal int bInheritHandle = 0;}}
StructLayoutAttributeStructLayoutAttribute
LayoutKind.ExplicitLayoutKind.ExplicitDetermines Managed LayoutDetermines Managed Layout
Use correct Use correct FieldOffsetFieldOffset
Use with ‘fixed’ in C#Use with ‘fixed’ in C#
LayoutKind.SequentialLayoutKind.SequentialDetermines Managed, Unmanaged LayoutDetermines Managed, Unmanaged Layout
Use correct Use correct PackingSizePackingSize
Default for VB, C#Default for VB, C#
Correct MarshalingCorrect Marshaling
Use Marshal.SizeOfUse Marshal.SizeOfStruct Marshaling SizeStruct Marshaling Size
Platform Pointer SizePlatform Pointer Size
internal class OSVERSIONINFO {internal class OSVERSIONINFO { public OSVERSIONINFO() {public OSVERSIONINFO() {
OSVersionInfoSize = OSVersionInfoSize =
(int)Marshal.SizeOf(this);(int)Marshal.SizeOf(this); }}Marshal.SizeOf(typeof(System.IntPtr))Marshal.SizeOf(typeof(System.IntPtr))
Examples:Examples:
Using COM ComponentsUsing COM Components
COM is nativeCOM is native
Neutral apps may use platform specific Neutral apps may use platform specific COM componentsCOM components
No COM interop between architecturesNo COM interop between architectures
Component may not exist on 64 bitComponent may not exist on 64 bit
May elect to run in WoW onlyMay elect to run in WoW only
Exposing To COM Exposing To COM
No interop between architecturesNo interop between architectures32 bit apps only exposed to 32 bit32 bit apps only exposed to 32 bit
May expose neutral apps on each May expose neutral apps on each architecturearchitecture
Must register for each architectureMust register for each architecture
Type Libraries are not neutralType Libraries are not neutral
Language SpecificsLanguage Specifics
Visual Basic .NETVisual Basic .NET
C#C#
Managed Extensions to C++Managed Extensions to C++
Visual BasicVisual Basic
Creates platform-neutral ILCreates platform-neutral IL
Safe, verifiableSafe, verifiable
Can ‘break’ portabilityCan ‘break’ portabilityExplicit or Sequential LayoutExplicit or Sequential Layout
Using ‘Declare’ or ‘DllImport’Using ‘Declare’ or ‘DllImport’
C#C#
Creates platform-neutral ILCreates platform-neutral IL
Mostly Safe, Verifiable Mostly Safe, Verifiable
‘‘Unsafe’ Unsafe’ allows pointer arithmeticallows pointer arithmetic
Can ‘break’ portabilityCan ‘break’ portabilityExplicit or Sequential LayoutExplicit or Sequential Layout
Using ‘DllImport’Using ‘DllImport’
Managed C++Managed C++
7.07.0Never verifiableNever verifiableContains native codeContains native code
‘‘IJW’ – doesn’t use DllImportIJW’ – doesn’t use DllImportUses native headers and librariesUses native headers and libraries
32-bit images32-bit images
7.17.1Use ‘cookbook’ Use ‘cookbook’
May create verifiable imagesMay create verifiable imagesMay be IL onlyMay be IL only
Still may use “IJW”Still may use “IJW”
WhidbeyWhidbeyCreate fully verifiable imagesCreate fully verifiable imagesGreatly improved IJWGreatly improved IJW
Closing SummaryClosing Summary
int and long are 32-bitsint and long are 32-bits
Pointers are 64-bitsPointers are 64-bits
Don’t assume data sizesDon’t assume data sizes
Align data on natural boundariesAlign data on natural boundaries
NativeNativeProfile guided optimization can greatly help Profile guided optimization can greatly help performance on IA/64performance on IA/64
ManagedManagedVerifiable code just runsVerifiable code just runs
The new power of the platform enables us to The new power of the platform enables us to do even more!do even more!
ResourcesResources
64-bit Windows Programming64-bit Windows Programming““Getting ready for 64-bit Windows”Getting ready for 64-bit Windows”
The New Data TypesThe New Data Types
““Designing 64-bit interfaces”Designing 64-bit interfaces”
““Running 32-bit applications”Running 32-bit applications” (wow64 registry redirection, debugging, performance, (wow64 registry redirection, debugging, performance, app installation)app installation)
““Migration Tips” (common compiler errors)Migration Tips” (common compiler errors)
““Introduction to Developing Applications for the Introduction to Developing Applications for the 64-bit Version of Windows”64-bit Version of Windows”
““Windows Data Alignment on IPF, x86, and x86-64”Windows Data Alignment on IPF, x86, and x86-64”
““Application Compatibility Guide”Application Compatibility Guide”
Attend a free chat or web castAttend a free chat or web casthttp://www.microsoft.com/communities/chats/default.mspxhttp://www.microsoft.com/communities/chats/default.mspx http://www.microsoft.com/usa/webcasts/default.asphttp://www.microsoft.com/usa/webcasts/default.asp
List of newsgroupsList of newsgroupshttp://communities2.microsoft.com/http://communities2.microsoft.com/communities/newsgroups/en-us/default.aspxcommunities/newsgroups/en-us/default.aspx
MS Community SitesMS Community Siteshttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx
Locate Local User GroupsLocate Local User Groupshttp://www.microsoft.com/communities/usergroups/default.mspxhttp://www.microsoft.com/communities/usergroups/default.mspx
Community sitesCommunity siteshttp://www.microsoft.com/communities/related/default.mspxhttp://www.microsoft.com/communities/related/default.mspx
Q1:Q1: Overall satisfaction with the sessionOverall satisfaction with the session
Q2:Q2: Usefulness of the informationUsefulness of the information
Q3:Q3: Presenter’s knowledge of the subjectPresenter’s knowledge of the subject
Q4:Q4: Presenter’s presentation skillsPresenter’s presentation skills
Q5:Q5: Effectiveness of the presentationEffectiveness of the presentation
Please fill out a session evaluation on CommNetPlease fill out a session evaluation on CommNet
© 2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.