memory inspector

Upload: ramaneesh

Post on 03-Jun-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Memory Inspector

    1/40

    Memory Inspector

    Speaker: Matt Kangas

    Duration of the eBook:

    15 minutes

  • 8/12/2019 Memory Inspector

    2/40

  • 8/12/2019 Memory Inspector

    3/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 3

    Content

    Motivation

    Memory Objects

    Memory Problems

    New Memory Tools for ABAP

  • 8/12/2019 Memory Inspector

    4/40 SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 4

    Motivation

    Different kinds of transactions

    Former Present Short-lived online SAP

    transactions, i.e. short-livedinternal modes.

    Long-lived online transactions

    (e.g. CRM: cic0, SEM-BCS:ucmon), i.e. long-lived internal

    modes. Memory leaks will not take

    effect as all memory is freed

    during deletion of an internalmode.

    Memory leaks will take effect by

    summing up as the internal

    mode will not be deleted.

    T1 T2 T1T3 T4 cic0

    A1 A2 A3 A4

    Internal modeLegend:

  • 8/12/2019 Memory Inspector

    5/40 SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 5

    Content

    Motivation

    Memory Objects

    Memory Problems

    New Memory Tools for ABAP

  • 8/12/2019 Memory Inspector

    6/40 SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 6

    Memory Objects

    Kind of Objects

    Named objects

    Declared with statement: DATA

    Manner-of-speaking: data object, variable

    Accessible by

    Value semantics

    Anonymous objects

    Instances of classes

    Created by the statement: CREATE OBJECT OO manner-of-speaking: object

    Instances of data types

    Created by the statement: CREATE DATA

    SAP manner-of-speaking: anonymous data object

    Accessible only via references

    Reference semantics

  • 8/12/2019 Memory Inspector

    7/40 SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 7

    Memory Objects

    Dynamic memory objects

    Internal tables

    Named objects

    Value semantic with Copy on write , i.e. table sharing with reference

    counting.

    The table body is in fact the dynamic memory object.

    Debugger: Access also via n{t}, where n is the id of the internal table.

  • 8/12/2019 Memory Inspector

    8/40 SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 8

    Memory Objects

    Internal tables

    DATA: itab1 TYPE TABLE OF I,

    itab2 TYPE TABLE OF I.

    APPEND 10 TO itab1.

    APPEND 20 TO itab1.

    itab2 = itab1.

    APPEND 30 TO itab2.

    itab1itab1 7

    7: Table header

    Table body

    itab2

    10

  • 8/12/2019 Memory Inspector

    9/40 SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 9

    Memory Objects

    Internal tables

    DATA: itab1 TYPE TABLE OF I,

    itab2 TYPE TABLE OF I.

    APPEND 10 TO itab1.

    APPEND 20 TO itab1.

    itab2 = itab1.

    APPEND 30 TO itab2.

    itab1 7 itab2

    7: Table header

    Table body10

    20

  • 8/12/2019 Memory Inspector

    10/40 SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 10

    Memory Objects

    Internal tables

    DATA: itab1 TYPE TABLE OF I,

    itab2 TYPE TABLE OF I.

    APPEND 10 TO itab1.

    APPEND 20 TO itab1.

    itab2 = itab1.

    APPEND 30 TO itab2.

    itab2itab1 7

    7: Table header

    Table body10

    20

    itab2 8

    8: Table header

  • 8/12/2019 Memory Inspector

    11/40 SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 11

    Memory Objects

    Internal tables

    DATA: itab1 TYPE TABLE OF I,

    itab2 TYPE TABLE OF I.

    APPEND 10 TO itab1.

    APPEND 20 TO itab1.

    itab2 = itab1.

    APPEND 30 TO itab2.

    itab2itab1 7

    7: Table header

    Table body10

    20

    itab2 8

    8: Table header

    Table body10

    20

    O

  • 8/12/2019 Memory Inspector

    12/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 12

    Memory Objects

    Internal tables

    DATA: itab1 TYPE TABLE OF I,

    itab2 TYPE TABLE OF I.

    APPEND 10 TO itab1.

    APPEND 20 TO itab1.

    itab2 = itab1.

    APPEND 30 TO itab2.

    itab1 7 itab2itab2 8

    8: Table header7: Table header

    Table body10

    20

    Table body10

    20

    Table body10

    20

    30

    M Obj t

  • 8/12/2019 Memory Inspector

    13/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 13

    Memory Objects

    Dynamic memory objects

    Internal tables

    Named objects

    Value semantic with Copy on write , i.e. table sharing with reference

    counting.

    The table body is in fact the dynamic memory object.

    Debugger: Access also via n{t}, where n is the id of the internal table.

    Strings

    Named objects

    Value semantics with Copy on write , i.e. string sharing with reference

    counting.

    Debugger: Access also via n{s}, where n is the string id.

    M Obj t

  • 8/12/2019 Memory Inspector

    14/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 14

    Memory Objects

    Strings

    str1 0 str2 0str1 2

    2: Stringheader

    Hallo

    DATA: str1 TYPE STRING,

    str2 TYPE STRING.

    str1 = Hallo.

    str2 = str1.

    str1 = Hugo.

    M Obj t

  • 8/12/2019 Memory Inspector

    15/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 15

    Memory Objects

    Strings

    str1 0 str2 0str1 2

    2: Stringheader

    Hallo

    str2 2DATA: str1 TYPE STRING,

    str2 TYPE STRING.

    str1 = Hallo.

    str2 = str1.

    str1 = Hugo.

    Memory Objects

  • 8/12/2019 Memory Inspector

    16/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 16

    Memory Objects

    Strings

    str1 0 str2 0str1 2

    2: Stringheader

    Hallo

    str2 2

    3: Stringheader

    Hugo

    DATA: str1 TYPE STRING,

    str2 TYPE STRING.

    str1 = Hallo.

    str2 = str1.

    str1 = Hugo.

    Memory Objects

  • 8/12/2019 Memory Inspector

    17/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 17

    Memory Objects

    Strings

    str1 2str1 3 str2 0

    2: Stringheader

    Hallo

    str2 2DATA: str1 TYPE STRING,

    str2 TYPE STRING.

    str1 = Hallo.

    str2 = str1.

    str1 = Hugo. 3: Stringheader

    Hugo

    Memory Objects

  • 8/12/2019 Memory Inspector

    18/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 18

    Memory Objects

    Dynamic memory objects

    Internal tables

    Named objects

    Value semantic with Copy on write , i.e. table sharing with reference counting.

    The table body is in fact the dynamic memory object.

    Debugger: Access also v ia n{t}, where n is the id of the internal table.

    Strings

    Named objects

    Value semantics with Copy on write , i.e. string sharing with reference counting.

    Debugger: Access also via n{s}, where n is the string id.

    Objects

    Anonymous objects

    Reference semantics

    No reference counting

    Debugger: Access via n{o}, where n is the object id.

    Anonymous data objects

    Anonymous objects

    Reference semantics

    No reference counting

    Debugger: Access via n{r}, where n is the anonymous data id.

    Memory Objects

  • 8/12/2019 Memory Inspector

    19/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 19

    Memory Objects

    Anonymous data objects

    DATA: ref1 TYPE REF TO I,

    ref2 TYPE REF TO I.

    CREATE DATA ref1.

    ref1->* = 10.

    ref2 = ref1.

    ref2->* = 20.

    ref1 0 ref2 0

    1{r}: 0

    ref1 1

    Memory Objects

  • 8/12/2019 Memory Inspector

    20/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 20

    Memory Objects

    Anonymous data objects

    DATA: ref1 TYPE REF TO I,

    ref2 TYPE REF TO I.

    CREATE DATA ref1.

    ref1->* = 10.

    ref2 = ref1.

    ref2->* = 20.

    1{r}: 01{r}: 10

    ref1 0 ref2 0ref1 1

    Memory Objects

  • 8/12/2019 Memory Inspector

    21/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 21

    Memory Objects

    Anonymous data objects

    DATA: ref1 TYPE REF TO I,

    ref2 TYPE REF TO I.

    CREATE DATA ref1.

    ref1->* = 10.

    ref2 = ref1.

    ref2->* = 20.

    ref1 0 ref2 0

    1{r}: 10

    ref1 1 ref2 1

    Memory Objects

  • 8/12/2019 Memory Inspector

    22/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 22

    Memory Objects

    Anonymous data objects

    DATA: ref1 TYPE REF TO I,

    ref2 TYPE REF TO I.

    CREATE DATA ref1.

    ref1->* = 10.

    ref2 = ref1.

    ref2->* = 20.

    1{r}: 101{r}: 20

    ref1 0 ref2 0ref1 1 ref2 1

    Memory Objects

  • 8/12/2019 Memory Inspector

    23/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 23

    Memory Objects

    Dynamic memory objects growth and shrinkage is controlled by

    the programmer

    Internal tables (table bodies)

    Growth: Appending or inserting a new line

    Shrinkage: FREE / CLEAR / REFRESH Strings

    Growth: Creating or modifying

    Shrinkage: FREE / CLEAR / REFRESH and some delete operations

    Objects Growth: Creating a new object

    Shrinkage: Clearing all references to an object. The garbage collector

    deletes the object.

    Anonymous data objects Growth: Creating a new anonymous data object

    Shrinkage: Clearing all references to a object. The garbage collector

    deletes the anonymous data object.

    Content

  • 8/12/2019 Memory Inspector

    24/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 24

    C

    Introduction

    Memory Objects

    Memory Problems

    New Memory Tools for ABAP

    Memory Problems

  • 8/12/2019 Memory Inspector

    25/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 25

    y

    Memory leaks

    Former Present Unintended growth of internal

    tables.

    Unintended long-lived internal

    tables.

    Objects that are

    pseudo-garbage, i.e. an

    application still holds

    references to objects that are

    no longer needed.

    Anonymous data objects that

    are pseudo-garbage.

    Unintended growth of internal

    tables.

    Unintended long-lived internal

    tables.

    Unintended growth of strings.

    Unintended long-lived strings.

    Memory Problems

  • 8/12/2019 Memory Inspector

    26/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 26

    y

    Example:

    cic0 + F4-help

    cic0

    A1 A2 A3 A4

    CREATE DATA dataref.

    APPEND dataref TO reftab.

    reftab Datref->*

    CREATE DATA dataref.APPEND dataref TO reftab.

    Datref->*

    CREATE DATA dataref.

    APPEND dataref TO reftab.

    Datref->*

    CREATE DATA dataref.

    APPEND dataref TO reftab.

    Datref->*

    Content

  • 8/12/2019 Memory Inspector

    27/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 27

    Introduction

    Memory Objects

    Memory Problems

    New Memory Tools for ABAP

    New Memory Tools for ABAP

  • 8/12/2019 Memory Inspector

    28/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 28

    Dynamic memory objects sizes

    Bound memory Minimum of memory that wil l be freed, if the dynamic memory object is deleted.

    Referenced memory

    Maximum of memory that may be freed, if the dynamic memory object is deleted.

    bound memory

  • 8/12/2019 Memory Inspector

    29/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 29

    Examples:s : {Anonymous objects} Bytes size of an object or an anonymous data object

    su : {Named objects} Bytes used size of a table body (internal table) or astring

    sa : {Named objects} Bytes allocated size of a table body (internal table) ora string

    obj3 str1

    obj4 str2

    obj5

    obj1 obj2

    ?Boundallocated Boundused Referencedallocated Referencedused

    s(obj1) s(obj1) s(obj1)+

    s(obj2)

    s(obj1)+

    s(obj2)

    s(obj4) s(obj4) s(obj4)+

    sa(str2)

    s(obj4)+

    su(str2)

    Boundallocated Boundused Referencedallocated Referencedused

    s(obj1) s(obj1) s(obj1)+

    s(obj2)

    s(obj1)+

    s(obj2)

    Rule: The size of a string or a table body is added to its fathers

    size if and only if the reference count is one.

    s(obj3)+

    sa(str1)

    s(obj3)+

    su(str1)

    s(obj3)+

    sa(str1)

    s(obj3)+

    su(str1)

    Boundallocated Boundused Referencedallocated Referencedused

    s(obj1) s(obj1) s(obj1)+

    s(obj2)

    s(obj1)+

    s(obj2)

    New Memory Tools for ABAP

  • 8/12/2019 Memory Inspector

    30/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 30

    TopN-Consumer-Lists (Debugger)

    Finding classes and datatypes with high memory

    consumption.

    Aggregation of objects

    List of instances

    Aggregation of anonymous data objects

    List of instances

    Finding objects with high

    memory consumption:

    Internal tables

    Strings

    Objects

    Anonymous data objects

    Table bodies (internal Tables)

    Strings

    Objects

    Anonymous data objects

    New Memory Tools for ABAP

  • 8/12/2019 Memory Inspector

    31/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 31

    The type is set during creation.

    Example: DATA obj_ref TYPE REF TO some_class.

    CREATE OBJECT obj_ref.

    This is the type.

    This is the type.

    Anonymous data objects can be categorized by their type (= data

    type) The type is set during creation.

    Example: DATA data_ref TYPE REF TO some_type.

    CREATE DATA data_ref.

    A lot of small-sized objects can sum up to a high memoryconsumption.

    A lot of small-sized objects can sum up to a high memory

    consumption.

    Objects can be categorized by their type (= class)

    New Memory Tools for ABAP

  • 8/12/2019 Memory Inspector

    32/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 32

    TopN-Consumer-Lists (Debugger)

    Finding classes and data

    types with high memory

    consumption.

    Aggregation of objects

    List of instances

    Aggregation of anonymous data objects

    List of instances

    Finding objects with high

    memory consumption:

    Internal tables

    Strings

    Objects

    Anonymous data objects

    Table bodies (internal Tables)

    Strings

    Objects

    Anonymous data objects

    Internal tables, strings, objects and

    anonymous data objects form a

    directed graph. Finding strongly

    connected components (SCC) ofthis graph.

    Strongly connected components (SCCs)

    List of nodes

    Strongly connected components (SCC)

  • 8/12/2019 Memory Inspector

    33/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 33

    Root set

    A strongly connected component of a directed graph is a subsetS of the graph such that for any nodes A and B of S exists alwaysa path from A to B and from B to A, and S is not a subset of anylarger such set.

    Strongly connected components (SCC)

  • 8/12/2019 Memory Inspector

    34/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 34

    Root set

    A strongly connected component of a directed graph is a subsetS of the graph such that for any nodes A and B of S exists alwaysa path from A to B and from B to A, and S is not a subset of anylarger such set.

    Strongly connected components (SCC)

  • 8/12/2019 Memory Inspector

    35/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 35

    To understand the memory consumption of an application it is necessary

    to know the SCCs as they can be treated as one node of the graph.

    That a SCC can be deleted by the garbage collector, it is suff icient toclear all references to the SCC.

    Root set

    Finding the path from the root set to some node, it is important to know

    the SCCs and the references to them.

    Strongly connected components (SCC)

  • 8/12/2019 Memory Inspector

    36/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 36

    To understand the memory consumption of an application it is necessary

    to know the SCCs as they can be treated as one node of the graph.

    That a SCC can be deleted by the garbage collector, it is suff icient toclear all references to the SCC.

    Finding the path from the root set to some node, it is important to know

    the SCCs and the references to them.

    Root set

    Strongly connected components (SCC)

  • 8/12/2019 Memory Inspector

    37/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 37

    To understand the memory consumption of an application it is necessary

    to know the SCCs as they can be treated as one node of the graph.

    That a SCC can be deleted by the garbage collector, it is suff icient toclear all references to the SCC.

    Finding the path from the root set to some node, it is important to know

    the SCCs and the references to them.

    Root set

    New Memory Tools for ABAP

  • 8/12/2019 Memory Inspector

    38/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 38

    Find References (Debugger)

    Finding references to table bodies

    (internal tables), str ings, objects

    and anonymous data objects

    keeping them alive.

    Finding references to table bodies

    (internal tables), str ings, objects

    and anonymous data objects

    keeping them alive.

    Table bodies (internal tables),strings, objects and anonymous

    data objects form a directed graph.

    Finding strongly connected

    components (SCC) of this graph.

    Objects

    Anonymous data objects Strongly connected components (SCCs)

    Table bodies (internal tables)

    Strings

    New Memory Tools for ABAP

  • 8/12/2019 Memory Inspector

    39/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 39

    Example:

    cic0 + F4-help

    cic0

    A1 A2 A3 A4

    CREATE DATA dataref.

    APPEND dataref TO reftab.

    reftab Datref->*

    t0 t1t1-t0

    New Memory Tools for ABAP

  • 8/12/2019 Memory Inspector

    40/40

    SAP AG 2003, Memory Inspector, Mathias Hanbuch, Dr. Christian Stork / 40

    Creating memory snapshots

    From debugger

    Via method call CL_ABAP_MEMORY_UTILITIES=>WRITE_MEMORY_CONSUMPTION_FILE( ).

    OK-code /HMUSA

    Analyzing and Comparing memory snapshots From debugger

    Starting transaction S_MEMORY_INSPECTOR

    Via transaction code S_MEMORY_INSPECTOR

    Comparison transaction S_MEMORY_INSPECTOR Different Views

    Sorted by kind of objects

    TopN-Consumer-lists

    Strongly connected components (SCCs)

    Comparing two memory snapshots

    Newly loaded programs, classes or interfaces

    Growth and shrinkage of table bodies (internal tables), strings, number of objectsor number of anonymous data objects

    Memory snapshots can be analyzed in other systems