1 / 48

Smaller, Faster and More Efficient Applications - a Micro Focus Developer Tells All

Smaller, Faster and More Efficient Applications - a Micro Focus Developer Tells All. Jeremy Wright, Micro Focus. Contents. Data Code Program Structure Application Structure. Data. Alignment Types typedefs and call prototypes Working-storage, local, or thread-local?. Data - alignment.

herbst
Télécharger la présentation

Smaller, Faster and More Efficient Applications - a Micro Focus Developer Tells All

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Smaller, Faster and More Efficient Applications - a Micro Focus Developer Tells All Jeremy Wright, Micro Focus

  2. Contents • Data • Code • Program Structure • Application Structure

  3. Data • Alignment • Types • typedefs and call prototypes • Working-storage, local, or thread-local?

  4. Data - alignment • Memory organized into 4 or 8 byte words • Access across word boundaries is slow • at least twice as slow, up to 50 times slower • Access across boundaries gives larger code • 9 extra instructions for 4 byte item on Itanium

  5. Data misalignment example • This comp-5 item count-a is aligned01 grp-item. 03 count-a pic x(4) comp-5. 03 ch pic x. • This comp-5 item count-b is not aligned01 grp2-item. 03 ch2 pic x. 03 count-b pic x(4) comp-5.

  6. Data misalignment - tables • The stride of a table should be a multiple of 4. Pad the table to ensureThis is misaligned01 tab1 occurs 200. 03 addr pic x(4) comp-5. 03 ref pic x(2) comp-5. 03 loc pic x comp-5.

  7. Data misalignment - tables • The stride of a table should be a multiple of 4. Pad the table to ensureThis is aligned01 tab1 occurs 200. 03 addr pic x(4) comp-5. 03 ref pic x(2) comp-5. 03 loc pic x comp-5.03 pic x.

  8. Avoiding misalignment • 01 level items are aligned on 8 byte boundary • Align subordinate data items • 1 byte items anywhere • 2 byte items on 2 byte boundary • 4 byte items on 4 byte boundary • 8 byte and longer items on 8 byte boundary • all data items - not just numeric

  9. Avoiding misalignment • Use the sync phrase and the mfsync directive • Introduced in SX 4.0 • Aligns data items correctly • Potentially changes record layout

  10. Avoiding misalignment - linkage items • call parameters should be 01 level aligned • This ensures parameters passed to subprograms are aligned • Use the NCG directive lnkalign • Allows the NCG to generate optimal code assuming best alignment • calling program MUST call using aligned parameters

  11. Types - Numeric data • Optimal is 4 byte integer comp-5 • Signed or unsigned, but try not to mix in same statement • 1, 2 or 8 byte OK if required • Advantages • Smaller faster code • Required for some APIs • Faster to generate

  12. typedef • Define record structure once • Get the alignment correct • Consistency, reliability, re-use

  13. typedef example 01 drec typedef.03 addr pic x(4) comp-5.03 ref pic x(2) comp-5.03 loc pic x comp-5.03 pic x. 01 cursor-item drec. 01 drt drec occurs 2000. 01 src-tgt. 03 src drec.03 tgt drec.

  14. typedef example contined 01 cursor-item drec. 01 drt drec occurs 2000. move 0 to addr of cursor-item move loc of drt(i) to loc of cursor-item move cursor-item to drt(i + 1)

  15. Call prototypes • Define the interface a sub program expects • Place in copy file - include in the defining sub-program, and any calling program • Define number and type of parameters, and result • Parameter type can be a typedef • Also define value vs reference, and call convention • And also define useful 78 level items • Detect run time problems at compile time

  16. Prototype - example 1 identification division. program-id. “malloc” is external. data division. 01 res pointer. linkage section. 01 amt pic x(4) comp-5. procedure division using value amt returning res. end-program “malloc”.

  17. Prototype - example 2 identification division. program-id. “printdrec” is external. environment division. special-names. call-convention 4 is void. procedure division void using reference drec. end-program “printdrec”.

  18. Where to declare • Local-storage section • Fast, stack-based, thread-safe, memory efficient • Easier to optimize • Working-storage • Fast, initialized, not thread-safe, persistent • Space allocated at program start up • Thread-local-storage section • Slower, initialized, thread-safe, persistent within thread

  19. Contents • Data • Code • Program Structure • Application Structure

  20. Arithmetic • Use operands of same type • Two operand style always efficient • add a to bdivide c into d • Compute statement without divide operation is also efficient

  21. Arithmetic - avoid these where possible • On size error • Multiple targets • Compute involving divide • split statement into a compute and a divide where possible

  22. Subscripting and Reference Modification • Subscripts and lengths should be aligned comp-5 • Keep it simple • Fixed length operation faster than a shorter variable length operation • Do not use checker directive odoslide

  23. Contents • Data • Code • Program Structure • Application Structure

  24. A structured program • Program composed of independent procedures • An initial main procedure finishing with goback • Logical separation of functionality • Use a section as a procedure • Use a paragraph as a label within a procedure

  25. Structure - how • Do: • Use sections • Perform sections • Use goback instead of exit program • Do not: • Use perform thru or perform paragraph • Use inter-section go to • Use alter, segments, OSVS or RM perform-style

  26. Structure - miscellaneous • Coding style can help prevent problems • Only use ‘.’ at end of paragraph • Use scope delimiters - end-if, end-perform • Enforce with checker directivesnoimplicitscope change-message(1227 E)

  27. In line perform • Excellent structured programming mechanism • Keep loop condition simple • Avoid go to out of loop • Code generator optimizes well structured, single exit loops • Easier to understand as well

  28. Contents • Data • Code • Program Structure • Application Structure

  29. Application Structure • Why use sub-programs • Invoking sub-programs • Building libraries and applications

  30. Why use sub-programs • Quicker to check and generate individual sub-programs • Easier to understand and maintain • Logically distinct code and data separated • Use sub-programs in multiple applications

  31. Perform vs. Call • Perform very fast • Acts locally, potentially on all data • Does not take parameters • Call is slower • Called code is external • Takes parameters • Only those parameters are affected

  32. Calls • Use NCG directive litlink • On by default when creating objects • Use call “literal”, or set proc-ptr to entry “literal” • Do not use on overflow or on exception • Use call prototypes. Always supply all the parameters • if address of linkage-parameter = NULL is inefficient

  33. Execution formats - .int to object • .int • slow, portable, dynamically loaded, not shared • .gnt • fast, dynamically loaded, not shared • object code • OS defined format, not directly executable • basis for native executable formats • more efficient than .gnt

  34. Shared object / shared library • Interchangeable terms on Unix • Not an executable, but contains executable code. Bound into address space of process at run time • shared library conventionally used for file with name libmine.so which is included on link command line • shared object conventionally used for code loaded at run time

  35. Executable • Create with cob –x • Features: • Loaded at process start - fixed memory footprint • Code shared by all instances of this executable • Executables can reference shared libraries

  36. Shared library • cob –Z • Features: • Loaded at process start - fixed memory footprint • Multiple Cobol objects (and C and C++) • All entry points visible • must be referenced when linking CSO or executable • Code shared by all instances

  37. Callable shared object ( CSO ) • Create with cob –z • Features: • Loaded at run time - variable memory footprint • Multiple Cobol, C, C++ objects linked into single CSO • Code shared by all instances • Only name of file visible as entry point before CSO is loaded. After loading, all names are visible • Can reference shared library from CSO

  38. Loading a CSO • Ensure LD_LIBRARY_PATH is set correctly • call “name” or call “name.so” • “name.so” must contain entry “name” • “name” is executed • set proc-ptr to entry “name.so” • “name.so” must contain entry “name”, or –e used when CSO built • does not execute code - just loads the CSO

  39. Self contained CSO ( scCSO ) • cob –y • Features: • Combines features of CSO and executable • Loaded by a non Cobol executable • Only one scCSO in a process at a time

  40. Loading a third party shared object • Use LD_PRELOAD environment variable • Not available on AIX • Specify it on the command line when creating a shared library of executable • Create a dummy CSO referencing the shared object in order to dynamically load it • cob –z dummy.cbl converter.so • cob –z dummy.cbl –L/usr/packages/conv -lconverter

  41. Example 1Standalone executable prog1 screen fileio

  42. Example 2Library for common code prog1 prog2 prog2b screen fileio

  43. Example 3Executable, CSOs and library menu prog1 prog2 prog2b screen fileio

  44. Example 4Non-Cobol invoking scCSO 3rd party application menu prog1 prog2 prog2b screen fileio

  45. Review of execution formats • Executable for stand alone code • scCSO for stand alone code invoked by 3rd party • Shared library for utility routines • CSO for dynamic loading

  46. noalternoseg Improves checker speed noqualproc Improves checker speed. Catches use of identical, and confusing, paragraph names noimplicitscope Enforce use of scope delimitersCatch subtle bugs early nocheck Turn off run time checking Some useful checker directives

  47. nocheck Turn off run time checking, including subscript, linkage and divide-by-0 checks lnkalign Assert that linkage items alignedGenerates faster code opt Turn on global optimisations. Generates faster code, but takes longer to generate litlink Ensure calls are linked rather than dynamically bound linkalias Specify aliasing of linkage items Some useful NCG directives

  48. Conclusions • ALIGN your data • Use typedef and call prototypes • Keep code simple • Structure your program • Structure your application

More Related